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