coer-elements 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/Signals/{index.d.ts → index.ts} +3 -3
- package/Signals/src/breakpoint.signal.ts +3 -0
- package/Signals/src/isLoading.signal.ts +2 -0
- package/Signals/src/isModalOpen.signal.ts +2 -0
- package/Tools/{index.d.ts → index.ts} +8 -8
- package/Tools/src/Breadcrumbs.class.ts +84 -0
- package/Tools/src/ControlValue.ts +63 -0
- package/Tools/src/DateTime.class.ts +27 -0
- package/Tools/src/Files.class.ts +119 -0
- package/Tools/src/Page.class.ts +195 -0
- package/Tools/src/Screen.class.ts +50 -0
- package/Tools/src/Source.class.ts +106 -0
- package/Tools/src/Tools.ts +217 -0
- package/components/index.ts +2 -0
- package/components/src/coer-alert/coer-alert.component.html +56 -0
- package/components/src/coer-alert/coer-alert.component.scss +100 -0
- package/components/src/coer-alert/coer-alert.component.ts +249 -0
- package/components/src/components.module.ts +97 -0
- package/esm2022/index.mjs +2 -4
- package/fesm2022/coer-elements.mjs +0 -1006
- package/fesm2022/coer-elements.mjs.map +1 -1
- package/index.d.ts +1 -3
- package/package.json +14 -1
- package/styles/index.css +249 -17
- package/styles/index.scss +98 -2
- package/README.md +0 -24
- package/Signals/src/breakpoint.signal.d.ts +0 -1
- package/Signals/src/isLoading.signal.d.ts +0 -1
- package/Signals/src/isModalOpen.signal.d.ts +0 -1
- package/Tools/src/Breadcrumbs.class.d.ts +0 -18
- package/Tools/src/ControlValue.d.ts +0 -23
- package/Tools/src/DateTime.class.d.ts +0 -11
- package/Tools/src/Files.class.d.ts +0 -16
- package/Tools/src/Page.class.d.ts +0 -66
- package/Tools/src/Screen.class.d.ts +0 -11
- package/Tools/src/Source.class.d.ts +0 -20
- package/Tools/src/Tools.d.ts +0 -33
- package/components/index.d.ts +0 -2
- package/components/src/coer-alert/coer-alert.component.d.ts +0 -23
- package/components/src/components.module.d.ts +0 -10
- package/esm2022/Signals/index.mjs +0 -4
- package/esm2022/Signals/src/breakpoint.signal.mjs +0 -4
- package/esm2022/Signals/src/isLoading.signal.mjs +0 -3
- package/esm2022/Signals/src/isModalOpen.signal.mjs +0 -3
- package/esm2022/Tools/index.mjs +0 -9
- package/esm2022/Tools/src/Breadcrumbs.class.mjs +0 -63
- package/esm2022/Tools/src/ControlValue.mjs +0 -44
- package/esm2022/Tools/src/DateTime.class.mjs +0 -22
- package/esm2022/Tools/src/Files.class.mjs +0 -93
- package/esm2022/Tools/src/Page.class.mjs +0 -160
- package/esm2022/Tools/src/Screen.class.mjs +0 -43
- package/esm2022/Tools/src/Source.class.mjs +0 -79
- package/esm2022/Tools/src/Tools.mjs +0 -200
- package/esm2022/components/index.mjs +0 -3
- package/esm2022/components/src/coer-alert/coer-alert.component.mjs +0 -227
- package/esm2022/components/src/components.module.mjs +0 -92
- package/esm2022/interfaces/index.mjs +0 -7
- package/esm2022/interfaces/src/IAppSource.interface.mjs +0 -2
- package/esm2022/interfaces/src/IBreadcrumb.interface.mjs +0 -2
- package/esm2022/interfaces/src/ICoerRef.interface.mjs +0 -2
- package/esm2022/interfaces/src/IGoBack.interface.mjs +0 -2
- package/esm2022/interfaces/src/IPatch.interface.mjs +0 -2
- package/esm2022/interfaces/src/IScreenSize.interface.mjs +0 -2
- package/interfaces/index.d.ts +0 -6
- package/interfaces/src/IAppSource.interface.d.ts +0 -4
- package/interfaces/src/IBreadcrumb.interface.d.ts +0 -6
- package/interfaces/src/ICoerRef.interface.d.ts +0 -10
- package/interfaces/src/IGoBack.interface.d.ts +0 -6
- package/interfaces/src/IPatch.interface.d.ts +0 -5
- package/interfaces/src/IScreenSize.interface.d.ts +0 -5
- package/styles/coer.scss +0 -96
@@ -1,3 +1,3 @@
|
|
1
|
-
export * from './src/breakpoint.signal';
|
2
|
-
export * from './src/isLoading.signal';
|
3
|
-
export * from './src/isModalOpen.signal';
|
1
|
+
export * from './src/breakpoint.signal';
|
2
|
+
export * from './src/isLoading.signal';
|
3
|
+
export * from './src/isModalOpen.signal';
|
@@ -1,8 +1,8 @@
|
|
1
|
-
export * from './src/Breadcrumbs.class';
|
2
|
-
export * from './src/ControlValue';
|
3
|
-
export * from './src/DateTime.class';
|
4
|
-
export * from './src/Files.class';
|
5
|
-
export * from './src/Page.class';
|
6
|
-
export * from './src/Screen.class';
|
7
|
-
export * from './src/Source.class';
|
8
|
-
export * from './src/Tools';
|
1
|
+
export * from './src/Breadcrumbs.class';
|
2
|
+
export * from './src/ControlValue';
|
3
|
+
export * from './src/DateTime.class';
|
4
|
+
export * from './src/Files.class';
|
5
|
+
export * from './src/Page.class';
|
6
|
+
export * from './src/Screen.class';
|
7
|
+
export * from './src/Source.class';
|
8
|
+
export * from './src/Tools';
|
@@ -0,0 +1,84 @@
|
|
1
|
+
import { IAppSource } from "../../interfaces";
|
2
|
+
import { Tools } from '../';
|
3
|
+
|
4
|
+
export class Breadcrumbs {
|
5
|
+
|
6
|
+
private static readonly storage = 'COER-System';
|
7
|
+
|
8
|
+
/** */
|
9
|
+
public static Add(page: string, path: string): void {
|
10
|
+
const breadcrumbs = this.Get();
|
11
|
+
const paths = breadcrumbs.map(item => item.path);
|
12
|
+
|
13
|
+
if (!paths.includes(path)) {
|
14
|
+
breadcrumbs.push({ page, path });
|
15
|
+
this.Save(breadcrumbs);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
|
20
|
+
/** */
|
21
|
+
public static Get(): IAppSource[] {
|
22
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
23
|
+
|
24
|
+
if (storage) {
|
25
|
+
storage = JSON.parse(storage);
|
26
|
+
|
27
|
+
if (storage.hasOwnProperty('breadcrumbs')) {
|
28
|
+
return Tools.BreakReference(storage.breadcrumbs);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
return [];
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
/** Source */
|
37
|
+
public static GetFirst(): IAppSource | null {
|
38
|
+
const breadcrumbs = this.Get();
|
39
|
+
return (breadcrumbs.length > 0) ? breadcrumbs.shift()! : null;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
/** */
|
44
|
+
public static Save(breadcrumbs: IAppSource[]): void {
|
45
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
46
|
+
if (storage) storage = JSON.parse(storage);
|
47
|
+
storage = Object.assign({}, storage, { breadcrumbs });
|
48
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
/** */
|
53
|
+
public static Remove(path: string): void {
|
54
|
+
let breadcrumbs = this.Get();
|
55
|
+
const index = breadcrumbs.findIndex(x => x.path.toLowerCase().trim() === path.toLowerCase().trim());
|
56
|
+
|
57
|
+
if (index >= 0) {
|
58
|
+
breadcrumbs = Tools.BreakReference(breadcrumbs).splice(0, index + 1);
|
59
|
+
this.Save(breadcrumbs);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
/** */
|
65
|
+
public static SetLast(page: string, path: string): void {
|
66
|
+
const breadcrumbs = this.Get();
|
67
|
+
|
68
|
+
if (breadcrumbs.length > 0) {
|
69
|
+
breadcrumbs[breadcrumbs.length - 1] = { page, path };
|
70
|
+
this.Save(breadcrumbs);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/** */
|
76
|
+
public static RemoveLast(): void {
|
77
|
+
const breadcrumbs = this.Get();
|
78
|
+
|
79
|
+
if (breadcrumbs.length > 0) {
|
80
|
+
breadcrumbs.pop();
|
81
|
+
this.Save(breadcrumbs);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from "@angular/forms";
|
2
|
+
import { forwardRef } from "@angular/core";
|
3
|
+
|
4
|
+
export const CONTROL_VALUE = <T>(component: T) => {
|
5
|
+
return {
|
6
|
+
provide: NG_VALUE_ACCESSOR,
|
7
|
+
useExisting: forwardRef(() => component),
|
8
|
+
multi: true
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
|
13
|
+
export class ControlValue implements ControlValueAccessor {
|
14
|
+
|
15
|
+
//Variables
|
16
|
+
protected _value: any;
|
17
|
+
private _isTouched: boolean = false;
|
18
|
+
protected _UpdateValue!: Function;
|
19
|
+
private _IsTouched!: Function;
|
20
|
+
|
21
|
+
|
22
|
+
public get isTouched() {
|
23
|
+
return this._isTouched;
|
24
|
+
}
|
25
|
+
|
26
|
+
|
27
|
+
/** */
|
28
|
+
protected SetValue(value: any): void {
|
29
|
+
if(typeof this._UpdateValue === 'function') {
|
30
|
+
this._UpdateValue(value);
|
31
|
+
}
|
32
|
+
|
33
|
+
this._value = value;
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
/** */
|
38
|
+
public SetTouched(isTouched: boolean): void {
|
39
|
+
if(typeof this._IsTouched === 'function') {
|
40
|
+
this._IsTouched(isTouched);
|
41
|
+
}
|
42
|
+
|
43
|
+
this._isTouched = isTouched;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
/** */
|
48
|
+
public writeValue(value: any): void {
|
49
|
+
this._value = value;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
/** */
|
54
|
+
public registerOnChange(callback: Function): void {
|
55
|
+
this._UpdateValue = callback;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/** */
|
60
|
+
public registerOnTouched(callback: Function): void {
|
61
|
+
this._IsTouched = callback;
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import moment from "moment";
|
2
|
+
|
3
|
+
export class DateTime {
|
4
|
+
/** Get UTC Offset */
|
5
|
+
public static GetUTCOffset(): number {
|
6
|
+
return moment().utcOffset();
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
/** Convert UTC Date to Local Zone */
|
11
|
+
public static ToLocalZone(utcDate: string | Date | moment.Moment): string {
|
12
|
+
return moment(utcDate).add(DateTime.GetUTCOffset(), 'minutes').format('YYYY-MM-DD HH:mm:ss');
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
/** Convert Local Zone Date to UTC */
|
17
|
+
public static ToUTC(utcDate: string | Date | moment.Moment): string {
|
18
|
+
return moment(utcDate).subtract(DateTime.GetUTCOffset(), 'minutes').format('YYYY-MM-DD HH:mm:ss');
|
19
|
+
}
|
20
|
+
|
21
|
+
|
22
|
+
/** DD MMM YYYY */
|
23
|
+
public static GetDateFormat(date: string | Date | moment.Moment): string {
|
24
|
+
if ((typeof date === 'string')) date = date.replaceAll('/', '-');
|
25
|
+
return moment(date).parseZone().local(true).format('DD MMM YYYY');
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
import { Tools } from "../";
|
2
|
+
import * as XLSX from 'xlsx';
|
3
|
+
|
4
|
+
export class Files {
|
5
|
+
public static readonly EXCEL_EXTENSIONS: string[] = ['xls', 'xlsx', 'csv'];
|
6
|
+
|
7
|
+
/** Get Extension File */
|
8
|
+
public static GetExtension(file: File): string | null {
|
9
|
+
const fileName = file.name;
|
10
|
+
|
11
|
+
if (fileName.includes('.')) {
|
12
|
+
let worlds = fileName.split('.') as string[];
|
13
|
+
|
14
|
+
if (worlds.length > 0) {
|
15
|
+
let extension = worlds.pop()!;
|
16
|
+
extension = extension.trim().toLowerCase();
|
17
|
+
if (extension.length > 0) return extension;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
return null;
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
/** Is Excel File */
|
26
|
+
public static IsExcel(file: File): boolean {
|
27
|
+
const EXTENSION = Files.GetExtension(file);
|
28
|
+
|
29
|
+
return Tools.IsNotNull(EXTENSION)
|
30
|
+
? this.EXCEL_EXTENSIONS.includes(EXTENSION!)
|
31
|
+
: false;
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
/** Read excel file */
|
36
|
+
public static ReadExcel<T>(file: File) {
|
37
|
+
return new Promise<{ columns: string[]; rows: T[]; }>(Resolve => {
|
38
|
+
let columns: string[] = [];
|
39
|
+
let rows: T[] = [];
|
40
|
+
|
41
|
+
const reader = new FileReader();
|
42
|
+
reader.readAsArrayBuffer(file);
|
43
|
+
|
44
|
+
reader.onload = () => {
|
45
|
+
const dataBytes = new Uint8Array(reader.result as any);
|
46
|
+
|
47
|
+
if (dataBytes) {
|
48
|
+
const workbook = XLSX.read(dataBytes, {});
|
49
|
+
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
50
|
+
let dataSheet: any[] = XLSX.utils.sheet_to_json(sheet, {
|
51
|
+
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']
|
52
|
+
});
|
53
|
+
|
54
|
+
//Get Headers
|
55
|
+
for(const column in dataSheet[0]) {
|
56
|
+
columns.push(Tools.FirstCharToLower(String(dataSheet[0][column]).replaceAll(' ', '')));
|
57
|
+
}
|
58
|
+
|
59
|
+
//Get Rows
|
60
|
+
rows = XLSX.utils.sheet_to_json(sheet, { header: columns });
|
61
|
+
rows.shift();
|
62
|
+
|
63
|
+
rows = rows.map(row => {
|
64
|
+
const item = Tools.BreakReference<any>(row);
|
65
|
+
delete item['__rowNum__'];
|
66
|
+
return item;
|
67
|
+
});
|
68
|
+
}
|
69
|
+
|
70
|
+
Resolve({ columns, rows });
|
71
|
+
}
|
72
|
+
|
73
|
+
reader.onerror = () => { Resolve({ columns, rows }) }
|
74
|
+
});
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/** Export to excel file */
|
79
|
+
public static ExportExcel<T>(data: T[], fileName: string = 'coer_report', sheetName: string = 'Sheet1') {
|
80
|
+
sheetName = Tools.CleanUpBlanks(sheetName);
|
81
|
+
fileName = Tools.CleanUpBlanks(fileName);
|
82
|
+
|
83
|
+
if(fileName.endsWith('.xls') || fileName.endsWith('.xlsx') || fileName.endsWith('.csv')) {
|
84
|
+
if (fileName.includes('.xls')) {
|
85
|
+
fileName = fileName.replaceAll('.xls', '.xlsx');
|
86
|
+
}
|
87
|
+
|
88
|
+
if (fileName.includes('.csv')) {
|
89
|
+
fileName = fileName.replaceAll('.csv', '.xlsx');
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
else {
|
94
|
+
fileName += '.xlsx';
|
95
|
+
}
|
96
|
+
|
97
|
+
const WORK_SHEET = XLSX.utils.json_to_sheet(data);
|
98
|
+
const WORK_BOOK = XLSX.utils.book_new();
|
99
|
+
XLSX.utils.book_append_sheet(WORK_BOOK, WORK_SHEET, 'Sheet1');
|
100
|
+
XLSX.writeFile(WORK_BOOK, fileName);
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
/** Convert file to string base64 */
|
105
|
+
public static ConvertToBase64(file: File) {
|
106
|
+
return new Promise<string>(Resolve => {
|
107
|
+
const reader = new FileReader();
|
108
|
+
reader.readAsDataURL(file);
|
109
|
+
|
110
|
+
reader.onload = () => {
|
111
|
+
Resolve(reader.result?.toString() || '');
|
112
|
+
}
|
113
|
+
|
114
|
+
reader.onerror = () => {
|
115
|
+
Resolve('');
|
116
|
+
}
|
117
|
+
});
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,195 @@
|
|
1
|
+
import { ActivatedRoute, Router } from '@angular/router';
|
2
|
+
import { AfterViewInit, Component, Inject, inject, OnDestroy } from '@angular/core';
|
3
|
+
import { IAppSource, IBreadcrumb, IGoBack } from '../../interfaces';
|
4
|
+
import { CoerAlert } from '../../components';
|
5
|
+
import { Breadcrumbs, Source, Tools } from '../';
|
6
|
+
|
7
|
+
@Component({ template: '' })
|
8
|
+
export class Page implements AfterViewInit, OnDestroy {
|
9
|
+
|
10
|
+
//Injection
|
11
|
+
protected readonly alert = inject(CoerAlert);
|
12
|
+
protected readonly router = inject(Router);
|
13
|
+
private readonly activatedRoute = inject(ActivatedRoute);
|
14
|
+
|
15
|
+
/** */
|
16
|
+
protected isUpdate: boolean = false;
|
17
|
+
|
18
|
+
/** */
|
19
|
+
protected isLoading: boolean = false;
|
20
|
+
|
21
|
+
/** */
|
22
|
+
protected isReady: boolean = false;
|
23
|
+
|
24
|
+
/** */
|
25
|
+
protected enableAnimations: boolean = false;
|
26
|
+
|
27
|
+
/** */
|
28
|
+
protected routeParams: any;
|
29
|
+
|
30
|
+
/** */
|
31
|
+
protected queryParams: any;
|
32
|
+
|
33
|
+
/** */
|
34
|
+
protected breadcrumbs: IBreadcrumb[] = [];
|
35
|
+
|
36
|
+
/** */
|
37
|
+
protected pageResponse: any = null;
|
38
|
+
|
39
|
+
/** */
|
40
|
+
protected goBack: IGoBack = { show: false };
|
41
|
+
|
42
|
+
//Private Variables
|
43
|
+
private _page: string = '';
|
44
|
+
private _source: IAppSource | null = null;
|
45
|
+
private _preventDestroy: boolean = false;
|
46
|
+
|
47
|
+
|
48
|
+
constructor(@Inject(String) page: string) {
|
49
|
+
this.SetPageName(page);
|
50
|
+
this.SetSource();
|
51
|
+
this.GetSource();
|
52
|
+
this.GetNavigation();
|
53
|
+
this.SetGoBack();
|
54
|
+
this.GetPageResponse();
|
55
|
+
}
|
56
|
+
|
57
|
+
ngAfterViewInit() {
|
58
|
+
this.routeParams = this.activatedRoute.snapshot.params;
|
59
|
+
this.queryParams = this.activatedRoute.snapshot.queryParams;
|
60
|
+
|
61
|
+
setTimeout(() => {
|
62
|
+
this.isReady = true;
|
63
|
+
this.RunPage();
|
64
|
+
setTimeout(() => { this.enableAnimations = true }, 1000);
|
65
|
+
});
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
ngOnDestroy() {
|
70
|
+
if (!this._preventDestroy) Source.ClearPageResponse();
|
71
|
+
}
|
72
|
+
|
73
|
+
/** Main method. Starts after ngAfterViewInit() */
|
74
|
+
protected RunPage(): void {};
|
75
|
+
|
76
|
+
|
77
|
+
/** Rename the last breadcrumb and update the url id */
|
78
|
+
protected SetPageName(name: string, id: string | number | null = null): void {
|
79
|
+
this._page = name;
|
80
|
+
|
81
|
+
let path = this.router.url;
|
82
|
+
if (path.includes('?')) path = path.split('?')[0];
|
83
|
+
|
84
|
+
if (id) {
|
85
|
+
const PATH_ARRAY = path.split('/');
|
86
|
+
const PATH_ID = Tools.BreakReference(PATH_ARRAY).pop();
|
87
|
+
if (PATH_ID) {
|
88
|
+
PATH_ARRAY[PATH_ARRAY.length - 1] = String(id);
|
89
|
+
path = PATH_ARRAY.join('/');
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
if (this.breadcrumbs.length > 0) {
|
94
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].page = name;
|
95
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].path = path;
|
96
|
+
Breadcrumbs.SetLast(name, path);
|
97
|
+
}
|
98
|
+
|
99
|
+
this.router.navigateByUrl(path)
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/** */
|
104
|
+
private SetSource(): void {
|
105
|
+
Source.Set(this._page);
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
/** */
|
110
|
+
private GetSource(): void {
|
111
|
+
this._source = Source.Get();
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
/** */
|
116
|
+
protected GetPageResponse(): void {
|
117
|
+
this.pageResponse = Source.GetPageResponse();
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
/** */
|
122
|
+
private GetNavigation(): void {
|
123
|
+
if (this._source) {
|
124
|
+
this.breadcrumbs = Breadcrumbs.Get().map(item => Object.assign({
|
125
|
+
page: item.page,
|
126
|
+
path: item.path,
|
127
|
+
click: this.GoBack(item.path)
|
128
|
+
}));
|
129
|
+
}
|
130
|
+
|
131
|
+
else this.breadcrumbs = [{ page: this._page }];
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
/** */
|
136
|
+
private SetGoBack(): void {
|
137
|
+
if (this._source) {
|
138
|
+
this.goBack = {
|
139
|
+
show: true,
|
140
|
+
path: this._source.path,
|
141
|
+
click: this.GoBack()
|
142
|
+
};
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
|
147
|
+
/** */
|
148
|
+
private GoBack = (path?: string) => (() => {
|
149
|
+
if (path) Breadcrumbs.Remove(path);
|
150
|
+
else Breadcrumbs.RemoveLast();
|
151
|
+
});
|
152
|
+
|
153
|
+
|
154
|
+
/** Navigate to previous page */
|
155
|
+
protected GoToSource<T>(pageResponse: T | null = null): void {
|
156
|
+
if(this._source) {
|
157
|
+
Breadcrumbs.RemoveLast();
|
158
|
+
this.SetPageResponse(pageResponse);
|
159
|
+
Tools.Sleep().then(_ => this.router.navigateByUrl(this._source!.path));
|
160
|
+
}
|
161
|
+
};
|
162
|
+
|
163
|
+
|
164
|
+
/** */
|
165
|
+
protected SetPageResponse<T>(pageResponse: T | null = null): void {
|
166
|
+
if (Tools.IsNotNull(pageResponse)) {
|
167
|
+
this._preventDestroy = true;
|
168
|
+
Source.SetPageResponse(pageResponse);
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
|
173
|
+
/** */
|
174
|
+
protected ReloadPage(): void {
|
175
|
+
Breadcrumbs.RemoveLast();
|
176
|
+
Tools.Sleep().then(_ => window.location.reload());
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
/** */
|
181
|
+
protected Log(value: any, log: string | null = null): void {
|
182
|
+
if (Tools.IsNotNull(log)) console.log({ log, value });
|
183
|
+
else console.log(value);
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
/** Returns true if the value is null or undefined, false otherwise */
|
188
|
+
protected IsNotNull = Tools.IsNotNull;
|
189
|
+
|
190
|
+
/** Returns true if the value is null or undefined, false otherwise */
|
191
|
+
protected IsNull = Tools.IsNull;
|
192
|
+
|
193
|
+
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
194
|
+
protected IsOnlyWhiteSpace = Tools.IsOnlyWhiteSpace;
|
195
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import { IScreenSize } from "../../interfaces";
|
2
|
+
import { Observable } from "rxjs";
|
3
|
+
|
4
|
+
export class Screen {
|
5
|
+
|
6
|
+
public static get WINDOW_WIDTH(): number {
|
7
|
+
return window.innerWidth;
|
8
|
+
}
|
9
|
+
|
10
|
+
|
11
|
+
public static get WINDOW_HEIGHT(): number {
|
12
|
+
return window.innerHeight;
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
public static get DEVICE_WIDTH(): number {
|
17
|
+
return window.screen.width;
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
public static get DEVICE_HEIGHT(): number {
|
22
|
+
return window.screen.height;
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
public static get BREAKPOINT(): 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' {
|
27
|
+
if (window.innerWidth < 576) return 'xs';
|
28
|
+
else if (window.innerWidth >= 576 && window.innerWidth < 768) return 'sm';
|
29
|
+
else if (window.innerWidth >= 768 && window.innerWidth < 992) return 'md';
|
30
|
+
else if (window.innerWidth >= 992 && window.innerWidth < 1200) return 'lg';
|
31
|
+
else if (window.innerWidth >= 1200 && window.innerWidth < 1400) return 'xl';
|
32
|
+
else return 'xxl';
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
/** */
|
37
|
+
public static Resize = new Observable<IScreenSize>(subscriber => {
|
38
|
+
window.addEventListener("load", () => {
|
39
|
+
window.dispatchEvent(new Event('resize'));
|
40
|
+
});
|
41
|
+
|
42
|
+
window.onresize = () => {
|
43
|
+
subscriber.next({
|
44
|
+
width: window.innerWidth,
|
45
|
+
height: window.innerHeight,
|
46
|
+
breakpoin: this.BREAKPOINT
|
47
|
+
});
|
48
|
+
}
|
49
|
+
});
|
50
|
+
}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
import { Router } from '@angular/router';
|
2
|
+
import { inject } from "@angular/core";
|
3
|
+
import { IAppSource } from '../../interfaces';
|
4
|
+
import { Breadcrumbs, Tools } from '../../Tools';
|
5
|
+
|
6
|
+
export class Source {
|
7
|
+
|
8
|
+
private static readonly storage = 'COER-System';
|
9
|
+
|
10
|
+
/** */
|
11
|
+
public static Set(page: string): void {
|
12
|
+
const ROUTER = inject(Router);
|
13
|
+
|
14
|
+
let path = ROUTER.url;
|
15
|
+
if (path.includes('?')) path = path.split('?')[0];
|
16
|
+
|
17
|
+
Breadcrumbs.Add(page, path);
|
18
|
+
|
19
|
+
const breadcrumbs = Breadcrumbs.Get();
|
20
|
+
|
21
|
+
if(breadcrumbs.length >= 2) {
|
22
|
+
breadcrumbs.pop();
|
23
|
+
const breadcrumb = breadcrumbs.pop()!;
|
24
|
+
this.Save({ page: breadcrumb.page, path: breadcrumb.path });
|
25
|
+
}
|
26
|
+
|
27
|
+
else this.Save(null);
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
/** */
|
32
|
+
private static Save(source: IAppSource | null): void {
|
33
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
34
|
+
if (storage) storage = JSON.parse(storage);
|
35
|
+
storage = Object.assign({}, storage, { source });
|
36
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
/** */
|
41
|
+
public static Get(): IAppSource | null {
|
42
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
43
|
+
|
44
|
+
if (storage) {
|
45
|
+
storage = JSON.parse(storage);
|
46
|
+
|
47
|
+
if (storage.hasOwnProperty('source')) {
|
48
|
+
return storage.source;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
return null;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
/** */
|
57
|
+
public static GetRoot(): IAppSource | null {
|
58
|
+
const breadcrumbs = Breadcrumbs.Get();
|
59
|
+
return (breadcrumbs.length > 0) ? breadcrumbs.shift()! : null;
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
/** */
|
64
|
+
public static SetPageResponse<T>(pageResponse: T): void {
|
65
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
66
|
+
storage = JSON.parse(storage);
|
67
|
+
storage = Object.assign({}, storage, { pageResponse });
|
68
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
/** */
|
73
|
+
public static GetPageResponse<T>(): T | null {
|
74
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
75
|
+
|
76
|
+
if (storage) {
|
77
|
+
storage = JSON.parse(storage);
|
78
|
+
|
79
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
80
|
+
return Tools.BreakReference(storage.pageResponse);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
return null;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
/** */
|
89
|
+
public static ClearPageResponse(): void {
|
90
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
91
|
+
storage = JSON.parse(storage);
|
92
|
+
|
93
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
94
|
+
delete storage.pageResponse;
|
95
|
+
}
|
96
|
+
|
97
|
+
storage = Object.assign({}, storage);
|
98
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
/** Clear Source */
|
103
|
+
public static Reset(): void {
|
104
|
+
sessionStorage.removeItem(this.storage);
|
105
|
+
}
|
106
|
+
}
|