18
18
use Ajax \semantic \html \modules \HtmlDropdown ;
19
19
use Ajax \semantic \html \modules \checkbox \HtmlCheckbox ;
20
20
use Ubiquity \cache \CacheManager ;
21
+ use Ubiquity \config \Configuration ;
21
22
use Ubiquity \controllers \Controller ;
22
23
use Ubiquity \controllers \Router ;
23
24
use Ubiquity \controllers \Startup ;
50
51
use Ubiquity \controllers \crud \viewers \ModelViewer ;
51
52
use Ubiquity \controllers \semantic \InsertJqueryTrait ;
52
53
use Ubiquity \controllers \semantic \MessagesTrait ;
54
+ use Ubiquity \core \Framework ;
53
55
use Ubiquity \domains \DDDManager ;
54
56
use Ubiquity \log \LoggerParams ;
55
57
use Ubiquity \orm \DAO ;
@@ -130,22 +132,61 @@ class UbiquityMyAdminBaseController extends Controller implements HasModelViewer
130
132
131
133
protected string $ nonce ;
132
134
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
+
133
176
protected $ styles = [
134
177
'inverted ' => [
135
178
'bgColor ' => '#303030 ' ,
136
- 'aceBgColor ' => '#fff ' ,
137
179
'inverted ' => true ,
138
180
'tdDefinition ' => '#fff ' ,
139
181
'selectedRow ' => 'black '
140
182
],
141
183
'' => [
142
184
'bgColor ' => '#fbfbee ' ,
143
- 'aceBgColor ' => '#002B36 ' ,
144
- 'selectedRow ' => 'positive '
185
+ 'selectedRow ' => 'positive ' ,
145
186
]
146
187
];
147
188
148
- public const version = '2.4.16 ' ;
189
+ public const VERSION = '2.5.0 ' ;
149
190
150
191
public $ style ;
151
192
@@ -162,6 +203,14 @@ public function _getStyle($part) {
162
203
return $ this ->styles [$ this ->style ][$ part ] ?? '' ;
163
204
}
164
205
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
+
165
214
public static function _getConfigFile () {
166
215
$ defaultConfig = [
167
216
'devtools-path ' => 'Ubiquity ' ,
@@ -170,6 +219,7 @@ public static function _getConfigFile() {
170
219
'controllers ' ,
171
220
'models '
172
221
],
222
+ 'ace-theme ' =>'automatic ' ,
173
223
'first-use ' => true ,
174
224
'maintenance ' => [
175
225
'on ' => false ,
@@ -332,9 +382,7 @@ private function displayDomains() {
332
382
333
383
public function finalize () {
334
384
if (! URequest::isAjax ()) {
335
- $ data = [
336
- 'js ' => $ this ->initializeJs ()
337
- ];
385
+ $ data = [];
338
386
if (isset ($ this ->nonce )) {
339
387
$ data ['nonce ' ] = $ this ->nonce ;
340
388
}
@@ -368,67 +416,32 @@ protected function reloadConfig($originalConfig) {
368
416
protected function _checkModelsUpdates (&$ config , $ onMainPage ) {
369
417
$ models = CacheManager::modelsCacheUpdated ($ config );
370
418
if (\is_array ($ models ) && \count ($ models ) > 0 ) {
371
- $ this ->_smallUpdateMessageCache ($ onMainPage , 'models ' , 'sticky note inverted ' , 'Updated models files (<b> ' . count ($ models ) . '</b>) ' , '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>) ' , 'warning ' , $ onMainPage ? '_initCache/models ' : '_initCache/models/models ' , $ onMainPage ? '#messages ' : '#main-content ' );
372
420
}
373
421
}
374
422
375
423
protected function _checkRouterUpdates (&$ config , $ onMainPage ) {
376
424
$ caches = CacheManager::controllerCacheUpdated ($ config );
377
425
if (\is_array ($ caches ) && \count ($ caches ) > 0 ) {
378
426
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 ' );
380
428
}
381
429
}
382
430
}
383
431
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 ' );
390
435
}
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> ' . $ message . " " . $ bt , $ messageType . ' icon mini ' , null , null , '' );
396
- echo " </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 , [
399
440
'dataType ' => 'html ' ,
400
441
'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 ]]]);
432
445
}
433
446
434
447
public function index () {
@@ -439,6 +452,8 @@ public function index() {
439
452
$ config = Startup::getConfig ();
440
453
$ this ->_checkModelsUpdates ($ config , true );
441
454
$ this ->_checkRouterUpdates ($ config , true );
455
+ $ this ->_checkConfigUpdates (true );
456
+
442
457
if ($ this ->hasMaintenance ()) {
443
458
$ this ->_smallMaintenanceActive (true , MaintenanceMode::getActiveMaintenance ($ this ->config ["maintenance " ]));
444
459
}
@@ -453,8 +468,7 @@ public function index() {
453
468
$ this ->jquery ->trigger ('#bt-customize ' , 'click ' , true );
454
469
}
455
470
$ this ->jquery ->compile ($ this ->view );
456
- $ this ->loadView ($ this ->_getFiles ()
457
- ->getViewIndex ());
471
+ $ this ->loadView ($ this ->_getFiles ()->getViewIndex ());
458
472
}
459
473
460
474
public function _closeMessage ($ type ) {
@@ -510,6 +524,11 @@ public function _indexCustomizing() {
510
524
$ dd1 ->setOnRemove ($ dd2 ->jsAddItem ("removedText " , "removedText " ));
511
525
$ dd2 ->setOnAdd ("$('# " . $ dd1 ->getIdentifier () . " .item[data-value='+addedText+']').remove(); " );
512
526
$ 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
+
513
532
$ this ->jquery ->click ('#cancel-btn ' , '$("#dialog").html("");$("#admin-elements").show();$("#bt-customize").removeClass("active"); ' );
514
533
$ this ->jquery ->getOnClick ("#reset-conf-btn " , $ baseRoute . "/_resetConfigParams " , 'body ' , [
515
534
'hasLoader ' => 'internal '
@@ -547,6 +566,7 @@ public function _indexCustomizingSubmit() {
547
566
$ part2Str = URequest::post ('t-part2 ' , []);
548
567
$ this ->config ['part1 ' ] = explode (', ' , $ part1Str );
549
568
$ this ->config ['part2 ' ] = explode (', ' , $ part2Str );
569
+ $ this ->config ['ace-theme ' ]=URequest::post ('ace-theme ' ,'automatic ' );
550
570
$ ckTheme = URequest::filled ('ck-theme ' );
551
571
if ($ ckTheme ) {
552
572
$ this ->config ['style ' ] = 'inverted ' ;
@@ -613,7 +633,7 @@ public function models($hasHeader = true) {
613
633
]);
614
634
echo $ menu ;
615
635
}
616
-
636
+ $ this -> _checkConfigUpdates ( false );
617
637
$ this ->_modelDatabase ($ hasHeader , false , $ activeDb );
618
638
}
619
639
@@ -824,14 +844,58 @@ public function rest() {
824
844
825
845
public function config ($ hasHeader = true ) {
826
846
$ config = Startup::getConfig ();
827
- if ($ hasHeader === true )
847
+ if ($ hasHeader === true ) {
828
848
$ 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 );
835
899
$ this ->jquery ->renderView ($ this ->_getFiles ()
836
900
->getViewConfigIndex (), [
837
901
'inverted ' => $ this ->style
0 commit comments