1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\HomePage; |
4
|
|
|
|
5
|
|
|
use Epesi\Core\System\Integration\Modules\ModuleView; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Epesi\Core\HomePage\Database\Models\HomePage; |
8
|
|
|
use Epesi\Core\Layout\Seeds\ActionBar; |
9
|
|
|
use Epesi\Core\System\Seeds\Form; |
10
|
|
|
use Spatie\Permission\Models\Role; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class HomePageSettings extends ModuleView |
13
|
|
|
{ |
14
|
|
|
protected $label = 'Home Page Administration'; |
15
|
|
|
|
16
|
|
|
protected $homepages; |
17
|
|
|
protected $grid; |
18
|
|
|
protected $form; |
19
|
|
|
|
20
|
|
|
public static function access() |
21
|
|
|
{ |
22
|
|
|
return Auth::user()->can('modify system settings'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function body() |
26
|
|
|
{ |
27
|
|
|
ActionBar::addButton('back')->link('view/system'); |
28
|
|
|
|
29
|
|
|
$this->grid = $this->add([ |
30
|
|
|
'CRUD', |
31
|
|
|
'itemCreate' => ActionBar::addButton('add'), |
32
|
|
|
'formCreate' => $this->getHomepageForm(), |
33
|
|
|
'formUpdate' => $this->getHomepageForm(), |
34
|
|
|
'notifyDefault' => ['jsNotify', 'content' => __('Data is saved!'), 'color' => 'green'], |
35
|
|
|
'canDelete' => false, //use custom delete routine |
36
|
|
|
'paginator' => false, |
37
|
|
|
'menu' => false |
38
|
|
|
]); |
39
|
|
|
|
40
|
|
|
$this->grid->setModel($this->getModel()); |
41
|
|
|
|
42
|
|
|
$availablePages = HomePageCommon::getAvailableHomePages(); |
43
|
|
|
|
44
|
|
|
$this->grid->addDecorator('path', ['Multiformat', function($row, $column) use ($availablePages) { |
|
|
|
|
45
|
|
|
return [['Template', $availablePages[$row[$column]]]]; |
46
|
|
|
}]); |
47
|
|
|
|
48
|
|
|
$this->grid->addDragHandler()->onReorder(function ($order) { |
|
|
|
|
49
|
|
|
$result = true; |
50
|
|
|
foreach ($this->getHomepages() as $homepage) { |
51
|
|
|
$homepage->priority = array_search($homepage->id, $order); |
52
|
|
|
|
53
|
|
|
$result &= $homepage->save(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $result? $this->notify(__('Homepages reordered!')): $this->notifyError(__('Error saving order!')); |
57
|
|
|
}); |
58
|
|
|
|
59
|
|
|
$this->grid->addAction(['icon' => 'red trash'], function ($jschain, $id) { |
|
|
|
|
60
|
|
|
HomePage::find($id)->delete(); |
61
|
|
|
|
62
|
|
|
return $jschain->closest('tr')->transition('fade left'); |
63
|
|
|
}, __('Are you sure?')); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getModel() |
67
|
|
|
{ |
68
|
|
|
$availablePages = HomePageCommon::getAvailableHomePages(); |
69
|
|
|
$availableRoles = Role::get()->pluck('name')->all(); |
70
|
|
|
|
71
|
|
|
$rows = []; |
72
|
|
|
foreach ($this->getHomepages() as $homepage) { |
73
|
|
|
$rows[] = [ |
74
|
|
|
'id' => $homepage->id, |
75
|
|
|
'path' => $homepage->path, |
76
|
|
|
'role' => $homepage->role |
77
|
|
|
]; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$model = new \atk4\data\Model(new \atk4\data\Persistence_Static($rows)); |
81
|
|
|
|
82
|
|
|
$model->hasField('path')->setDefaults(['caption' => __('Page'), 'values' => $availablePages]); |
83
|
|
|
$model->hasField('role')->setDefaults(['caption' => __('Role'), 'enum' => $availableRoles]); |
84
|
|
|
|
85
|
|
|
return $model; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getHomepages() |
89
|
|
|
{ |
90
|
|
|
return $this->homepages = $this->homepages?? HomePage::orderBy('priority')->get(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getHomepageForm() |
94
|
|
|
{ |
95
|
|
|
if (! $this->form) { |
96
|
|
|
$this->form = new Form(['buttonSave' => ['Button', __('Save'), 'primary']]); |
97
|
|
|
|
98
|
|
|
$this->form->addHook('submit', function($form) { |
99
|
|
|
$values = $form->getValues(); |
100
|
|
|
|
101
|
|
|
if ($id = $values['id']?? null) { |
102
|
|
|
HomePage::find($id)->update($values); |
103
|
|
|
|
104
|
|
|
return $this->grid->jsSaveUpdate(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
HomePage::create(array_merge($values, [ |
108
|
|
|
'priority' => HomePage::max('priority') + 1 |
109
|
|
|
])); |
110
|
|
|
|
111
|
|
|
return $this->grid->jsSaveCreate(); |
112
|
|
|
}); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $this->form; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths