Skip to content

Commit ed26bc9

Browse files
authored
Merge pull request #7 from phpMv/update-to-ubiquity-2.5.0
Update to ubiquity 2.5.0
2 parents 26edbae + 7373b0f commit ed26bc9

16 files changed

+528
-192
lines changed

src/Ubiquity/controllers/admin/UbiquityMyAdminBaseController.php

Lines changed: 128 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Ajax\semantic\html\modules\HtmlDropdown;
1919
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox;
2020
use Ubiquity\cache\CacheManager;
21+
use Ubiquity\config\Configuration;
2122
use Ubiquity\controllers\Controller;
2223
use Ubiquity\controllers\Router;
2324
use Ubiquity\controllers\Startup;
@@ -50,6 +51,7 @@
5051
use Ubiquity\controllers\crud\viewers\ModelViewer;
5152
use Ubiquity\controllers\semantic\InsertJqueryTrait;
5253
use Ubiquity\controllers\semantic\MessagesTrait;
54+
use Ubiquity\core\Framework;
5355
use Ubiquity\domains\DDDManager;
5456
use Ubiquity\log\LoggerParams;
5557
use Ubiquity\orm\DAO;
@@ -130,22 +132,61 @@ class UbiquityMyAdminBaseController extends Controller implements HasModelViewer
130132

131133
protected string $nonce;
132134

135+
private $ace_themes=[
136+
'automatic'=>'Automatic',
137+
'chrome' => 'Chrome',
138+
'clouds' => 'Clouds',
139+
'crimson_editor' => 'Crimson Editor',
140+
'dawn' => 'Dawn',
141+
'dreamweaver' => 'Dreamweaver',
142+
'eclipse' => 'Eclipse',
143+
'github' => 'GitHub',
144+
'iplastic' => 'IPlastic',
145+
'katzenmilch' => 'KatzenMilch',
146+
'kuroir' => 'Kuroir',
147+
'solarized_light' => 'Solarized Light',
148+
'sqlserver' => 'SQL Server',
149+
'textmate' => 'TextMate',
150+
'tomorrow' => 'Tomorrow',
151+
'xcode' => 'XCode',
152+
'ambiance' => 'Ambiance',
153+
'chaos' => 'Chaos',
154+
'clouds_midnight' => 'Clouds Midnight',
155+
'cobalt' => 'Cobalt',
156+
'dracula' => 'Dracula',
157+
'gob' => 'Greeon on Black',
158+
'gruvbox' => 'Gruvbox',
159+
'idle_fingers' => 'idle Fingers',
160+
'kr_theme' => 'krTheme',
161+
'merbivore' => 'Merbivore',
162+
'merbivore_soft' => 'Merbivore Soft',
163+
'mono_industrial' => 'Mono Industrial',
164+
'monokai' => 'Monokai',
165+
'pastel_on_dark' => 'Pastel on Dark',
166+
'solarized_dark' => 'Solarized Dark',
167+
'terminal' => 'Terminal',
168+
'tomorrow_night' => 'Tomorrow Night',
169+
'tomorrow_night_blue' => 'Tomorrow Night Blue',
170+
'tomorrow_night_bright' => 'Tomorrow Night Bright',
171+
'tomorrow_night_eighties' => 'Tomorrow Night 80s',
172+
'twilight' => 'Twilight',
173+
'vibrant_ink' => 'Vibrant Ink'
174+
];
175+
133176
protected $styles = [
134177
'inverted' => [
135178
'bgColor' => '#303030',
136-
'aceBgColor' => '#fff',
137179
'inverted' => true,
138180
'tdDefinition' => '#fff',
139181
'selectedRow' => 'black'
140182
],
141183
'' => [
142184
'bgColor' => '#fbfbee',
143-
'aceBgColor' => '#002B36',
144-
'selectedRow' => 'positive'
185+
'selectedRow' => 'positive',
145186
]
146187
];
147188

148-
public const version = '2.4.16';
189+
public const VERSION = '2.5.0';
149190

150191
public $style;
151192

@@ -162,6 +203,14 @@ public function _getStyle($part) {
162203
return $this->styles[$this->style][$part] ?? '';
163204
}
164205

