cyc-base 0.0.2 → 1.0.1

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 (31) hide show
  1. package/.editorconfig +17 -0
  2. package/.vscode/extensions.json +4 -0
  3. package/.vscode/launch.json +20 -0
  4. package/.vscode/tasks.json +42 -0
  5. package/README.md +4 -0
  6. package/angular.json +36 -0
  7. package/package.json +44 -16
  8. package/projects/cyc-base/README.md +26 -0
  9. package/projects/cyc-base/ng-package.json +7 -0
  10. package/projects/cyc-base/package.json +12 -0
  11. package/projects/cyc-base/src/classes/BasePage.ts +82 -0
  12. package/projects/cyc-base/src/classes/CommonPage.ts +211 -0
  13. package/projects/cyc-base/src/classes/ExtendedCommonPage.ts +125 -0
  14. package/projects/cyc-base/src/classes/FirebasePage.ts +66 -0
  15. package/projects/cyc-base/src/classes/SecurePage.ts +229 -0
  16. package/projects/cyc-base/src/components/mat-nav-bar/mat-nav-bar.component.html +21 -0
  17. package/projects/cyc-base/src/components/mat-nav-bar/mat-nav-bar.component.scss +5 -0
  18. package/projects/cyc-base/src/components/mat-nav-bar/mat-nav-bar.component.spec.ts +22 -0
  19. package/projects/cyc-base/src/components/mat-nav-bar/mat-nav-bar.component.ts +47 -0
  20. package/projects/cyc-base/src/lib/cyc-base.spec.ts +23 -0
  21. package/projects/cyc-base/src/lib/cyc-base.ts +15 -0
  22. package/projects/cyc-base/src/lib/shared-db.spec.ts +16 -0
  23. package/projects/cyc-base/src/lib/shared-db.ts +182 -0
  24. package/projects/cyc-base/src/public-api.ts +18 -0
  25. package/projects/cyc-base/tsconfig.lib.json +18 -0
  26. package/projects/cyc-base/tsconfig.lib.prod.json +11 -0
  27. package/projects/cyc-base/tsconfig.spec.json +15 -0
  28. package/tsconfig.json +39 -0
  29. package/fesm2022/cyc-base.mjs +0 -730
  30. package/fesm2022/cyc-base.mjs.map +0 -1
  31. package/index.d.ts +0 -333
@@ -1,730 +0,0 @@
1
- import * as i0 from '@angular/core';
2
- import { Component, Injectable } from '@angular/core';
3
- import { getAuth, onAuthStateChanged } from 'firebase/auth';
4
- import { getDatabase, ref, onValue, get, query, orderByChild, equalTo, push } from 'firebase/database';
5
- import { BehaviorSubject, ReplaySubject, Observable } from 'rxjs';
6
- import { PERMISSION, compareCG } from 'cyc-type-def';
7
-
8
- class CycBase {
9
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: CycBase, deps: [], target: i0.ɵɵFactoryTarget.Component });
10
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: CycBase, isStandalone: true, selector: "lib-cyc-base", ngImport: i0, template: `
11
- <p>
12
- cyc-base works!
13
- </p>
14
- `, isInline: true, styles: [""] });
15
- }
16
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: CycBase, decorators: [{
17
- type: Component,
18
- args: [{ selector: 'lib-cyc-base', imports: [], template: `
19
- <p>
20
- cyc-base works!
21
- </p>
22
- ` }]
23
- }] });
24
-
25
- class SharedDb {
26
- _db;
27
- firebaseAuth;
28
- dataSubject = new BehaviorSubject({});
29
- listeners = {};
30
- isInitialized = false;
31
- // Public observable for components to subscribe to
32
- data$ = this.dataSubject.asObservable();
33
- auth$ = new ReplaySubject(1);
34
- constructor() {
35
- this._db = getDatabase();
36
- this.firebaseAuth = getAuth();
37
- }
38
- async initializeData() {
39
- if (this.isInitialized) {
40
- return;
41
- }
42
- this.isInitialized = true;
43
- this.listenToCluster();
44
- this.listenToSmallTeam();
45
- this.listenToCG();
46
- this.listenToUser();
47
- }
48
- listenToCluster() {
49
- const dataRef = ref(this.db, 'move_follow_up_2023/clusters');
50
- this.listeners['clusters'] = onValue(dataRef, (snapshot) => {
51
- // console.log('listenToCluster');
52
- const obj = snapshot.val();
53
- this.updateData({ arrClusterForRef: obj });
54
- });
55
- }
56
- listenToSmallTeam() {
57
- const dataRef = ref(this.db, 'move_follow_up_2023/small_teams');
58
- this.listeners['small_teams'] = onValue(dataRef, (snapshot) => {
59
- // console.log('listenToSmallTeam');
60
- const obj = snapshot.val();
61
- this.updateData({ arrStForRef: obj });
62
- });
63
- }
64
- listenToCG() {
65
- const dataRef = ref(this.db, 'move_follow_up_2023/CGs');
66
- this.listeners['CGs'] = onValue(dataRef, (snapshot) => {
67
- // console.log('listenToCG');
68
- const obj = snapshot.val();
69
- this.updateData({ arrCgForRef: obj });
70
- });
71
- }
72
- listenToUser() {
73
- this.listeners['firebaseUser'] = onAuthStateChanged(this.firebaseAuth, (user) => {
74
- console.log('auth change');
75
- this.fetchUser(user);
76
- });
77
- }
78
- fetchUser(user) {
79
- if (!user) {
80
- this.auth$.next(undefined);
81
- return;
82
- }
83
- const dataRef = ref(this.db, 'move_follow_up_2023/users/' + user.uid);
84
- onValue(dataRef, (snapshot) => {
85
- console.log('userRef onValue');
86
- if (snapshot.exists()) {
87
- let _user = snapshot.val();
88
- this.auth$.next({ user: _user, firebaseUser: user });
89
- }
90
- else {
91
- this.auth$.next(undefined);
92
- }
93
- });
94
- }
95
- updateData(newData) {
96
- const currentData = this.dataSubject.value;
97
- const updatedData = { ...currentData, ...newData };
98
- this.dataSubject.next(updatedData);
99
- }
100
- get auth() {
101
- return new Observable((observer) => {
102
- this.auth$.subscribe((data) => {
103
- // console.log(data);
104
- console.log('auth$');
105
- if (!data) {
106
- observer.next(undefined);
107
- }
108
- else {
109
- observer.next({
110
- firebaseUser: data.firebaseUser,
111
- user: data.user,
112
- });
113
- }
114
- });
115
- });
116
- }
117
- get pastoralTeam() {
118
- return new Observable((observer) => {
119
- this.data$.subscribe((data) => {
120
- // console.log(data);
121
- observer.next({
122
- arrClusterForRef: data.arrClusterForRef,
123
- arrStForRef: data.arrStForRef,
124
- arrCgForRef: data.arrCgForRef,
125
- // firebaseUser: data.firebaseUser,
126
- // user: data.user,
127
- });
128
- });
129
- });
130
- }
131
- get cluster() {
132
- return new Observable((observer) => {
133
- this.data$.subscribe((data) => {
134
- observer.next(data.arrClusterForRef || {});
135
- });
136
- });
137
- }
138
- get smallTeam() {
139
- return new Observable((observer) => {
140
- this.data$.subscribe((data) => {
141
- observer.next(data.arrStForRef || {});
142
- });
143
- });
144
- }
145
- get CG() {
146
- return new Observable((observer) => {
147
- this.data$.subscribe((data) => {
148
- observer.next(data.arrCgForRef || {});
149
- });
150
- });
151
- }
152
- get db() {
153
- return this._db;
154
- }
155
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: SharedDb, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
156
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: SharedDb, providedIn: 'root' });
157
- }
158
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: SharedDb, decorators: [{
159
- type: Injectable,
160
- args: [{
161
- providedIn: 'root',
162
- }]
163
- }], ctorParameters: () => [] });
164
-
165
- // import { SettingDefaults, Settings } from '../constants/settings.constant';
166
- // import { environment } from '../../environments/environment';
167
- /**
168
- * Holds only the common data stored in `SharedDbService`,
169
- * - Pastoral team
170
- * - User
171
- *
172
- * ---
173
- * For other frequently used variables (not stored in `SharedDbService`), see `ExtendedCommonPage`.
174
- *
175
- * **Provides:**
176
- * `Cluster`, `SmallTeam`, `CG`, `AppUser`, `User`
177
- */
178
- class CommonPage {
179
- subscription;
180
- subscriptionAuth;
181
- user;
182
- firebaseUser;
183
- /** deleted record included */
184
- arrClusterForRef;
185
- /** deleted record included */
186
- arrStForRef;
187
- /** deleted record included */
188
- arrCgForRef;
189
- /** array of clusters, excluding deleted records */
190
- arrCluster;
191
- /** array of small teams, excluding deleted records */
192
- arrSt;
193
- /** array of CGs, excluding deleted records */
194
- arrCg;
195
- constructor() {
196
- this.arrClusterForRef = {};
197
- this.arrStForRef = {};
198
- this.arrCgForRef = {};
199
- this.arrCluster = [];
200
- this.arrSt = [];
201
- this.arrCg = [];
202
- }
203
- /**
204
- * subscribe to clusters, small teams, CGs observable
205
- * @param observerble
206
- */
207
- subscribeObserverble(observerble) {
208
- this.subscription = observerble.subscribe((snapshot) => {
209
- this.arrClusterForRef = snapshot.arrClusterForRef || {};
210
- this.arrCluster = Object.values(this.arrClusterForRef).filter((x) => !x.deleted);
211
- this.arrStForRef = snapshot.arrStForRef || {};
212
- this.arrSt = Object.values(this.arrStForRef).filter((x) => !x.deleted);
213
- this.arrCgForRef = snapshot.arrCgForRef || {};
214
- this.arrCg = Object.values(this.arrCgForRef).filter((x) => !x.deleted);
215
- // this.firebaseUser = snapshot.firebaseUser || null;
216
- // if (snapshot.user) this.user = snapshot.user;
217
- // this.checkAccessAndLoadData();
218
- });
219
- }
220
- subscribeAuthObserverble(observerble) {
221
- this.subscriptionAuth = observerble.subscribe((v) => {
222
- // console.log(v);
223
- // console.log('subscriptionAuth');
224
- if (v) {
225
- this.firebaseUser = v.firebaseUser;
226
- this.user = v.user;
227
- // if (!environment.production) {
228
- // console.log(this.user.id);
229
- // }
230
- // init setting if not exist
231
- this.initSettings(this.user);
232
- }
233
- else {
234
- }
235
- this.checkAccessAndLoadData();
236
- });
237
- }
238
- /**
239
- * unsubscribe all observables
240
- */
241
- unSubscribeObserverble() {
242
- this.subscription?.unsubscribe();
243
- this.subscriptionAuth?.unsubscribe();
244
- }
245
- /** get array of clusters, including deleted records */
246
- get arrClusterWithDel() {
247
- return Object.values(this.arrClusterForRef);
248
- }
249
- /** get array of small team, including deleted records */
250
- get arrStWithDel() {
251
- return Object.values(this.arrStForRef);
252
- }
253
- /** get array of CGs, including deleted records */
254
- get arrCgWithDel() {
255
- return Object.values(this.arrCgForRef);
256
- }
257
- /**
258
- * Returns small teams under a specified cluster.
259
- *
260
- * Optionally filters based on user access permissions.
261
- *
262
- * By default, not including deleted small teams.
263
- *
264
- * @param idCluster - The cluster ID to filter small teams by.
265
- * @param byUserAccess - If true, applies user permission-based filtering. Defaults to false.
266
- * @returns An array of filtered small teams.
267
- */
268
- filteredSmallTeam(idCluster, byUserAccess = false) {
269
- if (!byUserAccess) {
270
- return this.arrSt.filter((x) => x.cluster == idCluster);
271
- }
272
- else {
273
- if (this.user.permissions) {
274
- if (this.user.permissions.includes(PERMISSION.SUPER_USER) ||
275
- this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN)) {
276
- return this.arrSt.filter((x) => x.cluster == idCluster);
277
- }
278
- else if (this.user.permissions.includes(PERMISSION.TL) ||
279
- this.user.permissions.includes(PERMISSION.SCGL) ||
280
- this.user.permissions.includes(PERMISSION.CGL)) {
281
- return (this.arrSt = this.arrSt.filter((x) => x.id == this.user.pastoral_team?.st));
282
- }
283
- }
284
- return [];
285
- }
286
- }
287
- filteredSmallTeamWithDel(idCluster) {
288
- return this.arrStWithDel.filter((x) => x.cluster == idCluster);
289
- }
290
- /**
291
- * by default, not including deleted CG
292
- * @param idCluster
293
- * @returns array of CG under selected cluster and small team
294
- */
295
- filteredCg(idSt) {
296
- return this.arrCg.filter((x) => x.st == idSt).sort(compareCG);
297
- }
298
- filteredCgWithDel(idSt) {
299
- return this.arrCgWithDel.filter((x) => x.st == idSt);
300
- }
301
- /**
302
- * Returns the list of clusters accessible to the current user based on their permissions.
303
- *
304
- * @returns {Cluster[]} Filtered cluster list according to user role.
305
- */
306
- get arrClusterByUserAccess() {
307
- if (this.user.permissions) {
308
- if (this.user.permissions.includes(PERMISSION.SUPER_USER) ||
309
- this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN)) {
310
- return this.arrCluster;
311
- }
312
- else if (this.user.permissions.includes(PERMISSION.TL) ||
313
- this.user.permissions.includes(PERMISSION.SCGL) ||
314
- this.user.permissions.includes(PERMISSION.CGL)) {
315
- return this.arrCluster.filter((x) => x.id == this.user.pastoral_team?.cluster);
316
- }
317
- }
318
- return [];
319
- }
320
- /**
321
- * init setting if not exist
322
- * @param user
323
- */
324
- initSettings(user) { }
325
- // initSettings(user: AppUser) {
326
- // if (!user.settings) user.settings = {};
327
- // for (let s of Object.values(Settings)) {
328
- // if (user.settings?.[s] === undefined) {
329
- // user.settings[s] = SettingDefaults[s];
330
- // }
331
- // }
332
- // }
333
- checkAccessAndLoadData() { }
334
- }
335
-
336
- /**
337
- * Holds additional frequently used variables **not** stored in `SharedDbService`,
338
- * such as:
339
- * - `Sheep`
340
- * - `Title`
341
- *
342
- * ---
343
- * **For data stored in `SharedDbService`**
344
- * (pastoral team and user), see `CommonPage`.
345
- *
346
- * ---
347
- * @extends ExtendedCommonPage
348
- */
349
- class ExtendedCommonPage extends CommonPage {
350
- // title
351
- arrTitleForRef = {};
352
- arrTitle = [];
353
- // sheep
354
- arrSheepForRef = {};
355
- arrSheep = [];
356
- // user
357
- arrUserForRef = {};
358
- arrUser = [];
359
- // attendance
360
- arrAttendance = [];
361
- // msj
362
- arrMsjClassTypeForRef = {};
363
- arrMsjClassBatchForRef = {};
364
- arrMsjClassTimeForRef = {};
365
- arrMsjStudBatch = [];
366
- // selection
367
- cluster;
368
- st;
369
- cg;
370
- sheep;
371
- title;
372
- msjClassType;
373
- msjClassBatch;
374
- msjClassTime;
375
- loading = false;
376
- constructor() {
377
- super();
378
- }
379
- get arrTitleReserve() {
380
- return this.arrTitle.slice().reverse();
381
- }
382
- get arrMsjClassType() {
383
- return Object.values(this.arrMsjClassTypeForRef).filter((x) => !x.deleted);
384
- }
385
- get arrMsjClassBatch() {
386
- return Object.values(this.arrMsjClassBatchForRef).filter((x) => !x.deleted);
387
- }
388
- get arrMsjClassTime() {
389
- return Object.values(this.arrMsjClassTimeForRef).filter((x) => !x.deleted);
390
- }
391
- filteredMsjClassBatch(idMsjClassType) {
392
- return this.arrMsjClassBatch
393
- .filter((x) => x.idMsjClassType == idMsjClassType)
394
- .sort((b, a) => {
395
- a.dt = new Date(new Date(a.yearTimestamp).getFullYear(), new Date(a.monthTimestamp).getMonth());
396
- b.dt = new Date(new Date(b.yearTimestamp).getFullYear(), new Date(b.monthTimestamp).getMonth());
397
- if (a.dt.getFullYear() == b.dt.getFullYear()) {
398
- return a.dt.getMonth() - b.dt.getMonth();
399
- }
400
- else {
401
- return a.dt.getFullYear() - b.dt.getFullYear();
402
- }
403
- });
404
- }
405
- filteredMsjClassTime(idMsjClassBatch) {
406
- return this.arrMsjClassTime.filter((x) => x.idMsjClassBatch == idMsjClassBatch);
407
- }
408
- get isSuperUser() {
409
- if (this.user && this.user.permissions) {
410
- return this.user.permissions.includes(PERMISSION.SUPER_USER);
411
- }
412
- else {
413
- return false;
414
- }
415
- }
416
- get isPastoralAdmin() {
417
- if (this.user && this.user.permissions) {
418
- return this.user.permissions.includes(PERMISSION.PASTORAL_ADMIN);
419
- }
420
- else {
421
- return false;
422
- }
423
- }
424
- }
425
-
426
- /**
427
- * @extends CommonPage
428
- * @extends ExtendedCommonPage
429
- */
430
- class FirebasePage extends ExtendedCommonPage {
431
- db;
432
- auth;
433
- constructor() {
434
- super();
435
- this.auth = getAuth();
436
- this.db = getDatabase();
437
- }
438
- get userRef() {
439
- return ref(this.db, 'move_follow_up_2023/users');
440
- }
441
- get clusterRef() {
442
- return ref(this.db, 'move_follow_up_2023/clusters');
443
- }
444
- get stRef() {
445
- return ref(this.db, 'move_follow_up_2023/small_teams');
446
- }
447
- get cgRef() {
448
- return ref(this.db, 'move_follow_up_2023/CGs');
449
- }
450
- get sheepRef() {
451
- return ref(this.db, 'move_follow_up_2023/sheeps');
452
- }
453
- get sheepLogRef() {
454
- return ref(this.db, 'move_follow_up_2023/sheeps_log');
455
- }
456
- get msjClassTypeRef() {
457
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_type');
458
- }
459
- get msjClassBatchRef() {
460
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_batch');
461
- }
462
- get msjClassTimeRef() {
463
- return ref(this.db, 'move_follow_up_2023/msj/msj_class_time');
464
- }
465
- get msjStudBatchRef() {
466
- return ref(this.db, 'move_follow_up_2023/msj/msj_student_batch_record');
467
- }
468
- get attRef() {
469
- return ref(this.db, 'move_follow_up_2023/attendance/atts');
470
- }
471
- get titleRef() {
472
- return ref(this.db, 'move_follow_up_2023/attendance/titles');
473
- }
474
- }
475
-
476
- /**
477
- * using observable to read user
478
- * replace BasePage
479
- *
480
- * ---
481
- * @extends CommonPage
482
- * @extends ExtendedCommonPage
483
- * @extends FirebasePage
484
- */
485
- class SecurePage extends FirebasePage {
486
- isSecure;
487
- router;
488
- constructor(router, isSecure) {
489
- super();
490
- this.isSecure = isSecure;
491
- this.router = router;
492
- }
493
- checkAccessAndLoadData() {
494
- if (this.firebaseUser) {
495
- if (this.user) {
496
- if (this.user.permission == PERMISSION.NOT_VERIFIED && this.isSecure) {
497
- // not verified user
498
- // redirect to home page
499
- this.navigateHome();
500
- }
501
- // if (this.user.permissions) {
502
- // this.isSuperUser = this.user.permissions.includes(
503
- // PERMISSION.SUPER_USER
504
- // );
505
- // }
506
- this.checkPermission(this.user);
507
- this.readData();
508
- }
509
- else {
510
- // user logged in but no data
511
- // redirect to home page (how he came to here?)
512
- if (this.isSecure)
513
- this.navigateHome();
514
- // this.readData(); // navigated home, no need read data
515
- }
516
- }
517
- else {
518
- // user not logged in
519
- // redirect to home page
520
- if (this.isSecure)
521
- this.navigateHome();
522
- // this.readData(); // navigated home, no need read data
523
- }
524
- }
525
- navigateHome() {
526
- this.router.navigate(['']);
527
- }
528
- loadTitle() {
529
- const titleRef = ref(this.db, 'move_follow_up_2023/attendance/titles');
530
- onValue(titleRef, (v) => {
531
- if (v.exists()) {
532
- this.arrTitle = Object.values(v.val());
533
- this.arrTitleForRef = v.val();
534
- }
535
- });
536
- }
537
- loadSheep() {
538
- const sheepRef = ref(this.db, 'move_follow_up_2023/sheeps');
539
- onValue(sheepRef, (v) => {
540
- if (v.exists()) {
541
- this.arrSheep = Object.values(v.val());
542
- this.arrSheepForRef = v.val();
543
- }
544
- });
545
- }
546
- loadAttendance() { }
547
- loadUsers() { }
548
- loadUsersAsync() {
549
- const userRef = ref(this.db, 'move_follow_up_2023/users');
550
- return get(userRef);
551
- }
552
- handleTitleSelected() { }
553
- handleClusterSelected() { }
554
- handleSmallTeamSelected() { }
555
- handleCGSelected() { }
556
- loadMsjClassType() {
557
- const msjClassTypeRef = ref(this.db, 'move_follow_up_2023/msj/msj_class_type');
558
- return get(msjClassTypeRef);
559
- }
560
- loadMsjClassBatch() {
561
- const msjClassBatchRef = ref(this.db, 'move_follow_up_2023/msj/msj_class_batch');
562
- return get(msjClassBatchRef);
563
- }
564
- loadMsjClassTime(msjClassBatch) {
565
- const msjClassTimeRef = ref(this.db, 'move_follow_up_2023/msj/msj_class_time');
566
- let q = query(msjClassTimeRef);
567
- if (msjClassBatch)
568
- q = query(msjClassTimeRef, orderByChild('idMsjClassBatch'), equalTo(msjClassBatch.id));
569
- return get(q);
570
- }
571
- recordClick(action) {
572
- const testAccId = '5FUtbbtMe4RNPys6QSUzri5UXFN2';
573
- const testAcc2Id = 'q1GEMXkzbWOOEg2wreNuPsTgCw52';
574
- const testAcc3Id = 'XZUlKaa5aUhwJ2KlEa5oJfImwZA3';
575
- const testAcc4Id = '9O3bSHbL2pfWBC9BOJiwMbkHQdr2';
576
- const developerAccId = 'ZqdQyuc1uuTbAfmhkjw5HgLFnc82';
577
- let userId = this.user?.id;
578
- if (userId == testAccId ||
579
- userId == testAcc2Id ||
580
- userId == testAcc3Id ||
581
- userId == testAcc4Id ||
582
- userId == developerAccId) {
583
- return;
584
- }
585
- const obj = { action, timeStamp: new Date().getTime() };
586
- if (userId) {
587
- obj['userId'] = userId;
588
- }
589
- push(ref(this.db, 'move_follow_up_2023/attendance/clicks'), obj);
590
- }
591
- // FUNCTIONS INTERFACE
592
- /**
593
- * Execute after reading user data from database
594
- *
595
- * @Override
596
- *
597
- * @example
598
- this.firebaseUser = user;
599
- if (user) {
600
- const userRef = ref(this.db, 'move_follow_up_2023/users/' + user.uid);
601
- onValue(userRef, (v) => {
602
- if (v.exists()) {
603
- this.user = v.val();
604
-
605
- if (this.user.permission == PERMISSION.NOT_VERIFIED) {
606
- // not verified user
607
- // redirect to home page
608
- router.navigate(['']);
609
- // this.router.navigate(['']);
610
- }
611
-
612
- this.checkPermission(this.user);
613
- this.loadDataClone();
614
- }
615
- })
616
- }
617
-
618
- *
619
- * @param user
620
- */
621
- checkPermission(user) {
622
- // console.log('checkPermission');
623
- }
624
- /**
625
- * Execute after reading user data from database
626
- *
627
- * @Override
628
- *
629
- * @example
630
- this.firebaseUser = user;
631
- if (user) {
632
- const userRef = ref(this.db, 'move_follow_up_2023/users/' + user.uid);
633
- onValue(userRef, (v) => {
634
- if (v.exists()) {
635
- this.user = v.val();
636
-
637
- if (this.user.permission == PERMISSION.NOT_VERIFIED) {
638
- // not verified user
639
- // redirect to home page
640
- router.navigate(['']);
641
- // this.router.navigate(['']);
642
- }
643
-
644
- this.checkPermission(this.user);
645
- this.loadDataClone();
646
- }
647
- })
648
- }
649
- */
650
- readData() { }
651
- }
652
-
653
- class BasePage extends SecurePage {
654
- t1;
655
- t2;
656
- constructor(router, isSecure) {
657
- super(router, isSecure);
658
- this.isSecure = isSecure;
659
- this.router = router;
660
- this.load();
661
- }
662
- load() {
663
- onAuthStateChanged(this.auth, (user) => {
664
- this.readUser(user);
665
- // this.loadUser(user);
666
- });
667
- }
668
- readUser(user) {
669
- this.firebaseUser = user;
670
- if (user) {
671
- // console.log(user.email);
672
- const userRef = ref(this.db, 'move_follow_up_2023/users/' + user.uid);
673
- onValue(userRef, (v) => {
674
- if (v.exists()) {
675
- this.user = v.val();
676
- // console.log(this.user.name);
677
- if (this.user.permission == PERMISSION.NOT_VERIFIED &&
678
- this.isSecure) {
679
- // not verified user
680
- // redirect to home page
681
- this.router.navigate(['']);
682
- // this.router.navigate(['']);
683
- }
684
- // if (this.user.permissions) {
685
- // this.isSuperUser = this.user.permissions.includes(
686
- // PERMISSION.SUPER_USER
687
- // );
688
- // }
689
- this.checkPermission(this.user);
690
- this.readData();
691
- this.initSettings(this.user);
692
- }
693
- else {
694
- // user logged in but no data
695
- // redirect to home page (how he came to here?)
696
- if (this.isSecure)
697
- this.router.navigate(['']);
698
- // this.router.navigate(['']);
699
- this.readData();
700
- }
701
- });
702
- }
703
- else {
704
- // user not logged in
705
- // redirect to home page
706
- if (this.isSecure)
707
- this.router.navigate(['']);
708
- // this.router.navigate(['']);
709
- this.readData();
710
- }
711
- }
712
- timerStart() {
713
- this.t1 = new Date();
714
- }
715
- timerEnd() {
716
- this.t2 = new Date();
717
- console.log(this.t2.getTime() - this.t1.getTime());
718
- }
719
- }
720
-
721
- /*
722
- * Public API Surface of cyc-base
723
- */
724
-
725
- /**
726
- * Generated bundle index. Do not edit.
727
- */
728
-
729
- export { BasePage, CommonPage, CycBase, ExtendedCommonPage, FirebasePage, SecurePage, SharedDb };
730
- //# sourceMappingURL=cyc-base.mjs.map