1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import { SortMeta } from 'primeng/api'
import { Component, OnInit, ViewChild } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router'
import { MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core'
import { AdvancedInputFilter } from '@app/shared/shared-forms'
import { DropdownAction } from '@app/shared/shared-main'
import { UserRegistration, UserRegistrationState } from '@shared/models'
import { AdminRegistrationService } from './admin-registration.service'
import { ProcessRegistrationModalComponent } from './process-registration-modal.component'
@Component({
selector: 'my-registration-list',
templateUrl: './registration-list.component.html',
styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './registration-list.component.scss' ]
})
export class RegistrationListComponent extends RestTable implements OnInit {
@ViewChild('processRegistrationModal', { static: true }) processRegistrationModal: ProcessRegistrationModalComponent
registrations: (UserRegistration & { registrationReasonHTML?: string, moderationResponseHTML?: string })[] = []
totalRecords = 0
sort: SortMeta = { field: 'createdAt', order: -1 }
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
registrationActions: DropdownAction<UserRegistration>[][] = []
inputFilters: AdvancedInputFilter[] = []
requiresEmailVerification: boolean
constructor (
protected route: ActivatedRoute,
protected router: Router,
private server: ServerService,
private notifier: Notifier,
private markdownRenderer: MarkdownService,
private adminRegistrationService: AdminRegistrationService
) {
super()
this.registrationActions = [
[
{
label: $localize`Accept this registration`,
handler: registration => this.openRegistrationRequestProcessModal(registration, 'accept'),
isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING
},
{
label: $localize`Reject this registration`,
handler: registration => this.openRegistrationRequestProcessModal(registration, 'reject'),
isDisplayed: registration => registration.state.id === UserRegistrationState.PENDING
},
{
label: $localize`Remove this registration request`,
handler: registration => this.removeRegistration(registration),
isDisplayed: registration => registration.state.id !== UserRegistrationState.PENDING
}
]
]
}
ngOnInit () {
this.initialize()
this.server.getConfig()
.subscribe(config => {
this.requiresEmailVerification = config.signup.requiresEmailVerification
})
}
getIdentifier () {
return 'RegistrationListComponent'
}
isRegistrationAccepted (registration: UserRegistration) {
return registration.state.id === UserRegistrationState.ACCEPTED
}
isRegistrationRejected (registration: UserRegistration) {
return registration.state.id === UserRegistrationState.REJECTED
}
onRegistrationProcessed () {
this.reloadData()
}
protected reloadData () {
this.adminRegistrationService.listRegistrations({
pagination: this.pagination,
sort: this.sort,
search: this.search
}).subscribe({
next: async resultList => {
this.totalRecords = resultList.total
this.registrations = resultList.data
for (const registration of this.registrations) {
registration.registrationReasonHTML = await this.toHtml(registration.registrationReason)
registration.moderationResponseHTML = await this.toHtml(registration.moderationResponse)
}
},
error: err => this.notifier.error(err.message)
})
}
private openRegistrationRequestProcessModal (registration: UserRegistration, mode: 'accept' | 'reject') {
this.processRegistrationModal.openModal(registration, mode)
}
private removeRegistration (registration: UserRegistration) {
this.adminRegistrationService.removeRegistration(registration)
.subscribe({
next: () => {
this.notifier.success($localize`Registration request deleted.`)
this.reloadData()
},
error: err => this.notifier.error(err.message)
})
}
private toHtml (text: string) {
return this.markdownRenderer.textMarkdownToHTML({ markdown: text })
}
}
|