Passed
Push — develop ( 64fe87...280fbb )
by Nikolay
04:11
created

AssetProvider::makeOutOffWorkTimeAssets()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 13
rs 9.9
cc 3
nc 3
nop 1
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2020 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 Phalcon\Assets\Collection;
25
use Phalcon\Assets\Manager;
26
use Phalcon\Di\DiInterface;
27
use Phalcon\Di\ServiceProviderInterface;
28
use MatthiasMullie\Minify;
29
30
use function MikoPBX\Common\Config\appPath;
31
32
class AssetProvider implements ServiceProviderInterface
33
{
34
    public const SERVICE_NAME = 'assets';
35
36
    private Collection $headerCollectionJSForExtensions;
37
    private Collection $footerCollectionJSForExtensions;
38
    private Collection $headerCollectionJS;
39
    private Collection $headerCollectionCSS;
40
    private Collection $footerCollectionJS;
41
    private Collection $semanticCollectionCSS;
42
    private Collection $semanticCollectionJS;
43
    private Collection $footerCollectionACE;
44
    private Collection $footerCollectionLoc;
45
    private Collection $headerCollectionSentryJS;
46
    private string $cssCacheDir;
47
    private string $jsCacheDir;
48
    private Manager $manager;
49
50
    /**
51
     * Registers assets service provider
52
     *
53
     * @param \Phalcon\Di\DiInterface $di
54
     */
55
    public function register(DiInterface $di): void
56
    {
57
        $di->set(
58
            self::SERVICE_NAME,
59
            function () use ($di) {
60
                $assets = new AssetProvider();
61
                $assets->initializeClassVariables();
62
                $dispatcher = $di->get('dispatcher');
63
                $session    = $di->get('session');
64
                $controller = $dispatcher->getControllerName();
65
                $action     = $dispatcher->getActionName();
66
                $moduleName = $dispatcher->getModuleName();
67
68
                if ($action === null) {
69
                    $action = 'index';
70
                }
71
                if ($session !== null && $session->has('versionHash')) {
72
                    $version = (string)$session->get('versionHash');
73
                } else {
74
                    $version = str_replace(PHP_EOL, '', file_get_contents('/etc/version'));
75
                }
76
77
                $assets->makeSentryAssets($version);
78
                $assets->makeHeaderAssets($session, $moduleName);
79
80
                // Generates Controllers assets
81
                $method_name = "make{$controller}Assets";
82
                if (method_exists($assets, $method_name)) {
83
                    $assets->$method_name($action);
84
                }
85
86
                $assets->makeFooterAssets();
87
                $assets->makeLocalizationAssets($di, $version);
88
                $assets->generateFilesAndLinks($controller, $action, $version);
89
90
                return $assets->manager;
91
            }
92
        );
93
    }
94
95
    /**
96
     * Initialize class variables
97
     */
98
    public function initializeClassVariables()
99
    {
100
        $this->manager = new Manager();
101
102
        $this->cssCacheDir = appPath('sites/admin-cabinet/assets/css/cache');
103
        $this->jsCacheDir  = appPath('sites/admin-cabinet/assets/js/cache');
104
105
        $this->headerCollectionJSForExtensions = $this->manager->collection('headerJS');
106
        $this->headerCollectionJSForExtensions->setPrefix('assets/');
107
        $this->footerCollectionJSForExtensions = $this->manager->collection('footerJS');
108
        $this->footerCollectionJSForExtensions->setPrefix('assets/');
109
        $this->headerCollectionJS = $this->manager->collection('headerPBXJS');
110
        $this->headerCollectionJS->setPrefix('assets/');
111
        $this->headerCollectionCSS = $this->manager->collection('headerCSS');
112
        $this->headerCollectionCSS->setPrefix('assets/');
113
        $this->footerCollectionJS = $this->manager->collection('footerPBXJS');
114
        $this->footerCollectionJS->setPrefix('assets/');
115
        $this->headerCollectionSentryJS = $this->manager->collection('headerSentryJS');
116
        $this->semanticCollectionCSS    = $this->manager->collection('SemanticUICSS');
117
        $this->semanticCollectionCSS->setPrefix('assets/');
118
        $this->semanticCollectionJS = $this->manager->collection('SemanticUIJS');
119
        $this->semanticCollectionJS->setPrefix('assets/');
120
        $this->footerCollectionACE = $this->manager->collection('footerACE');
121
        $this->footerCollectionACE->setPrefix('assets/');
122
        $this->footerCollectionLoc = $this->manager->collection('footerLoc');
123
        $this->footerCollectionLoc->setPrefix('assets/');
124
    }
125
126
    /**
127
     * Makes assets for the Sentry error logger
128
     *
129
     * @param string $version
130
     */
131
    private function makeSentryAssets(string $version): void
132
    {
133
        if (file_exists('/tmp/sendmetrics')) {
134
            $this->headerCollectionSentryJS->addjs(
135
                'assets/js/vendor/sentry/bundle.min.js',
136
                true
137
            );
138
            $this->headerCollectionSentryJS->addJs(
139
                "assets/js/pbx/main/sentry-error-logger.js?v={$version}",
140
                true
141
            );
142
        }
143
    }
144
145
    /**
146
     * Makes assets for all controllers. Base set of scripts and styles
147
     *
148
     * @param $session
149
     * @param $moduleName
150
     */
151
    private function makeHeaderAssets($session, $moduleName): void
152
    {
153
        $this->semanticCollectionCSS
154
            ->addCss('css/vendor/semantic/grid.min.css', true)
155
            ->addCss('css/vendor/semantic/divider.min.css', true)
156
            ->addCss('css/vendor/semantic/container.min.css', true)
157
            ->addCss('css/vendor/semantic/header.min.css', true)
158
            ->addCss('css/vendor/semantic/button.min.css', true)
159
            ->addCss('css/vendor/semantic/form.min.css', true)
160
            ->addCss('css/vendor/semantic/icon.min.css', true)
161
            ->addCss('css/vendor/semantic/flag.min.css', true)
162
            ->addCss('css/vendor/semantic/image.min.css', true)
163
            ->addCss('css/vendor/semantic/input.min.css', true)
164
            ->addCss('css/vendor/semantic/message.min.css', true)
165
            ->addCss('css/vendor/semantic/segment.min.css', true)
166
            ->addCss('css/vendor/semantic/site.min.css', true)
167
            ->addCss('css/vendor/semantic/reset.min.css', true)
168
            ->addCss('css/vendor/semantic/transition.min.css', true)
169
            ->addCss('css/vendor/semantic/dropdown.min.css', true)
170
            ->addCss('css/vendor/semantic/checkbox.min.css', true);
171
172
        $this->headerCollectionJS
173
            ->addJs('js/pbx/main/header.js', true)
174
            ->addJs('js/vendor/jquery.min.js', true);
175
176
        $this->footerCollectionJS
177
            ->addJs('js/pbx/main/language-select.js', true);
178
179
        $this->semanticCollectionJS
180
            ->addJs('js/vendor/semantic/form.min.js', true)
181
            ->addJs('js/vendor/semantic/api.min.js', true)
182
            ->addJs('js/vendor/semantic/site.min.js', true)
183
            ->addJs('js/vendor/semantic/popup.min.js', true)
184
            ->addJs('js/vendor/semantic/dropdown.min.js', true)
185
            ->addJs('js/vendor/semantic/transition.min.js', true)
186
            ->addJs('js/vendor/semantic/checkbox.min.js', true);
187
188
        // Если пользователь залогинился, сформируем необходимые CSS кеши
189
        if ($session && $session->has('auth')) {
190
            $this->semanticCollectionCSS
191
                ->addCss('css/vendor/semantic/menu.min.css', true)
192
                ->addCss('css/vendor/semantic/sidebar.min.css', true)
193
                ->addCss('css/vendor/semantic/table.min.css', true)
194
                ->addCss('css/vendor/semantic/loader.min.css', true)
195
                ->addCss('css/vendor/semantic/label.min.css', true)
196
                ->addCss('css/vendor/semantic/dimmer.min.css', true)
197
                ->addCss('css/vendor/semantic/accordion.min.css', true)
198
                ->addCss('css/vendor/semantic/placeholder.min.css', true)
199
                ->addCss('css/vendor/semantic/item.min.css', true)
200
                ->addCss('css/vendor/semantic/tab.min.css', true)
201
                ->addCss('css/vendor/semantic/popup.min.css', true)
202
                ->addCss('css/vendor/semantic/toast.min.css', true);
203
204
            $this->semanticCollectionJS
205
                ->addJs('js/vendor/semantic/accordion.min.js', true)
206
                ->addJs('js/vendor/semantic/dimmer.min.js', true)
207
                ->addJs('js/vendor/semantic/sidebar.min.js', true)
208
                ->addJs('js/vendor/semantic/toast.min.js', true)
209
                ->addJs('js/vendor/semantic/tab.min.js', true);
210
211
            $this->footerCollectionJS
212
                ->addJs(
213
                    'js/pbx/main/config.js',
214
                    true
215
                )
216
                ->addJs(
217
                    'js/pbx/main/pbxapi.js',
218
                    true
219
                )
220
                ->addJs(
221
                    'js/pbx/main/connection-check-worker.js',
222
                    true
223
                )
224
                ->addJs(
225
                    'js/pbx/main/semantic-localization.js',
226
                    true
227
                )
228
                ->addJs(
229
                    'js/pbx/Advices/advices-worker.js',
230
                    true
231
                )
232
                ->addJs(
233
                    'js/pbx/SendMetrics/send-metrics-index.js',
234
                    true
235
                )
236
                ->addJs(
237
                    'js/pbx/main/ssh-console.js',
238
                    true
239
                )
240
                ->addJs(
241
                    'js/pbx/main/delete-something.js',
242
                    true
243
                )
244
                ->addJs(
245
                    'js/pbx/main/user-message.js',
246
                    true
247
                )
248
                ->addJs(
249
                    'js/pbx/Extensions/extensions.js',
250
                    true
251
                )
252
                ->addJs(
253
                    'js/pbx/PbxExtensionModules/pbx-extension-menu-addition.js',
254
                    true
255
                )
256
                ->addJs(
257
                    'js/pbx/TopMenuSearch/top-menu-search.js',
258
                    true
259
                );
260
261
            if ($moduleName === 'PBXExtension') {
262
                $this->footerCollectionJS->addJs(
263
                    'js/pbx/PbxExtensionModules/pbx-extension-module-status.js',
264
                    true
265
                );
266
            }
267
        }
268
    }
269
270
    /**
271
     * Makes footer assets
272
     */
273
    private function makeFooterAssets(): void
274
    {
275
        $this->headerCollectionCSS
276
            ->addCss('css/custom.css', true);
277
278
        $this->footerCollectionJS->addJs(
279
            'js/pbx/main/footer.js',
280
            true
281
        );
282
    }
283
284
    /**
285
     * Makes Language cache for browser JS scripts
286
     *
287
     * @param \Phalcon\Di\DiInterface $di
288
     * @param string                  $version
289
     */
290
    private function makeLocalizationAssets(DiInterface $di, string $version): void
291
    {
292
        $language   = $di->getShared('language');
293
        $langJSFile = "js/cache/localization-{$language}-{$version}.min.js";
294
        if ( ! file_exists($langJSFile)) {
295
            $arrStr = [];
296
            foreach ($di->getShared('messages') as $key => $value) {
297
                $arrStr[$key] = str_replace(
298
                    "'",
299
                    "\\'",
300
                    str_replace(["\n", '  '], '', $value)
301
                );
302
            }
303
304
            $fileName    = "{$this->jsCacheDir}/localization-{$language}-{$version}.min.js";
305
            $scriptArray = json_encode($arrStr);
306
            file_put_contents($fileName, "globalTranslate = {$scriptArray}");
307
        }
308
309
310
        $this->footerCollectionLoc->addJs($langJSFile, true);
311
    }
312
313
    /**
314
     * Makes caches and versioned links for scripts and styles
315
     *
316
     * @param        $controller
317
     * @param string $action
318
     * @param string $version
319
     */
320
    private function generateFilesAndLinks($controller, string $action, string $version): void
321
    {
322
        //$resultCombinedName = Text::uncamelize(ucfirst($controller) . ucfirst($action), '-');
323
        //$resultCombinedName = strlen($resultCombinedName) !== '' ? $resultCombinedName . '-' : '';
324
325
326
        foreach ($this->headerCollectionJS as $resource) {
327
            $resource->setPath($resource->getPath() . '?v=' . $version);
328
        }
329
        foreach ($this->footerCollectionJS as $resource) {
330
            $resource->setPath($resource->getPath() . '?v=' . $version);
331
        }
332
        foreach ($this->semanticCollectionJS as $resource) {
333
            $resource->setPath($resource->getPath() . '?v=' . $version);
334
        }
335
        foreach ($this->semanticCollectionCSS as $resource) {
336
            $resource->setPath($resource->getPath() . '?v=' . $version);
337
        }
338
        foreach ($this->footerCollectionACE as $resource) {
339
            $resource->setPath($resource->getPath() . '?v=' . $version);
340
        }
341
        foreach ($this->headerCollectionCSS as $resource) {
342
            $resource->setPath($resource->getPath() . '?v=' . $version);
343
        }
344
        foreach ($this->headerCollectionJSForExtensions as $resource) {
345
            $resource->setPath($resource->getPath() . '?v=' . $version);
346
        }
347
        foreach ($this->footerCollectionJSForExtensions as $resource) {
348
            $resource->setPath($resource->getPath() . '?v=' . $version);
349
        }
350
351
        // $this->headerCollectionCSS->join(true);
352
        // $this->headerCollectionCSS->setTargetPath("{$this->cssCacheDir}/{$resultCombinedName}header.min.css");
353
        // $this->headerCollectionCSS->setTargetUri("css/cache/{$resultCombinedName}header.min.css?v={$version}");
354
355
        // $this->headerCollectionJSForExtensions->join(true);
356
        // $this->headerCollectionJSForExtensions->setTargetPath("{$this->jsCacheDir}/{$resultCombinedName}header.min.js");
357
        // $this->headerCollectionJSForExtensions->setTargetUri(
358
        //     "js/cache/{$resultCombinedName}header.min.js?v={$version}"
359
        // );
360
361
        // $this->footerCollectionJSForExtensions->join(true);
362
        // $this->footerCollectionJSForExtensions->setTargetPath("{$this->jsCacheDir}/{$resultCombinedName}footer.min.js");
363
        // $this->footerCollectionJSForExtensions->setTargetUri(
364
        //     "js/cache/{$resultCombinedName}footer.min.js?v={$version}"
365
        // );
366
367
368
        // $minifier = new Minify\JS();
369
        // foreach ($this->footerCollectionJSForExtensions as $resource) {
370
        //     try {
371
        //         $minifier->addFile($resource->getPath());
372
        //     } catch (Minify\Exceptions\IOException $e) {
373
        //
374
        //     }
375
        //
376
        //     $resource->setPath($resource->getPath() . '?v=' . $version);
377
        // }
378
        // $minifier->minify("{$this->jsCacheDir}/{$resultCombinedName}footer.min.js");
379
    }
380
381
    /**
382
     * Makes assets for the CallQueues controller
383
     *
384
     * @param string $action
385
     */
386
    private function makeCallQueuesAssets(string $action)
387
    {
388
        if ($action === 'index') {
389
            $this->headerCollectionCSS
390
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
391
            $this->footerCollectionJS
392
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
393
                ->addJs('js/pbx/CallQueues/callqueues-index.js', true);
394
        } elseif ($action === 'modify') {
395
            $this->footerCollectionJS
396
                ->addJs('js/vendor/jquery.debounce-1.0.5.js', true)
397
                ->addJs('js/vendor/jquery.tablednd.js', true)
398
                ->addJs('js/pbx/main/form.js', true)
399
                ->addJs('js/pbx/CallQueues/callqueue-modify.js', true)
400
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
401
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
402
        }
403
    }
404
405
    /**
406
     * Makes assets for the ConferenceRooms controller
407
     *
408
     * @param string $action
409
     */
410
    private function makeConferenceRoomsAssets(string $action)
411
    {
412
        if ($action === 'index') {
413
            $this->footerCollectionJS
414
                ->addJs('js/pbx/ConferenceRooms/conference-rooms-index.js', true);
415
        } elseif ($action === 'modify') {
416
            $this->footerCollectionJS
417
                ->addJs('js/pbx/main/form.js', true)
418
                ->addJs('js/pbx/ConferenceRooms/conference-room-modify.js', true);
419
        }
420
    }
421
422
    /**
423
     * Makes assets for the SystemDiagnostic controller
424
     *
425
     * @param string $action
426
     */
427
    private function makeSystemDiagnosticAssets(string $action): void
428
    {
429
        if ($action === 'index') {
430
            $this->footerCollectionJS
431
                ->addJs('js/vendor/semantic/popup.min.js', true)
432
                ->addJs('js/vendor/semantic/dropdown.min.js', true)
433
                ->addJs('js/pbx/main/form.js', true)
434
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index.js', true)
435
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-showlogs.js', true)
436
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-sysinfo.js', true)
437
                ->addJs('js/pbx/SystemDiagnostic/system-diagnostic-index-logcapture.js', true);
438
            $this->footerCollectionACE
439
                ->addJs('js/vendor/ace/ace.js', true)
440
                ->addJs('js/vendor/ace/mode-julia.js', true);
441
        }
442
    }
443
444
    /**
445
     * Makes assets for the SoundFiles controller
446
     *
447
     * @param string $action
448
     */
449
    private function makeSoundFilesAssets(string $action): void
450
    {
451
        if ($action === 'index') {
452
            $this->headerCollectionCSS
453
                ->addCss('css/vendor/range/range.css')
454
                ->addCss(
455
                    'css/vendor/datatable/dataTables.semanticui.css',
456
                    true
457
                );
458
            $this->footerCollectionJS->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
459
                ->addJs('js/vendor/range/range.min.js', true)
460
                ->addJs('js/vendor/jquery.address.min.js', true)
461
                ->addJs('js/pbx/SoundFiles/sound-files-index-player.js', true)
462
                ->addJs('js/pbx/SoundFiles/sound-files-index.js', true);
463
        } elseif ($action === 'modify') {
464
            $this->headerCollectionCSS->addCss('css/vendor/range/range.css');
465
466
            $this->headerCollectionJS
467
                ->addJs(
468
                    'js/vendor/webrtc/MediaStreamRecorder.min.js',
469
                    true
470
                )
471
                ->addJs('js/vendor/webrtc/adapter-latest.min.js', true);
472
473
            $this->footerCollectionJS
474
                ->addJs('js/vendor/range/range.min.js', true)
475
                ->addJs('js/pbx/main/form.js', true)
476
                ->addJs('js/vendor/resumable.js', true)
477
                ->addJs('js/pbx/SoundFiles/sound-file-modify-player.js', true)
478
                ->addJs('js/pbx/SoundFiles/sound-file-modify-upload-worker.js', true)
479
                ->addJs('js/pbx/SoundFiles/sound-file-modify-webkit-recorder.js', true)
480
                ->addJs('js/pbx/SoundFiles/sound-file-modify.js', true);
481
        }
482
    }
483
484
    /**
485
     * Makes assets for the TimeSettings controller
486
     *
487
     * @param string $action
488
     */
489
    private function makeTimeSettingsAssets(string $action): void
490
    {
491
        if ($action === 'modify') {
492
            $this->footerCollectionJS
493
                ->addJs('js/pbx/main/form.js', true)
494
                ->addJs('js/vendor/moment/moment-with-locales.min.js',true)
495
                ->addJs('js/vendor/moment/moment-timezone-with-data.js', true)
496
                ->addJs('js/pbx/TimeSettings/time-settings-worker.js', true)
497
                ->addJs('js/pbx/TimeSettings/time-settings-modify.js', true);
498
        }
499
    }
500
501
    /**
502
     * Makes assets for the Update controller
503
     *
504
     * @param string $action
505
     */
506
    private function makeUpdateAssets(string $action): void
507
    {
508
        if ($action === 'index') {
509
            $this->footerCollectionJS
510
                ->addJs('js/pbx/main/version-compare.js', true)
511
                ->addJs('js/pbx/main/form.js', true)
512
                ->addJs('js/vendor/resumable.js', true)
513
                ->addJs('js/vendor/showdown/showdown.min.js', true)
514
                ->addJs('js/pbx/Update/update-index.js', true);
515
            $this->semanticCollectionCSS
516
                ->addCss('css/vendor/semantic/progress.min.css', true)
517
                ->addCss('css/vendor/semantic/modal.min.css', true);
518
519
            $this->semanticCollectionJS
520
                ->addJs('js/vendor/semantic/progress.min.js', true)
521
                ->addJs('js/vendor/semantic/modal.min.js', true);
522
        }
523
    }
524
525
    /**
526
     * Makes assets for the Session controller
527
     *
528
     * @param string $action
529
     */
530
    private function makeSessionAssets(string $action): void
531
    {
532
        if ($action === 'index') {
533
            $this->footerCollectionJS
534
                ->addJs('js/pbx/main/form.js', true)
535
                ->addJs('js/pbx/Session/login-form.js', true);
536
        }
537
    }
538
539
    /**
540
     * Makes assets for the Restart controller
541
     *
542
     * @param string $action
543
     */
544
    private function makeRestartAssets(string $action): void
545
    {
546
        if ($action === 'index') {
547
            $this->footerCollectionJS
548
                ->addJs('js/pbx/Restart/restart-index.js', true);
549
        }
550
    }
551
552
    /**
553
     * Makes assets for the Providers controller
554
     *
555
     * @param string $action
556
     */
557
    private function makeProvidersAssets(string $action): void
558
    {
559
        if ($action === 'index') {
560
            $this->semanticCollectionCSS
561
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true)
562
                ->addCss('css/vendor/semantic/modal.min.css', true);
563
564
            $this->semanticCollectionJS
565
                ->addJs('js/vendor/semantic/modal.min.js', true);
566
            $this->footerCollectionJS
567
                ->addJs('js/pbx/main/debugger-info.js', true)
568
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
569
                ->addJs('js/pbx/Providers/providers-index.js', true);
570
        } elseif ($action === 'modifysip' || $action === 'modifyiax') {
571
            $this->footerCollectionJS
572
                ->addJs('js/pbx/main/form.js', true)
573
                ->addJs('js/pbx/main/debugger-info.js', true)
574
                ->addJs('js/pbx/Providers/provider-modify-status-worker.js', true)
575
                ->addJs('js/pbx/Providers/provider-modify.js', true);
576
        }
577
    }
