]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/navigation/task-manager/task-manager.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / navigation / task-manager / task-manager.component.ts
1 import { Component, OnInit } from '@angular/core';
2
3 import { ExecutingTask } from '../../../shared/models/executing-task';
4 import { FinishedTask } from '../../../shared/models/finished-task';
5 import { SummaryService } from '../../../shared/services/summary.service';
6 import { TaskMessageService } from '../../../shared/services/task-message.service';
7
8 @Component({
9 selector: 'cd-task-manager',
10 templateUrl: './task-manager.component.html',
11 styleUrls: ['./task-manager.component.scss']
12 })
13 export class TaskManagerComponent implements OnInit {
14 executingTasks: ExecutingTask[] = [];
15 finishedTasks: FinishedTask[] = [];
16
17 icon = 'fa-hourglass-o';
18
19 constructor(
20 private summaryService: SummaryService,
21 private taskMessageService: TaskMessageService
22 ) {}
23
24 ngOnInit() {
25 this.summaryService.subscribe((data: any) => {
26 if (!data) {
27 return;
28 }
29 this._handleTasks(data.executing_tasks, data.finished_tasks);
30 this._setIcon(data.executing_tasks.length);
31 });
32 }
33
34 _handleTasks(executingTasks: ExecutingTask[], finishedTasks: FinishedTask[]) {
35 for (const excutingTask of executingTasks) {
36 excutingTask.description = this.taskMessageService.getRunningTitle(excutingTask);
37 }
38 for (const finishedTask of finishedTasks) {
39 if (finishedTask.success === false) {
40 finishedTask.description = this.taskMessageService.getErrorTitle(finishedTask);
41 finishedTask.errorMessage = this.taskMessageService.getErrorMessage(finishedTask);
42 } else {
43 finishedTask.description = this.taskMessageService.getSuccessTitle(finishedTask);
44 }
45 }
46 this.executingTasks = executingTasks;
47 this.finishedTasks = finishedTasks;
48 }
49
50 _setIcon(executingTasks: number) {
51 const iconSuffix = ['o', 'start', 'half', 'end']; // TODO: Use all suffixes
52 const iconIndex = executingTasks > 0 ? 1 : 0;
53 this.icon = 'fa-hourglass-' + iconSuffix[iconIndex];
54 }
55 }