@tech4good/angular-schematics 17.0.2 → 17.0.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tech4good/angular-schematics",
3
- "version": "17.0.2",
3
+ "version": "17.0.3",
4
4
  "description": "A set of schematics for generating modules, containers, components, and entities",
5
5
  "scripts": {
6
6
  "build": "tsc -p tsconfig.json",
@@ -10,16 +10,10 @@
10
10
  <!-- Access Status Column -->
11
11
  <ng-container matColumnDef="accessState">
12
12
  <th mat-header-cell *matHeaderCellDef> Access State </th>
13
- <td mat-cell *matCellDef="let user">{{ user.accessState }}</td>
14
- </ng-container>
15
-
16
- <!-- Update Column -->
17
- <ng-container matColumnDef="update">
18
- <th mat-header-cell *matHeaderCellDef> Update Status </th>
19
13
  <td mat-cell *matCellDef="let user">
20
- <span class="update-btn" [matMenuTriggerFor]="menu" aria-label="Update state button">[Update Button]</span>
21
- <mat-menu #menu="matMenu">
22
- <button mat-menu-item (click)="updateState$.next({ user, state: option })" *ngFor="let option of accessOptions">{{ option }}</button>
14
+ <span class="update-btn" [matMenuTriggerFor]="accessStateMenu" aria-label="accessState">{{ user.accessState }}</span>
15
+ <mat-menu #accessStateMenu="matMenu">
16
+ <button mat-menu-item (click)="updateState$.next({ user, key: 'accessState', value: option })" *ngFor="let option of accessOptions">{{ option }}</button>
23
17
  </mat-menu>
24
18
  </td>
25
19
  </ng-container>
@@ -18,6 +18,9 @@ import { User, AccessState } from '../../core/store/user/user.model';
18
18
  import { ShowSnackbar } from '../../core/snackbar/snackbar.actions';
19
19
  import { UpdateUser, UserActionTypes } from '../../core/store/user/user.actions';
20
20
 
21
+ // If you add other columns, update this, e.g. AccessState | string | boolean;
22
+ type UpdateValueTypes = AccessState;
23
+
21
24
  @Component({
22
25
  selector: 'app-waitlist',
23
26
  templateUrl: './waitlist.component.html',
@@ -32,8 +35,8 @@ export class WaitlistComponent implements OnInit, OnDestroy {
32
35
  // --------------- LOCAL AND GLOBAL STATE --------------
33
36
 
34
37
  /** Access options for menu sorted alphabetically. */
35
- accessOptions = Object.keys(AccessState)
36
- .map((k) => AccessState[k])
38
+ accessOptions: AccessState[] = Object.keys(AccessState)
39
+ .map((k) => AccessState[k] as AccessState)
37
40
  .sort((a, b) => {
38
41
  if (a > b) {
39
42
  return 1;
@@ -43,9 +46,9 @@ export class WaitlistComponent implements OnInit, OnDestroy {
43
46
  return 0;
44
47
  }
45
48
  });
46
-
49
+
47
50
  /** Columns to display in the table */
48
- displayedColumns = ['userName', 'accessState', 'update'];
51
+ displayedColumns = ['userName', 'accessState'];
49
52
 
50
53
  // --------------- DB ENTITY DATA ----------------------
51
54
 
@@ -61,7 +64,7 @@ export class WaitlistComponent implements OnInit, OnDestroy {
61
64
  // --------------- EVENT BINDING -----------------------
62
65
 
63
66
  /** Event stream for updating user accessState. */
64
- updateState$: Subject<{ user: User, state: AccessState }> = new Subject<{ user: User, state: AccessState }>();
67
+ updateState$: Subject<{ user: User, key: string, value: UpdateValueTypes }> = new Subject<{ user: User, key: string, value: UpdateValueTypes }>();
65
68
 
66
69
 
67
70
  // --------------- HELPER FUNCTIONS AND OTHER ----------
@@ -83,10 +86,12 @@ export class WaitlistComponent implements OnInit, OnDestroy {
83
86
 
84
87
  this.updateState$.pipe(
85
88
  takeUntil(this.unsubscribe$),
86
- ).subscribe(({ user, state }) => {
89
+ ).subscribe(({ user, key, value }) => {
90
+ const data = {};
91
+ data[key] = value;
87
92
  const actionSets: ActionSet[] = [{
88
93
  action: new UpdateUser(user.__id, {
89
- accessState: state,
94
+ ...data,
90
95
  }, this.containerId),
91
96
  responseActionTypes: {
92
97
  success: UserActionTypes.UPDATE_SUCCESS,
@@ -100,7 +105,7 @@ export class WaitlistComponent implements OnInit, OnDestroy {
100
105
  successActionFn: (actionSetResponses) => {
101
106
  return [
102
107
  new ShowSnackbar({
103
- message: `Updated ${user.name}'s accessState to ${state}`,
108
+ message: `Set ${user.name}'s ${key} to ${value}`,
104
109
  config: { duration: 3000 },
105
110
  }),
106
111
  ];
@@ -5,8 +5,12 @@ import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from '
5
5
  import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
6
6
  import { FirebaseService } from '../../firebase/firebase.service';
7
7
  import { CachedLoadConnectionsService } from '../cached-load-connections.service';
8
+ import { Store, select } from '@ngrx/store';
9
+ import * as fromStore from '../../store/app.reducer';
10
+ import * as fromAuth from '../../store/auth/auth.reducer';
11
+ import { UpdateAppState } from '../../store/app-state/app-state.actions';
8
12
 
9
- import { User } from './user.model';
13
+ import { User, AccessState } from './user.model';
10
14
  import { UserActionTypes, UserActions,
11
15
  AddedUser, RemovedUser,
12
16
  StreamUser, StreamUserSuccess, StreamUserFail,
@@ -116,7 +120,20 @@ export class UserEffects {
116
120
  }
117
121
 
118
122
  actionsOnUpdate(action: UpdateUser): Observable<Action> {
119
- return EMPTY;
123
+
124
+ if (action.changes.hasOwnProperty('accessState')) {
125
+ // TODO: inefficient since we're querying all users. replace with count query
126
+ // once added to library
127
+ return this.db.queryListOnce('users', [['accessState', '==', AccessState.WAITING]]).pipe(
128
+ mergeMap((users: User[]) => {
129
+ return [new UpdateAppState('app', {
130
+ _totalWaiting: users.length,
131
+ }, action.correlationId)];
132
+ }),
133
+ );
134
+ } else {
135
+ return EMPTY;
136
+ }
120
137
  }
121
138
 
122
139
  actionsOnRemove(action: RemoveUser): Observable<Action> {
@@ -124,6 +141,7 @@ export class UserEffects {
124
141
  }
125
142
 
126
143
  constructor(
144
+ private store: Store<fromStore.State>,
127
145
  private actions$: Actions,
128
146
  private db: FirebaseService,
129
147
  private clc: CachedLoadConnectionsService,