coer-elements 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/esm2022/interfaces/index.mjs +7 -0
- package/esm2022/interfaces/lib/app-source.interface.mjs +2 -0
- package/esm2022/interfaces/lib/breadcrumb.interface.mjs +2 -0
- package/esm2022/interfaces/lib/coer-ref.interface.mjs +2 -0
- package/esm2022/interfaces/lib/go-back.interface.mjs +2 -0
- package/esm2022/interfaces/lib/patch.interface.mjs +2 -0
- package/esm2022/interfaces/lib/screen-size.interface.mjs +2 -0
- package/esm2022/public_api.mjs +2 -1
- package/esm2022/signals/index.mjs +4 -0
- package/esm2022/signals/lib/breakpoint.signal.mjs +4 -0
- package/esm2022/signals/lib/is-loading.signal.mjs +3 -0
- package/esm2022/signals/lib/is-modal-open.signal.mjs +3 -0
- package/esm2022/tools/index.mjs +9 -2
- package/esm2022/tools/lib/breadcrumbs.class.mjs +63 -0
- package/esm2022/tools/lib/control-value.class.mjs +46 -0
- package/esm2022/tools/lib/date-time.class.mjs +22 -0
- package/esm2022/tools/lib/files.class.mjs +91 -0
- package/esm2022/tools/lib/generi-tools.mjs +199 -0
- package/esm2022/tools/lib/page.class.mjs +156 -0
- package/esm2022/tools/lib/screen.class.mjs +43 -0
- package/esm2022/tools/lib/source.class.mjs +80 -0
- package/fesm2022/coer-elements.mjs +649 -3
- package/fesm2022/coer-elements.mjs.map +1 -1
- package/interfaces/index.d.ts +6 -0
- package/interfaces/lib/app-source.interface.d.ts +4 -0
- package/interfaces/lib/breadcrumb.interface.d.ts +6 -0
- package/interfaces/lib/coer-ref.interface.d.ts +10 -0
- package/interfaces/lib/go-back.interface.d.ts +6 -0
- package/interfaces/lib/patch.interface.d.ts +5 -0
- package/interfaces/lib/screen-size.interface.d.ts +5 -0
- package/package.json +1 -1
- package/public_api.d.ts +1 -0
- package/signals/index.d.ts +3 -0
- package/signals/lib/breakpoint.signal.d.ts +1 -0
- package/signals/lib/is-loading.signal.d.ts +1 -0
- package/signals/lib/is-modal-open.signal.d.ts +1 -0
- package/src/interfaces/index.ts +6 -0
- package/src/interfaces/lib/app-source.interface.ts +4 -0
- package/src/interfaces/lib/breadcrumb.interface.ts +6 -0
- package/src/interfaces/lib/coer-ref.interface.ts +11 -0
- package/src/interfaces/lib/go-back.interface.ts +6 -0
- package/src/interfaces/lib/patch.interface.ts +5 -0
- package/src/interfaces/lib/screen-size.interface.ts +5 -0
- package/tools/index.d.ts +8 -1
- package/tools/lib/breadcrumbs.class.d.ts +18 -0
- package/tools/lib/date-time.class.d.ts +11 -0
- package/tools/lib/files.class.d.ts +16 -0
- package/tools/lib/generi-tools.d.ts +32 -0
- package/tools/lib/page.class.d.ts +60 -0
- package/tools/lib/screen.class.d.ts +11 -0
- package/tools/lib/source.class.d.ts +20 -0
- package/esm2022/tools/lib/controlValue.mjs +0 -46
- /package/tools/lib/{controlValue.d.ts → control-value.class.d.ts} +0 -0
@@ -1,10 +1,13 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
|
-
import { Component, NgModule, forwardRef } from '@angular/core';
|
2
|
+
import { Component, NgModule, signal, forwardRef, inject, Inject } from '@angular/core';
|
3
3
|
import { CommonModule } from '@angular/common';
|
4
|
-
import { RouterModule } from '@angular/router';
|
4
|
+
import { RouterModule, Router, ActivatedRoute } from '@angular/router';
|
5
5
|
import { FormsModule, ReactiveFormsModule, NG_VALUE_ACCESSOR } from '@angular/forms';
|
6
6
|
import * as bootstrap from 'bootstrap';
|
7
7
|
import Swal from 'sweetalert2';
|
8
|
+
import moment from 'moment';
|
9
|
+
import * as XLSX from 'xlsx';
|
10
|
+
import { Observable } from 'rxjs';
|
8
11
|
|
9
12
|
class CoerAlert {
|
10
13
|
/** */
|
@@ -305,6 +308,266 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
|
|
305
308
|
}]
|
306
309
|
}] });
|
307
310
|
|
311
|
+
const reference_signal = signal({});
|
312
|
+
const Tools = {
|
313
|
+
/** Generate a Guid */
|
314
|
+
GetGuid: (seed = 'coer-system') => {
|
315
|
+
let time = new Date().getTime();
|
316
|
+
seed = seed.toString().trim();
|
317
|
+
return seed + `-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g, (c) => {
|
318
|
+
const random = (time + Math.random() * 16) % 16 | 0;
|
319
|
+
time = Math.floor(time / 16);
|
320
|
+
return (c == 'x' ? random : (random & 0x3 | 0x8)).toString(16);
|
321
|
+
});
|
322
|
+
},
|
323
|
+
/** Returns true if the value is null or undefined, false otherwise */
|
324
|
+
IsNull: (value) => {
|
325
|
+
if (value === undefined)
|
326
|
+
return true;
|
327
|
+
if (value === null)
|
328
|
+
return true;
|
329
|
+
return false;
|
330
|
+
},
|
331
|
+
/** Returns true if the value is not null or undefined, false otherwise */
|
332
|
+
IsNotNull: (value) => {
|
333
|
+
if (value === undefined)
|
334
|
+
return false;
|
335
|
+
if (value === null)
|
336
|
+
return false;
|
337
|
+
return true;
|
338
|
+
},
|
339
|
+
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
340
|
+
IsOnlyWhiteSpace: (value) => {
|
341
|
+
if (value === undefined)
|
342
|
+
return true;
|
343
|
+
if (value === null)
|
344
|
+
return true;
|
345
|
+
if (value.toString().trim() === '')
|
346
|
+
return true;
|
347
|
+
return false;
|
348
|
+
},
|
349
|
+
/** Break reference of a object or array */
|
350
|
+
BreakReference: (object) => {
|
351
|
+
if (object === undefined)
|
352
|
+
return undefined;
|
353
|
+
if (object === null)
|
354
|
+
return null;
|
355
|
+
const OBJECT = JSON.parse(JSON.stringify(object));
|
356
|
+
return (Array.isArray(OBJECT)) ? [...OBJECT] : { ...OBJECT };
|
357
|
+
},
|
358
|
+
/** Clean extra whitespaces */
|
359
|
+
CleanUpBlanks: (text) => {
|
360
|
+
if (Tools.IsNull(text))
|
361
|
+
return '';
|
362
|
+
let worlds = String(text).split(' ');
|
363
|
+
worlds = worlds.filter(x => x.length > 0);
|
364
|
+
return worlds.join(' ');
|
365
|
+
},
|
366
|
+
/** Get properties of an object */
|
367
|
+
GetObjectProperties: (obj) => {
|
368
|
+
const properties = [];
|
369
|
+
if (Tools.IsNull(obj))
|
370
|
+
return properties;
|
371
|
+
for (const property in obj)
|
372
|
+
properties.push(String(property));
|
373
|
+
return properties;
|
374
|
+
},
|
375
|
+
/**
|
376
|
+
* Set an index and merge more arrays of the same type
|
377
|
+
* */
|
378
|
+
SetIndex: (array, ...args) => {
|
379
|
+
let index = 0;
|
380
|
+
for (const arg of args) {
|
381
|
+
array = Tools.BreakReference(array).concat(Tools.BreakReference(arg));
|
382
|
+
}
|
383
|
+
return Tools.BreakReference(array).map(item => Object.assign({ index: index++ }, item));
|
384
|
+
},
|
385
|
+
/** Set First Char To Lower */
|
386
|
+
FirstCharToLower: (text) => {
|
387
|
+
if (Tools.IsNull(text))
|
388
|
+
return '';
|
389
|
+
const textArray = [];
|
390
|
+
for (let i = 0; i < text.length; i++) {
|
391
|
+
if (i === 0)
|
392
|
+
textArray.push(text[i].toLowerCase());
|
393
|
+
else
|
394
|
+
textArray.push(text[i]);
|
395
|
+
}
|
396
|
+
return textArray.join('');
|
397
|
+
},
|
398
|
+
/** Set First Char To Upper */
|
399
|
+
FirstCharToUpper: (text) => {
|
400
|
+
if (Tools.IsNull(text))
|
401
|
+
return '';
|
402
|
+
const textArray = [];
|
403
|
+
for (let i = 0; i < text.length; i++) {
|
404
|
+
if (i === 0)
|
405
|
+
textArray.push(text[i].toUpperCase());
|
406
|
+
else
|
407
|
+
textArray.push(text[i]);
|
408
|
+
}
|
409
|
+
return textArray.join('');
|
410
|
+
},
|
411
|
+
/** Sort an array in ascending order by property */
|
412
|
+
SortBy: (array, property, propertyType = 'string') => {
|
413
|
+
switch (propertyType) {
|
414
|
+
case 'string': {
|
415
|
+
return array.sort((x, y) => {
|
416
|
+
if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
|
417
|
+
return -1;
|
418
|
+
else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
|
419
|
+
return 1;
|
420
|
+
else
|
421
|
+
return 0;
|
422
|
+
});
|
423
|
+
}
|
424
|
+
case 'number': {
|
425
|
+
return array.sort((x, y) => Number(x[property] - Number(y[property])));
|
426
|
+
}
|
427
|
+
}
|
428
|
+
},
|
429
|
+
/** Sort an array in descending order by property */
|
430
|
+
SortByDesc: (array, property, propertyType = 'string') => {
|
431
|
+
switch (propertyType) {
|
432
|
+
case 'string': {
|
433
|
+
return array.sort((x, y) => {
|
434
|
+
if (String(x[property]).toUpperCase().trim() < String(y[property]).toUpperCase().trim())
|
435
|
+
return 1;
|
436
|
+
else if (String(x[property]).toUpperCase().trim() > String(y[property]).toUpperCase().trim())
|
437
|
+
return -1;
|
438
|
+
else
|
439
|
+
return 0;
|
440
|
+
});
|
441
|
+
}
|
442
|
+
case 'number': {
|
443
|
+
return array.sort((x, y) => Number(Number(y[property])) - x[property]);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
},
|
447
|
+
/** Return a string with forman numeric */
|
448
|
+
GetNumericFormat: (value, decimals = 0) => {
|
449
|
+
if (value == undefined
|
450
|
+
|| value == null
|
451
|
+
|| value.toString().trim() == ''
|
452
|
+
|| isNaN(Number(value))) {
|
453
|
+
return '0';
|
454
|
+
}
|
455
|
+
let valueInteger = '';
|
456
|
+
let valueDecimal = '';
|
457
|
+
value = value.toString().replaceAll(' ', '');
|
458
|
+
if (value.includes('.') || (decimals > 0)) {
|
459
|
+
valueInteger = value.includes('.') ? value.split('.')[0] : value;
|
460
|
+
if (decimals > 0) {
|
461
|
+
const PADDING = decimals - valueDecimal.length;
|
462
|
+
valueDecimal = value.includes('.') ? value.split('.')[1] : '';
|
463
|
+
for (let i = 0; i < PADDING; i++)
|
464
|
+
valueDecimal += '0';
|
465
|
+
valueDecimal = valueDecimal.substring(0, decimals);
|
466
|
+
valueDecimal = `.${valueDecimal}`;
|
467
|
+
}
|
468
|
+
}
|
469
|
+
else {
|
470
|
+
valueInteger = value;
|
471
|
+
}
|
472
|
+
let counter = 0;
|
473
|
+
const VALUE_INTEGER_ARRAY = [];
|
474
|
+
for (const char of valueInteger.split('').reverse()) {
|
475
|
+
if (counter == 3) {
|
476
|
+
VALUE_INTEGER_ARRAY.push(',');
|
477
|
+
counter = 0;
|
478
|
+
}
|
479
|
+
VALUE_INTEGER_ARRAY.push(char);
|
480
|
+
++counter;
|
481
|
+
}
|
482
|
+
valueInteger = VALUE_INTEGER_ARRAY.reverse().join('');
|
483
|
+
return `${valueInteger}${valueDecimal}`;
|
484
|
+
},
|
485
|
+
/** Wait the time indicated */
|
486
|
+
Sleep: (milliseconds = 0, reference = null) => {
|
487
|
+
if (Tools.IsNull(reference)) {
|
488
|
+
return new Promise(Resolve => setTimeout(Resolve, milliseconds));
|
489
|
+
}
|
490
|
+
else
|
491
|
+
return new Promise(Resolve => {
|
492
|
+
reference = reference.replaceAll(' ', '_').toLowerCase();
|
493
|
+
if (reference_signal().hasOwnProperty(reference)) {
|
494
|
+
clearInterval(reference_signal()[reference]);
|
495
|
+
}
|
496
|
+
reference_signal.set(Object.assign(reference_signal(), {
|
497
|
+
[reference]: setTimeout(() => {
|
498
|
+
Resolve();
|
499
|
+
clearInterval(reference_signal()[reference]);
|
500
|
+
const _reference = { ...reference_signal() };
|
501
|
+
delete _reference[reference];
|
502
|
+
reference_signal.set({ ..._reference });
|
503
|
+
}, milliseconds)
|
504
|
+
}));
|
505
|
+
});
|
506
|
+
}
|
507
|
+
};
|
508
|
+
|
509
|
+
class Breadcrumbs {
|
510
|
+
static { this.storage = 'COER-System'; }
|
511
|
+
/** */
|
512
|
+
static Add(page, path) {
|
513
|
+
const breadcrumbs = this.Get();
|
514
|
+
const paths = breadcrumbs.map(item => item.path);
|
515
|
+
if (!paths.includes(path)) {
|
516
|
+
breadcrumbs.push({ page, path });
|
517
|
+
this.Save(breadcrumbs);
|
518
|
+
}
|
519
|
+
}
|
520
|
+
/** */
|
521
|
+
static Get() {
|
522
|
+
let storage = sessionStorage.getItem(this.storage);
|
523
|
+
if (storage) {
|
524
|
+
storage = JSON.parse(storage);
|
525
|
+
if (storage.hasOwnProperty('breadcrumbs')) {
|
526
|
+
return Tools.BreakReference(storage.breadcrumbs);
|
527
|
+
}
|
528
|
+
}
|
529
|
+
return [];
|
530
|
+
}
|
531
|
+
/** */
|
532
|
+
static GetFirst() {
|
533
|
+
const breadcrumbs = this.Get();
|
534
|
+
return (breadcrumbs.length > 0) ? breadcrumbs.shift() : null;
|
535
|
+
}
|
536
|
+
/** */
|
537
|
+
static Save(breadcrumbs) {
|
538
|
+
let storage = sessionStorage.getItem(this.storage);
|
539
|
+
if (storage)
|
540
|
+
storage = JSON.parse(storage);
|
541
|
+
storage = Object.assign({}, storage, { breadcrumbs });
|
542
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
543
|
+
}
|
544
|
+
/** */
|
545
|
+
static Remove(path) {
|
546
|
+
let breadcrumbs = this.Get();
|
547
|
+
const index = breadcrumbs.findIndex(x => x.path.toLowerCase().trim() === path.toLowerCase().trim());
|
548
|
+
if (index >= 0) {
|
549
|
+
breadcrumbs = Tools.BreakReference(breadcrumbs).splice(0, index + 1);
|
550
|
+
this.Save(breadcrumbs);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
/** */
|
554
|
+
static SetLast(page, path) {
|
555
|
+
const breadcrumbs = this.Get();
|
556
|
+
if (breadcrumbs.length > 0) {
|
557
|
+
breadcrumbs[breadcrumbs.length - 1] = { page, path };
|
558
|
+
this.Save(breadcrumbs);
|
559
|
+
}
|
560
|
+
}
|
561
|
+
/** */
|
562
|
+
static RemoveLast() {
|
563
|
+
const breadcrumbs = this.Get();
|
564
|
+
if (breadcrumbs.length > 0) {
|
565
|
+
breadcrumbs.pop();
|
566
|
+
this.Save(breadcrumbs);
|
567
|
+
}
|
568
|
+
}
|
569
|
+
}
|
570
|
+
|
308
571
|
const CONTROL_VALUE = (component) => {
|
309
572
|
return {
|
310
573
|
provide: NG_VALUE_ACCESSOR,
|
@@ -349,9 +612,392 @@ class ControlValue {
|
|
349
612
|
setDisabledState(isDisabled) { }
|
350
613
|
}
|
351
614
|
|
615
|
+
class DateTime {
|
616
|
+
/** Get UTC Offset */
|
617
|
+
static GetOffset() {
|
618
|
+
return moment().utcOffset();
|
619
|
+
}
|
620
|
+
/** Convert UTC Date to Local Zone */
|
621
|
+
static ToLocalZone(utcDate) {
|
622
|
+
return moment(utcDate).add(DateTime.GetOffset(), 'minutes').format('YYYY-MM-DD HH:mm:ss');
|
623
|
+
}
|
624
|
+
/** Convert Local Zone Date to UTC */
|
625
|
+
static ToUTC(utcDate) {
|
626
|
+
return moment(utcDate).subtract(DateTime.GetOffset(), 'minutes').format('YYYY-MM-DD HH:mm:ss');
|
627
|
+
}
|
628
|
+
/** DD MMM YYYY */
|
629
|
+
static GetDateFormat(date) {
|
630
|
+
if ((typeof date === 'string'))
|
631
|
+
date = date.replaceAll('/', '-');
|
632
|
+
return moment(date).parseZone().local(true).format('DD MMM YYYY');
|
633
|
+
}
|
634
|
+
}
|
635
|
+
|
636
|
+
class Files {
|
637
|
+
static { this.EXCEL_EXTENSIONS = ['xls', 'xlsx', 'csv']; }
|
638
|
+
/** Get Extension File */
|
639
|
+
static GetExtension(file) {
|
640
|
+
const fileName = file.name;
|
641
|
+
if (fileName.includes('.')) {
|
642
|
+
let worlds = fileName.split('.');
|
643
|
+
if (worlds.length > 0) {
|
644
|
+
let extension = worlds.pop();
|
645
|
+
extension = extension.trim().toLowerCase();
|
646
|
+
if (extension.length > 0)
|
647
|
+
return extension;
|
648
|
+
}
|
649
|
+
}
|
650
|
+
return null;
|
651
|
+
}
|
652
|
+
/** Is Excel File */
|
653
|
+
static IsExcel(file) {
|
654
|
+
const EXTENSION = Files.GetExtension(file);
|
655
|
+
return Tools.IsNotNull(EXTENSION)
|
656
|
+
? this.EXCEL_EXTENSIONS.includes(EXTENSION)
|
657
|
+
: false;
|
658
|
+
}
|
659
|
+
/** Read excel file */
|
660
|
+
static ReadExcel(file) {
|
661
|
+
return new Promise(Resolve => {
|
662
|
+
let columns = [];
|
663
|
+
let rows = [];
|
664
|
+
const reader = new FileReader();
|
665
|
+
reader.readAsArrayBuffer(file);
|
666
|
+
reader.onload = () => {
|
667
|
+
const dataBytes = new Uint8Array(reader.result);
|
668
|
+
if (dataBytes) {
|
669
|
+
const workbook = XLSX.read(dataBytes, {});
|
670
|
+
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
671
|
+
let dataSheet = XLSX.utils.sheet_to_json(sheet, {
|
672
|
+
header: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
|
673
|
+
});
|
674
|
+
//Get Headers
|
675
|
+
for (const column in dataSheet[0]) {
|
676
|
+
columns.push(Tools.FirstCharToLower(String(dataSheet[0][column]).replaceAll(' ', '')));
|
677
|
+
}
|
678
|
+
//Get Rows
|
679
|
+
rows = XLSX.utils.sheet_to_json(sheet, { header: columns });
|
680
|
+
rows.shift();
|
681
|
+
rows = rows.map(row => {
|
682
|
+
const item = Tools.BreakReference(row);
|
683
|
+
delete item['__rowNum__'];
|
684
|
+
return item;
|
685
|
+
});
|
686
|
+
}
|
687
|
+
Resolve({ columns, rows });
|
688
|
+
};
|
689
|
+
reader.onerror = () => { Resolve({ columns, rows }); };
|
690
|
+
});
|
691
|
+
}
|
692
|
+
/** Export to excel file */
|
693
|
+
static ExportExcel(data, fileName = 'coer_report', sheetName = 'Sheet1') {
|
694
|
+
sheetName = Tools.CleanUpBlanks(sheetName);
|
695
|
+
fileName = Tools.CleanUpBlanks(fileName);
|
696
|
+
if (fileName.endsWith('.xls') || fileName.endsWith('.xlsx') || fileName.endsWith('.csv')) {
|
697
|
+
if (fileName.includes('.xls')) {
|
698
|
+
fileName = fileName.replaceAll('.xls', '.xlsx');
|
699
|
+
}
|
700
|
+
if (fileName.includes('.csv')) {
|
701
|
+
fileName = fileName.replaceAll('.csv', '.xlsx');
|
702
|
+
}
|
703
|
+
}
|
704
|
+
else {
|
705
|
+
fileName += '.xlsx';
|
706
|
+
}
|
707
|
+
const WORK_SHEET = XLSX.utils.json_to_sheet(data);
|
708
|
+
const WORK_BOOK = XLSX.utils.book_new();
|
709
|
+
XLSX.utils.book_append_sheet(WORK_BOOK, WORK_SHEET, sheetName);
|
710
|
+
XLSX.writeFile(WORK_BOOK, fileName);
|
711
|
+
}
|
712
|
+
/** Convert file to string base64 */
|
713
|
+
static ConvertToBase64(file) {
|
714
|
+
return new Promise(Resolve => {
|
715
|
+
const reader = new FileReader();
|
716
|
+
reader.readAsDataURL(file);
|
717
|
+
reader.onload = () => {
|
718
|
+
Resolve(reader.result?.toString() || '');
|
719
|
+
};
|
720
|
+
reader.onerror = () => Resolve('');
|
721
|
+
});
|
722
|
+
}
|
723
|
+
}
|
724
|
+
|
725
|
+
class Source {
|
726
|
+
static { this.storage = 'COER-System'; }
|
727
|
+
/** */
|
728
|
+
static Set(page) {
|
729
|
+
const ROUTER = inject(Router);
|
730
|
+
let path = ROUTER.url;
|
731
|
+
if (path.includes('?'))
|
732
|
+
path = path.split('?')[0];
|
733
|
+
Breadcrumbs.Add(page, path);
|
734
|
+
const breadcrumbs = Breadcrumbs.Get();
|
735
|
+
if (breadcrumbs.length >= 2) {
|
736
|
+
breadcrumbs.pop();
|
737
|
+
const breadcrumb = breadcrumbs.pop();
|
738
|
+
this.Save({ page: breadcrumb.page, path: breadcrumb.path });
|
739
|
+
}
|
740
|
+
else
|
741
|
+
this.Save(null);
|
742
|
+
}
|
743
|
+
/** */
|
744
|
+
static Save(source) {
|
745
|
+
let storage = sessionStorage.getItem(this.storage);
|
746
|
+
if (storage)
|
747
|
+
storage = JSON.parse(storage);
|
748
|
+
storage = Object.assign({}, storage, { source });
|
749
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
750
|
+
}
|
751
|
+
/** */
|
752
|
+
static Get() {
|
753
|
+
let storage = sessionStorage.getItem(this.storage);
|
754
|
+
if (storage) {
|
755
|
+
storage = JSON.parse(storage);
|
756
|
+
if (storage.hasOwnProperty('source')) {
|
757
|
+
return storage.source;
|
758
|
+
}
|
759
|
+
}
|
760
|
+
return null;
|
761
|
+
}
|
762
|
+
/** */
|
763
|
+
static GetRoot() {
|
764
|
+
const breadcrumbs = Breadcrumbs.Get();
|
765
|
+
return (breadcrumbs.length > 0) ? breadcrumbs.shift() : null;
|
766
|
+
}
|
767
|
+
/** */
|
768
|
+
static SetPageResponse(pageResponse) {
|
769
|
+
let storage = sessionStorage.getItem(this.storage);
|
770
|
+
storage = JSON.parse(storage);
|
771
|
+
storage = Object.assign({}, storage, { pageResponse });
|
772
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
773
|
+
}
|
774
|
+
/** */
|
775
|
+
static GetPageResponse() {
|
776
|
+
let storage = sessionStorage.getItem(this.storage);
|
777
|
+
if (storage) {
|
778
|
+
storage = JSON.parse(storage);
|
779
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
780
|
+
return Tools.BreakReference(storage.pageResponse);
|
781
|
+
}
|
782
|
+
}
|
783
|
+
return null;
|
784
|
+
}
|
785
|
+
/** */
|
786
|
+
static ClearPageResponse() {
|
787
|
+
let storage = sessionStorage.getItem(this.storage);
|
788
|
+
storage = JSON.parse(storage);
|
789
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
790
|
+
delete storage.pageResponse;
|
791
|
+
}
|
792
|
+
storage = Object.assign({}, storage);
|
793
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
794
|
+
}
|
795
|
+
/** */
|
796
|
+
static Reset() {
|
797
|
+
sessionStorage.removeItem(this.storage);
|
798
|
+
}
|
799
|
+
}
|
800
|
+
|
801
|
+
class Page {
|
802
|
+
constructor(page) {
|
803
|
+
//Injection
|
804
|
+
this.alert = inject(CoerAlert);
|
805
|
+
this.router = inject(Router);
|
806
|
+
this.activatedRoute = inject(ActivatedRoute);
|
807
|
+
/** */
|
808
|
+
this.isUpdate = false;
|
809
|
+
/** */
|
810
|
+
this.isLoading = false;
|
811
|
+
/** */
|
812
|
+
this.isReadyPage = false;
|
813
|
+
/** */
|
814
|
+
this.enableAnimations = false;
|
815
|
+
/** */
|
816
|
+
this.breadcrumbs = [];
|
817
|
+
/** */
|
818
|
+
this.pageResponse = null;
|
819
|
+
/** */
|
820
|
+
this.goBack = { show: false };
|
821
|
+
//Private Variables
|
822
|
+
this._page = '';
|
823
|
+
this._source = null;
|
824
|
+
this._preventDestroy = false;
|
825
|
+
/** */
|
826
|
+
this.GoBack = (path) => (() => {
|
827
|
+
if (path)
|
828
|
+
Breadcrumbs.Remove(path);
|
829
|
+
else
|
830
|
+
Breadcrumbs.RemoveLast();
|
831
|
+
});
|
832
|
+
this.SetPageName(page);
|
833
|
+
this.SetSource();
|
834
|
+
this.GetSource();
|
835
|
+
this.GetNavigation();
|
836
|
+
this.SetGoBack();
|
837
|
+
this.GetPageResponse();
|
838
|
+
}
|
839
|
+
ngAfterViewInit() {
|
840
|
+
this.routeParams = this.activatedRoute.snapshot.params;
|
841
|
+
this.queryParams = this.activatedRoute.snapshot.queryParams;
|
842
|
+
setTimeout(() => {
|
843
|
+
this.isReadyPage = true;
|
844
|
+
this.RunPage();
|
845
|
+
setTimeout(() => { this.enableAnimations = true; }, 1000);
|
846
|
+
});
|
847
|
+
}
|
848
|
+
ngOnDestroy() {
|
849
|
+
if (!this._preventDestroy)
|
850
|
+
Source.ClearPageResponse();
|
851
|
+
}
|
852
|
+
/** Main method. Starts after ngAfterViewInit() */
|
853
|
+
RunPage() { }
|
854
|
+
;
|
855
|
+
/** Rename the last breadcrumb and update the url id */
|
856
|
+
SetPageName(name, id = null) {
|
857
|
+
this._page = name;
|
858
|
+
let path = this.router.url;
|
859
|
+
if (path.includes('?'))
|
860
|
+
path = path.split('?')[0];
|
861
|
+
if (id) {
|
862
|
+
const PATH_ARRAY = path.split('/');
|
863
|
+
const PATH_ID = Tools.BreakReference(PATH_ARRAY).pop();
|
864
|
+
if (PATH_ID) {
|
865
|
+
PATH_ARRAY[PATH_ARRAY.length - 1] = String(id);
|
866
|
+
path = PATH_ARRAY.join('/');
|
867
|
+
}
|
868
|
+
}
|
869
|
+
if (this.breadcrumbs.length > 0) {
|
870
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].page = name;
|
871
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].path = path;
|
872
|
+
Breadcrumbs.SetLast(name, path);
|
873
|
+
}
|
874
|
+
this.router.navigateByUrl(path);
|
875
|
+
}
|
876
|
+
/** */
|
877
|
+
SetSource() {
|
878
|
+
Source.Set(this._page);
|
879
|
+
}
|
880
|
+
/** */
|
881
|
+
GetSource() {
|
882
|
+
this._source = Source.Get();
|
883
|
+
}
|
884
|
+
/** */
|
885
|
+
GetPageResponse() {
|
886
|
+
this.pageResponse = Source.GetPageResponse();
|
887
|
+
}
|
888
|
+
/** */
|
889
|
+
GetNavigation() {
|
890
|
+
if (this._source) {
|
891
|
+
this.breadcrumbs = Breadcrumbs.Get().map(item => Object.assign({
|
892
|
+
page: item.page,
|
893
|
+
path: item.path,
|
894
|
+
click: this.GoBack(item.path)
|
895
|
+
}));
|
896
|
+
}
|
897
|
+
else
|
898
|
+
this.breadcrumbs = [{ page: this._page }];
|
899
|
+
}
|
900
|
+
/** */
|
901
|
+
SetGoBack() {
|
902
|
+
if (this._source) {
|
903
|
+
this.goBack = {
|
904
|
+
show: true,
|
905
|
+
path: this._source.path,
|
906
|
+
click: this.GoBack()
|
907
|
+
};
|
908
|
+
}
|
909
|
+
}
|
910
|
+
/** Navigate to previous page */
|
911
|
+
GoToSource(pageResponse = null) {
|
912
|
+
if (this._source) {
|
913
|
+
Breadcrumbs.RemoveLast();
|
914
|
+
this.SetPageResponse(pageResponse);
|
915
|
+
Tools.Sleep().then(_ => this.router.navigateByUrl(this._source.path));
|
916
|
+
}
|
917
|
+
}
|
918
|
+
;
|
919
|
+
/** */
|
920
|
+
SetPageResponse(pageResponse = null) {
|
921
|
+
if (Tools.IsNotNull(pageResponse)) {
|
922
|
+
this._preventDestroy = true;
|
923
|
+
Source.SetPageResponse(pageResponse);
|
924
|
+
}
|
925
|
+
}
|
926
|
+
;
|
927
|
+
/** */
|
928
|
+
ReloadPage() {
|
929
|
+
Breadcrumbs.RemoveLast();
|
930
|
+
setTimeout(() => window.location.reload());
|
931
|
+
}
|
932
|
+
/** */
|
933
|
+
Log(value, log = null) {
|
934
|
+
if (Tools.IsNotNull(log))
|
935
|
+
console.log({ log, value });
|
936
|
+
else
|
937
|
+
console.log(value);
|
938
|
+
}
|
939
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: Page, deps: [{ token: String }], target: i0.ɵɵFactoryTarget.Component }); }
|
940
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.12", type: Page, selector: "ng-component", ngImport: i0, template: '', isInline: true }); }
|
941
|
+
}
|
942
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: Page, decorators: [{
|
943
|
+
type: Component,
|
944
|
+
args: [{ template: '' }]
|
945
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
946
|
+
type: Inject,
|
947
|
+
args: [String]
|
948
|
+
}] }] });
|
949
|
+
|
950
|
+
class Screen {
|
951
|
+
static get WINDOW_WIDTH() {
|
952
|
+
return window.innerWidth;
|
953
|
+
}
|
954
|
+
static get WINDOW_HEIGHT() {
|
955
|
+
return window.innerHeight;
|
956
|
+
}
|
957
|
+
static get DEVICE_WIDTH() {
|
958
|
+
return window.screen.width;
|
959
|
+
}
|
960
|
+
static get DEVICE_HEIGHT() {
|
961
|
+
return window.screen.height;
|
962
|
+
}
|
963
|
+
static get BREAKPOINT() {
|
964
|
+
if (window.innerWidth < 576)
|
965
|
+
return 'xs';
|
966
|
+
else if (window.innerWidth >= 576 && window.innerWidth < 768)
|
967
|
+
return 'sm';
|
968
|
+
else if (window.innerWidth >= 768 && window.innerWidth < 992)
|
969
|
+
return 'md';
|
970
|
+
else if (window.innerWidth >= 992 && window.innerWidth < 1200)
|
971
|
+
return 'lg';
|
972
|
+
else if (window.innerWidth >= 1200 && window.innerWidth < 1400)
|
973
|
+
return 'xl';
|
974
|
+
else
|
975
|
+
return 'xxl';
|
976
|
+
}
|
977
|
+
/** */
|
978
|
+
static { this.Resize = new Observable(subscriber => {
|
979
|
+
window.addEventListener("load", () => {
|
980
|
+
window.dispatchEvent(new Event('resize'));
|
981
|
+
});
|
982
|
+
window.onresize = () => {
|
983
|
+
subscriber.next({
|
984
|
+
width: this.WINDOW_WIDTH,
|
985
|
+
height: this.WINDOW_HEIGHT,
|
986
|
+
breakpoin: this.BREAKPOINT
|
987
|
+
});
|
988
|
+
};
|
989
|
+
}); }
|
990
|
+
}
|
991
|
+
|
992
|
+
const breakpointSIGNAL = signal(Screen?.BREAKPOINT || 'xs');
|
993
|
+
|
994
|
+
const isLoadingSIG = signal(false);
|
995
|
+
|
996
|
+
const isModalOpenSIG = signal(false);
|
997
|
+
|
352
998
|
/**
|
353
999
|
* Generated bundle index. Do not edit.
|
354
1000
|
*/
|
355
1001
|
|
356
|
-
export { CONTROL_VALUE, CoerAlert, ComponentsModule, ControlValue };
|
1002
|
+
export { Breadcrumbs, CONTROL_VALUE, CoerAlert, ComponentsModule, ControlValue, DateTime, Files, Page, Screen, Source, Tools, breakpointSIGNAL, isLoadingSIG, isModalOpenSIG };
|
357
1003
|
//# sourceMappingURL=coer-elements.mjs.map
|