Passed
Push — develop ( 92210f...e51e97 )
by Nikolay
05:11
created

AssetProvider::getVersionsHash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 0
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
declare(strict_types=1);
21
22
namespace MikoPBX\AdminCabinet\Providers;
23
24
use MikoPBX\AdminCabinet\Controllers\SessionController;
25
use MikoPBX\AdminCabinet\Plugins\AssetManager as Manager;
26
use MikoPBX\Common\Models\PbxExtensionModules;
27
use MikoPBX\Common\Models\PbxSettings;
28
use MikoPBX\Common\Providers\ManagedCacheProvider;
29
use MikoPBX\Common\Providers\PBXConfModulesProvider;
30
use MikoPBX\Common\Providers\SessionProvider;
31
use MikoPBX\Modules\Config\WebUIConfigInterface;
32
use Phalcon\Assets\Collection;
33
use Phalcon\Di\DiInterface;
34
use Phalcon\Di\ServiceProviderInterface;
35
use Phalcon\Mvc\Dispatcher;
36
use function MikoPBX\Common\Config\appPath;
37
38
/**
39
 * Prepares list of CSS and JS files according to called controller/action
40
 *
41
 * @package MikoPBX\AdminCabinet\Providers
42
 */
43
class AssetProvider implements ServiceProviderInterface
44
{
45
    public const SERVICE_NAME = 'assets';
46
47
    private Collection $headerCollectionJSForExtensions;
48
    private Collection $footerCollectionJSForExtensions;
49
    private Collection $headerCollectionJS;
50
    private Collection $headerCollectionCSS;
51
    private Collection $footerCollectionJS;
52
    private Collection $semanticCollectionCSS;
53
    private Collection $semanticCollectionJS;
54
    private Collection $footerCollectionACE;
55
    private Collection $footerCollectionLoc;
56
    private Collection $headerCollectionSentryJS;
57
    private string $jsCacheDir;
58
    private Manager $manager;
59
60
    /**
61
     * Registers assets service provider
62
     *
63
     * @param DiInterface $di The DI container.
64
     */
65
    public function register(DiInterface $di): void
66
    {
67
        $di->set(
68
            self::SERVICE_NAME,
69
            function () use ($di) {
70
71
                $session = $di->get(SessionProvider::SERVICE_NAME);
72
73
                $assets = new AssetProvider();
74
75
                // Module and PBX version caching for proper PBX operation when installing modules.
76
                $version = PBXConfModulesProvider::getVersionsHash();
77
                $assets->initializeClassVariables($version);
78
                $dispatcher = $di->get(DispatcherProvider::SERVICE_NAME);
79
                $controller = $dispatcher->getControllerName();
80
                $action = $dispatcher->getActionName();
81
82
                if ($action === null) {
83
                    $action = 'index';
84
                }
85
86
                $assets->makeSentryAssets();
87
                $assets->makeHeaderAssets($session, $dispatcher);
88
89
                // Generates Controllers assets
90
                $method_name = "make{$controller}Assets";
91
                if (method_exists($assets, $method_name)) {
92
                    $assets->$method_name($action);
93
                }
94
95
                $assets->makeFooterAssets();
96
                $assets->makeLocalizationAssets($di, $version);
97
98
                $assetsManager = $assets->manager;
99
100
                // Register additional assets from external enabled modules
101
                PBXConfModulesProvider::hookModulesMethod(WebUIConfigInterface::ON_AFTER_ASSETS_PREPARED, [$assetsManager]);
102
103
                return $assetsManager;
104
            }
105
        );
106
    }
107
108
    /**
109
     * Initialize class variables
110
     */
111
    public function initializeClassVariables(string $version)
112
    {
113
        $this->manager = new Manager();
0 ignored issues
show
Bug introduced by
The call to MikoPBX\AdminCabinet\Plu...tManager::__construct() has too few arguments starting with tagFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $this->manager = /** @scrutinizer ignore-call */ new Manager();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
114
        $this->manager->setVersion($version);
115
116
        $this->jsCacheDir = appPath('sites/admin-cabinet/assets/js/cache');
117
118
        $this->headerCollectionJSForExtensions = $this->manager->collection('headerJS');
119
        $this->headerCollectionJSForExtensions->setPrefix('assets/');
120
121
        $this->footerCollectionJSForExtensions = $this->manager->collection('footerJS');
122
        $this->footerCollectionJSForExtensions->setPrefix('assets/');
123
        $this->headerCollectionJS = $this->manager->collection('headerPBXJS');
124
        $this->headerCollectionJS->setPrefix('assets/');
125
        $this->headerCollectionCSS = $this->manager->collection('headerCSS');
126
        $this->headerCollectionCSS->setPrefix('assets/');
127
        $this->footerCollectionJS = $this->manager->collection('footerPBXJS');
128
        $this->footerCollectionJS->setPrefix('assets/');
129
        $this->headerCollectionSentryJS = $this->manager->collection('headerSentryJS');
130
        $this->semanticCollectionCSS = $this->manager->collection('SemanticUICSS');
131
        $this->semanticCollectionCSS->setPrefix('assets/');
132
        $this->semanticCollectionJS = $this->manager->collection('SemanticUIJS');
133
        $this->semanticCollectionJS->setPrefix('assets/');
134
        $this->footerCollectionACE = $this->manager->collection('footerACE');
135
        $this->footerCollectionACE->setPrefix('assets/');
136
        $this->footerCollectionLoc = $this->manager->collection('footerLoc');
137
        $this->footerCollectionLoc->setPrefix('assets/');
138
    }
139
140
    /**
141
     * Makes assets for the Sentry error logger
142
     *
143
     */
144
    private function makeSentryAssets(): void
145
    {
146
        if (file_exists('/etc/sendmetrics')) {
147
            $this->headerCollectionSentryJS->addjs(
148
                'assets/js/vendor/sentry/bundle.min.js',
149
                true
150
            );
151
            $this->headerCollectionSentryJS->addJs(
152
                "assets/js/pbx/main/sentry-error-logger.js",
153
                true
154
            );
155
        }
156
    }
157
158
    /**
159
     * Makes assets for all controllers. Base set of scripts and styles
160
     *
161
     * @param $session
162
     * @param Dispatcher $dispatcher
163
     */
164
    private function makeHeaderAssets($session, Dispatcher $dispatcher): void
165
    {
166
        $this->semanticCollectionCSS
167
            ->addCss('css/vendor/semantic/grid.min.css', true)
168
            ->addCss('css/vendor/semantic/divider.min.css', true)
169
            ->addCss('css/vendor/semantic/container.min.css', true)
170
            ->addCss('css/vendor/semantic/header.min.css', true)
171
            ->addCss('css/vendor/semantic/button.min.css', true)
172
            ->addCss('css/vendor/semantic/form.min.css', true)
173
            ->addCss('css/vendor/semantic/icon.min.css', true)
174
            ->addCss('css/vendor/semantic/flag.min.css', true)
175
            ->addCss('css/vendor/semantic/image.min.css', true)
176
            ->addCss('css/vendor/semantic/input.min.css', true)
177
            ->addCss('css/vendor/semantic/message.min.css', true)
178
            ->addCss('css/vendor/semantic/segment.min.css', true)
179
            ->addCss('css/vendor/semantic/site.min.css', true)
180
            ->addCss('css/vendor/semantic/reset.min.css', true)
181
            ->addCss('css/vendor/semantic/transition.min.css', true)
182
            ->addCss('css/vendor/semantic/dropdown.min.css', true)
183
            ->addCss('css/vendor/semantic/checkbox.min.css', true);
184
185
        $this->headerCollectionJS
186
            ->addJs('js/pbx/main/header.js', true)
187
            ->addJs('js/vendor/jquery.min.js', true);
188
189
        $this->footerCollectionJS
190
            ->addJs('js/pbx/main/language-select.js', true);
191
192
        $this->semanticCollectionJS
193
            ->addJs('js/vendor/semantic/form.min.js', true)
194
            ->addJs('js/vendor/semantic/api.min.js', true)
195
            ->addJs('js/vendor/semantic/site.min.js', true)
196
            ->addJs('js/vendor/semantic/popup.min.js', true)
197
            ->addJs('js/vendor/semantic/dropdown.min.js', true)
198
            ->addJs('js/vendor/semantic/transition.min.js', true)
199
            ->addJs('js/vendor/semantic/checkbox.min.js', true);
200
201
        // If the user is logged in, let's generate the required CSS caches.
202
        if ($session->has(SessionController::SESSION_ID)) {
203
            $this->semanticCollectionCSS
204
                ->addCss('css/vendor/semantic/menu.min.css', true)
205
                ->addCss('css/vendor/semantic/sidebar.min.css', true)
206
                ->addCss('css/vendor/semantic/table.min.css', true)
207
                ->addCss('css/vendor/semantic/loader.min.css', true)
208
                ->addCss('css/vendor/semantic/label.min.css', true)
209
                ->addCss('css/vendor/semantic/dimmer.min.css', true)
210
                ->addCss('css/vendor/semantic/accordion.min.css', true)
211
                ->addCss('css/vendor/semantic/placeholder.min.css', true)
212
                ->addCss('css/vendor/semantic/item.min.css', true)
213
                ->addCss('css/vendor/semantic/tab.min.css', true)
214
                ->addCss('css/vendor/semantic/popup.min.css', true)
215
                ->addCss('css/vendor/semantic/toast.min.css', true);
216
217
            $this->semanticCollectionJS
218
                ->addJs('js/vendor/semantic/accordion.min.js', true)
219
                ->addJs('js/vendor/semantic/dimmer.min.js', true)
220
                ->addJs('js/vendor/semantic/sidebar.min.js', true)
221
                ->addJs('js/vendor/semantic/toast.min.js', true)
222
                ->addJs('js/vendor/semantic/tab.min.js', true);
223
224
            $this->footerCollectionJS
225
                ->addJs('js/pbx/main/config.js', true)
226
                ->addJs('js/pbx/main/pbxapi.js', true)
227
                ->addJs('js/pbx/main/connection-check-worker.js', true)
228
                ->addJs('js/pbx/main/semantic-localization.js', true)
229
                ->addJs('js/pbx/main/responsive-ui.js', true)
230
                ->addJs('js/pbx/Advices/advices-worker.js', true)
231
                ->addJs('js/pbx/Security/check-passwords.js', true)
232
                ->addJs('js/pbx/SendMetrics/send-metrics-index.js', true)
233
                ->addJs('js/pbx/main/ssh-console.js', true)
234
                ->addJs('js/pbx/main/delete-something.js', true)
235
                ->addJs('js/pbx/main/user-message.js', true)
236
                ->addJs('js/pbx/Extensions/extensions.js', true)
237
                ->addJs('js/pbx/main/sidebar-menu-show-active.js', true)
238
                ->addJs('js/pbx/TopMenuSearch/top-menu-search.js', true)
239
                ->addJs('js/pbx/WikiLinksReplacement/wiki-links-replacement-worker.js', true);
240
241
            // We can disable module status toggle from module controller, using the showModuleStatusToggle variable
242
            $isExternalModulePage = str_starts_with($dispatcher->getNamespaceName(), '\\Module');
243
244
            if ($isExternalModulePage) {
245
                $currentControllerObject = $dispatcher->getActiveController();
246
                $showModuleStatusToggle = property_exists($currentControllerObject, 'showModuleStatusToggle')
247
                    ? $currentControllerObject->showModuleStatusToggle
248
                    : true;
249
250
                if ($showModuleStatusToggle) {
251
                    $this->footerCollectionJS->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-status.js', true);
252
                }
253
            }
254
        }
255
    }
256
257
    /**
258
     * Makes footer assets
259
     */
260
    private function makeFooterAssets(): void
261
    {
262
        $this->headerCollectionCSS
263
            ->addCss('css/custom.css', true);
264
265
        $this->footerCollectionJS->addJs(
266
            'js/pbx/main/footer.js',
267
            true
268
        );
269
    }
270
271
    /**
272
     * Makes Language cache for browser JS scripts
273
     *
274
     * @param DiInterface $di The DI container.
275
     * @param string $version
276
     */
277
    private function makeLocalizationAssets(DiInterface $di, string $version): void
278
    {
279
        $language = $di->getShared('language');
280
        $fileName = "{$this->jsCacheDir}/localization-{$language}-{$version}.min.js";
281
        if (!file_exists($fileName)) {
282
            $arrStr = [];
283
            foreach ($di->getShared('messages') as $key => $value) {
284
                $arrStr[$key] = str_replace(
285
                    "'",
286
                    "\\'",
287
                    str_replace(["\n", '  '], '', $value)
288
                );
289
            }
290
            $scriptArray = json_encode($arrStr);
291
            file_put_contents($fileName, "globalTranslate = {$scriptArray}");
292
        }
293
294
        $langJSFile = "js/cache/localization-{$language}-{$version}.min.js";
295
        $this->footerCollectionLoc->addJs($langJSFile, true);
296
    }
297
298
    /**
299
     * Makes assets for the CallQueues controller
300
     *
301
     * @param string $action
302
     */
303
    private function makeCallQueuesAssets(string $action)
304
    {
305
        if ($action === 'index') {
306
            $this->headerCollectionCSS
307
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
308
            $this->footerCollectionJS
309
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
310
                ->addJs('js/pbx/CallQueues/callqueues-index.js', true);
311
        } elseif ($action === 'modify') {
312
            $this->footerCollectionJS
313
                ->addJs('js/vendor/jquery.debounce-1.0.5.js', true)
314
                ->addJs('js/vendor/jquery.tablednd.js', true)
315
                ->addJs('js/pbx/main/form.js', true)
316
                ->addJs('js/pbx/CallQueues/callqueue-modify.js', true)
317
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
318
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
319
        }
320
    }
321
322
    /**
323
     * Makes assets for the ConferenceRooms controller
324
     *
325
     * @param string $action
326
     */
327
    private function makeConferenceRoomsAssets(string $action)
328
    {
329
        if ($action === 'index') {
330
            $this->footerCollectionJS
331
                ->addJs('js/pbx/ConferenceRooms/conference-rooms-index.js', true);
332
        } elseif ($action === 'modify') {
333
            $this->footerCollectionJS
334
                ->addJs('js/pbx/main/form.js', true)
335
                ->addJs('js/pbx/ConferenceRooms/conference-room-modify.js', true);
336
        }
337
    }
338
339
    /**
340
     * Makes assets for the SystemDiagnostic controller
341
     *
342
     * @param string $action
343
     */
344
    private function makeSystemDiagnosticAssets(string $action): void
345
    {
346
        if ($action === 'index') {
347
            $this->footerCollectionJS
348
                ->addJs('js/vendor/semantic/popup.min.js', true)
349
                ->addJs('js/vendor/semantic/dropdown.min.js', true)
350
                ->addJs('js/pbx/main/form.js', true)
351
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index.js', true)
352
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-showlogs-worker.js', true)
353
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-showlogs.js', true)
354
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-sysinfo.js', true)
355
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-logscapture-worker.js', true)
356
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-logcapture.js', true);
357
            $this->footerCollectionACE
358
                ->addJs('js/vendor/ace/ace.js', true)
359
                ->addJs('js/vendor/ace/mode-julia.js', true);
360
        }
361
    }
362
363
    /**
364
     * Makes assets for the SoundFiles controller
365
     *
366
     * @param string $action
367
     */
368
    private function makeSoundFilesAssets(string $action): void
369
    {
370
        if ($action === 'index') {
371
            $this->headerCollectionCSS
372
                ->addCss('css/vendor/range/range.css')
373
                ->addCss(
374
                    'css/vendor/datatable/dataTables.semanticui.css',
375
                    true
376
                );
377
            $this->footerCollectionJS->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
378
                ->addJs('js/vendor/range/range.min.js', true)
379
                ->addJs('js/vendor/jquery.address.min.js', true)
380
                ->addJs('js/pbx/SoundFiles/sound-files-index-player.js', true)
381
                ->addJs('js/pbx/SoundFiles/sound-files-index.js', true);
382
        } elseif ($action === 'modify') {
383
            $this->headerCollectionCSS->addCss('css/vendor/range/range.css');
384
385
            $this->headerCollectionJS
386
                ->addJs(
387
                    'js/vendor/webrtc/MediaStreamRecorder.min.js',
388
                    true
389
                )
390
                ->addJs('js/vendor/webrtc/adapter-latest.min.js', true);
391
392
            $this->footerCollectionJS
393
                ->addJs('js/vendor/range/range.min.js', true)
394
                ->addJs('js/pbx/main/form.js', true)
395
                ->addJs('js/vendor/resumable.js', true)
396
                ->addJs('js/pbx/SoundFiles/sound-file-modify-player.js', true)
397
                ->addJs('js/pbx/SoundFiles/sound-file-modify-upload-worker.js', true)
398
                ->addJs('js/pbx/SoundFiles/sound-file-modify-webkit-recorder.js', true)
399
                ->addJs('js/pbx/SoundFiles/sound-file-modify.js', true);
400
        }
401
    }
402
403
    /**
404
     * Makes assets for the TimeSettings controller
405
     *
406
     * @param string $action
407
     */
408
    private function makeTimeSettingsAssets(string $action): void
409
    {
410
        if ($action === 'modify') {
411
            $this->footerCollectionJS
412
                ->addJs('js/pbx/main/form.js', true)
413
                ->addJs('js/vendor/moment/moment-with-locales.min.js', true)
414
                ->addJs('js/vendor/moment-timezone/moment-timezone-with-data.min.js', true)
415
                ->addJs('js/pbx/TimeSettings/time-settings-worker.js', true)
416
                ->addJs('js/pbx/TimeSettings/time-settings-modify.js', true);
417
        }
418
    }
419
420
    /**
421
     * Makes assets for the Update controller
422
     *
423
     * @param string $action
424
     */
425
    private function makeUpdateAssets(string $action): void
426
    {
427
        if ($action === 'index') {
428
            $this->footerCollectionJS
429
                ->addJs('js/pbx/main/version-compare.js', true)
430
                ->addJs('js/pbx/main/form.js', true)
431
                ->addJs('js/vendor/resumable.js', true)
432
                ->addJs('js/vendor/showdown/showdown.min.js', true)
433
                ->addJs('js/pbx/Update/update-status-worker.js', true)
434
                ->addJs('js/pbx/Update/update-merging-worker.js', true)
435
                ->addJs('js/pbx/Update/update-index.js', true);
436
            $this->semanticCollectionCSS
437
                ->addCss('css/vendor/semantic/progress.min.css', true)
438
                ->addCss('css/vendor/semantic/modal.min.css', true);
439
440
            $this->semanticCollectionJS
441
                ->addJs('js/vendor/semantic/progress.min.js', true)
442
                ->addJs('js/vendor/semantic/modal.min.js', true);
443
        }
444
    }
445
446
    /**
447
     * Makes assets for the Session controller
448
     *
449
     * @param string $action
450
     */
451
    private function makeSessionAssets(string $action): void
452
    {
453
        if ($action === 'index') {
454
            $this->footerCollectionJS
455
                ->addJs('js/pbx/main/form.js', true)
456
                ->addJs('js/pbx/Session/login-form.js', true);
457
        } elseif ($action === 'end') {
458
            $this->footerCollectionJS
459
                ->addJs('js/pbx/Session/session-end.js', true);
460
        }
461
    }
462
463
    /**
464
     * Makes assets for the Restart controller
465
     *
466
     * @param string $action
467
     */
468
    private function makeRestartAssets(string $action): void
469
    {
470
        if ($action === 'index') {
471
            $this->footerCollectionJS
472
                ->addJs('js/pbx/Restart/restart-index.js', true)
473
                ->addJs('js/pbx/Restart/current-calls-worker.js',true);
474
        }
475
    }
476
477
    /**
478
     * Makes assets for the Providers controller
479
     *
480
     * @param string $action
481
     */
482
    private function makeProvidersAssets(string $action): void
483
    {
484
        if ($action === 'index') {
485
            $this->semanticCollectionCSS
486
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true)
487
                ->addCss('css/vendor/semantic/modal.min.css', true);
488
489
            $this->semanticCollectionJS
490
                ->addJs('js/vendor/semantic/modal.min.js', true);
491
            $this->footerCollectionJS
492
                ->addJs('js/pbx/main/debugger-info.js', true)
493
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
494
                ->addJs('js/pbx/Providers/providers-index.js', true)
495
                ->addJs('js/pbx/Providers/providers-status-worker.js', true);
496
        } elseif ($action === 'modifysip' || $action === 'modifyiax') {
497
            $this->footerCollectionJS
498
                ->addJs('js/pbx/main/form.js', true)
499
                ->addJs('js/pbx/main/debugger-info.js', true)
500
                ->addJs('js/vendor/clipboard/clipboard.js', true)
501
                ->addJs('js/pbx/Providers/provider-modify-status-worker.js', true)
502
                ->addJs('js/pbx/Providers/provider-modify.js', true);
503
        }
504
    }