578
579
    /**
580
     *  Makes assets for the PbxExtensionModules controller
581
     *
582
     * @param string $action
583
     */
584
    private function makePbxExtensionModulesAssets(string $action): void
585
    {
586
        if ($action === 'index') {
587
            $this->semanticCollectionJS->addJs('js/vendor/semantic/modal.min.js', true);
588
            $this->footerCollectionJS
589
                ->addJs('js/pbx/Update/update-api.js', true)
590
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
591
                ->addJs('js/vendor/resumable.js', true)
592
                ->addJs(
593
                    'js/pbx/PbxExtensionModules/pbx-extension-module-upgrade-status-worker.js',
594
                    true
595
                )
596
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-status.js', true)
597
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-modules-index.js', true)
598
                ->addJs('js/vendor/semantic/progress.min.js', true)
599
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-add-new.js', true);
600
            $this->semanticCollectionCSS
601
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true)
602
                ->addCss('css/vendor/semantic/modal.min.css', true)
603
                ->addCss('css/vendor/semantic/progress.min.css', true);
604
        } elseif ($action === 'modify') {
605
            $this->footerCollectionJS
606
                ->addJs('js/pbx/main/form.js', true)
607
                ->addJs('js/pbx/PbxExtensionModules/pbx-extension-module-modify.js', true);
608
        }
