cyc-base 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +0 -4
  2. package/fesm2022/cyc-base.mjs +773 -0
  3. package/fesm2022/cyc-base.mjs.map +1 -0
  4. package/index.d.ts +346 -0
  5. package/package.json +16 -44
  6. package/.editorconfig +0 -17
  7. package/.vscode/extensions.json +0 -4
  8. package/.vscode/launch.json +0 -20
  9. package/.vscode/tasks.json +0 -42
  10. package/angular.json +0 -36
  11. package/projects/cyc-base/README.md +0 -26
  12. package/projects/cyc-base/ng-package.json +0 -7
  13. package/projects/cyc-base/package.json +0 -12
  14. package/projects/cyc-base/src/classes/BasePage.ts +0 -82
  15. package/projects/cyc-base/src/classes/CommonPage.ts +0 -211
  16. package/projects/cyc-base/src/classes/ExtendedCommonPage.ts +0 -125
  17. package/projects/cyc-base/src/classes/FirebasePage.ts +0 -66
  18. package/projects/cyc-base/src/classes/SecurePage.ts +0 -229
  19. package/projects/cyc-base/src/lib/alert/alert.css +0 -0
  20. package/projects/cyc-base/src/lib/alert/alert.html +0 -1
  21. package/projects/cyc-base/src/lib/alert/alert.spec.ts +0 -23
  22. package/projects/cyc-base/src/lib/alert/alert.ts +0 -11
  23. package/projects/cyc-base/src/lib/components/mat-nav-bar/mat-nav-bar.css +0 -0
  24. package/projects/cyc-base/src/lib/components/mat-nav-bar/mat-nav-bar.html +0 -19
  25. package/projects/cyc-base/src/lib/components/mat-nav-bar/mat-nav-bar.spec.ts +0 -23
  26. package/projects/cyc-base/src/lib/components/mat-nav-bar/mat-nav-bar.ts +0 -46
  27. package/projects/cyc-base/src/lib/cyc-base.spec.ts +0 -23
  28. package/projects/cyc-base/src/lib/cyc-base.ts +0 -15
  29. package/projects/cyc-base/src/lib/shared-db.spec.ts +0 -16
  30. package/projects/cyc-base/src/lib/shared-db.ts +0 -182
  31. package/projects/cyc-base/src/public-api.ts +0 -18
  32. package/projects/cyc-base/tsconfig.lib.json +0 -18
  33. package/projects/cyc-base/tsconfig.lib.prod.json +0 -11
  34. package/projects/cyc-base/tsconfig.spec.json +0 -15
  35. package/tsconfig.json +0 -39