505
506
    /**
507
     *  Makes assets for the PbxExtensionModules controller
508
     *
509
     * @param string $action
510
     */
511
    private function makePbxExtensionModulesAssets(string $action): void
512
    {
513
        if ($action === 'index') {
514
            $this->semanticCollectionJS->addJs('js/vendor/semantic/modal.min.js', true);
515
            $this->footerCollectionJS
516
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
517
                ->addJs('js/vendor/resumable.js', true)
518
                ->addJs('js/vendor/jquery.address.min.js', true)
519
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-upgrade-status-worker.js', true)
520
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-install-status-worker.js', true)
521
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-merging-status-worker.js', true)
522
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-status.js', true)
523
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-modules-index.js', true)
524
                ->addJs('js/vendor/semantic/progress.min.js', true)
525
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-ping-lic-worker.js', true)
526
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-add-new.js', true)
527
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
528
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
529
                ->addJs('js/vendor/inputmask/init.js', true)
530
                ->addJs('js/pbx/main/form.js', true)
531
                ->addJs('js/pbx/Licensing/licensing-modify.js', true);
532
533
            $this->semanticCollectionCSS
534
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true)
535
                ->addCss('css/vendor/semantic/modal.min.css', true)
536
                ->addCss('css/vendor/semantic/progress.min.css', true);
537
        } elseif ($action === 'modify') {
538
            $this->footerCollectionJS
539
                ->addJs('js/pbx/main/form.js', true)
540
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-modify.js', true);
541
        }