609
    }
610
611
    /**
612
     * Makes assets for the OutOffWorkTime controller
613
     *
614
     * @param string $action
615
     */
616
    private function makeOutOffWorkTimeAssets(string $action): void
617
    {
618
        if ($action === 'index') {
619
            $this->footerCollectionJS
620
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-times-index.js', true);
621
        } elseif ($action === 'modify') {
622
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/calendar.min.css', true);
623
            $this->semanticCollectionJS->addJs('js/vendor/semantic/calendar.min.js', true);
624
            $this->footerCollectionJS
625
                ->addJs('js/pbx/main/form.js', true)
626
                ->addJs('js/pbx/OutOffWorkTime/out-of-work-time-modify.js', true)
627
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
628
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true);
629
        }
630
    }
631
632
    /**
633
     * Makes assets for the OutboundRoutes controller
634
     *
635
     * @param string $action
636
     */
637
    private function makeOutboundRoutesAssets(string $action): void
638
    {
639
        if ($action === 'index') {
640
            $this->footerCollectionJS
641
                ->addJs('js/vendor/jquery.tablednd.min.js', true)
642
                ->addJs('js/pbx/OutboundRoutes/outbound-routes-index.js', true);
643
        } elseif ($action === 'modify') {
644
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
645
                ->addJs('js/pbx/OutboundRoutes/outbound-route-modify.js', true);
646
        }
647
    }
