@tech4good/angular-schematics 20.2.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 +2 -0
- package/.agents/skills/publish-npm/eval.yaml +1 -1
- package/.t4g/agent-memory.db +0 -0
- package/CHANGELOG.md +44 -0
- package/README.md +16 -7
- package/package.json +1 -1
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.scss.template +1 -0
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +1 -1
- 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/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/files/src/app/core/auth/auth.guard.ts.template +0 -96
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Component, OnInit, ChangeDetectionStrategy, input, output, inject, WritableSignal, Signal, signal, computed, Inject, Injector } from '@angular/core';
|
|
2
|
+
import { AdminCountPillAnimations } from './admin-count-pill.animations';
|
|
3
|
+
|
|
4
|
+
@Component({
|
|
5
|
+
selector: 'app-admin-count-pill',
|
|
6
|
+
templateUrl: './admin-count-pill.component.html',
|
|
7
|
+
styleUrls: ['./admin-count-pill.component.scss'],
|
|
8
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
9
|
+
animations: AdminCountPillAnimations,
|
|
10
|
+
imports: [
|
|
11
|
+
],
|
|
12
|
+
})
|
|
13
|
+
export class AdminCountPillComponent implements OnInit {
|
|
14
|
+
// --------------- INPUTS AND OUTPUTS ------------------
|
|
15
|
+
|
|
16
|
+
/** The text label to display on the pill. */
|
|
17
|
+
label = input.required<string>();
|
|
18
|
+
|
|
19
|
+
/** The numerical value to display. */
|
|
20
|
+
value = input.required<number>();
|
|
21
|
+
|
|
22
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
23
|
+
|
|
24
|
+
// --------------- COMPUTED DATA -----------------------
|
|
25
|
+
|
|
26
|
+
// --------------- EVENT HANDLING ----------------------
|
|
27
|
+
|
|
28
|
+
// --------------- OTHER -------------------------------
|
|
29
|
+
|
|
30
|
+
constructor() { }
|
|
31
|
+
|
|
32
|
+
// --------------- LOAD AND CLEANUP --------------------
|
|
33
|
+
|
|
34
|
+
ngOnInit(): void {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<div class="list-header">
|
|
2
|
+
<div class="counts">
|
|
3
|
+
<app-admin-count-pill label="Interested" [value]="counts().submitInterest"></app-admin-count-pill>
|
|
4
|
+
<app-admin-count-pill label="Waitlist" [value]="counts().waiting"></app-admin-count-pill>
|
|
5
|
+
<app-admin-count-pill label="Consent" [value]="counts().consent"></app-admin-count-pill>
|
|
6
|
+
<app-admin-count-pill label="Done" [value]="counts().done"></app-admin-count-pill>
|
|
7
|
+
</div>
|
|
8
|
+
<button mat-button class="refresh-btn" (click)="refresh.emit()">
|
|
9
|
+
<mat-icon>refresh</mat-icon> Refresh Counts
|
|
10
|
+
</button>
|
|
11
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.list-header {
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: space-between;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
gap: 10px;
|
|
11
|
+
margin-bottom: 16px;
|
|
12
|
+
|
|
13
|
+
.counts {
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-wrap: wrap;
|
|
16
|
+
gap: 16px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.refresh-btn {
|
|
20
|
+
color: #1976d2;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { render } from '@testing-library/angular';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
|
|
4
|
+
import { AdminUserCountsComponent } from './admin-user-counts.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 AdminUserCountsComponent using render.*/
|
|
11
|
+
async function setup() {
|
|
12
|
+
const user = userEvent.setup();
|
|
13
|
+
const checkedSpy = jest.fn();
|
|
14
|
+
|
|
15
|
+
const view = await render(AdminUserCountsComponent, {
|
|
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('AdminUserCountsComponent', () => {
|
|
33
|
+
it('should create', async () => {
|
|
34
|
+
const { fixture } = await setup();
|
|
35
|
+
expect(fixture.componentInstance).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Component, OnInit, ChangeDetectionStrategy, input, output, inject, WritableSignal, Signal, signal, computed, Inject, Injector } from '@angular/core';
|
|
2
|
+
import { AdminUserCountsAnimations } from './admin-user-counts.animations';
|
|
3
|
+
import { MatButton } from '@angular/material/button';
|
|
4
|
+
import { MatIcon } from '@angular/material/icon';
|
|
5
|
+
import { AdminCountPillComponent } from './admin-count-pill/admin-count-pill.component';
|
|
6
|
+
|
|
7
|
+
export interface AdminCounts {
|
|
8
|
+
submitInterest: number;
|
|
9
|
+
waiting: number;
|
|
10
|
+
consent: number;
|
|
11
|
+
done: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Component({
|
|
15
|
+
selector: 'app-admin-user-counts',
|
|
16
|
+
templateUrl: './admin-user-counts.component.html',
|
|
17
|
+
styleUrls: ['./admin-user-counts.component.scss'],
|
|
18
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
+
animations: AdminUserCountsAnimations,
|
|
20
|
+
imports: [
|
|
21
|
+
MatButton, MatIcon, AdminCountPillComponent
|
|
22
|
+
],
|
|
23
|
+
})
|
|
24
|
+
export class AdminUserCountsComponent implements OnInit {
|
|
25
|
+
// --------------- INPUTS AND OUTPUTS ------------------
|
|
26
|
+
|
|
27
|
+
/** The counts for each user state. */
|
|
28
|
+
counts = input.required<AdminCounts>();
|
|
29
|
+
|
|
30
|
+
/** Emitted when the user clicks the refresh button. */
|
|
31
|
+
refresh = output<void>();
|
|
32
|
+
|
|
33
|
+
// --------------- LOCAL UI STATE ----------------------
|
|
34
|
+
|
|
35
|
+
// --------------- COMPUTED DATA -----------------------
|
|
36
|
+
|
|
37
|
+
// --------------- EVENT HANDLING ----------------------
|
|
38
|
+
|
|
39
|
+
// --------------- OTHER -------------------------------
|
|
40
|
+
|
|
41
|
+
constructor() { }
|
|
42
|
+
|
|
43
|
+
// --------------- LOAD AND CLEANUP --------------------
|
|
44
|
+
|
|
45
|
+
ngOnInit(): void {
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<app-admin-user-counts [counts]="counts()" (refresh)="refreshCounts()"></app-admin-user-counts>
|
|
2
|
+
|
|
3
|
+
<div class="table-section">
|
|
4
|
+
<div class="section-header">
|
|
5
|
+
<h3>
|
|
6
|
+
Waitlist
|
|
7
|
+
<mat-icon matTooltip="Displays users currently on the waitlist. Sorted by time waiting.">info_outline</mat-icon>
|
|
8
|
+
</h3>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<app-admin-user-table
|
|
12
|
+
[dataSource]="waitingUsers()"
|
|
13
|
+
[displayedColumns]="displayedColumns"
|
|
14
|
+
[accessOptions]="accessOptions"
|
|
15
|
+
(updateState)="updateState($event.user, $event.key, $event.value)">
|
|
16
|
+
</app-admin-user-table>
|
|
17
|
+
|
|
18
|
+
@if (waitingUsers().length < counts().waiting) {
|
|
19
|
+
<div class="load-more-container">
|
|
20
|
+
<button mat-button class="load-more-btn" (click)="loadMore()">Load More (Showing {{limitState()}})</button>
|
|
21
|
+
</div>
|
|
22
|
+
}
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<div class="table-section">
|
|
26
|
+
<div class="section-header">
|
|
27
|
+
<h3>
|
|
28
|
+
Other Users
|
|
29
|
+
<mat-icon matTooltip="Displays all other users. Sorted by most recently updated.">info_outline</mat-icon>
|
|
30
|
+
</h3>
|
|
31
|
+
</div>
|
|
32
|
+
|
|
33
|
+
<app-admin-user-table
|
|
34
|
+
[dataSource]="otherUsers()"
|
|
35
|
+
[displayedColumns]="displayedColumns"
|
|
36
|
+
[accessOptions]="accessOptions"
|
|
37
|
+
[sortable]="true"
|
|
38
|
+
[sortActive]="otherSortState().active"
|
|
39
|
+
[sortDirection]="otherSortState().direction"
|
|
40
|
+
[showFilter]="true"
|
|
41
|
+
[filterState]="filterState()"
|
|
42
|
+
(sortChange)="onOtherSortChange($event)"
|
|
43
|
+
(updateState)="updateState($event.user, $event.key, $event.value)"
|
|
44
|
+
(filterChange)="filterState.set($event)">
|
|
45
|
+
</app-admin-user-table>
|
|
46
|
+
|
|
47
|
+
@if (otherUsersFetchedCount() < (counts().submitInterest + counts().consent + counts().done)) {
|
|
48
|
+
<div class="load-more-container">
|
|
49
|
+
<button mat-button class="load-more-btn" (click)="loadMoreOther()">Load More (Showing {{otherLimitState()}})</button>
|
|
50
|
+
</div>
|
|
51
|
+
}
|
|
52
|
+
</div>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
|
|
4
|
+
.note {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: 6px;
|
|
8
|
+
font-size: 13px;
|
|
9
|
+
color: #666;
|
|
10
|
+
background: #e3f2fd;
|
|
11
|
+
padding: 8px 12px;
|
|
12
|
+
border-radius: 6px;
|
|
13
|
+
margin-bottom: 16px;
|
|
14
|
+
|
|
15
|
+
.info-icon {
|
|
16
|
+
font-size: 18px;
|
|
17
|
+
width: 18px;
|
|
18
|
+
height: 18px;
|
|
19
|
+
color: #1976d2;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.table-section {
|
|
24
|
+
margin-bottom: 40px;
|
|
25
|
+
|
|
26
|
+
.section-header {
|
|
27
|
+
margin-bottom: 16px;
|
|
28
|
+
|
|
29
|
+
h3 {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
gap: 8px;
|
|
33
|
+
margin: 0;
|
|
34
|
+
font-size: 18px;
|
|
35
|
+
font-weight: 500;
|
|
36
|
+
color: #333;
|
|
37
|
+
|
|
38
|
+
mat-icon {
|
|
39
|
+
font-size: 18px;
|
|
40
|
+
width: 18px;
|
|
41
|
+
height: 18px;
|
|
42
|
+
color: #888;
|
|
43
|
+
cursor: help;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
.load-more-container {
|
|
52
|
+
display: flex;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
margin-top: 16px;
|
|
55
|
+
|
|
56
|
+
.load-more-btn {
|
|
57
|
+
color: #1976d2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Highlight the active filter option in the dropdown
|
|
63
|
+
::ng-deep .mat-mdc-menu-item.selected {
|
|
64
|
+
background: #e3f2fd;
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
}
|
|
@@ -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>
|