All files / src/app/core/navigation/task-manager task-manager.component.ts

94.59% Statements 35/37
78.57% Branches 11/14
100% Functions 6/6
93.33% Lines 28/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 565x       5x 5x             5x 6x 6x   6x     6x 6x     6x 6x 6x 6x             5x 6x 1x   6x 4x 2x 2x   2x     3x 3x     5x 2x 2x 2x   5x  
import { Component, OnInit } from '@angular/core';
 
import { ExecutingTask } from '../../../shared/models/executing-task';
import { FinishedTask } from '../../../shared/models/finished-task';
import { SummaryService } from '../../../shared/services/summary.service';
import { TaskMessageService } from '../../../shared/services/task-message.service';
 
@Component({
  selector: 'cd-task-manager',
  template: require('./task-manager.component.html'),
  styles: []
})
export class TaskManagerComponent implements OnInit {
  executingTasks: ExecutingTask[] = [];
  finishedTasks: FinishedTask[] = [];
 
  icon = 'fa-hourglass-o';
 
  constructor(
    private summaryService: SummaryService,
    private taskMessageService: TaskMessageService
  ) {}
 
  ngOnInit() {
    this.summaryService.subscribe((data: any) => {
      Eif (!data) {
        return;
      }
      this._handleTasks(data.executing_tasks, data.finished_tasks);
      this._setIcon(data.executing_tasks.length);
    });
  }
 
  _handleTasks(executingTasks: ExecutingTask[], finishedTasks: FinishedTask[]) {
    for (const excutingTask of executingTasks) {
      excutingTask.description = this.taskMessageService.getRunningTitle(excutingTask);
    }
    for (const finishedTask of finishedTasks) {
      if (finishedTask.success === false) {
        finishedTask.description = this.taskMessageService.getErrorTitle(finishedTask);
        finishedTask.errorMessage = this.taskMessageService.getErrorMessage(finishedTask);
      } else {
        finishedTask.description = this.taskMessageService.getSuccessTitle(finishedTask);
      }
    }
    this.executingTasks = executingTasks;
    this.finishedTasks = finishedTasks;
  }
 
  _setIcon(executingTasks: number) {
    const iconSuffix = ['o', 'start', 'half', 'end']; // TODO: Use all suffixes
    const iconIndex = executingTasks > 0 ? 1 : 0;
    this.icon = 'fa-hourglass-' + iconSuffix[iconIndex];
  }
}