diff options
author | Chocobozzz <me@florianbigard.com> | 2023-05-19 14:27:27 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-05-19 14:27:27 +0200 |
commit | 476ce1d7f42701cb2ce456b52c27a23ccfcef6d4 (patch) | |
tree | 94a327905dd7327194918f18158d4578bfb18a1d /client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts | |
parent | 01283e2066314aaa167a2b0b55952b2ae26e650a (diff) | |
download | PeerTube-476ce1d7f42701cb2ce456b52c27a23ccfcef6d4.tar.gz PeerTube-476ce1d7f42701cb2ce456b52c27a23ccfcef6d4.tar.zst PeerTube-476ce1d7f42701cb2ce456b52c27a23ccfcef6d4.zip |
Add bulk actions on runner jobs
Diffstat (limited to 'client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts')
-rw-r--r-- | client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts index ea889f0f7..8ba956eb8 100644 --- a/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts +++ b/client/src/app/+admin/system/runners/runner-job-list/runner-job-list.component.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { SortMeta } from 'primeng/api' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | 3 | import { ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' |
4 | import { prepareIcu } from '@app/helpers' | ||
4 | import { DropdownAction } from '@app/shared/shared-main' | 5 | import { DropdownAction } from '@app/shared/shared-main' |
5 | import { RunnerJob } from '@shared/models' | 6 | import { RunnerJob, RunnerJobState } from '@shared/models' |
6 | import { RunnerJobFormatted, RunnerService } from '../runner.service' | 7 | import { RunnerJobFormatted, RunnerService } from '../runner.service' |
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
@@ -17,6 +18,7 @@ export class RunnerJobListComponent extends RestTable <RunnerJob> implements OnI | |||
17 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | 18 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
18 | 19 | ||
19 | actions: DropdownAction<RunnerJob>[][] = [] | 20 | actions: DropdownAction<RunnerJob>[][] = [] |
21 | bulkActions: DropdownAction<RunnerJob[]>[][] = [] | ||
20 | 22 | ||
21 | constructor ( | 23 | constructor ( |
22 | private runnerService: RunnerService, | 24 | private runnerService: RunnerService, |
@@ -31,7 +33,18 @@ export class RunnerJobListComponent extends RestTable <RunnerJob> implements OnI | |||
31 | [ | 33 | [ |
32 | { | 34 | { |
33 | label: $localize`Cancel this job`, | 35 | label: $localize`Cancel this job`, |
34 | handler: job => this.cancelJob(job) | 36 | handler: job => this.cancelJobs([ job ]), |
37 | isDisplayed: job => this.canCancelJob(job) | ||
38 | } | ||
39 | ] | ||
40 | ] | ||
41 | |||
42 | this.bulkActions = [ | ||
43 | [ | ||
44 | { | ||
45 | label: $localize`Cancel`, | ||
46 | handler: jobs => this.cancelJobs(jobs), | ||
47 | isDisplayed: jobs => jobs.every(j => this.canCancelJob(j)) | ||
35 | } | 48 | } |
36 | ] | 49 | ] |
37 | ] | 50 | ] |
@@ -43,19 +56,20 @@ export class RunnerJobListComponent extends RestTable <RunnerJob> implements OnI | |||
43 | return 'RunnerJobListComponent' | 56 | return 'RunnerJobListComponent' |
44 | } | 57 | } |
45 | 58 | ||
46 | async cancelJob (job: RunnerJob) { | 59 | async cancelJobs (jobs: RunnerJob[]) { |
47 | const res = await this.confirmService.confirm( | 60 | const message = prepareIcu( |
48 | $localize`Do you really want to cancel this job? Children won't be processed.`, | 61 | $localize`Do you really want to cancel {count, plural, =1 {this job} other {{count} jobs}}? Children jobs will also be cancelled.` |
49 | $localize`Cancel job` | 62 | )({ count: jobs.length }, $localize`Do you really want to cancel these jobs? Children jobs will also be cancelled.`) |
50 | ) | 63 | |
64 | const res = await this.confirmService.confirm(message, $localize`Cancel`) | ||
51 | 65 | ||
52 | if (res === false) return | 66 | if (res === false) return |
53 | 67 | ||
54 | this.runnerService.cancelJob(job) | 68 | this.runnerService.cancelJobs(jobs) |
55 | .subscribe({ | 69 | .subscribe({ |
56 | next: () => { | 70 | next: () => { |
57 | this.reloadData() | 71 | this.reloadData() |
58 | this.notifier.success($localize`Job cancelled.`) | 72 | this.notifier.success($localize`Job(s) cancelled.`) |
59 | }, | 73 | }, |
60 | 74 | ||
61 | error: err => this.notifier.error(err.message) | 75 | error: err => this.notifier.error(err.message) |
@@ -73,4 +87,10 @@ export class RunnerJobListComponent extends RestTable <RunnerJob> implements OnI | |||
73 | error: err => this.notifier.error(err.message) | 87 | error: err => this.notifier.error(err.message) |
74 | }) | 88 | }) |
75 | } | 89 | } |
90 | |||
91 | private canCancelJob (job: RunnerJob) { | ||
92 | return job.state.id === RunnerJobState.PENDING || | ||
93 | job.state.id === RunnerJobState.PROCESSING || | ||
94 | job.state.id === RunnerJobState.WAITING_FOR_PARENT_JOB | ||
95 | } | ||
76 | } | 96 | } |