@tech4good/angular-schematics 13.6.0 → 13.8.0
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/README.md +3 -2
- package/package.json +1 -1
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +8 -8
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.actions.ts.template +3 -2
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.effects.ts.template +6 -5
- package/src/container/files/__name@dasherize__/+state/__name@dasherize__.selectors.ts.template +2 -2
- package/src/container/files/__name@dasherize__/__name@dasherize__.component.ts.template +25 -14
- package/src/container/index.js +13 -2
- package/src/container/index.js.map +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.actions.ts.template +9 -30
- package/src/entity/files/__name@dasherize__/__name@dasherize__.effects.ts.template +23 -24
- package/src/init/files/CHANGELOG.md.template +10 -0
- package/src/init/files/README.md.template +24 -0
- package/src/init/files/package.json.template +4 -2
- package/src/init/files/src/app/admin/admin-routing.module.ts.template +17 -0
- package/src/init/files/src/app/admin/admin.module.spec.ts.template +13 -0
- package/src/init/files/src/app/admin/admin.module.ts.template +28 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.actions.ts.template +23 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.effects.ts.template +50 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.selectors.ts.template +39 -0
- package/src/init/files/src/app/admin/waitlist/+state/waitlist.state.ts.template +13 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.animations.ts.template +4 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.html.template +30 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.scss.template +14 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.spec.ts.template +25 -0
- package/src/init/files/src/app/admin/waitlist/waitlist.component.ts.template +136 -0
- package/src/init/files/src/app/app-routing.module.ts.template +13 -5
- package/src/init/files/src/app/core/analytics/log.service.ts.template +89 -4
- package/src/init/files/src/app/core/analytics/time-analytics.service.ts.template +204 -69
- package/src/init/files/src/app/core/auth/auth.guard.ts.template +85 -0
- package/src/init/files/src/app/core/core.module.ts.template +4 -0
- package/src/init/files/src/app/core/firebase/firebase.service.ts.template +4 -4
- package/src/init/files/src/app/core/local-storage/local-storage.service.ts.template +47 -0
- package/src/init/files/src/app/core/local-storage/session-local-storage.service.ts.template +67 -0
- package/src/init/files/src/app/core/local-storage/session.service.ts.template +48 -0
- package/src/init/files/src/app/core/store/app-state/app-state.actions.ts.template +270 -0
- package/src/init/files/src/app/core/store/app-state/app-state.effects.ts.template +131 -0
- package/src/init/files/src/app/core/store/app-state/app-state.model.ts.template +8 -0
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/app-state/app-state.reducer.ts.template +51 -0
- package/src/init/files/src/app/core/store/app-state/app-state.service.ts.template +50 -0
- package/src/init/files/src/app/core/store/app.effects.ts.template +10 -2
- package/src/init/files/src/app/core/store/app.reducer.ts.template +6 -0
- package/src/init/files/src/app/core/store/app.selectors.ts.template +12 -0
- package/src/init/files/src/app/core/store/auth/auth.actions.ts.template +3 -1
- package/src/init/files/src/app/core/store/auth/auth.effects.ts.template +27 -31
- package/src/init/files/src/app/core/store/auth/auth.reducer.ts.template +1 -1
- package/src/init/files/src/app/core/store/auth/auth.selectors.ts.template +5 -1
- package/src/init/files/src/app/core/store/cached-load-connections.service.ts.template +9 -8
- package/src/init/files/src/app/core/store/user/user.model.ts.template +14 -0
- package/src/init/files/src/app/core/store/user-context/user-context.actions.ts.template +270 -0
- package/src/init/files/src/app/core/store/user-context/user-context.effects.ts.template +131 -0
- package/src/init/files/src/app/core/store/user-context/user-context.model.ts.template +13 -0
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.spec.ts.template +13 -0
- package/src/init/files/src/app/core/store/user-context/user-context.reducer.ts.template +51 -0
- package/src/init/files/src/app/core/store/user-context/user-context.service.ts.template +50 -0
- package/src/init/files/src/app/general/general-routing.module.ts.template +6 -2
- package/src/init/files/src/app/general/general.module.ts.template +8 -2
- package/src/init/files/src/app/general/home/+state/home.actions.ts.template +26 -0
- package/src/init/files/src/app/general/home/+state/home.effects.ts.template +48 -0
- package/src/init/files/src/app/general/home/+state/home.model.ts.template +0 -0
- package/src/init/files/src/app/general/home/+state/home.selectors.ts.template +20 -0
- package/src/init/files/src/app/general/home/+state/home.state.ts.template +13 -0
- package/src/init/files/src/app/general/home/home.animations.ts.template +4 -0
- package/src/init/files/src/app/general/home/home.component.html.template +5 -0
- package/src/init/files/src/app/general/home/home.component.scss.template +5 -0
- package/src/init/files/src/app/general/{e404/e404.component.spec.ts.template → home/home.component.spec.ts.template} +6 -6
- package/src/init/files/src/app/general/home/home.component.ts.template +88 -0
- package/src/init/files/src/app/general/landing/+state/landing.actions.ts.template +26 -0
- package/src/init/files/src/app/general/landing/+state/landing.effects.ts.template +48 -0
- package/src/init/files/src/app/general/landing/+state/landing.model.ts.template +0 -0
- package/src/init/files/src/app/general/landing/+state/landing.selectors.ts.template +20 -0
- package/src/init/files/src/app/general/landing/+state/landing.state.ts.template +13 -0
- package/src/init/files/src/app/general/landing/landing.animations.ts.template +4 -0
- package/src/init/files/src/app/general/landing/landing.component.html.template +3 -0
- package/src/init/files/src/app/general/landing/landing.component.scss.template +13 -0
- package/src/init/files/src/app/general/landing/landing.component.spec.ts.template +25 -0
- package/src/init/files/src/app/general/landing/landing.component.ts.template +98 -0
- package/src/init/files/src/app/general/login/login.component.html.template +5 -5
- package/src/init/files/src/app/general/login/login.component.ts.template +12 -4
- package/src/init/files/src/app/onboarding/consent/+state/consent.actions.ts.template +23 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.effects.ts.template +47 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.model.ts.template +0 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.selectors.ts.template +20 -0
- package/src/init/files/src/app/onboarding/consent/+state/consent.state.ts.template +13 -0
- package/src/init/files/src/app/onboarding/consent/consent.animations.ts.template +4 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.html.template +61 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.scss.template +77 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.spec.ts.template +25 -0
- package/src/init/files/src/app/onboarding/consent/consent.component.ts.template +152 -0
- package/src/init/files/src/app/onboarding/onboarding-routing.module.ts.template +19 -0
- package/src/init/files/src/app/onboarding/onboarding.module.spec.ts.template +13 -0
- package/src/init/files/src/app/onboarding/onboarding.module.ts.template +32 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.actions.ts.template +26 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.effects.ts.template +52 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.model.ts.template +9 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.selectors.ts.template +42 -0
- package/src/init/files/src/app/onboarding/waiting/+state/waiting.state.ts.template +13 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.animations.ts.template +4 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.html.template +57 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.scss.template +99 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.spec.ts.template +25 -0
- package/src/init/files/src/app/onboarding/waiting/waiting.component.ts.template +279 -0
- package/src/init/files/src/app/shared/shared.module.ts.template +3 -0
- package/src/init/files/src/index.html.template +0 -3
- package/src/module/files/__name@dasherize__/__name@dasherize__-routing.module.ts.template +2 -0
- package/src/init/files/src/app/general/e404/e404.component.html.template +0 -1
- package/src/init/files/src/app/general/e404/e404.component.ts.template +0 -28
- /package/src/init/files/src/app/{general/e404/e404.component.scss.template → admin/waitlist/+state/waitlist.model.ts.template} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { LocalStorageService } from './local-storage.service';
|
|
3
|
+
import { LoggingAngularFirestore } from '../setup/firebase-setup';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a sessionId and deviceId for the user. The sessionId should be stored
|
|
7
|
+
* in sessionStorage and the deviceId in localStorage.
|
|
8
|
+
*/
|
|
9
|
+
@Injectable({
|
|
10
|
+
providedIn: 'root',
|
|
11
|
+
})
|
|
12
|
+
export class SessionService {
|
|
13
|
+
/** Keys for localStorage/sessionStorage */
|
|
14
|
+
private SESSION_ID_KEY = 'sessionId';
|
|
15
|
+
private DEVICE_ID_KEY = 'deviceId';
|
|
16
|
+
|
|
17
|
+
/** The actual sessionId/deviceId */
|
|
18
|
+
private sessionId;
|
|
19
|
+
private deviceId;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
private local: LocalStorageService,
|
|
23
|
+
private log: LoggingAngularFirestore,
|
|
24
|
+
) {
|
|
25
|
+
// Get sessionId from sessionStorage. If does not exist, create one
|
|
26
|
+
this.sessionId = sessionStorage.getItem(this.SESSION_ID_KEY);
|
|
27
|
+
if (!this.sessionId) {
|
|
28
|
+
this.sessionId = this.log.createId();
|
|
29
|
+
sessionStorage.setItem(this.SESSION_ID_KEY, this.sessionId);
|
|
30
|
+
}
|
|
31
|
+
// console.log('SESSION_ID', this.sessionId);
|
|
32
|
+
|
|
33
|
+
this.deviceId = this.local.getItem(this.DEVICE_ID_KEY);
|
|
34
|
+
if (!this.deviceId) {
|
|
35
|
+
this.deviceId = this.log.createId();
|
|
36
|
+
this.local.setItem(this.DEVICE_ID_KEY, this.deviceId);
|
|
37
|
+
}
|
|
38
|
+
// console.log('DEVICE_ID', this.deviceId);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public getSessionId(): string {
|
|
42
|
+
return this.sessionId;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public getDeviceId(): string {
|
|
46
|
+
return this.deviceId;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
import { LoadAction } from '../app.actions';
|
|
3
|
+
import { AppState } from './app-state.model';
|
|
4
|
+
|
|
5
|
+
export enum AppStateActionTypes {
|
|
6
|
+
STREAM = '[AppState] stream appState',
|
|
7
|
+
STREAM_SUCCESS = '[AppState] stream appState success',
|
|
8
|
+
STREAM_FAIL = '[AppState] stream appState fail',
|
|
9
|
+
LOAD = '[AppState] load appState',
|
|
10
|
+
LOAD_SUCCESS = '[AppState] load appState success',
|
|
11
|
+
LOAD_FAIL = '[AppState] load appState fail',
|
|
12
|
+
ADD = '[AppState] add appState',
|
|
13
|
+
ADD_SUCCESS = '[AppState] add appState success',
|
|
14
|
+
ADD_FAIL = '[AppState] add appState fail',
|
|
15
|
+
UPDATE = '[AppState] update appState',
|
|
16
|
+
UPDATE_SUCCESS = '[AppState] update appState success',
|
|
17
|
+
UPDATE_FAIL = '[AppState] update appState fail',
|
|
18
|
+
UPSERT = '[AppState] upsert appState',
|
|
19
|
+
UPSERT_SUCCESS = '[AppState] upsert appState success',
|
|
20
|
+
UPSERT_FAIL = '[AppState] upsert appState fail',
|
|
21
|
+
REMOVE = '[AppState] remove appState',
|
|
22
|
+
REMOVE_SUCCESS = '[AppState] remove appState success',
|
|
23
|
+
REMOVE_FAIL = '[AppState] remove appState fail',
|
|
24
|
+
LOADED = '[AppState] loaded',
|
|
25
|
+
ADDED = '[AppState] added',
|
|
26
|
+
MODIFIED = '[AppState] modified',
|
|
27
|
+
REMOVED = '[AppState] removed',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// See Firebase Docs for current constraints on valid queries
|
|
31
|
+
export class StreamAppState implements Action {
|
|
32
|
+
readonly type = AppStateActionTypes.STREAM;
|
|
33
|
+
constructor(
|
|
34
|
+
// property, comparator, value
|
|
35
|
+
public queryParams: [string, string, any][],
|
|
36
|
+
public queryOptions: {
|
|
37
|
+
orderBy?: string | [string, string],
|
|
38
|
+
limit?: number,
|
|
39
|
+
startAt?: string,
|
|
40
|
+
startAfter?: string,
|
|
41
|
+
endAt?: string,
|
|
42
|
+
endBefore?: string,
|
|
43
|
+
},
|
|
44
|
+
public correlationId: string,
|
|
45
|
+
public followupActions?: (appState: AppState) => LoadAction[],
|
|
46
|
+
) {}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class StreamAppStateSuccess implements Action {
|
|
50
|
+
readonly type = AppStateActionTypes.STREAM_SUCCESS;
|
|
51
|
+
constructor(
|
|
52
|
+
public queryParams: [string, string, any][],
|
|
53
|
+
public queryOptions: {
|
|
54
|
+
orderBy?: string | [string, string],
|
|
55
|
+
limit?: number,
|
|
56
|
+
startAt?: string,
|
|
57
|
+
startAfter?: string,
|
|
58
|
+
endAt?: string,
|
|
59
|
+
endBefore?: string,
|
|
60
|
+
},
|
|
61
|
+
public correlationId: string,
|
|
62
|
+
public followupActions?: (appState: AppState) => LoadAction[],
|
|
63
|
+
) {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class StreamAppStateFail implements Action {
|
|
67
|
+
readonly type = AppStateActionTypes.STREAM_FAIL;
|
|
68
|
+
constructor(
|
|
69
|
+
public error: any,
|
|
70
|
+
public correlationId?: string,
|
|
71
|
+
) {}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
export class LoadAppState implements Action {
|
|
76
|
+
readonly type = AppStateActionTypes.LOAD;
|
|
77
|
+
constructor(
|
|
78
|
+
// property, comparator, value
|
|
79
|
+
public queryParams: [string, string, any][],
|
|
80
|
+
public queryOptions: {
|
|
81
|
+
orderBy?: string | [string, string],
|
|
82
|
+
limit?: number,
|
|
83
|
+
startAt?: string,
|
|
84
|
+
startAfter?: string,
|
|
85
|
+
endAt?: string,
|
|
86
|
+
endBefore?: string,
|
|
87
|
+
},
|
|
88
|
+
public correlationId: string,
|
|
89
|
+
public followupActions?: (appState: AppState) => LoadAction[],
|
|
90
|
+
) {}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export class LoadAppStateSuccess implements Action {
|
|
94
|
+
readonly type = AppStateActionTypes.LOAD_SUCCESS;
|
|
95
|
+
constructor(
|
|
96
|
+
public queryParams: [string, string, any][],
|
|
97
|
+
public queryOptions: {
|
|
98
|
+
orderBy?: string | [string, string],
|
|
99
|
+
limit?: number,
|
|
100
|
+
startAt?: string,
|
|
101
|
+
startAfter?: string,
|
|
102
|
+
endAt?: string,
|
|
103
|
+
endBefore?: string,
|
|
104
|
+
},
|
|
105
|
+
public correlationId: string,
|
|
106
|
+
public followupActions?: (appState: AppState) => LoadAction[],
|
|
107
|
+
) {}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class LoadAppStateFail implements Action {
|
|
111
|
+
readonly type = AppStateActionTypes.LOAD_FAIL;
|
|
112
|
+
constructor(
|
|
113
|
+
public error: any,
|
|
114
|
+
public correlationId?: string,
|
|
115
|
+
) {}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class AddAppState implements Action {
|
|
119
|
+
readonly type = AppStateActionTypes.ADD;
|
|
120
|
+
constructor(
|
|
121
|
+
public appState: AppState,
|
|
122
|
+
public correlationId?: string,
|
|
123
|
+
) {}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class AddAppStateSuccess implements Action {
|
|
127
|
+
readonly type = AppStateActionTypes.ADD_SUCCESS;
|
|
128
|
+
constructor(
|
|
129
|
+
public appState: AppState,
|
|
130
|
+
public correlationId?: string,
|
|
131
|
+
) {}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class AddAppStateFail implements Action {
|
|
135
|
+
readonly type = AppStateActionTypes.ADD_FAIL;
|
|
136
|
+
constructor(
|
|
137
|
+
public error: any,
|
|
138
|
+
public correlationId?: string,
|
|
139
|
+
) {}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class UpdateAppState implements Action {
|
|
143
|
+
readonly type = AppStateActionTypes.UPDATE;
|
|
144
|
+
constructor(
|
|
145
|
+
public __id: string,
|
|
146
|
+
public changes: Partial<AppState>,
|
|
147
|
+
public correlationId?: string,
|
|
148
|
+
) { }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export class UpdateAppStateSuccess implements Action {
|
|
152
|
+
readonly type = AppStateActionTypes.UPDATE_SUCCESS;
|
|
153
|
+
constructor(
|
|
154
|
+
public __id: string,
|
|
155
|
+
public changes: Partial<AppState>,
|
|
156
|
+
public correlationId?: string,
|
|
157
|
+
) {}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export class UpdateAppStateFail implements Action {
|
|
161
|
+
readonly type = AppStateActionTypes.UPDATE_FAIL;
|
|
162
|
+
constructor(
|
|
163
|
+
public error: any,
|
|
164
|
+
public correlationId?: string,
|
|
165
|
+
) {}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export class UpsertAppState implements Action {
|
|
169
|
+
readonly type = AppStateActionTypes.UPSERT;
|
|
170
|
+
constructor(
|
|
171
|
+
public appState: AppState,
|
|
172
|
+
public correlationId?: string,
|
|
173
|
+
) {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export class UpsertAppStateSuccess implements Action {
|
|
177
|
+
readonly type = AppStateActionTypes.UPSERT_SUCCESS;
|
|
178
|
+
constructor(
|
|
179
|
+
public appState: AppState,
|
|
180
|
+
public correlationId?: string,
|
|
181
|
+
) {}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class UpsertAppStateFail implements Action {
|
|
185
|
+
readonly type = AppStateActionTypes.UPSERT_FAIL;
|
|
186
|
+
constructor(
|
|
187
|
+
public error: any,
|
|
188
|
+
public correlationId?: string,
|
|
189
|
+
) {}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export class RemoveAppState implements Action {
|
|
193
|
+
readonly type = AppStateActionTypes.REMOVE;
|
|
194
|
+
constructor(
|
|
195
|
+
public __id: string,
|
|
196
|
+
public correlationId?: string,
|
|
197
|
+
) { }
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export class RemoveAppStateSuccess implements Action {
|
|
201
|
+
readonly type = AppStateActionTypes.REMOVE_SUCCESS;
|
|
202
|
+
constructor(
|
|
203
|
+
public __id: string,
|
|
204
|
+
public correlationId?: string,
|
|
205
|
+
) {}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export class RemoveAppStateFail implements Action {
|
|
209
|
+
readonly type = AppStateActionTypes.REMOVE_FAIL;
|
|
210
|
+
constructor(
|
|
211
|
+
public error: any,
|
|
212
|
+
public correlationId?: string,
|
|
213
|
+
) {}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export class LoadedAppState implements Action {
|
|
217
|
+
readonly type = AppStateActionTypes.LOADED;
|
|
218
|
+
constructor(
|
|
219
|
+
public payload: AppState[],
|
|
220
|
+
public correlationId?: string,
|
|
221
|
+
) {}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class AddedAppState implements Action {
|
|
225
|
+
readonly type = AppStateActionTypes.ADDED;
|
|
226
|
+
constructor(
|
|
227
|
+
public payload: AppState,
|
|
228
|
+
public correlationId?: string,
|
|
229
|
+
) {}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class ModifiedAppState implements Action {
|
|
233
|
+
readonly type = AppStateActionTypes.MODIFIED;
|
|
234
|
+
constructor(
|
|
235
|
+
public payload: AppState,
|
|
236
|
+
public correlationId?: string,
|
|
237
|
+
) {}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export class RemovedAppState implements Action {
|
|
241
|
+
readonly type = AppStateActionTypes.REMOVED;
|
|
242
|
+
constructor(
|
|
243
|
+
public payload: AppState,
|
|
244
|
+
public correlationId?: string,
|
|
245
|
+
) {}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export type AppStateActions =
|
|
249
|
+
StreamAppState |
|
|
250
|
+
StreamAppStateSuccess |
|
|
251
|
+
StreamAppStateFail |
|
|
252
|
+
LoadAppState |
|
|
253
|
+
LoadAppStateSuccess |
|
|
254
|
+
LoadAppStateFail |
|
|
255
|
+
AddAppState |
|
|
256
|
+
AddAppStateSuccess |
|
|
257
|
+
AddAppStateFail |
|
|
258
|
+
UpdateAppState |
|
|
259
|
+
UpdateAppStateSuccess |
|
|
260
|
+
UpdateAppStateFail |
|
|
261
|
+
UpsertAppState |
|
|
262
|
+
UpsertAppStateSuccess |
|
|
263
|
+
UpsertAppStateFail |
|
|
264
|
+
RemoveAppState |
|
|
265
|
+
RemoveAppStateSuccess |
|
|
266
|
+
RemoveAppStateFail |
|
|
267
|
+
LoadedAppState |
|
|
268
|
+
AddedAppState |
|
|
269
|
+
ModifiedAppState |
|
|
270
|
+
RemovedAppState;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Action } from '@ngrx/store';
|
|
3
|
+
import { Actions, createEffect, ofType } from '@ngrx/effects';
|
|
4
|
+
import { EMPTY, of, Observable, throwError, forkJoin, from, pipe, merge } from 'rxjs';
|
|
5
|
+
import { switchMap, flatMap, mergeMap, map, catchError, tap, take } from 'rxjs/operators';
|
|
6
|
+
import { FirebaseService } from '../../firebase/firebase.service';
|
|
7
|
+
import { CachedLoadConnectionsService } from '../cached-load-connections.service';
|
|
8
|
+
|
|
9
|
+
import { AppState } from './app-state.model';
|
|
10
|
+
import { AppStateActionTypes, AppStateActions,
|
|
11
|
+
StreamAppState, StreamAppStateSuccess, StreamAppStateFail,
|
|
12
|
+
LoadAppState, LoadAppStateSuccess, LoadAppStateFail,
|
|
13
|
+
AddAppState, AddAppStateSuccess, AddAppStateFail,
|
|
14
|
+
UpdateAppState, UpdateAppStateSuccess, UpdateAppStateFail,
|
|
15
|
+
UpsertAppState, UpsertAppStateSuccess, UpsertAppStateFail,
|
|
16
|
+
RemoveAppState, RemoveAppStateSuccess, RemoveAppStateFail } from './app-state.actions';
|
|
17
|
+
|
|
18
|
+
@Injectable()
|
|
19
|
+
export class AppStateEffects {
|
|
20
|
+
/** Process the stream action to create firebase connections. */
|
|
21
|
+
stream$: Observable<Action> = createEffect(
|
|
22
|
+
() => this.actions$.pipe(
|
|
23
|
+
ofType<StreamAppState>(AppStateActionTypes.STREAM),
|
|
24
|
+
mergeMap((action: StreamAppState) => {
|
|
25
|
+
const connection = this.clc.processLoadAction(action);
|
|
26
|
+
return connection.loadStream.pipe(
|
|
27
|
+
take(1),
|
|
28
|
+
map(() => new StreamAppStateSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
|
|
29
|
+
catchError((error) => of(new StreamAppStateFail(error, action.correlationId))),
|
|
30
|
+
);
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
/** Process the load action to create firebase connections. */
|
|
36
|
+
load$: Observable<Action> = createEffect(
|
|
37
|
+
() => this.actions$.pipe(
|
|
38
|
+
ofType<LoadAppState>(AppStateActionTypes.LOAD),
|
|
39
|
+
mergeMap((action: LoadAppState) => {
|
|
40
|
+
const connection = this.clc.processLoadAction(action);
|
|
41
|
+
return connection.loadStream.pipe(
|
|
42
|
+
take(1),
|
|
43
|
+
map(() => new LoadAppStateSuccess(action.queryParams, action.queryOptions, action.correlationId, action.followupActions)),
|
|
44
|
+
catchError((error) => of(new LoadAppStateFail(error, action.correlationId))),
|
|
45
|
+
);
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
/** Process the add action to update database and initiate callbacks. */
|
|
51
|
+
add$: Observable<Action> = createEffect(
|
|
52
|
+
() => this.actions$.pipe(
|
|
53
|
+
ofType<AddAppState>(AppStateActionTypes.ADD),
|
|
54
|
+
mergeMap((action: AddAppState) => {
|
|
55
|
+
return this.db.addEntity('appStates', action.appState).pipe(
|
|
56
|
+
mergeMap(() => merge(
|
|
57
|
+
of(new AddAppStateSuccess(action.appState, action.correlationId)),
|
|
58
|
+
this.actionsOnAdd(action),
|
|
59
|
+
)),
|
|
60
|
+
catchError((error) => of(new AddAppStateFail(error, action.correlationId))),
|
|
61
|
+
);
|
|
62
|
+
}),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/** Process the update action to update database and initiate callbacks. */
|
|
67
|
+
update$: Observable<Action> = createEffect(
|
|
68
|
+
() => this.actions$.pipe(
|
|
69
|
+
ofType<UpdateAppState>(AppStateActionTypes.UPDATE),
|
|
70
|
+
mergeMap((action: UpdateAppState) => {
|
|
71
|
+
return this.db.updateEntity('appStates', action.__id, action.changes).pipe(
|
|
72
|
+
mergeMap(() => merge(
|
|
73
|
+
of(new UpdateAppStateSuccess(action.__id, action.changes, action.correlationId)),
|
|
74
|
+
this.actionsOnUpdate(action),
|
|
75
|
+
)),
|
|
76
|
+
catchError((error) => of(new UpdateAppStateFail(error, action.correlationId))),
|
|
77
|
+
);
|
|
78
|
+
}),
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
/** Process the upsert action to update database and initiate callbacks. */
|
|
83
|
+
upsert$: Observable<Action> = createEffect(
|
|
84
|
+
() => this.actions$.pipe(
|
|
85
|
+
ofType<UpsertAppState>(AppStateActionTypes.UPSERT),
|
|
86
|
+
mergeMap((action: UpsertAppState) => {
|
|
87
|
+
return this.db.upsertEntity('appStates', action.appState).pipe(
|
|
88
|
+
mergeMap((results) => merge(
|
|
89
|
+
of(new UpsertAppStateSuccess(action.appState, action.correlationId)),
|
|
90
|
+
results.type === 'add' ? this.actionsOnAdd(new AddAppState(action.appState, action.correlationId)) : this.actionsOnUpdate(new UpdateAppState(action.appState.__id, action.appState, action.correlationId)),
|
|
91
|
+
)),
|
|
92
|
+
catchError((error) => of(new UpsertAppStateFail(error, action.correlationId))),
|
|
93
|
+
);
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
/** Process the remove action to update database and initiate callbacks. */
|
|
99
|
+
remove$: Observable<Action> = createEffect(
|
|
100
|
+
() => this.actions$.pipe(
|
|
101
|
+
ofType<RemoveAppState>(AppStateActionTypes.REMOVE),
|
|
102
|
+
mergeMap((action: RemoveAppState) => {
|
|
103
|
+
return this.db.removeEntity('appStates', action.__id).pipe(
|
|
104
|
+
mergeMap(() => merge(
|
|
105
|
+
of(new RemoveAppStateSuccess(action.__id, action.correlationId)),
|
|
106
|
+
this.actionsOnRemove(action),
|
|
107
|
+
)),
|
|
108
|
+
catchError((error) => of(new RemoveAppStateFail(error, action.correlationId))),
|
|
109
|
+
);
|
|
110
|
+
}),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
actionsOnAdd(action: AddAppState): Observable<Action> {
|
|
115
|
+
return EMPTY;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
actionsOnUpdate(action: UpdateAppState): Observable<Action> {
|
|
119
|
+
return EMPTY;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
actionsOnRemove(action: RemoveAppState): Observable<Action> {
|
|
123
|
+
return EMPTY;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
constructor(
|
|
127
|
+
private actions$: Actions,
|
|
128
|
+
private db: FirebaseService,
|
|
129
|
+
private clc: CachedLoadConnectionsService,
|
|
130
|
+
) {}
|
|
131
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { reducer, initialState } from './app-state.reducer';
|
|
2
|
+
|
|
3
|
+
describe('AppState Reducer', () => {
|
|
4
|
+
describe('unknown action', () => {
|
|
5
|
+
it('should return the initial state', () => {
|
|
6
|
+
const action = {} as any;
|
|
7
|
+
|
|
8
|
+
const result = reducer(initialState, action);
|
|
9
|
+
|
|
10
|
+
expect(result).toBe(initialState);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
|
|
2
|
+
import { AppState } from './app-state.model';
|
|
3
|
+
import { AppStateActions, AppStateActionTypes } from './app-state.actions';
|
|
4
|
+
import { createFeatureSelector } from '@ngrx/store';
|
|
5
|
+
|
|
6
|
+
export interface State extends EntityState<AppState> {
|
|
7
|
+
// additional entities state properties
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const adapter: EntityAdapter<AppState> = createEntityAdapter<AppState>({
|
|
11
|
+
selectId: (appState: AppState) => appState.__id,
|
|
12
|
+
sortComparer: false,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const initialState: State = adapter.getInitialState({
|
|
16
|
+
// additional entity state properties
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export function reducer(
|
|
20
|
+
state: State = initialState,
|
|
21
|
+
action: AppStateActions,
|
|
22
|
+
) {
|
|
23
|
+
switch (action.type) {
|
|
24
|
+
case AppStateActionTypes.ADDED:
|
|
25
|
+
return adapter.upsertOne(action.payload, state);
|
|
26
|
+
|
|
27
|
+
case AppStateActionTypes.LOADED:
|
|
28
|
+
return adapter.upsertMany(action.payload, state);
|
|
29
|
+
|
|
30
|
+
case AppStateActionTypes.MODIFIED:
|
|
31
|
+
return adapter.updateOne({
|
|
32
|
+
id: action.payload.__id,
|
|
33
|
+
changes: action.payload,
|
|
34
|
+
}, state);
|
|
35
|
+
|
|
36
|
+
case AppStateActionTypes.REMOVED:
|
|
37
|
+
return adapter.removeOne(action.payload.__id, state);
|
|
38
|
+
|
|
39
|
+
default:
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const getAppStateState = createFeatureSelector<State>('appState');
|
|
45
|
+
|
|
46
|
+
export const {
|
|
47
|
+
selectIds,
|
|
48
|
+
selectEntities,
|
|
49
|
+
selectAll,
|
|
50
|
+
selectTotal,
|
|
51
|
+
} = adapter.getSelectors(getAppStateState);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { CachedSelectorsService } from '../cached-selectors.service';
|
|
4
|
+
import { FirebaseService } from '../../firebase/firebase.service';
|
|
5
|
+
import { AppState } from './app-state.model';
|
|
6
|
+
|
|
7
|
+
@Injectable({
|
|
8
|
+
providedIn: 'root',
|
|
9
|
+
})
|
|
10
|
+
export class AppStateService {
|
|
11
|
+
constructor(
|
|
12
|
+
private cs: CachedSelectorsService,
|
|
13
|
+
private db: FirebaseService,
|
|
14
|
+
) { }
|
|
15
|
+
|
|
16
|
+
/** Select a appState from the store. */
|
|
17
|
+
public selectAppState = <T extends AppState>(
|
|
18
|
+
id: string,
|
|
19
|
+
correlationId: string,
|
|
20
|
+
childrenFn?: (e: AppState) => { [index: string]: Observable<any> },
|
|
21
|
+
): Observable<T> => {
|
|
22
|
+
return this.cs.selectEntityObj<AppState, T>('appState', id, correlationId, childrenFn);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Select appStates from the store. */
|
|
26
|
+
public selectAppStates = <T extends AppState>(
|
|
27
|
+
queryParams: [string, string, any][],
|
|
28
|
+
correlationId: string,
|
|
29
|
+
childrenFn?: (e: AppState) => { [index: string]: Observable<any> },
|
|
30
|
+
): Observable<Array<T>> => {
|
|
31
|
+
return this.cs.selectEntityList<AppState, T>('appState', queryParams, correlationId, childrenFn);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Get a appState directly from the database. */
|
|
35
|
+
public getAppState = <T extends AppState>(
|
|
36
|
+
id: string,
|
|
37
|
+
childrenFn?: (e: AppState) => { [index: string]: Observable<any> },
|
|
38
|
+
): Observable<T> => {
|
|
39
|
+
return this.db.queryObjOnce<AppState, T>('appStates', id, childrenFn);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Get appStates directly from the database. */
|
|
43
|
+
public getAppStates = <T extends AppState>(
|
|
44
|
+
queryParams: [string, string, any][],
|
|
45
|
+
queryOptions?: { [index: string]: any },
|
|
46
|
+
childrenFn?: (e: AppState) => { [index: string]: Observable<any> },
|
|
47
|
+
): Observable<Array<T>> => {
|
|
48
|
+
return this.db.queryListOnce<AppState, T>('appStates', queryParams, queryOptions, childrenFn);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -117,7 +117,11 @@ export class AppEffects {
|
|
|
117
117
|
// If no actions, we should run the success callback
|
|
118
118
|
if (responseObsArr.length === 0) {
|
|
119
119
|
// If there are no actions, just run the success callback
|
|
120
|
-
|
|
120
|
+
if (actionFlow.payload.successActionFn) {
|
|
121
|
+
return actionFlow.payload.successActionFn([]);
|
|
122
|
+
} else {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
121
125
|
} else {
|
|
122
126
|
return forkJoin(responseObsArr).pipe(
|
|
123
127
|
mergeMap((actionSetResponses) => {
|
|
@@ -147,7 +151,11 @@ export class AppEffects {
|
|
|
147
151
|
return actionSetCallbacks;
|
|
148
152
|
}
|
|
149
153
|
} else {
|
|
150
|
-
|
|
154
|
+
if (actionFlow.payload.successActionFn) {
|
|
155
|
+
return actionFlow.payload.successActionFn(actionSetResponses);
|
|
156
|
+
} else {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
151
159
|
}
|
|
152
160
|
}),
|
|
153
161
|
);
|
|
@@ -11,12 +11,16 @@ import { routerReducer, RouterReducerState } from '@ngrx/router-store';
|
|
|
11
11
|
import * as fromAuth from './auth/auth.reducer';
|
|
12
12
|
|
|
13
13
|
// Entity Reducers
|
|
14
|
+
import * as fromAppState from './app-state/app-state.reducer';
|
|
15
|
+
import * as fromUserContext from './user-context/user-context.reducer';
|
|
14
16
|
import * as fromUser from './user/user.reducer';
|
|
15
17
|
|
|
16
18
|
export interface State {
|
|
17
19
|
auth: fromAuth.State;
|
|
18
20
|
router: RouterReducerState;
|
|
19
21
|
// Entity State
|
|
22
|
+
appState: fromAppState.State;
|
|
23
|
+
userContext: fromUserContext.State;
|
|
20
24
|
user: fromUser.State;
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -24,6 +28,8 @@ export const reducers: ActionReducerMap<State> = {
|
|
|
24
28
|
router: routerReducer,
|
|
25
29
|
auth: fromAuth.reducer,
|
|
26
30
|
// Entity Reducers
|
|
31
|
+
appState: fromAppState.reducer,
|
|
32
|
+
userContext: fromUserContext.reducer,
|
|
27
33
|
user: fromUser.reducer,
|
|
28
34
|
};
|
|
29
35
|
|
|
@@ -4,6 +4,8 @@ import { CachedSelectorsService } from './cached-selectors.service';
|
|
|
4
4
|
import { AuthSelectorsService } from './auth/auth.selectors';
|
|
5
5
|
|
|
6
6
|
// Entity Selectors
|
|
7
|
+
import { AppStateService } from './app-state/app-state.service';
|
|
8
|
+
import { UserContextService } from './user-context/user-context.service';
|
|
7
9
|
import { UserService } from './user/user.service';
|
|
8
10
|
|
|
9
11
|
@Injectable({
|
|
@@ -14,6 +16,8 @@ export class EntitySelectorService {
|
|
|
14
16
|
private cachedSelectors: CachedSelectorsService,
|
|
15
17
|
private auth: AuthSelectorsService,
|
|
16
18
|
// Entity Selectors
|
|
19
|
+
private appState: AppStateService,
|
|
20
|
+
private userContext: UserContextService,
|
|
17
21
|
private user: UserService,
|
|
18
22
|
) { }
|
|
19
23
|
|
|
@@ -23,6 +27,14 @@ export class EntitySelectorService {
|
|
|
23
27
|
public selectAuthUser = this.auth.selectAuthUser;
|
|
24
28
|
|
|
25
29
|
// Entity Selectors
|
|
30
|
+
public getAppState = this.appState.getAppState;
|
|
31
|
+
public getAppStates = this.appState.getAppStates;
|
|
32
|
+
public selectAppState = this.appState.selectAppState;
|
|
33
|
+
public selectAppStates = this.appState.selectAppStates;
|
|
34
|
+
public getUserContext = this.userContext.getUserContext;
|
|
35
|
+
public getUserContexts = this.userContext.getUserContexts;
|
|
36
|
+
public selectUserContext = this.userContext.selectUserContext;
|
|
37
|
+
public selectUserContexts = this.userContext.selectUserContexts;
|
|
26
38
|
public selectUser = this.user.selectUser;
|
|
27
39
|
public selectUser = this.user.selectUser;
|
|
28
40
|
public getUser = this.user.getUser;
|
|
@@ -51,7 +51,9 @@ export class LoginFail implements Action {
|
|
|
51
51
|
|
|
52
52
|
export class Logout implements Action {
|
|
53
53
|
readonly type = LOGOUT;
|
|
54
|
-
constructor(public
|
|
54
|
+
constructor(public payload?: {
|
|
55
|
+
doNotRoute?: boolean,
|
|
56
|
+
}, public correlationId?: string) { }
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
export class LogoutSuccess implements Action {
|