648
649
    /**
650
     * Makes assets for the Network controller
651
     *
652
     * @param string $action
653
     */
654
    private function makeNetworkAssets(string $action): void
655
    {
656
        if ($action === 'modify') {
657
            $this->footerCollectionJS
658
                ->addJs('js/vendor/inputmask/inputmask.js', true)
659
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
660
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
661
                ->addJs('js/vendor/inputmask/init.js', true)
662
                ->addJs('js/pbx/main/form.js', true)
663
                ->addJs('js/pbx/Network/network-modify.js', true);
664
        }
665
    }
666
667
    /**
668
     * Makes assets for the MailSettings controller
669
     *
670
     * @param string $action
671
     */
672
    private function makeMailSettingsAssets(string $action): void
673
    {
674
        if ($action === 'modify') {
675
            $this->footerCollectionJS
676
                ->addJs('js/pbx/main/form.js', true)
677
                ->addJs('js/pbx/MailSettings/mail-settings-modify.js', true);
678
        }
679
    }
680
681
    /**
682
     * Makes assets for the Licensing controller
683
     *
684
     * @param string $action
685
     */
686
    private function makeLicensingAssets(string $action): void
687
    {
688
        if ($action === 'modify') {
689
            $this->footerCollectionJS
690
                ->addJs('js/vendor/inputmask/inputmask.js', true)
691
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
692
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
693
                ->addJs('js/vendor/inputmask/init.js', true)
694
                ->addJs('js/pbx/main/form.js', true)
695
                ->addJs('js/pbx/Licensing/licensing-modify.js', true);
696
        }
697
    }
