@tech4good/angular-schematics 20.1.0 → 20.3.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/.agents/skills/publish-npm/SKILL.md +37 -0
- package/.agents/skills/publish-npm/eval.yaml +17 -0
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +66 -0
- package/README.md +16 -7
- package/changelog.config.json +19 -0
- package/contributing-docs/branches-and-releases.md +57 -0
- package/contributing-docs/commit-message.md +117 -0
- package/package.json +10 -2
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +1 -0
- package/src/component/schema.json +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +1 -1
- package/src/entity/schema.json +1 -0
- package/src/ng-add/files/.gitignore.template +3 -0
- package/src/ng-add/files/package.json.template +3 -2
- package/src/ng-add/files/public/images/abstract.png +0 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.html.template +27 -22
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.scss.template +35 -4
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.ts.template +31 -75
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.html.template +25 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.scss.template +67 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.ts.template +74 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.html.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-count-pill/admin-count-pill.component.ts.template +36 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.html.template +11 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.scss.template +22 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-counts/admin-user-counts.component.ts.template +47 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.html.template +52 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.scss.template +66 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +220 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.animations.ts.template +4 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.html.template +81 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.scss.template +136 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +37 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +118 -0
- package/src/ng-add/files/src/app/app.component.html.template +2 -0
- package/src/ng-add/files/src/app/app.component.ts.template +2 -0
- package/src/ng-add/files/src/app/app.routes.ts.template +14 -18
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +58 -0
- package/src/ng-add/files/src/app/core/auth/guards/admin-override.ts.template +9 -0
- package/src/ng-add/files/src/app/core/auth/guards/index.ts.template +11 -0
- package/src/ng-add/files/src/app/core/auth/guards/redirect-if-authenticated.guard.ts.template +42 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.ts.template +39 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth-and-consent.guard.ts.template +69 -0
- package/src/ng-add/files/src/app/core/auth/guards/require-auth.guard.ts.template +35 -0
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +2 -17
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +1 -1
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +7 -1
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +1 -1
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +71 -6
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +94 -53
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +5 -5
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +5 -7
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +3 -5
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +2 -5
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +4 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.guard.ts.template +54 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.animations.ts.template +6 -0
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.html.template +70 -52
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.scss.template +73 -6
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +59 -111
- package/src/ng-add/files/src/app/first-time/early-access/early-access.guard.ts.template +44 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.animations.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.html.template +12 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.scss.template +79 -0
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +20 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.html.template +1 -1
- package/src/ng-add/files/src/app/first-time/landing/landing.component.scss.template +11 -8
- package/src/ng-add/files/src/app/first-time/landing/landing.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.html.template +3 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.scss.template +26 -0
- package/src/ng-add/files/src/app/first-time/landing/rotating-quotes/rotating-quotes.component.ts.template +52 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.html.template +21 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.scss.template +71 -0
- package/src/ng-add/files/src/app/shared/dev-status-bar/dev-status-bar.component.ts.template +70 -0
- package/src/ng-add/files/src/app/shared/hint-visibility/hint-visibility.directive.ts.template +131 -0
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.html.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +1 -1
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +2 -2
- package/src/ng-add/files/src/environments/environment.ts.template +1 -1
- package/src/ng-add/files/src/index.html.template +3 -2
- package/src/ng-add/files/src/styles/_variables.scss.template +1 -0
- package/src/ng-add/files/src/styles.scss.template +4 -2
- package/src/ng-add/schema.json +1 -0
- package/src/ng-add/files/src/app/core/auth/auth.guard.ts.template +0 -96
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { Component, OnInit, ChangeDetectionStrategy, inject, Signal, signal, computed, effect, Injector } from '@angular/core';
|
|
2
|
+
import { User, AccessState } from '../../../core/store/user/user.model';
|
|
3
|
+
import { AuthStore } from '../../../core/store/auth/auth.store';
|
|
4
|
+
import { UserStore } from '../../../core/store/user/user.store';
|
|
5
|
+
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
6
|
+
import { BatchWriteService, BATCH_WRITE_SERVICE } from 'src/app/core/store/batch-write.service';
|
|
7
|
+
import { UserContextStore, StreamUserContext } from '../../../core/store/user-context/user-context.store';
|
|
8
|
+
import { DATABASE_SERVICE } from '../../../core/firebase/database.service';
|
|
9
|
+
import { UserContext } from '../../../core/store/user-context/user-context.model';
|
|
10
|
+
import { MatIcon } from '@angular/material/icon';
|
|
11
|
+
import { MatTooltip } from '@angular/material/tooltip';
|
|
12
|
+
import { Sort } from '@angular/material/sort';
|
|
13
|
+
import { MatButton } from '@angular/material/button';
|
|
14
|
+
import { AdminUserCountsComponent } from './admin-user-counts/admin-user-counts.component';
|
|
15
|
+
import { AdminUserTableComponent } from './admin-user-table/admin-user-table.component';
|
|
16
|
+
|
|
17
|
+
export interface AdminRow {
|
|
18
|
+
user: User;
|
|
19
|
+
context: UserContext | undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If you add other columns, update this, e.g. AccessState | string | boolean;
|
|
23
|
+
type UpdateValueTypes = AccessState;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Displays the user management table with filtering and sorting.
|
|
27
|
+
* Allows admins to view all users and update their access states.
|
|
28
|
+
*/
|
|
29
|
+
@Component({
|
|
30
|
+
selector: 'app-admin-user-list',
|
|
31
|
+
templateUrl: './admin-user-list.component.html',
|
|
32
|
+
styleUrls: ['./admin-user-list.component.scss'],
|
|
33
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
34
|
+
imports: [
|
|
35
|
+
MatIcon,
|
|
36
|
+
MatTooltip,
|
|
37
|
+
MatButton,
|
|
38
|
+
AdminUserCountsComponent,
|
|
39
|
+
AdminUserTableComponent,
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
export class AdminUserListComponent implements OnInit {
|
|
43
|
+
readonly userStore = inject(UserStore);
|
|
44
|
+
readonly userContextStore = inject(UserContextStore);
|
|
45
|
+
readonly db = inject(DATABASE_SERVICE);
|
|
46
|
+
readonly injector = inject(Injector);
|
|
47
|
+
|
|
48
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
49
|
+
|
|
50
|
+
filterState = signal<AccessState | 'ALL'>('ALL');
|
|
51
|
+
limitState = signal(20);
|
|
52
|
+
|
|
53
|
+
otherSortState = signal<Sort>({ active: '_updatedAt', direction: 'desc' });
|
|
54
|
+
otherLimitState = signal(20);
|
|
55
|
+
counts = signal({ submitInterest: 0, waiting: 0, consent: 0, done: 0 });
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
/** Access options for menu sorted alphabetically. */
|
|
59
|
+
accessOptions: AccessState[] = Object.keys(AccessState)
|
|
60
|
+
.map((k) => AccessState[k] as AccessState)
|
|
61
|
+
.sort((a, b) => {
|
|
62
|
+
if (a > b) {
|
|
63
|
+
return 1;
|
|
64
|
+
} else if (a < b) {
|
|
65
|
+
return -1;
|
|
66
|
+
} else {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/** Columns to display in the table */
|
|
72
|
+
displayedColumns = ['userName', 'questionOne', 'questionTwo', 'accessState'];
|
|
73
|
+
|
|
74
|
+
// --------------- COMPUTED DATA -----------------------
|
|
75
|
+
|
|
76
|
+
/** Get array of all waiting users and their context. */
|
|
77
|
+
waitingUsers: Signal<AdminRow[]> = computed(() => {
|
|
78
|
+
// Fetch all users locally to perform client-side sort and filter
|
|
79
|
+
const users = this.userStore.selectEntities([
|
|
80
|
+
['accessState', '==', AccessState.WAITING]
|
|
81
|
+
], {});
|
|
82
|
+
|
|
83
|
+
let rows = users.map((user) => {
|
|
84
|
+
const context = this.userContextStore.selectFirst([['__userId', '==', user.__id]], {});
|
|
85
|
+
return { user, context };
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return rows;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/** Get array of all other users and their context. */
|
|
92
|
+
otherUsersFetchedCount = computed(() => {
|
|
93
|
+
return this.userStore.selectEntities([
|
|
94
|
+
['accessState', 'in', [AccessState.SUBMIT_INTEREST, AccessState.CONSENT, AccessState.DONE]]
|
|
95
|
+
], {}).length;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
otherUsers: Signal<AdminRow[]> = computed(() => {
|
|
99
|
+
const users = this.userStore.selectEntities([
|
|
100
|
+
['accessState', 'in', [AccessState.SUBMIT_INTEREST, AccessState.CONSENT, AccessState.DONE]]
|
|
101
|
+
], {});
|
|
102
|
+
|
|
103
|
+
let rows = users.map((user) => {
|
|
104
|
+
const context = this.userContextStore.selectFirst([['__userId', '==', user.__id]], {});
|
|
105
|
+
return { user, context };
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const filter = this.filterState();
|
|
109
|
+
if (filter !== 'ALL') {
|
|
110
|
+
rows = rows.filter((r) => r.user.accessState === filter);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const sort = this.otherSortState();
|
|
114
|
+
if (sort.direction) {
|
|
115
|
+
rows.sort((a, b) => {
|
|
116
|
+
const direction = sort.direction === 'asc' ? 1 : -1;
|
|
117
|
+
switch (sort.active) {
|
|
118
|
+
case 'userName': {
|
|
119
|
+
const nameA = a.user.name?.toLowerCase() || '';
|
|
120
|
+
const nameB = b.user.name?.toLowerCase() || '';
|
|
121
|
+
return nameA.localeCompare(nameB) * direction;
|
|
122
|
+
}
|
|
123
|
+
case 'accessState': {
|
|
124
|
+
const timeA = this.getStateDate(a.user)?.getTime() || 0;
|
|
125
|
+
const timeB = this.getStateDate(b.user)?.getTime() || 0;
|
|
126
|
+
return (timeA < timeB ? -1 : timeA > timeB ? 1 : 0) * direction;
|
|
127
|
+
}
|
|
128
|
+
case '_updatedAt': {
|
|
129
|
+
const timeA = a.user._updatedAt?.toDate().getTime() || 0;
|
|
130
|
+
const timeB = b.user._updatedAt?.toDate().getTime() || 0;
|
|
131
|
+
return (timeA < timeB ? -1 : timeA > timeB ? 1 : 0) * direction;
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return rows;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
onOtherSortChange(sort: Sort) {
|
|
143
|
+
this.otherSortState.set(sort);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// --------------- EVENT HANDLING ----------------------
|
|
147
|
+
|
|
148
|
+
/** Event stream for updating user accessState. */
|
|
149
|
+
async updateState(user: User, key: string, value: UpdateValueTypes) {
|
|
150
|
+
const data = {};
|
|
151
|
+
data[key] = value;
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
await this.userStore.update(user.__id, { ...data });
|
|
155
|
+
this.snackBar.open(`Set ${user.name}'s ${key} to ${value}`, '', { duration: 3000 });
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.error(e);
|
|
158
|
+
this.snackBar.open('Failed to submit response', '', { duration: 3000 });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
getStateDate(user: User): Date | null {
|
|
164
|
+
if (user.accessState === AccessState.WAITING && user.joinedWaitlistAt) {
|
|
165
|
+
return user.joinedWaitlistAt.toDate();
|
|
166
|
+
}
|
|
167
|
+
const timestamp = user._updatedAt || user._createdAt;
|
|
168
|
+
return timestamp ? timestamp.toDate() : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// --------------- OTHER -------------------------------
|
|
172
|
+
|
|
173
|
+
constructor(
|
|
174
|
+
private snackBar: MatSnackBar,
|
|
175
|
+
) {
|
|
176
|
+
}
|
|
177
|
+
// --------------- LOAD AND CLEANUP --------------------
|
|
178
|
+
|
|
179
|
+
ngOnInit() {
|
|
180
|
+
this.refreshCounts();
|
|
181
|
+
this.triggerStream();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async refreshCounts() {
|
|
185
|
+
const [submitInterest, waiting, consent, done] = await Promise.all([
|
|
186
|
+
this.db.count('users', [['accessState', '==', AccessState.SUBMIT_INTEREST]]),
|
|
187
|
+
this.db.count('users', [['accessState', '==', AccessState.WAITING]]),
|
|
188
|
+
this.db.count('users', [['accessState', '==', AccessState.CONSENT]]),
|
|
189
|
+
this.db.count('users', [['accessState', '==', AccessState.DONE]])
|
|
190
|
+
]);
|
|
191
|
+
this.counts.set({ submitInterest, waiting, consent, done });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
triggerStream() {
|
|
195
|
+
this.userStore.stream(
|
|
196
|
+
[['accessState', '==', AccessState.WAITING]],
|
|
197
|
+
{ limit: this.limitState(), orderBy: [['_createdAt', 'asc']] },
|
|
198
|
+
this.injector,
|
|
199
|
+
(user) => [StreamUserContext.create(this.userContextStore, [['__userId', '==', user.__id]], {})]
|
|
200
|
+
);
|
|
201
|
+
this.userStore.stream(
|
|
202
|
+
[['accessState', 'in', [AccessState.SUBMIT_INTEREST, AccessState.CONSENT, AccessState.DONE]]],
|
|
203
|
+
{ limit: this.otherLimitState(), orderBy: [['_updatedAt', 'desc']] },
|
|
204
|
+
this.injector,
|
|
205
|
+
(user) => [StreamUserContext.create(this.userContextStore, [['__userId', '==', user.__id]], {})]
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
loadMore() {
|
|
212
|
+
this.limitState.update(l => l + 20);
|
|
213
|
+
this.triggerStream();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
loadMoreOther() {
|
|
217
|
+
this.otherLimitState.update(l => l + 20);
|
|
218
|
+
this.triggerStream();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<div class="table-wrapper">
|
|
2
|
+
<table mat-table [dataSource]="dataSource()"
|
|
3
|
+
matSort
|
|
4
|
+
[matSortActive]="sortActive()"
|
|
5
|
+
[matSortDirection]="$any(sortDirection())"
|
|
6
|
+
(matSortChange)="sortChange.emit($event)">
|
|
7
|
+
|
|
8
|
+
<ng-container matColumnDef="userName">
|
|
9
|
+
<th mat-header-cell *matHeaderCellDef [mat-sort-header]="sortable() ? 'userName' : ''" [disabled]="!sortable()">Name</th>
|
|
10
|
+
<td mat-cell *matCellDef="let row">
|
|
11
|
+
<div class="user-info">
|
|
12
|
+
@if (row.user.photoURL) {
|
|
13
|
+
<img [src]="row.user.photoURL" alt="avatar" class="avatar" referrerpolicy="no-referrer" />
|
|
14
|
+
}
|
|
15
|
+
<span class="name">{{ row.user.name }}</span>
|
|
16
|
+
</div>
|
|
17
|
+
</td>
|
|
18
|
+
</ng-container>
|
|
19
|
+
|
|
20
|
+
<ng-container matColumnDef="questionOne">
|
|
21
|
+
<th mat-header-cell *matHeaderCellDef>Question One</th>
|
|
22
|
+
<td mat-cell *matCellDef="let row">
|
|
23
|
+
{{ row.context?.questionOne || 'N/A' }}
|
|
24
|
+
</td>
|
|
25
|
+
</ng-container>
|
|
26
|
+
|
|
27
|
+
<ng-container matColumnDef="questionTwo">
|
|
28
|
+
<th mat-header-cell *matHeaderCellDef>Question Two</th>
|
|
29
|
+
<td mat-cell *matCellDef="let row">
|
|
30
|
+
{{ row.context?.questionTwo || 'N/A' }}
|
|
31
|
+
</td>
|
|
32
|
+
</ng-container>
|
|
33
|
+
|
|
34
|
+
<ng-container matColumnDef="accessState">
|
|
35
|
+
<th mat-header-cell *matHeaderCellDef [mat-sort-header]="sortable() ? '_updatedAt' : ''" [disabled]="!sortable()">
|
|
36
|
+
@if (showFilter()) {
|
|
37
|
+
<button mat-button class="access-state-filter" [matMenuTriggerFor]="filterMenu" (click)="$event.stopPropagation()">
|
|
38
|
+
State
|
|
39
|
+
<mat-icon>filter_list</mat-icon>
|
|
40
|
+
</button>
|
|
41
|
+
<mat-menu #filterMenu="matMenu">
|
|
42
|
+
<button mat-menu-item (click)="filterChange.emit('ALL')"
|
|
43
|
+
[class.selected]="filterState() === 'ALL'">
|
|
44
|
+
All States
|
|
45
|
+
</button>
|
|
46
|
+
@for (option of accessOptions(); track option) {
|
|
47
|
+
<button mat-menu-item (click)="filterChange.emit(option)"
|
|
48
|
+
[class.selected]="filterState() === option">
|
|
49
|
+
{{ option }}
|
|
50
|
+
</button>
|
|
51
|
+
}
|
|
52
|
+
</mat-menu>
|
|
53
|
+
} @else {
|
|
54
|
+
State
|
|
55
|
+
}
|
|
56
|
+
</th>
|
|
57
|
+
<td mat-cell *matCellDef="let row">
|
|
58
|
+
<div class="update-btn status-container" [matMenuTriggerFor]="accessStateMenu" aria-label="accessState">
|
|
59
|
+
<mat-icon [matTooltip]="row.user.accessState" [style.color]="getAccessStateColor(row.user.accessState)">{{
|
|
60
|
+
getAccessStateIcon(row.user.accessState) }}</mat-icon>
|
|
61
|
+
<span class="status-date">{{ getStateDate(row.user) | date:'MM.dd' }}</span>
|
|
62
|
+
</div>
|
|
63
|
+
<mat-menu #accessStateMenu="matMenu">
|
|
64
|
+
@for (option of accessOptions(); track option) {
|
|
65
|
+
<button mat-menu-item (click)="updateState.emit({user: row.user, key: 'accessState', value: option})">{{ option }}</button>
|
|
66
|
+
}
|
|
67
|
+
</mat-menu>
|
|
68
|
+
</td>
|
|
69
|
+
</ng-container>
|
|
70
|
+
|
|
71
|
+
<tr mat-header-row *matHeaderRowDef="displayedColumns(); sticky: true"></tr>
|
|
72
|
+
<tr mat-row *matRowDef="let row; columns: displayedColumns();"></tr>
|
|
73
|
+
</table>
|
|
74
|
+
|
|
75
|
+
@if (dataSource().length === 0) {
|
|
76
|
+
<div class="empty-state">
|
|
77
|
+
<mat-icon>people_outline</mat-icon>
|
|
78
|
+
<p>No users to display.</p>
|
|
79
|
+
</div>
|
|
80
|
+
}
|
|
81
|
+
</div>
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.table-wrapper {
|
|
6
|
+
border: 1px solid #e0e0e0;
|
|
7
|
+
border-radius: 8px;
|
|
8
|
+
overflow-y: auto;
|
|
9
|
+
overflow-x: auto;
|
|
10
|
+
height: 250px;
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
background: #fafafa;
|
|
14
|
+
|
|
15
|
+
table.mat-mdc-table {
|
|
16
|
+
width: 100%;
|
|
17
|
+
min-width: 800px;
|
|
18
|
+
table-layout: fixed;
|
|
19
|
+
|
|
20
|
+
// Fixed column widths to prevent resizing on filter
|
|
21
|
+
.mat-column-userName { width: 22%; }
|
|
22
|
+
.mat-column-questionOne { width: 30%; }
|
|
23
|
+
.mat-column-questionTwo { width: 30%; }
|
|
24
|
+
.mat-column-accessState {
|
|
25
|
+
width: 18%;
|
|
26
|
+
padding-right: 24px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Header row styling
|
|
30
|
+
tr.mat-mdc-header-row,
|
|
31
|
+
tr.mat-header-row {
|
|
32
|
+
background: #f5f7fa;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
th.mat-header-cell,
|
|
36
|
+
th.mat-mdc-header-cell {
|
|
37
|
+
padding: 12px 16px !important;
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
font-weight: 600;
|
|
40
|
+
color: #555;
|
|
41
|
+
text-transform: uppercase;
|
|
42
|
+
letter-spacing: 0.03em;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
td.mat-cell,
|
|
46
|
+
td.mat-mdc-cell {
|
|
47
|
+
padding: 10px 16px !important;
|
|
48
|
+
font-size: 13px;
|
|
49
|
+
color: #333;
|
|
50
|
+
border-bottom: 1px solid #f0f0f0;
|
|
51
|
+
|
|
52
|
+
.user-info {
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
gap: 10px;
|
|
56
|
+
|
|
57
|
+
.avatar {
|
|
58
|
+
width: 28px;
|
|
59
|
+
height: 28px;
|
|
60
|
+
border-radius: 50%;
|
|
61
|
+
object-fit: cover;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.name {
|
|
65
|
+
font-weight: 500;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Alternating row backgrounds
|
|
71
|
+
tr.mat-mdc-row:nth-child(even),
|
|
72
|
+
tr.mat-row:nth-child(even) {
|
|
73
|
+
background: #fafbfc;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Hover effect
|
|
77
|
+
tr.mat-mdc-row:hover,
|
|
78
|
+
tr.mat-row:hover {
|
|
79
|
+
background: #f0f4ff;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.update-btn {
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.status-container {
|
|
87
|
+
display: flex;
|
|
88
|
+
align-items: center;
|
|
89
|
+
gap: 6px;
|
|
90
|
+
|
|
91
|
+
.status-date {
|
|
92
|
+
font-size: 0.85em;
|
|
93
|
+
color: #666;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.mat-column-questionOne,
|
|
98
|
+
.mat-column-questionTwo {
|
|
99
|
+
max-width: 300px;
|
|
100
|
+
white-space: pre-wrap;
|
|
101
|
+
padding-right: 24px;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.empty-state {
|
|
106
|
+
flex: 1;
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
align-items: center;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
padding: 48px 24px;
|
|
112
|
+
color: #757575;
|
|
113
|
+
text-align: center;
|
|
114
|
+
background: #fafafa;
|
|
115
|
+
|
|
116
|
+
mat-icon {
|
|
117
|
+
font-size: 48px;
|
|
118
|
+
width: 48px;
|
|
119
|
+
height: 48px;
|
|
120
|
+
margin-bottom: 12px;
|
|
121
|
+
color: #bdbdbd;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
p {
|
|
125
|
+
margin: 0;
|
|
126
|
+
font-size: 14px;
|
|
127
|
+
font-weight: 500;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Highlight the active filter option in the dropdown
|
|
133
|
+
::ng-deep .mat-mdc-menu-item.selected {
|
|
134
|
+
background: #e3f2fd;
|
|
135
|
+
font-weight: 600;
|
|
136
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { render } from '@testing-library/angular';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import { AdminUserTableComponent } from './admin-user-table.component';
|
|
5
|
+
import { DATABASE_SERVICE } from 'src/app/core/firebase/database.service';
|
|
6
|
+
import { FirebaseMockService } from 'src/app/core/firebase/firebase.mock.service';
|
|
7
|
+
import { BatchWriteMockService } from 'src/app/core/store/batch-write.mock.service';
|
|
8
|
+
import { BATCH_WRITE_SERVICE } from 'src/app/core/store/batch-write.service';
|
|
9
|
+
|
|
10
|
+
/** Sets up the testing environment for AdminUserTableComponent using render.*/
|
|
11
|
+
async function setup() {
|
|
12
|
+
const user = userEvent.setup();
|
|
13
|
+
const checkedSpy = jest.fn();
|
|
14
|
+
|
|
15
|
+
const view = await render(AdminUserTableComponent, {
|
|
16
|
+
imports: [],
|
|
17
|
+
providers: [
|
|
18
|
+
{ provide: DATABASE_SERVICE, useClass: FirebaseMockService },
|
|
19
|
+
{ provide: BATCH_WRITE_SERVICE, useClass: BatchWriteMockService },
|
|
20
|
+
],
|
|
21
|
+
componentInputs: {},
|
|
22
|
+
on: {},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
user,
|
|
27
|
+
fixture: view.fixture,
|
|
28
|
+
rerender: () => view.rerender(), // add component inputs if needed
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('AdminUserTableComponent', () => {
|
|
33
|
+
it('should create', async () => {
|
|
34
|
+
const { fixture } = await setup();
|
|
35
|
+
expect(fixture.componentInstance).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Component, OnInit, ChangeDetectionStrategy, input, output, inject, WritableSignal, Signal, signal, computed, Inject, Injector } from '@angular/core';
|
|
2
|
+
import { AdminUserTableAnimations } from './admin-user-table.animations';
|
|
3
|
+
import { DatePipe } from '@angular/common';
|
|
4
|
+
import { MatTable, MatColumnDef, MatHeaderCellDef, MatHeaderCell, MatCellDef, MatCell, MatHeaderRowDef, MatHeaderRow, MatRowDef, MatRow } from '@angular/material/table';
|
|
5
|
+
import { MatMenuTrigger, MatMenu, MatMenuItem } from '@angular/material/menu';
|
|
6
|
+
import { MatIcon } from '@angular/material/icon';
|
|
7
|
+
import { MatButton } from '@angular/material/button';
|
|
8
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
9
|
+
import { MatSortModule, Sort } from '@angular/material/sort';
|
|
10
|
+
import { User, AccessState } from 'src/app/core/store/user/user.model';
|
|
11
|
+
import { AdminRow } from '../admin-user-list.component';
|
|
12
|
+
|
|
13
|
+
@Component({
|
|
14
|
+
selector: 'app-admin-user-table',
|
|
15
|
+
templateUrl: './admin-user-table.component.html',
|
|
16
|
+
styleUrls: ['./admin-user-table.component.scss'],
|
|
17
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
18
|
+
animations: AdminUserTableAnimations,
|
|
19
|
+
imports: [
|
|
20
|
+
DatePipe,
|
|
21
|
+
MatTable,
|
|
22
|
+
MatColumnDef,
|
|
23
|
+
MatHeaderCellDef,
|
|
24
|
+
MatHeaderCell,
|
|
25
|
+
MatCellDef,
|
|
26
|
+
MatCell,
|
|
27
|
+
MatHeaderRowDef,
|
|
28
|
+
MatHeaderRow,
|
|
29
|
+
MatRowDef,
|
|
30
|
+
MatRow,
|
|
31
|
+
MatMenuTrigger,
|
|
32
|
+
MatMenu,
|
|
33
|
+
MatMenuItem,
|
|
34
|
+
MatIcon,
|
|
35
|
+
MatButton,
|
|
36
|
+
MatTooltipModule,
|
|
37
|
+
MatSortModule
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
export class AdminUserTableComponent implements OnInit {
|
|
41
|
+
// --------------- INPUTS AND OUTPUTS ------------------
|
|
42
|
+
|
|
43
|
+
/** The user data to display. */
|
|
44
|
+
dataSource = input.required<AdminRow[]>();
|
|
45
|
+
|
|
46
|
+
/** Columns to render. */
|
|
47
|
+
displayedColumns = input.required<string[]>();
|
|
48
|
+
|
|
49
|
+
/** Available access states for the dropdown menu. */
|
|
50
|
+
accessOptions = input.required<AccessState[]>();
|
|
51
|
+
|
|
52
|
+
/** Whether to enable table sorting. */
|
|
53
|
+
sortable = input<boolean>(false);
|
|
54
|
+
|
|
55
|
+
/** The currently active sort column. */
|
|
56
|
+
sortActive = input<string>('');
|
|
57
|
+
|
|
58
|
+
/** The current sort direction. */
|
|
59
|
+
sortDirection = input<string>('');
|
|
60
|
+
|
|
61
|
+
/** Whether to show the state filter in the column header. */
|
|
62
|
+
showFilter = input<boolean>(false);
|
|
63
|
+
|
|
64
|
+
/** The current filter state. */
|
|
65
|
+
filterState = input<AccessState | 'ALL'>('ALL');
|
|
66
|
+
|
|
67
|
+
/** Emitted when the user changes sorting. */
|
|
68
|
+
sortChange = output<Sort>();
|
|
69
|
+
|
|
70
|
+
/** Emitted when the user changes an access state. */
|
|
71
|
+
updateState = output<{user: User, key: string, value: AccessState}>();
|
|
72
|
+
|
|
73
|
+
/** Emitted when the user changes the state filter. */
|
|
74
|
+
filterChange = output<AccessState | 'ALL'>();
|
|
75
|
+
|
|
76
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
77
|
+
|
|
78
|
+
// --------------- COMPUTED DATA -----------------------
|
|
79
|
+
|
|
80
|
+
// --------------- EVENT HANDLING ----------------------
|
|
81
|
+
|
|
82
|
+
// --------------- OTHER -------------------------------
|
|
83
|
+
|
|
84
|
+
getAccessStateIcon(state: AccessState): string {
|
|
85
|
+
switch (state) {
|
|
86
|
+
case AccessState.SUBMIT_INTEREST: return 'forum';
|
|
87
|
+
case AccessState.WAITING: return 'pending_actions';
|
|
88
|
+
case AccessState.CONSENT: return 'psychology';
|
|
89
|
+
case AccessState.DONE: return 'check_circle';
|
|
90
|
+
default: return 'help_outline';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getAccessStateColor(state: AccessState): string {
|
|
95
|
+
switch (state) {
|
|
96
|
+
case AccessState.SUBMIT_INTEREST: return '#1976d2'; // Blue
|
|
97
|
+
case AccessState.WAITING: return '#f57c00'; // Orange
|
|
98
|
+
case AccessState.CONSENT: return '#7b1fa2'; // Purple
|
|
99
|
+
case AccessState.DONE: return '#388e3c'; // Green
|
|
100
|
+
default: return '#757575'; // Grey
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getStateDate(user: User): Date | null {
|
|
105
|
+
if (user.accessState === AccessState.WAITING && user.joinedWaitlistAt) {
|
|
106
|
+
return user.joinedWaitlistAt.toDate();
|
|
107
|
+
}
|
|
108
|
+
const timestamp = user._updatedAt || user._createdAt;
|
|
109
|
+
return timestamp ? timestamp.toDate() : null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
constructor() { }
|
|
113
|
+
|
|
114
|
+
// --------------- LOAD AND CLEANUP --------------------
|
|
115
|
+
|
|
116
|
+
ngOnInit(): void {
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -5,6 +5,7 @@ import { TimeAnalyticsService } from './core/analytics/time-analytics.service';
|
|
|
5
5
|
import { AuthStore } from './core/store/auth/auth.store';
|
|
6
6
|
import { DetectRedeploymentService } from './shared/redeployment-warning/redeployment-warning.service';
|
|
7
7
|
import { RedeploymentWarningComponent } from './shared/redeployment-warning/redeployment-warning.component';
|
|
8
|
+
import { DevStatusBarComponent } from './shared/dev-status-bar/dev-status-bar.component';
|
|
8
9
|
|
|
9
10
|
@Component({
|
|
10
11
|
selector: 'app-root',
|
|
@@ -12,6 +13,7 @@ import { RedeploymentWarningComponent } from './shared/redeployment-warning/rede
|
|
|
12
13
|
styleUrls: ['./app.component.scss'],
|
|
13
14
|
imports: [
|
|
14
15
|
RedeploymentWarningComponent,
|
|
16
|
+
DevStatusBarComponent,
|
|
15
17
|
RouterOutlet,
|
|
16
18
|
],
|
|
17
19
|
})
|
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
import { Routes } from '@angular/router';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { LoginComponent } from './first-time/login/login.component';
|
|
6
|
-
import { ConsentComponent } from './first-time/consent/consent.component';
|
|
7
|
-
import { EarlyAccessComponent } from './first-time/early-access/early-access.component';
|
|
8
|
-
import { OnboardingComponent } from './first-time/onboarding/onboarding.component';
|
|
9
|
-
import { HomeComponent } from './main/home/home.component';
|
|
2
|
+
import { requireAuth, redirectIfAuthenticated, requireAdmin, requireAuthAndConsent } from './core/auth/guards';
|
|
3
|
+
import { earlyAccessGuard } from './first-time/early-access/early-access.guard';
|
|
4
|
+
import { consentGuard } from './first-time/consent/consent.guard';
|
|
10
5
|
|
|
11
6
|
export const routes: Routes = [
|
|
12
|
-
// Admin Routes
|
|
7
|
+
// Admin Routes — must be logged in + must be admin
|
|
13
8
|
{ path: 'admin', loadComponent: () => import('./admin/admin-panel/admin-panel.component')
|
|
14
|
-
.then((mod) => mod.AdminPanelComponent), canActivate: [
|
|
15
|
-
// First-Time User Experience Routes
|
|
9
|
+
.then((mod) => mod.AdminPanelComponent), canActivate: [requireAuth, requireAdmin] },
|
|
10
|
+
// First-Time User Experience Routes (public pages)
|
|
16
11
|
{ path: 'landing', loadComponent: () => import('./first-time/landing/landing.component')
|
|
17
|
-
.then((mod) => mod.LandingComponent), canActivate: [
|
|
12
|
+
.then((mod) => mod.LandingComponent), canActivate: [redirectIfAuthenticated] },
|
|
18
13
|
{ path: 'login', loadComponent: () => import('./first-time/login/login.component')
|
|
19
|
-
.then((mod) => mod.LoginComponent) },
|
|
14
|
+
.then((mod) => mod.LoginComponent), canActivate: [redirectIfAuthenticated] },
|
|
15
|
+
// First-Time User Experience Routes (gated pages)
|
|
20
16
|
{ path: 'consent', loadComponent: () => import('./first-time/consent/consent.component')
|
|
21
|
-
.then((mod) => mod.ConsentComponent), canActivate: [
|
|
17
|
+
.then((mod) => mod.ConsentComponent), canActivate: [requireAuth, consentGuard] },
|
|
22
18
|
{ path: 'early-access', loadComponent: () => import('./first-time/early-access/early-access.component')
|
|
23
|
-
.then((mod) => mod.EarlyAccessComponent), canActivate: [
|
|
19
|
+
.then((mod) => mod.EarlyAccessComponent), canActivate: [requireAuth, earlyAccessGuard] },
|
|
24
20
|
{ path: 'onboarding', loadComponent: () => import('./first-time/onboarding/onboarding.component')
|
|
25
|
-
.then((mod) => mod.OnboardingComponent), canActivate: [
|
|
21
|
+
.then((mod) => mod.OnboardingComponent), canActivate: [requireAuthAndConsent] },
|
|
26
22
|
// Main Routes
|
|
27
23
|
{ path: 'home', loadComponent: () => import('./main/home/home.component')
|
|
28
|
-
.then((mod) => mod.HomeComponent), canActivate: [
|
|
24
|
+
.then((mod) => mod.HomeComponent), canActivate: [requireAuthAndConsent] },
|
|
29
25
|
{ path: '', loadComponent: () => import('./first-time/landing/landing.component')
|
|
30
|
-
.then((mod) => mod.LandingComponent), canActivate: [
|
|
26
|
+
.then((mod) => mod.LandingComponent), canActivate: [redirectIfAuthenticated] },
|
|
31
27
|
{ path: '**', redirectTo: 'landing', pathMatch: 'full' },
|
|
32
28
|
];
|