542
    }
543
544
    /**
545
     * Makes assets for the OutOffWorkTime controller
546
     *
547
     * @param string $action
548
     */
549
    private function makeOutOffWorkTimeAssets(string $action): void
550
    {
551
        if ($action === 'index') {
552
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
553
            $this->footerCollectionJS
554
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
555
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-times-index.js', true);
556
        } elseif ($action === 'modify') {
557
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/calendar.min.css', true);
558
            $this->semanticCollectionJS->addJs('js/vendor/semantic/calendar.min.js', true);
559
            $this->footerCollectionJS
560
                ->addJs('js/pbx/main/form.js', true)
561
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-time-modify.js', true)
562
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
563
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
564
        }
565
    }
566
567
    /**
568
     * Makes assets for the OutboundRoutes controller
569
     *
570
     * @param string $action
571
     */
572
    private function makeOutboundRoutesAssets(string $action): void
573
    {
574
        if ($action === 'index') {
575
            $this->footerCollectionJS
576
                ->addJs('js/vendor/jquery.tablednd.min.js', true)
577
                ->addJs('js/pbx/OutboundRoutes/outbound-routes-index.js', true);
578
        } elseif ($action === 'modify') {
579
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
580
                ->addJs('js/pbx/OutboundRoutes/outbound-route-modify.js', true);
581
        }
582
    }