698
699
    /**
700
     * Makes assets for the IvrMenu controller
701
     *
702
     * @param string $action
703
     */
704
    private function makeIvrMenuAssets(string $action): void
705
    {
706
        if ($action === 'index') {
707
            $this->headerCollectionCSS
708
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
709
            $this->footerCollectionJS
710
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
711
                ->addJs('js/pbx/IvrMenu/ivrmenu-index.js', true);
712
        } elseif ($action === 'modify') {
713
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
714
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
715
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
716
                ->addJs('js/pbx/IvrMenu/ivrmenu-modify.js', true);
717
        }
718
    }
719
720
    /**
721
     * Makes assets for the IncomingRoutes controller
722
     *
723
     * @param string $action
724
     */
725
    private function makeIncomingRoutesAssets(string $action): void
726
    {
727
        if ($action === 'index') {
728
            $this->footerCollectionJS->addJs('js/vendor/jquery.tablednd.js', true)
729
                ->addJs('js/pbx/main/form.js', true)
730
                ->addJs('js/pbx/IncomingRoutes/incoming-route-index.js', true);
731
        } elseif ($action === 'modify') {
732
            $this->footerCollectionJS->addJs('js/pbx/main/form.js', true)
733
                ->addJs('js/pbx/IncomingRoutes/incoming-route-modify.js', true);
734
        }
735
    }
