diff options
Diffstat (limited to 'client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts')
-rw-r--r-- | client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts new file mode 100644 index 000000000..f03aab189 --- /dev/null +++ b/client/src/app/+admin/system/runners/runner-registration-token-list/runner-registration-token-list.component.ts | |||
@@ -0,0 +1,88 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { Component, OnInit } from '@angular/core' | ||
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | ||
4 | import { DropdownAction } from '@app/shared/shared-main' | ||
5 | import { RunnerRegistrationToken } from '@shared/models' | ||
6 | import { RunnerService } from '../runner.service' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-runner-registration-token-list', | ||
10 | templateUrl: './runner-registration-token-list.component.html' | ||
11 | }) | ||
12 | export class RunnerRegistrationTokenListComponent extends RestTable <RunnerRegistrationToken> implements OnInit { | ||
13 | registrationTokens: RunnerRegistrationToken[] = [] | ||
14 | totalRecords = 0 | ||
15 | |||
16 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
18 | |||
19 | actions: DropdownAction<RunnerRegistrationToken>[][] = [] | ||
20 | |||
21 | constructor ( | ||
22 | private runnerService: RunnerService, | ||
23 | private notifier: Notifier, | ||
24 | private confirmService: ConfirmService | ||
25 | ) { | ||
26 | super() | ||
27 | } | ||
28 | |||
29 | ngOnInit () { | ||
30 | this.actions = [ | ||
31 | [ | ||
32 | { | ||
33 | label: $localize`Remove this token`, | ||
34 | handler: token => this.removeToken(token) | ||
35 | } | ||
36 | ] | ||
37 | ] | ||
38 | |||
39 | this.initialize() | ||
40 | } | ||
41 | |||
42 | getIdentifier () { | ||
43 | return 'RunnerRegistrationTokenListComponent' | ||
44 | } | ||
45 | |||
46 | generateToken () { | ||
47 | this.runnerService.generateToken() | ||
48 | .subscribe({ | ||
49 | next: () => { | ||
50 | this.reloadData() | ||
51 | this.notifier.success($localize`Registration token generated.`) | ||
52 | }, | ||
53 | |||
54 | error: err => this.notifier.error(err.message) | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | async removeToken (token: RunnerRegistrationToken) { | ||
59 | const res = await this.confirmService.confirm( | ||
60 | $localize`Do you really want to remove this registration token? All associated runners will also be removed.`, | ||
61 | $localize`Remove registration token` | ||
62 | ) | ||
63 | |||
64 | if (res === false) return | ||
65 | |||
66 | this.runnerService.removeToken(token) | ||
67 | .subscribe({ | ||
68 | next: () => { | ||
69 | this.reloadData() | ||
70 | this.notifier.success($localize`Registration token removed.`) | ||
71 | }, | ||
72 | |||
73 | error: err => this.notifier.error(err.message) | ||
74 | }) | ||
75 | } | ||
76 | |||
77 | protected reloadDataInternal () { | ||
78 | this.runnerService.listRegistrationTokens({ pagination: this.pagination, sort: this.sort }) | ||
79 | .subscribe({ | ||
80 | next: resultList => { | ||
81 | this.registrationTokens = resultList.data | ||
82 | this.totalRecords = resultList.total | ||
83 | }, | ||
84 | |||
85 | error: err => this.notifier.error(err.message) | ||
86 | }) | ||
87 | } | ||
88 | } | ||