583
584
    /**
585
     * Makes assets for the Network controller
586
     *
587
     * @param string $action
588
     */
589
    private function makeNetworkAssets(string $action): void
590
    {
591
        if ($action === 'modify') {
592
            $this->footerCollectionJS
593
                //->addJs('js/vendor/inputmask/inputmask.js', true)
594
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
595
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
596
                ->addJs('js/vendor/inputmask/init.js', true)
597
                ->addJs('js/pbx/main/form.js', true)
598
                ->addJs('js/pbx/Network/network-modify.js', true);
599
        }
600
    }
601
602
    /**
603
     * Makes assets for the MailSettings controller
604
     *
605
     * @param string $action
606
     */
607
    private function makeMailSettingsAssets(string $action): void
608
    {
609
        if ($action === 'modify') {
610
            $this->footerCollectionJS
611
                ->addJs('js/pbx/main/form.js', true)
612
                ->addJs('js/pbx/MailSettings/mail-settings-modify.js', true);
613
        }
614
    }
615
616
617
    /**
618
     * Makes assets for the IvrMenu controller
619
     *
620
     * @param string $action
621
     */
622
    private function makeIvrMenuAssets(string $action): void
623
    {
624
        if ($action === 'index') {
625
            $this->headerCollectionCSS
626
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
627
            $this->footerCollectionJS
628
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
629
                ->addJs('js/pbx/IvrMenu/ivrmenu-index.js', true);
630
        } elseif ($action === 'modify') {
631
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
632
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
633
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
634
                ->addJs('js/pbx/IvrMenu/ivrmenu-modify.js', true);
635
        }
636
    }
