coer-elements 1.0.7 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/Tools/Breadcrumbs.class.ts +84 -0
- package/Tools/ControlValue.ts +63 -0
- package/Tools/Page.class.ts +197 -0
- package/Tools/Source.class.ts +107 -0
- package/Tools/Tools.ts +3 -3
- package/index.ts +6 -2
- package/interfaces/index.ts +36 -0
- package/package.json +3 -1
@@ -0,0 +1,84 @@
|
|
1
|
+
import { IAppSource } from "../interfaces";
|
2
|
+
import { Tools } from './Tools';
|
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,197 @@
|
|
1
|
+
import { AfterViewInit, Component, Inject, inject, OnDestroy } from '@angular/core';
|
2
|
+
import { Breadcrumbs } from "./Breadcrumbs.class";
|
3
|
+
import { Source } from './Source.class';
|
4
|
+
//import { CoerAlert } from 'src/app/shared/components/coer-alert/coer-alert.component';
|
5
|
+
import { IAppSource, IBreadcrumb, IGoBack } from '../interfaces';
|
6
|
+
import { ActivatedRoute, Router } from '@angular/router';
|
7
|
+
import { Tools } from './Tools';
|
8
|
+
|
9
|
+
@Component({ template: '' })
|
10
|
+
export class Page implements AfterViewInit, OnDestroy {
|
11
|
+
|
12
|
+
//Injection
|
13
|
+
//protected readonly alert = inject(CoerAlert);
|
14
|
+
protected readonly router = inject(Router);
|
15
|
+
private readonly activatedRoute = inject(ActivatedRoute);
|
16
|
+
|
17
|
+
/** */
|
18
|
+
protected isUpdate: boolean = false;
|
19
|
+
|
20
|
+
/** */
|
21
|
+
protected isLoading: boolean = false;
|
22
|
+
|
23
|
+
/** */
|
24
|
+
protected isReady: boolean = false;
|
25
|
+
|
26
|
+
/** */
|
27
|
+
protected enableAnimations: boolean = false;
|
28
|
+
|
29
|
+
/** */
|
30
|
+
protected routeParams: any;
|
31
|
+
|
32
|
+
/** */
|
33
|
+
protected queryParams: any;
|
34
|
+
|
35
|
+
/** */
|
36
|
+
protected breadcrumbs: IBreadcrumb[] = [];
|
37
|
+
|
38
|
+
/** */
|
39
|
+
protected pageResponse: any = null;
|
40
|
+
|
41
|
+
/** */
|
42
|
+
protected goBack: IGoBack = { show: false };
|
43
|
+
|
44
|
+
//Private Variables
|
45
|
+
private _page: string = '';
|
46
|
+
private _source: IAppSource | null = null;
|
47
|
+
private _preventDestroy: boolean = false;
|
48
|
+
|
49
|
+
|
50
|
+
constructor(@Inject(String) page: string) {
|
51
|
+
this.SetPageName(page);
|
52
|
+
this.SetSource();
|
53
|
+
this.GetSource();
|
54
|
+
this.GetNavigation();
|
55
|
+
this.SetGoBack();
|
56
|
+
this.GetPageResponse();
|
57
|
+
}
|
58
|
+
|
59
|
+
ngAfterViewInit() {
|
60
|
+
this.routeParams = this.activatedRoute.snapshot.params;
|
61
|
+
this.queryParams = this.activatedRoute.snapshot.queryParams;
|
62
|
+
|
63
|
+
setTimeout(() => {
|
64
|
+
this.isReady = true;
|
65
|
+
this.RunPage();
|
66
|
+
setTimeout(() => { this.enableAnimations = true }, 1000);
|
67
|
+
});
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
ngOnDestroy() {
|
72
|
+
if (!this._preventDestroy) Source.ClearPageResponse();
|
73
|
+
}
|
74
|
+
|
75
|
+
/** Main method. Starts after ngAfterViewInit() */
|
76
|
+
protected RunPage(): void {};
|
77
|
+
|
78
|
+
|
79
|
+
/** Rename the last breadcrumb and update the url id */
|
80
|
+
protected SetPageName(name: string, id: string | number | null = null): void {
|
81
|
+
this._page = name;
|
82
|
+
|
83
|
+
let path = this.router.url;
|
84
|
+
if (path.includes('?')) path = path.split('?')[0];
|
85
|
+
|
86
|
+
if (id) {
|
87
|
+
const PATH_ARRAY = path.split('/');
|
88
|
+
const PATH_ID = Tools.BreakReference(PATH_ARRAY).pop();
|
89
|
+
if (PATH_ID) {
|
90
|
+
PATH_ARRAY[PATH_ARRAY.length - 1] = String(id);
|
91
|
+
path = PATH_ARRAY.join('/');
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
if (this.breadcrumbs.length > 0) {
|
96
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].page = name;
|
97
|
+
this.breadcrumbs[this.breadcrumbs.length - 1].path = path;
|
98
|
+
Breadcrumbs.SetLast(name, path);
|
99
|
+
}
|
100
|
+
|
101
|
+
this.router.navigateByUrl(path)
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
/** */
|
106
|
+
private SetSource(): void {
|
107
|
+
Source.Set(this._page);
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
/** */
|
112
|
+
private GetSource(): void {
|
113
|
+
this._source = Source.Get();
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
/** */
|
118
|
+
protected GetPageResponse(): void {
|
119
|
+
this.pageResponse = Source.GetPageResponse();
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
/** */
|
124
|
+
private GetNavigation(): void {
|
125
|
+
if (this._source) {
|
126
|
+
this.breadcrumbs = Breadcrumbs.Get().map(item => Object.assign({
|
127
|
+
page: item.page,
|
128
|
+
path: item.path,
|
129
|
+
click: this.GoBack(item.path)
|
130
|
+
}));
|
131
|
+
}
|
132
|
+
|
133
|
+
else this.breadcrumbs = [{ page: this._page }];
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
/** */
|
138
|
+
private SetGoBack(): void {
|
139
|
+
if (this._source) {
|
140
|
+
this.goBack = {
|
141
|
+
show: true,
|
142
|
+
path: this._source.path,
|
143
|
+
click: this.GoBack()
|
144
|
+
};
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/** */
|
150
|
+
private GoBack = (path?: string) => (() => {
|
151
|
+
if (path) Breadcrumbs.Remove(path);
|
152
|
+
else Breadcrumbs.RemoveLast();
|
153
|
+
});
|
154
|
+
|
155
|
+
|
156
|
+
/** Navigate to previous page */
|
157
|
+
protected GoToSource<T>(pageResponse: T | null = null): void {
|
158
|
+
if(this._source) {
|
159
|
+
Breadcrumbs.RemoveLast();
|
160
|
+
this.SetPageResponse(pageResponse);
|
161
|
+
Tools.Sleep().then(_ => this.router.navigateByUrl(this._source!.path));
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
|
166
|
+
/** */
|
167
|
+
protected SetPageResponse<T>(pageResponse: T | null = null): void {
|
168
|
+
if (Tools.IsNotNull(pageResponse)) {
|
169
|
+
this._preventDestroy = true;
|
170
|
+
Source.SetPageResponse(pageResponse);
|
171
|
+
}
|
172
|
+
};
|
173
|
+
|
174
|
+
|
175
|
+
/** */
|
176
|
+
protected ReloadPage(): void {
|
177
|
+
Breadcrumbs.RemoveLast();
|
178
|
+
Tools.Sleep().then(_ => window.location.reload());
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
/** */
|
183
|
+
protected Log(value: any, log: string | null = null): void {
|
184
|
+
if (Tools.IsNotNull(log)) console.log({ log, value });
|
185
|
+
else console.log(value);
|
186
|
+
}
|
187
|
+
|
188
|
+
|
189
|
+
/** Returns true if the value is null or undefined, false otherwise */
|
190
|
+
protected IsNotNull = Tools.IsNotNull;
|
191
|
+
|
192
|
+
/** Returns true if the value is null or undefined, false otherwise */
|
193
|
+
protected IsNull = Tools.IsNull;
|
194
|
+
|
195
|
+
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
196
|
+
protected IsOnlyWhiteSpace = Tools.IsOnlyWhiteSpace;
|
197
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { Breadcrumbs } from "./Breadcrumbs.class";
|
2
|
+
import { IAppSource } from '../interfaces';
|
3
|
+
import { Router } from '@angular/router';
|
4
|
+
import { inject } from "@angular/core";
|
5
|
+
import { Tools } from './Tools';
|
6
|
+
|
7
|
+
export class Source {
|
8
|
+
|
9
|
+
private static readonly storage = 'COER-System';
|
10
|
+
|
11
|
+
/** */
|
12
|
+
public static Set(page: string): void {
|
13
|
+
const ROUTER = inject(Router);
|
14
|
+
|
15
|
+
let path = ROUTER.url;
|
16
|
+
if (path.includes('?')) path = path.split('?')[0];
|
17
|
+
|
18
|
+
Breadcrumbs.Add(page, path);
|
19
|
+
|
20
|
+
const breadcrumbs = Breadcrumbs.Get();
|
21
|
+
|
22
|
+
if(breadcrumbs.length >= 2) {
|
23
|
+
breadcrumbs.pop();
|
24
|
+
const breadcrumb = breadcrumbs.pop()!;
|
25
|
+
this.Save({ page: breadcrumb.page, path: breadcrumb.path });
|
26
|
+
}
|
27
|
+
|
28
|
+
else this.Save(null);
|
29
|
+
}
|
30
|
+
|
31
|
+
|
32
|
+
/** */
|
33
|
+
private static Save(source: IAppSource | null): void {
|
34
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
35
|
+
if (storage) storage = JSON.parse(storage);
|
36
|
+
storage = Object.assign({}, storage, { source });
|
37
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
/** */
|
42
|
+
public static Get(): IAppSource | null {
|
43
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
44
|
+
|
45
|
+
if (storage) {
|
46
|
+
storage = JSON.parse(storage);
|
47
|
+
|
48
|
+
if (storage.hasOwnProperty('source')) {
|
49
|
+
return storage.source;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
return null;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/** */
|
58
|
+
public static GetRoot(): IAppSource | null {
|
59
|
+
const breadcrumbs = Breadcrumbs.Get();
|
60
|
+
return (breadcrumbs.length > 0) ? breadcrumbs.shift()! : null;
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
/** */
|
65
|
+
public static SetPageResponse<T>(pageResponse: T): void {
|
66
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
67
|
+
storage = JSON.parse(storage);
|
68
|
+
storage = Object.assign({}, storage, { pageResponse });
|
69
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
/** */
|
74
|
+
public static GetPageResponse<T>(): T | null {
|
75
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
76
|
+
|
77
|
+
if (storage) {
|
78
|
+
storage = JSON.parse(storage);
|
79
|
+
|
80
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
81
|
+
return Tools.BreakReference(storage.pageResponse);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
return null;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
/** */
|
90
|
+
public static ClearPageResponse(): void {
|
91
|
+
let storage = sessionStorage.getItem(this.storage) as any;
|
92
|
+
storage = JSON.parse(storage);
|
93
|
+
|
94
|
+
if (storage.hasOwnProperty('pageResponse')) {
|
95
|
+
delete storage.pageResponse;
|
96
|
+
}
|
97
|
+
|
98
|
+
storage = Object.assign({}, storage);
|
99
|
+
sessionStorage.setItem(this.storage, JSON.stringify(storage));
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/** Clear Source */
|
104
|
+
public static Reset(): void {
|
105
|
+
sessionStorage.removeItem(this.storage);
|
106
|
+
}
|
107
|
+
}
|
package/Tools/Tools.ts
CHANGED
@@ -10,7 +10,7 @@ export const Tools = {
|
|
10
10
|
|
11
11
|
|
12
12
|
/** Returns true if the value is null or undefined, false otherwise */
|
13
|
-
IsNull: (value:
|
13
|
+
IsNull: <T>(value: T | null | undefined): boolean => {
|
14
14
|
if (value === undefined) return true;
|
15
15
|
if (value === null) return true;
|
16
16
|
return false;
|
@@ -18,7 +18,7 @@ export const Tools = {
|
|
18
18
|
|
19
19
|
|
20
20
|
/** Returns true if the value is not null or undefined, false otherwise */
|
21
|
-
IsNotNull: (value:
|
21
|
+
IsNotNull: <T>(value: T | null | undefined): boolean => {
|
22
22
|
if (value === undefined) return false;
|
23
23
|
if (value === null) return false;
|
24
24
|
return true;
|
@@ -26,7 +26,7 @@ export const Tools = {
|
|
26
26
|
|
27
27
|
|
28
28
|
/** Returns true if the value is null or undefined or contains only whitespace, false otherwise */
|
29
|
-
IsOnlyWhiteSpace: (value:
|
29
|
+
IsOnlyWhiteSpace: <T>(value: T | null | undefined): boolean => {
|
30
30
|
if (value === undefined) return true;
|
31
31
|
if (value === null) return true;
|
32
32
|
if((value as string).toString().trim() === '') return true;
|
package/index.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
export * from './Tools/
|
1
|
+
export * from './Tools/Breadcrumbs.class';
|
2
|
+
export * from './Tools/ControlValue';
|
2
3
|
export * from './Tools/DateTime.class';
|
3
4
|
export * from './Tools/Files.class';
|
4
|
-
export * from './Tools/
|
5
|
+
export * from './Tools/Page.class';
|
6
|
+
export * from './Tools/Screen.class';
|
7
|
+
export * from './Tools/Source.class';
|
8
|
+
export * from './Tools/Tools'
|
package/interfaces/index.ts
CHANGED
@@ -1,11 +1,47 @@
|
|
1
|
+
import { TemplateRef, WritableSignal } from '@angular/core';
|
2
|
+
|
1
3
|
export interface IPatch {
|
2
4
|
op: 'remove' | 'add' | 'replace';
|
3
5
|
path: string;
|
4
6
|
value: any;
|
5
7
|
}
|
6
8
|
|
9
|
+
|
7
10
|
export interface IScreenSize {
|
8
11
|
width: number;
|
9
12
|
height: number;
|
10
13
|
breakpoin: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
export interface IAppSource {
|
18
|
+
page: string;
|
19
|
+
path: string;
|
20
|
+
}
|
21
|
+
|
22
|
+
|
23
|
+
export interface IBreadcrumb {
|
24
|
+
page: string;
|
25
|
+
path?: string | null;
|
26
|
+
queryParams?: any;
|
27
|
+
click?: (() => any);
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
export interface IGoBack {
|
32
|
+
show: boolean;
|
33
|
+
path?: string | null;
|
34
|
+
queryParams?: any;
|
35
|
+
click?: (() => any);
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
export interface ICoerRef {
|
40
|
+
coerRef: WritableSignal<string>;
|
41
|
+
title: WritableSignal<string>;
|
42
|
+
icon: WritableSignal<string>;
|
43
|
+
isDisabled: WritableSignal<boolean>;
|
44
|
+
show: WritableSignal<boolean>;
|
45
|
+
tooltip: WritableSignal<string>;
|
46
|
+
template: TemplateRef<any>;
|
11
47
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "coer-elements",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.9",
|
4
4
|
"author": "Christian Omar Escamilla Rodríguez",
|
5
5
|
"keywords": [
|
6
6
|
"coer",
|
@@ -23,6 +23,8 @@
|
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
25
|
"@angular/core": "^17.3.0",
|
26
|
+
"@angular/forms": "^17.3.0",
|
27
|
+
"@angular/router": "^17.3.0",
|
26
28
|
"guid-typescript": "^1.0.9",
|
27
29
|
"moment": "^2.30.1",
|
28
30
|
"rxjs": "^7.8.1",
|