@@ -1,26 +0,0 @@
1
- ## Building
2
-
3
- To build the library, run:
4
-
5
- ```bash
6
- ng build cyc-base
7
- ```
8
-
9
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
10
-
11
- ### Publishing the Library
12
-
13
- Once the project is built, you can publish your library by following these steps:
14
-
15
- 1. Navigate to the `dist` directory:
16
-
17
- ```bash
18
- cd dist/cyc-base
19
- ```
20
-
21
- 2. Run the `npm publish` command to publish your library to the npm registry:
22
- ```bash
23
- npm config set //registry.npmjs.org/:_authToken=YOUR_NPM_TOKEN
24
- npm publish
25
- npm config delete //registry.npmjs.org/:_authToken
26
- ```
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/cyc-base",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- }
7
- }
@@ -1,12 +0,0 @@
1
- {
2
- "name": "cyc-base",
3
- "version": "1.0.3",
4
- "peerDependencies": {
5
- "@angular/common": "^20.3.0",
6
- "@angular/core": "^20.3.0"
7
- },
8
- "dependencies": {
9
- "tslib": "^2.3.0"
10
- },
11
- "sideEffects": false
12
- }
@@ -1,82 +0,0 @@
1
- import { onValue, ref } from 'firebase/database';
2
- import { onAuthStateChanged, User } from 'firebase/auth';
3
- import { Router } from '@angular/router';
4
- import { PERMISSION } from 'cyc-type-def';
5
- import { SecurePage } from './SecurePage';
6
-
7
- export class BasePage extends SecurePage {
8
- t1!: Date;
9
- t2!: Date;
10
-
11
- constructor(router: Router, isSecure: boolean) {
12
- super(router, isSecure);
13
-
14
- this.isSecure = isSecure;
15
- this.router = router;
16
-
17
- this.load();
18
- }
19
-
20
- load() {
21
- onAuthStateChanged(this.auth, (user) => {
22
- this.readUser(user);
23
- // this.loadUser(user);
24
- });
25
- }
26
-
27
- readUser(user: User | null) {
28
- this.firebaseUser = user;
29
- if (user) {
30
- // console.log(user.email);
31
- const userRef = ref(this.db, 'move_follow_up_2023/users/' + user.uid);
32
- onValue(userRef, (v) => {
33
- if (v.exists()) {
34
- this.user = v.val();
35
- // console.log(this.user.name);
36
-
37
- if (
38
- this.user.permission == PERMISSION.NOT_VERIFIED &&
39
- this.isSecure
40
- ) {
41
- // not verified user
42
- // redirect to home page
43
- this.router.navigate(['']);
44
- // this.router.navigate(['']);
45
- }
46
-
47
- // if (this.user.permissions) {
48
- // this.isSuperUser = this.user.permissions.includes(
49
- // PERMISSION.SUPER_USER
50
- // );
51
- // }
52
-
53
- this.checkPermission(this.user);
54
- this.readData();
55
-
56
- this.initSettings(this.user);
57
- } else {
58
- // user logged in but no data
59
- // redirect to home page (how he came to here?)
60
- if (this.isSecure) this.router.navigate(['']);
61
- // this.router.navigate(['']);
62
- this.readData();
63
- }
64
- });
65
- } else {
66
- // user not logged in
67
- // redirect to home page
68
- if (this.isSecure) this.router.navigate(['']);
69
- // this.router.navigate(['']);
70
- this.readData();
71
- }
72
- }
73
-
74
- timerStart() {
75
- this.t1 = new Date();
76
- }
77
-
78
- timerEnd() {
79
- this.t2 = new Date();
80
- console.log(this.t2.getTime() - this.t1.getTime());
81
- }
82
- }
@@ -1,211 +0,0 @@
1
- import { Cluster, SmallTeam, CG, AppUser, PERMISSION, compareCG } from 'cyc-type-def';
2
- import { Observable, Subscription } from 'rxjs';
3
- // import { AppData } from '../../app/services/shared-db.service';
4
- // import { compareCG } from '../util/sort.util';
5
- import { User } from 'firebase/auth';
6
- import { AppData } from '../lib/shared-db';
7
- // import { SettingDefaults, Settings } from '../constants/settings.constant';
8
- // import { environment } from '../../environments/environment';
9
-
10
- /**
11
- * Holds only the common data stored in `SharedDbService`,
12
- * - Pastoral team
13
- * - User
14
- *
15
- * ---
16
- * For other frequently used variables (not stored in `SharedDbService`), see `ExtendedCommonPage`.
17
- *
18
- * **Provides:**
19
- * `Cluster`, `SmallTeam`, `CG`, `AppUser`, `User`
20
- */
21
- export class CommonPage {
22
- protected subscription?: Subscription;
23
- protected subscriptionAuth?: Subscription;
24
-
25
- user!: AppUser;
26
- firebaseUser!: User | null;
27
-
28
- /** deleted record included */
29
- arrClusterForRef: { [key: string]: Cluster };
30
- /** deleted record included */
31
- arrStForRef: { [key: string]: SmallTeam };
32
- /** deleted record included */
33
- arrCgForRef: { [key: string]: CG };
34
-
35
- /** array of clusters, excluding deleted records */
36
- arrCluster: Cluster[];
37
- /** array of small teams, excluding deleted records */
38
- arrSt: SmallTeam[];
39
- /** array of CGs, excluding deleted records */
40
- arrCg: CG[];
41
-
42
- constructor() {
43
- this.arrClusterForRef = {};
44
- this.arrStForRef = {};
45
- this.arrCgForRef = {};
46
-
47
- this.arrCluster = [];
48
- this.arrSt = [];
49
- this.arrCg = [];
50
- }
51
-
52
- /**
53
- * subscribe to clusters, small teams, CGs observable
54
- * @param observerble
55
- */
56
- subscribeObserverble(observerble: Observable<AppData>) {
57
- this.subscription = observerble.subscribe((snapshot) => {
58
- this.arrClusterForRef = snapshot.arrClusterForRef || {};
59
- this.arrCluster = Object.values(this.arrClusterForRef).filter((x) => !x.deleted);
60
-
61
- this.arrStForRef = snapshot.arrStForRef || {};
62
- this.arrSt = Object.values(this.arrStForRef).filter((x) => !x.deleted);
63
-
64
- this.arrCgForRef = snapshot.arrCgForRef || {};
65
- this.arrCg = Object.values(this.arrCgForRef).filter((x) => !x.deleted);
66
-
67
- // this.firebaseUser = snapshot.firebaseUser || null;
68
- // if (snapshot.user) this.user = snapshot.user;
69
-
70
- // this.checkAccessAndLoadData();
71
- });
72
- }
73
-
74
- subscribeAuthObserverble(
75
- observerble: Observable<{ user: AppUser; firebaseUser: User } | undefined>
76
- ) {
77
- this.subscriptionAuth = observerble.subscribe((v) => {
78
- // console.log(v);
79
- // console.log('subscriptionAuth');
80
-
81
- if (v) {
82
- this.firebaseUser = v.firebaseUser;
83
- this.user = v.user;
84
-
85
- // if (!environment.production) {
86
- // console.log(this.user.id);
87
- // }
88
-
89
- // init setting if not exist
90
- this.initSettings(this.user);
91
- } else {
92
- }
93
-
94
- this.checkAccessAndLoadData();
95
- });
96
- }
97
-
98
- /**
99
- * unsubscribe all observables
100
- */
101
- unSubscribeObserverble(): void {
102
- this.subscription?.unsubscribe();
103
- this.subscriptionAuth?.unsubscribe();
104
- }
105
-
106
- /** get array of clusters, including deleted records */
107
- get arrClusterWithDel() {
108
- return Object.values(this.arrClusterForRef);
109
- }
110
-
111
- /** get array of small team, including deleted records */
112
- get arrStWithDel() {
113
- return Object.values(this.arrStForRef);
114
- }
115
-
116
- /** get array of CGs, including deleted records */
117
- get arrCgWithDel() {
118
- return Object.values(this.arrCgForRef);
119
- }
120
-
121
- /**
122
- * Returns small teams under a specified cluster.
123
- *
124
- * Optionally filters based on user access permissions.
125
- *
126
- * By default, not including deleted small teams.
127
- *
128
- * @param idCluster - The cluster ID to filter small teams by.
129
- * @param byUserAccess - If true, applies user permission-based filtering. Defaults to false.
130
- * @returns An array of filtered small teams.
131
- */
132
- filteredSmallTeam(idCluster: string | undefined, byUserAccess: boolean = false) {
133
- if (!byUserAccess) {
134
- return this.arrSt.filter((x) => x.cluster == idCluster);
135
- } else {
136
- if (this.user.permissions) {
137
- if (
138
- this.user.permissions.includes(PERMISSION.SUPER_USER) ||
139
- this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN)
140
- ) {
141
- return this.arrSt.filter((x) => x.cluster == idCluster);
142
- } else if (
143
- this.user.permissions.includes(PERMISSION.TL) ||
144
- this.user.permissions.includes(PERMISSION.SCGL) ||
145
- this.user.permissions.includes(PERMISSION.CGL)
146
- ) {
147
- return (this.arrSt = this.arrSt.filter((x) => x.id == this.user.pastoral_team?.st));
148
- }
149
- }
150
-
151
- return [];
152
- }
153
- }
154
-
155
- filteredSmallTeamWithDel(idCluster: string) {
156
- return this.arrStWithDel.filter((x) => x.cluster == idCluster);
157
- }
158
-
159
- /**
160
- * by default, not including deleted CG
161
- * @param idCluster
162
- * @returns array of CG under selected cluster and small team
163
- */
164
- filteredCg(idSt: string | undefined) {
165
- return this.arrCg.filter((x) => x.st == idSt).sort(compareCG);
166
- }
167
-
168
- filteredCgWithDel(idSt: string) {
169
- return this.arrCgWithDel.filter((x) => x.st == idSt);
170
- }
171
-
172
- /**
173
- * Returns the list of clusters accessible to the current user based on their permissions.
174
- *
175
- * @returns {Cluster[]} Filtered cluster list according to user role.
176
- */
177
- get arrClusterByUserAccess() {
178
- if (this.user.permissions) {
179
- if (
180
- this.user.permissions.includes(PERMISSION.SUPER_USER) ||
181
- this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN)
182
- ) {
183
- return this.arrCluster;
184
- } else if (
185
- this.user.permissions.includes(PERMISSION.TL) ||
186
- this.user.permissions.includes(PERMISSION.SCGL) ||
187
- this.user.permissions.includes(PERMISSION.CGL)
188
- ) {
189
- return this.arrCluster.filter((x) => x.id == this.user.pastoral_team?.cluster);
190
- }
191
- }
192
-
193
- return [];
194
- }
195
-
196
- /**
197
- * init setting if not exist
198
- * @param user
199
- */
200
- initSettings(user: AppUser) {}
201
- // initSettings(user: AppUser) {
202
- // if (!user.settings) user.settings = {};
203
- // for (let s of Object.values(Settings)) {
204
- // if (user.settings?.[s] === undefined) {
205
- // user.settings[s] = SettingDefaults[s];
206
- // }
207
- // }
208
- // }
209
-
210
- checkAccessAndLoadData() {}
211
- }
@@ -1,125 +0,0 @@
1
- import {
2
- AppUser,
3
- Attendance,
4
- CG,
5
- Cluster,
6
- MsjClassBatch,
7
- MsjClassTime,
8
- MsjClassType,
9
- MsjStudBatch,
10
- PERMISSION,
11
- Sheep,
12
- SmallTeam,
13
- Title,
14
- } from 'cyc-type-def';
15
- import { CommonPage } from './CommonPage';
16
-
17
- /**
18
- * Holds additional frequently used variables **not** stored in `SharedDbService`,
19
- * such as:
20
- * - `Sheep`
21
- * - `Title`
22
- *
23
- * ---
24
- * **For data stored in `SharedDbService`**
25
- * (pastoral team and user), see `CommonPage`.
26
- *
27
- * ---
28
- * @extends ExtendedCommonPage
29
- */
30
- export class ExtendedCommonPage extends CommonPage {
31
- // title
32
- arrTitleForRef: { [key: string]: Title } = {};
33
- arrTitle: Title[] = [];
34
-
35
- // sheep
36
- arrSheepForRef: { [key: string]: Sheep } = {};
37
- arrSheep: Sheep[] = [];
38
-
39
- // user
40
- arrUserForRef: { [key: string]: AppUser } = {};
41
- arrUser: AppUser[] = [];
42
-
43
- // attendance
44
- arrAttendance: Attendance[] = [];
45
-
46
- // msj
47
- arrMsjClassTypeForRef: { [key: string]: MsjClassType } = {};
48
- arrMsjClassBatchForRef: { [key: string]: MsjClassBatch } = {};
49
- arrMsjClassTimeForRef: { [key: string]: MsjClassTime } = {};
50
- arrMsjStudBatch: MsjStudBatch[] = [];
51
-
52
- // selection
53
- cluster: Cluster | undefined;
54
- st: SmallTeam | undefined;
55
- cg: CG | undefined;
56
- sheep: Sheep | undefined;
57
- title: Title | undefined;
58
- msjClassType: MsjClassType | undefined;
59
- msjClassBatch: MsjClassBatch | undefined;
60
- msjClassTime: MsjClassTime | undefined;
61
-
62
- loading = false;
63
-
64
- constructor() {
65
- super();
66
- }
67
-
68
- get arrTitleReserve() {
69
- return this.arrTitle.slice().reverse();
70
- }
71
-
72
- get arrMsjClassType() {
73
- return Object.values(this.arrMsjClassTypeForRef).filter((x) => !x.deleted);
74
- }
75
-
76
- get arrMsjClassBatch() {
77
- return Object.values(this.arrMsjClassBatchForRef).filter((x) => !x.deleted);
78
- }
79
-
80
- get arrMsjClassTime() {
81
- return Object.values(this.arrMsjClassTimeForRef).filter((x) => !x.deleted);
82
- }
83
-
84
- filteredMsjClassBatch(idMsjClassType: string) {
85
- return this.arrMsjClassBatch
86
- .filter((x) => x.idMsjClassType == idMsjClassType)
87
- .sort((b: MsjClassBatch, a: MsjClassBatch) => {
88
- a.dt = new Date(
89
- new Date(a.yearTimestamp).getFullYear(),
90
- new Date(a.monthTimestamp).getMonth()
91
- );
92
- b.dt = new Date(
93
- new Date(b.yearTimestamp).getFullYear(),
94
- new Date(b.monthTimestamp).getMonth()
95
- );
96
- if (a.dt.getFullYear() == b.dt.getFullYear()) {
97
- return a.dt.getMonth() - b.dt.getMonth();
98
- } else {
99
- return a.dt.getFullYear() - b.dt.getFullYear();
100
- }
101
- });
102
- }
103
-
104
- filteredMsjClassTime(idMsjClassBatch: string) {
105
- return this.arrMsjClassTime.filter(
106
- (x) => x.idMsjClassBatch == idMsjClassBatch
107
- );
108
- }
109
-
110
- get isSuperUser() {
111
- if (this.user && this.user.permissions) {
112
- return this.user.permissions.includes(PERMISSION.SUPER_USER);
113
- } else {
114
- return false;
115
- }
116
- }
117
-
118
- get isPastoralAdmin() {
119
- if (this.user && this.user.permissions) {
120
- return this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN);
121
- } else {
122
- return false;
123
- }
124
- }
125
- }
@@ -1,66 +0,0 @@
1
- import { Auth, getAuth } from 'firebase/auth';
2
- import { Database, getDatabase, ref } from 'firebase/database';
3
- import { ExtendedCommonPage } from './ExtendedCommonPage';
4
-
5
- /**
6
- * @extends CommonPage
7
- * @extends ExtendedCommonPage
8
- */
9
- export class FirebasePage extends ExtendedCommonPage {
10
- db!: Database;
11
- auth!: Auth;
12
- constructor() {
13
- super();
14
-
15
- this.auth = getAuth();
16
- this.db = getDatabase();
17
- }
18
-
19
- get userRef() {
20
- return ref(this.db, 'move_follow_up_2023/users');
21
- }
22
-
23
- get clusterRef() {
24
- return ref(this.db, 'move_follow_up_2023/clusters');
25
- }
26
-
27
- get stRef() {
28
- return ref(this.db, 'move_follow_up_2023/small_teams');
29
- }
30
-
31
- get cgRef() {
32
- return ref(this.db, 'move_follow_up_2023/CGs');
33
- }
34
-
35
- get sheepRef() {
36
- return ref(this.db, 'move_follow_up_2023/sheeps');
37
- }
38
-
39
- get sheepLogRef() {
40
- return ref(this.db, 'move_follow_up_2023/sheeps_log');
41
- }
42
-
43
- get msjClassTypeRef() {
44
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_type');
45
- }
46
-
47
- get msjClassBatchRef() {
48
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_batch');
49
- }
50
-
51
- get msjClassTimeRef() {
52
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_time');
53
- }
54
-
55
- get msjStudBatchRef() {
56
- return ref(this.db, 'move_follow_up_2023/msj/msj_student_batch_record');
57
- }
58
-
59
- get attRef() {
60
- return ref(this.db, 'move_follow_up_2023/attendance/atts');
61
- }
62
-
63
- get titleRef() {
64
- return ref(this.db, 'move_follow_up_2023/attendance/titles');
65
- }
66
- }