637
638
    /**
639
     * Makes assets for the IncomingRoutes controller
640
     *
641
     * @param string $action
642
     */
643
    private function makeIncomingRoutesAssets(string $action): void
644
    {
645
        if ($action === 'index') {
646
            $this->footerCollectionJS->addJs('js/vendor/jquery.tablednd.js', true)
647
                ->addJs('js/pbx/main/form.js', true)
648
                ->addJs('js/pbx/IncomingRoutes/incoming-route-index.js', true);
649
        } elseif ($action === 'modify') {
650
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
651
                ->addJs('js/pbx/IncomingRoutes/incoming-route-modify.js', true);
652
        }
653
    }
654
655
    /**
656
     * Makes assets for the GeneralSettings controller
657
     *
658
     * @param string $action
659
     */
660
    private function makeGeneralSettingsAssets(string $action): void
661
    {
662
        if ($action === 'modify') {
663
            $this->semanticCollectionCSS
664
                ->addCss('css/vendor/semantic/slider.min.css', true)
665
                ->addCss('css/vendor/semantic/progress.min.css', true);
666
            $this->semanticCollectionJS
667
                ->addJs('js/vendor/semantic/slider.min.js', true)
668
                ->addJs('js/vendor/semantic/progress.min.js', true);
669
670
            $this->footerCollectionJS
671
                ->addJs('js/vendor/jquery.address.min.js', true)
672
                ->addJs('js/vendor/jquery.tablednd.js', true)
673
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
674
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
675
                ->addJs('js/pbx/main/form.js', true)
676
                ->addJs('js/pbx/main/password-score.js', true)
677
                ->addJs(
678
                    'js/pbx/GeneralSettings/general-settings-modify.js',
679
                    true
680
                );
681
        }
682
    }