736
737
    /**
738
     * Makes assets for the GeneralSettings controller
739
     *
740
     * @param string $action
741
     */
742
    private function makeGeneralSettingsAssets(string $action): void
743
    {
744
        if ($action === 'modify') {
745
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/progress.min.css', true);
746
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
747
            $this->footerCollectionJS
748
                ->addJs('js/vendor/jquery.address.min.js', true)
749
                ->addJs('js/vendor/jquery.tablednd.js', true)
750
                ->addJs('js/pbx/SoundFiles/sound-files-selector.js', true)
751
                ->addJs('js/pbx/SoundFiles/one-button-sound-player.js', true)
752
                ->addJs('js/pbx/main/form.js', true)
753
                ->addJs('js/pbx/main/password-score.js', true)
754
                ->addJs(
755
                    'js/pbx/GeneralSettings/general-settings-modify.js',
756
                    true
757
                );
758
        }
759
    }
760
761
    /**
762
     * Makes assets for the Firewall controller
763
     *
764
     * @param string $action
765
     */
766
    private function makeFirewallAssets(string $action): void
767
    {
768
        if ($action === 'index') {
769
            $this->footerCollectionJS
770
                ->addJs('js/pbx/Firewall/firewall-index.js', true);
771
        } elseif ($action === 'modify') {
772
            $this->footerCollectionJS
773
                ->addJs('js/pbx/main/form.js', true)
774
                ->addJs('js/pbx/Firewall/firewall-modify.js', true);
775
        }
776
    }
