Passed
Push — develop ( 280fbb...a193d4 )
by Nikolay
05:10 queued 15s
created

AssetProvider::makeSentryAssets()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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