683
684
    /**
685
     * Makes assets for the Firewall controller
686
     *
687
     * @param string $action
688
     */
689
    private function makeFirewallAssets(string $action): void
690
    {
691
        if ($action === 'index') {
692
            $this->footerCollectionJS
693
                ->addJs('js/pbx/Firewall/firewall-index.js', true);
694
        } elseif ($action === 'modify') {
695
            $this->footerCollectionJS
696
                ->addJs('js/pbx/main/form.js', true)
697
                ->addJs('js/pbx/Firewall/firewall-modify.js', true);
698
        }
699
    }
700
701
    /**
702
     * Makes assets for the Fail2Ban controller
703
     *
704
     * @param string $action
705
     */
706
    private function makeFail2BanAssets(string $action): void
707
    {
708
        if ($action === 'index') {
709
            $this->footerCollectionJS
710
                ->addJs('js/pbx/main/form.js', true)
711
                ->addJs('js/pbx/Fail2Ban/fail-to-ban-index.js', true);
712
        }
713
    }
714
715
    /**
716
     * Makes assets for the Extensions controller
717
     *
718
     * @param string $action
719
     */
720
    private function makeExtensionsAssets(string $action): void
721
    {
722
        if ($action === 'index') {
723
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
724
725
            $this->footerCollectionJS
726
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
727
                //->addJs('js/vendor/inputmask/inputmask.js', true)
728
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
729
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
730
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
731
                ->addJs('js/vendor/inputmask/init.js', true)
732
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
733
                ->addJs('js/pbx/Extensions/extensions-index.js', true)
734
                ->addJs('js/pbx/Extensions/extensions-index-status-worker.js', true)
735
                ->addJs('js/pbx/main/debugger-info.js', true)
736
                ->addJs('js/vendor/clipboard/clipboard.js', true);
737
        } elseif ($action === 'modify') {
738
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/card.min.css', true);
739
            $this->footerCollectionJS
740
                //->addJs('js/vendor/inputmask/inputmask.js', true)
741
                ->addJs('js/vendor/inputmask/jquery.inputmask.min.js', true)
742
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
743
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
744
                ->addJs('js/vendor/inputmask/init.js', true)
745
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
746
                ->addJs('js/pbx/main/form.js', true)
747
                ->addJs('js/pbx/main/debugger-info.js', true)
748
                ->addJs('js/pbx/Extensions/extension-modify-avatar.js', true)
749
                ->addJs('js/pbx/Extensions/extension-modify-status-worker.js', true)
750
                ->addJs('js/pbx/Extensions/extension-modify.js', true);
751
        }
752
    }
