1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\System; |
4
|
|
|
|
5
|
|
|
use Epesi\Core\System\Integration\Modules\ModuleView; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Epesi\Core\System\Integration\Modules\ModuleManager; |
8
|
|
|
use Epesi\Core\Layout\Seeds\ActionBar; |
9
|
|
|
use atk4\ui\jsFunction; |
10
|
|
|
use atk4\ui\jsExpression; |
11
|
|
|
|
12
|
|
|
class ModuleAdministration extends ModuleView |
13
|
|
|
{ |
14
|
|
|
protected $label = 'Module Administration'; |
15
|
|
|
|
16
|
|
|
public static function access() |
17
|
|
|
{ |
18
|
|
|
return Auth::user()->can('modify system settings'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function body() |
22
|
|
|
{ |
23
|
|
|
$this->addControlButtons(); |
24
|
|
|
|
25
|
|
|
$this->addAccordion($this, $this->topLevelModules()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function topLevelModules() |
29
|
|
|
{ |
30
|
|
|
$modules = ModuleManager::getAll(); |
31
|
|
|
|
32
|
|
|
return $modules->filter(function ($subModuleClass) use ($modules) { |
33
|
|
|
return ! $modules->map(function($moduleClass){ |
34
|
|
|
return $moduleClass::namespace(); |
35
|
|
|
})->contains($subModuleClass::parentNamespace()); |
36
|
|
|
})->sort(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function addAccordion($container, $modules) |
40
|
|
|
{ |
41
|
|
|
$accordion = $container->add(['Accordion', 'type' => ['styled', 'fluid'], 'settings' => ['animateChildren' => false]])->setStyle(['max-width' => '800px', 'margin-left' => 'auto', 'margin-right' => 'auto']); |
42
|
|
|
|
43
|
|
|
foreach ($modules as $moduleClass) { |
44
|
|
|
$section = $accordion->addSection($moduleClass::label()); |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
$section->add(['Message', 'ui' => 'tiny message'])->template->appendHTML('Content', $this->formatModuleInfo($moduleClass)); |
48
|
|
|
|
49
|
|
|
if (ModuleManager::isInstalled($moduleClass)) { |
50
|
|
|
$label = ['Label', __('Installed'), 'green']; |
51
|
|
|
|
52
|
|
|
$this->addUninstallButton($section, $moduleClass); |
53
|
|
|
|
54
|
|
|
$this->addReinstallButton($section, $moduleClass); |
55
|
|
|
} |
56
|
|
|
else { |
57
|
|
|
$label = ['Label', __('Available'), 'yellow']; |
58
|
|
|
|
59
|
|
|
$this->addInstallButton($section, $moduleClass); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$section->add($label, 'title')->setStyle('float', 'right'); |
63
|
|
|
|
64
|
|
|
$submodules = ModuleManager::getAll()->filter(function ($subModuleClass) use ($moduleClass) { |
65
|
|
|
return $subModuleClass::isSubModuleOf($moduleClass); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
if ($submodules->isEmpty()) continue; |
69
|
|
|
|
70
|
|
|
$this->addAccordion($section, $submodules); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function formatModuleInfo($moduleClass) |
75
|
|
|
{ |
76
|
|
|
$moduleInfo = (array) ($moduleClass::info()?: __(' No details provided by author')); |
77
|
|
|
|
78
|
|
|
$ret = []; |
79
|
|
|
foreach ($moduleInfo as $label => $text) { |
80
|
|
|
$ret[] = (is_string($label)? "<strong>$label</strong>: ": '') . $text; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return implode('<br>', $ret); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function addInstallButton($container, $moduleClass) |
87
|
|
|
{ |
88
|
|
|
$installCallback = $this->add('jsCallback')->set(function() use ($moduleClass) { |
|
|
|
|
89
|
|
|
ob_start(); |
90
|
|
|
ModuleManager::install($moduleClass); |
91
|
|
|
|
92
|
|
|
return ob_get_clean(); |
93
|
|
|
}); |
94
|
|
|
|
95
|
|
|
$modal = $this->add(['Modal', 'title' => __('Module Installation')])->set(function($view) use ($installCallback) { |
|
|
|
|
96
|
|
|
$view->add('Header')->set('Module has following dependencies which will be installed'); |
97
|
|
|
|
98
|
|
|
$view->add(['Button', __('Install'), 'primary'])->on('click', [ |
99
|
|
|
$installCallback |
100
|
|
|
]); |
101
|
|
|
}); |
102
|
|
|
|
103
|
|
|
$container->add(['Button', __('Install'), 'class' => ['green']])->on('click', $modal->show()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function addUninstallButton($container, $moduleClass) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$container->add(['Button', __('Uninstall'), 'class' => ['red']]); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function addReinstallButton($container, $moduleClass) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
$container->add(['Button', __('Re-install')]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function addControlButtons() |
117
|
|
|
{ |
118
|
|
|
ActionBar::addButton('back')->link(url('view/system')); |
119
|
|
|
|
120
|
|
|
$this->addClearCacheButton(); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function addClearCacheButton() |
124
|
|
|
{ |
125
|
|
|
ActionBar::addButton(['icon' => 'refresh', 'label' => __('Clear Cache')])->callback(function($callback) { |
|
|
|
|
126
|
|
|
ModuleManager::clearCache(); |
127
|
|
|
|
128
|
|
|
return $this->notify(__('Cache cleared!')); |
129
|
|
|
}); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|