777
778
    /**
779
     * Makes assets for the Fail2Ban controller
780
     *
781
     * @param string $action
782
     */
783
    private function makeFail2BanAssets(string $action): void
784
    {
785
        if ($action === 'index') {
786
            $this->footerCollectionJS
787
                ->addJs('js/pbx/main/form.js', true)
788
                ->addJs('js/pbx/Fail2Ban/fail-to-ban-index.js', true);
789
        }
790
    }
791
792
    /**
793
     * Makes assets for the Extensions controller
794
     *
795
     * @param string $action
796
     */
797
    private function makeExtensionsAssets(string $action): void
798
    {
799
        if ($action === 'index') {
800
            $this->headerCollectionCSS->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
801
802
            $this->footerCollectionJS
803
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
804
                ->addJs('js/vendor/inputmask/inputmask.js', true)
805
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
806
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
807
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
808
                ->addJs('js/vendor/inputmask/init.js', true)
809
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
810
                ->addJs('js/pbx/Extensions/extensions-index.js', true)
811
                ->addJs('js/pbx/main/debugger-info.js', true)
812
                ->addJs('js/vendor/clipboard/clipboard.js', true);
813
        } elseif ($action === 'modify') {
814
            $this->semanticCollectionCSS->addCss('css/vendor/semantic/card.min.css', true);
815
            $this->footerCollectionJS
816
                ->addJs('js/vendor/inputmask/inputmask.js', true)
817
                ->addJs('js/vendor/inputmask/jquery.inputmask.js', true)
818
                ->addJs('js/vendor/inputmask/jquery.inputmask-multi.js', true)
819
                ->addJs('js/vendor/inputmask/bindings/inputmask.binding.js', true)
820
                ->addJs('js/vendor/inputmask/init.js', true)
821
                ->addJs('js/pbx/Extensions/input-mask-patterns.js', true)
822
                ->addJs('js/pbx/main/form.js', true)
823
                ->addJs('js/pbx/main/debugger-info.js', true)
824
                ->addJs('js/pbx/Extensions/extension-modify.js', true);
825
        }
826
    }