753
754
    /**
755
     *  Makes assets for the DialplanApplications controller
756
     *
757
     * @param string $action
758
     */
759
    private function makeDialplanApplicationsAssets(string $action): void
760
    {
761
        if ($action === 'index') {
762
            $this->headerCollectionCSS
763
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
764
            $this->footerCollectionJS
765
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
766
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-index.js', true);
767
        } elseif ($action === 'modify') {
768
            $this->footerCollectionACE
769
                ->addJs('js/vendor/ace/ace.js', true)
770
                ->addJs('js/vendor/ace/mode-php.js', true)
771
                ->addJs('js/vendor/ace/mode-julia.js', true);
772
            $this->footerCollectionJS
773
                ->addJs('js/pbx/main/form.js', true)
774
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-modify.js', true);
775
        }
776
    }
777
778
    /**
779
     * Makes assets for the CustomFiles controller
780
     *
781
     * @param string $action
782
     */
783
    private function makeCustomFilesAssets(string $action): void
784
    {
785
        if ($action === 'index') {
786
            $this->headerCollectionCSS
787
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
788
            $this->footerCollectionJS
789
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
790
                ->addJs('js/pbx/CustomFiles/custom-files-index.js', true);
791
        } elseif ($action === 'modify') {
792
            $this->footerCollectionJS
793
                ->addJs('js/pbx/main/form.js', true)
794
                ->addJs('js/pbx/CustomFiles/custom-files-modify.js', true);
795
            $this->footerCollectionACE
796
                ->addJs('js/vendor/ace/ace.js', true)
797
                ->addJs('js/vendor/ace/mode-julia.js', true);
798
        }
799
    }
