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'
9 selector: 'my-runner-registration-token-list',
10 templateUrl: './runner-registration-token-list.component.html'
12 export class RunnerRegistrationTokenListComponent extends RestTable <RunnerRegistrationToken> implements OnInit {
13 registrationTokens: RunnerRegistrationToken[] = []
16 sort: SortMeta = { field: 'createdAt', order: -1 }
17 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
19 actions: DropdownAction<RunnerRegistrationToken>[][] = []
22 private runnerService: RunnerService,
23 private notifier: Notifier,
24 private confirmService: ConfirmService
33 label: $localize`Remove this token`,
34 handler: token => this.removeToken(token)
43 return 'RunnerRegistrationTokenListComponent'
47 this.runnerService.generateToken()
51 this.notifier.success($localize`Registration token generated.`)
54 error: err => this.notifier.error(err.message)
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`
64 if (res === false) return
66 this.runnerService.removeToken(token)
70 this.notifier.success($localize`Registration token removed.`)
73 error: err => this.notifier.error(err.message)
77 protected reloadDataInternal () {
78 this.runnerService.listRegistrationTokens({ pagination: this.pagination, sort: this.sort })
81 this.registrationTokens = resultList.data
82 this.totalRecords = resultList.total
85 error: err => this.notifier.error(err.message)