827
828
    /**
829
     *  Makes assets for the DialplanApplications controller
830
     *
831
     * @param string $action
832
     */
833
    private function makeDialplanApplicationsAssets(string $action): void
834
    {
835
        if ($action === 'index') {
836
            $this->headerCollectionCSS
837
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
838
            $this->footerCollectionJS
839
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
840
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-index.js', true);
841
        } elseif ($action === 'modify') {
842
            $this->footerCollectionACE
843
                ->addJs('js/vendor/ace/ace.js', true)
844
                ->addJs('js/vendor/ace/mode-php.js', true)
845
                ->addJs('js/vendor/ace/mode-julia.js', true);
846
            $this->footerCollectionJS
847
                ->addJs('js/pbx/main/form.js', true)
848
                ->addJs('js/pbx/DialplanApplications/dialplan-applications-modify.js', true);
849
        }
850
    }
851
852
    /**
853
     * Makes assets for the CustomFiles controller
854
     *
855
     * @param string $action
856
     */
857
    private function makeCustomFilesAssets(string $action): void
858
    {
859
        if ($action === 'index') {
860
            $this->headerCollectionCSS
861
                ->addCss('css/vendor/datatable/dataTables.semanticui.css', true);
862
            $this->footerCollectionJS
863
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
864
                ->addJs('js/pbx/CustomFiles/custom-files-index.js', true);
865
        } elseif ($action === 'modify') {
866
            $this->footerCollectionJS
867
                ->addJs('js/pbx/main/form.js', true)
868
                ->addJs('js/pbx/CustomFiles/custom-files-modify.js', true);
869
            $this->footerCollectionACE
870
                ->addJs('js/vendor/ace/ace.js', true)
871
                ->addJs('js/vendor/ace/mode-julia.js', true);
872
        }
873
    }
874
875
    /**
876
     * Makes assets for the CallDetailRecords controller
877
     *
878
     * @param string $action
879
     */
880
    private function makeCallDetailRecordsAssets(string $action): void
881
    {
882
        if ($action === 'index') {
883
            $this->semanticCollectionJS->addJs('js/vendor/semantic/progress.min.js', true);
884
885
            $this->semanticCollectionCSS
886
                ->addCss('css/vendor/range/range.min.css', true)
887
                ->addCss('css/vendor/datatable/scroller.dataTables.min.css', true)
888
                ->addCss('css/vendor/datepicker/daterangepicker.css', true)
889
                ->addCss('css/vendor/datatable/dataTables.semanticui.min.css', true);
890
891
            $this->semanticCollectionJS
892
                ->addJs('js/vendor/datatable/dataTables.semanticui.js', true)
893
                ->addJs('js/vendor/datatable/dataTables.scroller.min.js', true)
894
                ->addJs('js/vendor/datatable/scroller.semanticui.js', true)
895
                //->addJs('js/vendor/datatable/dataTables.pageResize.min.js', TRUE)
896
                ->addJs('js/vendor/range/range.min.js', true)
897
                ->addJS('js/vendor/datepicker/moment.min.js', true)
898
                ->addJS('js/vendor/datepicker/daterangepicker.js', true);
899
900
            $this->footerCollectionJS
901
                ->addJs(
902
                    'js/pbx/CallDetailRecords/call-detail-records-index.js',
903
                    true
904
                );
905
        }
906
    }
907
908
    /**
909
     * Makes assets for the AsteriskManagers controller
910
     *
911
     * @param string $action
912
     */
913
    private function makeAsteriskManagersAssets(string $action): void
914
    {
915
        if ($action === 'index') {
916
            $this->footerCollectionJS->addJs('js/pbx/AsteriskManagers/managers-index.js', true);
917
        } elseif ($action === 'modify') {
918
            $this->footerCollectionJS
919
                ->addJs('js/pbx/main/form.js', true)
920
                ->addJs('js/pbx/AsteriskManagers/manager-modify.js', true);
921
        }
922
    }
923
924
925
}