800
801
    /**
802
     * Makes assets for the CallDetailRecords controller
803
     *
804
     * @param string $action
805
     */
806
    private function makeCallDetailRecordsAssets(string $action): void
807
    {
808
        if ($action === 'index') {
809
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
810
811
            $this->semanticCollectionCSS
812
                ->addCss('css/vendor/range/range.min.css', true)
813
                ->addCss('css/vendor/datatable/scroller.dataTables.min.css', true)
814
                ->addCss('css/vendor/datepicker/daterangepicker.css', true)
815
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
816
817
            $this->semanticCollectionJS
818
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
819
                ->addJs('js/vendor/datatable/dataTables.scroller.min.js', true)
820
                ->addJs('js/vendor/datatable/scroller.semanticui.js', true)
821
                //->addJs('js/vendor/datatable/dataTables.pageResize.min.js', TRUE)
822
                ->addJs('js/vendor/range/range.min.js', true)
823
                ->addJS('js/vendor/moment/moment.min.js', true)
824
                ->addJS('js/vendor/datepicker/daterangepicker.js', true);
825
826
            $this->footerCollectionJS
827
                ->addJs(
828
                    'js/pbx/CallDetailRecords/call-detail-records-player.js',
829
                    true
830
                )
831
                ->addJs(
832
                    'js/pbx/CallDetailRecords/call-detail-records-index.js',
833
                    true
834
                );
835
        }
836
    }
837
838
    /**
839
     * Makes assets for the AsteriskManagers controller
840
     *
841
     * @param string $action
842
     */
843
    private function makeAsteriskManagersAssets(string $action): void
844
    {
845
        if ($action === 'index') {
846
            $this->footerCollectionJS->addJs('js/pbx/AsteriskManagers/managers-index.js', true);
847
        } elseif ($action === 'modify') {
848
            $this->footerCollectionJS
849
                ->addJs('js/pbx/main/form.js', true)
850
                ->addJs('js/pbx/AsteriskManagers/manager-modify.js', true);
851
        }
852
    }
853
854
}