206+
public function _getAceTheme(){
207+
$theme=$this->config['ace-theme']??'automatic';
208+
if($theme=='automatic'){
209+
$theme=($this->style=='inverted')?'tomorrow_night':'github';
210+
}
211+
return $theme;
212+
}
213+
165214
public static function _getConfigFile() {
166215
$defaultConfig = [
167216
'devtools-path' => 'Ubiquity',
@@ -170,6 +219,7 @@ public static function _getConfigFile() {
170219
'controllers',
171220
'models'
172221
],
222+
'ace-theme'=>'automatic',
173223
'first-use' => true,
174224
'maintenance' => [
175225
'on' => false,
@@ -332,9 +382,7 @@ private function displayDomains() {
332382

333383
public function finalize() {
334384
if (! URequest::isAjax()) {
335-
$data = [
336-
'js' => $this->initializeJs()
337-
];
385+
$data = [];
338386
if (isset($this->nonce)) {
339387
$data['nonce'] = $this->nonce;
340388
}
@@ -368,67 +416,32 @@ protected function reloadConfig($originalConfig) {
368416
protected function _checkModelsUpdates(&$config, $onMainPage) {
369417
$models = CacheManager::modelsCacheUpdated($config);
370418
if (\is_array($models) && \count($models) > 0) {
371-
$this->_smallUpdateMessageCache($onMainPage, 'models', 'sticky note inverted', 'Updated models files (<b>' . count($models) . '</b>)&nbsp;', 'inverted', $onMainPage ? '_initCache/models' : '_initCache/models/models', $onMainPage ? '#models-refresh' : '#main-content');
419+
$this->_smallUpdateMessageCache($onMainPage, 'models', 'sticky note inverted', 'Updated models files (<b>' . count($models) . '</b>)&nbsp;', 'warning', $onMainPage ? '_initCache/models' : '_initCache/models/models', $onMainPage ? '#messages' : '#main-content');
372420
}
373421
}
374422

375423
protected function _checkRouterUpdates(&$config, $onMainPage) {
376424
$caches = CacheManager::controllerCacheUpdated($config);
377425
if (\is_array($caches) && \count($caches) > 0) {
378426
if (! $this->hasMaintenance()) {
379-
$this->_smallUpdateMessageCache($onMainPage, 'router', 'car', 'Updated controller files ', '', $onMainPage ? '_initCache/controllers' : '_initCacheRouter', $onMainPage ? '#router-refresh' : '#divRoutes');
427+
$this->_smallUpdateMessageCache($onMainPage, 'router', 'car', 'Updated controller files ', 'warning', $onMainPage ? '_initCache/controllers' : '_initCacheRouter', $onMainPage ? '#messages' : '#divRoutes');
380428
}
381429
}
382430
}
383431

384-
protected function _smallUpdateMessageCache($onMainPage, $type, $icon, $message, $messageType, $url, $target) {
385-
$js = [];
386-
if (! $onMainPage) {
387-
$js = [
388-
'jsCallback' => '$("#' . $type . '-refresh").html("");'
389-
];
432+
protected function _checkConfigUpdates($onMainPage){
433+
if(Configuration::isConfigUpdated()){
434+
$this->_smallUpdateMessageCache($onMainPage, 'config', 'settings', 'Updated configuration files ', 'warning', $onMainPage ? '_initCache/config' : '_initCache/config/config', $onMainPage ? '#messages' : '#main-content');
390435
}
391-
$bt = $this->jquery->semantic()->htmlButton("bt-mini-init-{$type}-cache", null, 'orange mini ' . $this->style);
392-
$bt->setProperty('title', "Re-init {$type} cache");
393-
$bt->asIcon('refresh');
394-
echo "<div class='ui container' id='{$type}-refresh' style='display:inline;'>";
395-
echo $this->_showSimpleMessage('<i class="ui icon ' . $icon . '"></i>&nbsp;' . $message . "&nbsp;" . $bt, $messageType . ' icon mini', null, null, '');
396-
echo "&nbsp;</div>";
397-
$this->jquery->getOnClick("#bt-mini-init-{$type}-cache", $this->_getFiles()
398-
->getAdminBaseRoute() . '/' . $url, $target, [
436+
}
437+
438+
protected function _smallUpdateMessageCache($onMainPage, $type, $icon, $message, $messageType, $url, $target) {
439+
$js=$this->jquery->getDeferred($this->_getFiles()->getAdminBaseRoute() . '/' . $url, $target, [
399440
'dataType' => 'html',
400441
'attr' => '',
401-
'hasLoader' => 'internal'
402-
] + $js);
403-
}
404-
405-
protected function initializeJs() {
406-
$js = 'var setAceEditor=function(elementId,readOnly,mode,maxLines){
407-
mode=mode || "sql";readOnly=readOnly || false;maxLines=maxLines || 100;
408-
var editor = ace.edit(elementId);
409-
editor.setTheme("ace/theme/solarized_dark");
410-
editor.getSession().setMode({path:"ace/mode/"+mode, inline:true});
411-
editor.setOptions({
412-
maxLines: maxLines,
413-
minLines: 2,
414-
showInvisibles: true,
415-
showGutter: !readOnly,
416-
showPrintMargin: false,
417-
readOnly: readOnly,
418-
showLineNumbers: !readOnly,
419-
highlightActiveLine: !readOnly,
420-
highlightGutterLine: !readOnly
421-
});
422-
var input = $("#"+elementId +" + input");
423-
if(input.length){
424-
input.val(editor.getSession().getValue());
425-
console.log(input.val());
426-
editor.getSession().on("change", function () {
427-
input.val(editor.getSession().getValue());
428-
});
429-
}
430-
};';
431-
return $this->jquery->inline($js);
442+
'hasLoader' => false
443+
] );
444+
$this->jquery->semantic()->toast('body',['preserveHTML'=>true,'title'=>"<i class='ui $icon icon' ></i> Cache updated",'message'=>$message,'class'=>$this->style.' '.$messageType,'actions'=>[['text'=>"Re-init {$type} cache",'class'=>$this->style.' orange','icon'=>'refresh','click'=>$js]]]);
432445
}
433446

434447
public function index() {
@@ -439,6 +452,8 @@ public function index() {
439452
$config = Startup::getConfig();
440453
$this->_checkModelsUpdates($config, true);
441454
$this->_checkRouterUpdates($config, true);
455+
$this->_checkConfigUpdates(true);
456+
442457
if ($this->hasMaintenance()) {
443458
$this->_smallMaintenanceActive(true, MaintenanceMode::getActiveMaintenance($this->config["maintenance"]));
444459
}
@@ -453,8 +468,7 @@ public function index() {
453468
$this->jquery->trigger('#bt-customize', 'click', true);
454469
}
455470
$this->jquery->compile($this->view);
456-
$this->loadView($this->_getFiles()
457-
->getViewIndex());
471+
$this->loadView($this->_getFiles()->getViewIndex());
458472
}
459473

460474
public function _closeMessage($type) {
@@ -510,6 +524,11 @@ public function _indexCustomizing() {
510524
$dd1->setOnRemove($dd2->jsAddItem("removedText", "removedText"));
511525
$dd2->setOnAdd("$('#" . $dd1->getIdentifier() . " .item[data-value='+addedText+']').remove();");
512526
$dd2->setOnRemove($dd1->jsAddItem("removedText", "removedText"));
527+
528+
$dd3=$this->jquery->semantic()->htmlDropdown('dd-ace',$this->config['ace-theme']??'automatic',$this->ace_themes);
529+
$dd3->asSearch('ace-theme');
530+
$dd3->addClass('fluid '.$this->style);
531+
513532
$this->jquery->click('#cancel-btn', '$("#dialog").html("");$("#admin-elements").show();$("#bt-customize").removeClass("active");');
514533
$this->jquery->getOnClick("#reset-conf-btn", $baseRoute . "/_resetConfigParams", 'body', [
515534
'hasLoader' => 'internal'
@@ -547,6 +566,7 @@ public function _indexCustomizingSubmit() {
547566
$part2Str = URequest::post('t-part2', []);
548567
$this->config['part1'] = explode(',', $part1Str);
549568
$this->config['part2'] = explode(',', $part2Str);
569+
$this->config['ace-theme']=URequest::post('ace-theme','automatic');
550570
$ckTheme = URequest::filled('ck-theme');
551571
if ($ckTheme) {
552572
$this->config['style'] = 'inverted';
@@ -613,7 +633,7 @@ public function models($hasHeader = true) {
613633
]);
614634
echo $menu;
615635
}
616-
636+
$this->_checkConfigUpdates(false);
617637
$this->_modelDatabase($hasHeader, false, $activeDb);
618638
}
619639

@@ -824,14 +844,58 @@ public function rest() {
824844

825845
public function config($hasHeader = true) {
826846
$config = Startup::getConfig();
827-
if ($hasHeader === true)
847+
if ($hasHeader === true) {
828848
$this->getHeader("config");
829-
$this->_getAdminViewer()->getConfigDataElement($config);
830-
$this->jquery->getOnClick("#edit-config-btn", $this->_getFiles()
831-
->getAdminBaseRoute() . "/_formConfig/ajax", "#action-response", [
832-
"hasLoader" => "internal",
833-
"jsCallback" => '$("#config-div").hide();'
834-
]);
849+
}
850+
$style=$this->style;
851+
$appEnv=Framework::getEnv();
852+
$configFiles=Configuration::getTheoreticalLoadedConfigFiles($appEnv);
853+
$data=['app.env'=>$appEnv,'env.files'=>Configuration::getEnvFiles()];
854+
$fields=\array_keys($data);
855+
$deEnvVars=$this->jquery->semantic()->dataElement('deEnv',$data);
856+
$deEnvVars->setFields($fields);
857+
$deEnvVars->setCaptions(['App.env <span class="ui label '.$style.'">APP_ENV</span>','Env. files']);
858+
$deEnvVars->fieldAsLabel('app.env','dot circle',['class'=>"ui green label $style",'jsCallback'=>function($lbl){
859+
$lbl->addPopup('Active','APP_ENV value');
860+
}]);
861+
$deEnvVars->setEdition(true);
862+
$callback=function($files) use($configFiles,$style){
863+
$result=[];
864+
foreach ($files as $file){
865+
$bn=basename($file);
866+
$type='config';
867+
if(\rtrim($bn,'.php')===$bn){
868+
$type='env';
869+
}
870+
$rpFile=\realpath($file);
871+
$loadedFile=\array_search($rpFile,$configFiles)!==false;
872+
$bt=new HtmlButton($bn,$bn,"$style mini $type-file ".($loadedFile?'teal':''));
873+
$bt->setProperty('data-ajax',rtrim($bn,'.php'));
874+
$bt->addIcon('file');
875+
$bt->addPopup($loadedFile?'Loaded file':'File',$rpFile);
876+
$result[]=$bt;
877+
}
878+
return $result;
879+
};
880+
$deEnvVars->setValueFunction('env.files',$callback);
881+
$data=['config.files'=>Configuration::getConfigFiles()];
882+
$fields=\array_keys($data);
883+
$deConfFiles=$this->jquery->semantic()->dataElement('deConf',$data);
884+
$deConfFiles->setFields($fields);
885+
$deConfFiles->setCaptions(['Config. files']);
886+
$deConfFiles->setValueFunction('config.files',$callback);
887+
888+
$this->_setStyle($deEnvVars);
889+
$this->_setStyle($deConfFiles);
890+
$baseRoute=$this->_getFiles()->getAdminBaseRoute();
891+
$this->jquery->getOnClick('#bt-init-cache',$baseRoute.'/_initCache/config/config','#main-content',['hasLoader'=>'internal']);
892+
$this->jquery->getOnClick("#see-active-conf", $baseRoute."/configRead", "#action-response",['jsCallback'=>'$("#config-div").hide();','hasLoader'=>'internal']);
893+
894+
$this->jquery->getOnClick(".config-file", $baseRoute."/_formConfig", "#action-response",['attr'=>'data-ajax','jsCallback'=>'$("#config-div").hide();','hasLoader'=>'internal']);
895+
$this->jquery->getOnClick(".env-file", $baseRoute."/_formEnv", "#action-response",['attr'=>'data-ajax','jsCallback'=>'$("#config-div").hide();','hasLoader'=>'internal']);
896+
$this->jquery->getOnClick("#add-env-btn", $baseRoute."/_formEnv", "#action-response",['attr'=>'','jsCallback'=>'$("#config-div").hide();','hasLoader'=>'internal']);
897+
898+
$this->_checkConfigUpdates(false);
835899
$this->jquery->renderView($this->_getFiles()
836900
->getViewConfigIndex(), [
837901
'inverted' => $this->style

src/Ubiquity/controllers/admin/UbiquityMyAdminFiles.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,22 @@ public function getViewConfigIndex() {
6868
return $this->viewBase . "/config/index.html";
6969
}
7070

71+
public function getViewConfigRead() {
72+
return $this->viewBase . "/config/configRead.html";
73+
}
74+
7175
public function getViewConfigForm() {
7276
return $this->viewBase . "/config/form.html";
7377
}
7478

79+
public function getViewConfigFormPartial() {
80+
return $this->viewBase . "/config/formPartial.html";
81+
}
82+
83+
public function getViewEnvForm() {
84+
return $this->viewBase . "/config/formEnv.html";
85+
}
86+
7587
public function getViewFrmNewDbConnection() {
7688
return $this->viewBase . "/config/formNewDbConnection.html";
7789
}

0 commit comments

Comments
 (0)