File

src/app/tasks/task-schedules-destroy/task-schedules-destroy.component.ts

Description

Component used to delete task schedules.

Extends

Modal

Implements

OnDestroy

Example

Metadata

selector app-task-schedules-destroy
templateUrl ./task-schedules-destroy.component.html

Index

Properties
Methods

Constructor

constructor(modalRef: BsModalRef, tasksService: TasksService, loggerService: LoggerService, blockerService: BlockerService, notificationService: NotificationService)

Initialize component

Parameters :
Name Type Optional Description
modalRef BsModalRef

used to control the current modal

tasksService TasksService
loggerService LoggerService
blockerService BlockerService
notificationService NotificationService

Methods

destroy
destroy()

Submit destroy task schedule(s)

Returns : void
ngOnDestroy
ngOnDestroy()

Destroy operations

Returns : void
open
open(args: literal type)

Initialize

Parameters :
Name Type Optional Description
args literal type
Returns : Observable<any>

Properties

confirm
confirm: EventEmitter<string>
Type : EventEmitter<string>

Emit after delete success

Private ngUnsubscribe$
ngUnsubscribe$: Subject<any>
Type : Subject<any>

Unsubscribe

taskSchedules
taskSchedules: TaskSchedule[]
Type : TaskSchedule[]

Task Schedules

import { Component, EventEmitter, OnDestroy } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap';
import { Modal } from '../../shared/components/modal/modal-abstract';
import { Observable, Subject } from 'rxjs';
import { finalize, takeUntil } from 'rxjs/operators';
import { TasksService } from '../tasks.service';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { TaskSchedule } from '../model/task-schedule';
import { BlockerService } from '../../shared/components/blocker/blocker.service';

/**
 * Component used to delete task schedules.
 *
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-task-schedules-destroy',
  templateUrl: './task-schedules-destroy.component.html'
})
export class TaskSchedulesDestroyComponent extends Modal implements OnDestroy {

  /**
   * Unsubscribe
   */
  private ngUnsubscribe$: Subject<any> = new Subject();

  /**
   * Task Schedules
   */
  taskSchedules: TaskSchedule[];

  /**
   * Emit after delete success
   */
  confirm: EventEmitter<string> = new EventEmitter();

  /**
   * Initialize component
   *
   * @param {BsModalRef} modalRef used to control the current modal
   * @param {TasksService} tasksService
   * @param {BlockerService} blockerService
   * @param {NotificationService} notificationService
   * @param {LoggerService} loggerService
   */
  constructor(private modalRef: BsModalRef,
              private tasksService: TasksService,
              private loggerService: LoggerService,
              private blockerService: BlockerService,
              private notificationService: NotificationService) {
    super(modalRef);
  }

  /**
   * Initialize
   */
  open(args: { taskSchedules: TaskSchedule[] }): Observable<any> {
    this.taskSchedules = args.taskSchedules;
    return this.confirm;
  }

  /**
   * Submit destroy task schedule(s)
   */
  destroy() {
    this.loggerService.log(`Proceeding to delete ${this.taskSchedules.length} task schedule(s).`, this.taskSchedules);
    this.blockerService.lock();
    this.tasksService.destroySchedules(this.taskSchedules)
      .pipe(takeUntil(this.ngUnsubscribe$), finalize(() => this.blockerService.unlock()))
      .subscribe((data) => {
        this.notificationService.success(`${data.length} task schedule(s) deleted.`);
        this.confirm.emit('done');
        this.cancel();
      }, () => {
        this.notificationService.error('An error occurred while bulk deleting Schedules. ' +
          'Please check the server logs for more details.');
        this.confirm.emit('done');
        this.cancel();
      });
  }

  /**
   * Destroy operations
   */
  ngOnDestroy() {
    this.ngUnsubscribe$.next();
    this.ngUnsubscribe$.complete();
  }

}
<div *ngIf="taskSchedules">
  <div class="modal-header">
    <h4 class="modal-title pull-left">Confirm the Deletion of Task Schedule(s)</h4>
    <button type="button" class="close pull-right" aria-label="Close" (click)="cancel()">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body" *ngIf="taskSchedules.length == 1">
    <p>This action will delete the task schedule <strong>{{ taskSchedules[0].name }}</strong>.
      Are you sure?</p>
  </div>
  <div class="modal-body" *ngIf="taskSchedules.length > 1">
    <p>
      This action will delete the <strong>{{ taskSchedules.length }} task schedules</strong> listed below.
      Are you sure?
    </p>
    <br/>
    <table id="table-tasks" class="table table-striped">
      <thead>
      <tr>
        <th>Schedule Name</th>
        <th>Task Name</th>
        <th>Schedule Trigger</th>
      </tr>
      </thead>
      <tbody>
      <tr *ngFor="let item of taskSchedules">
        <td>{{ item.name }}</td>
        <td>{{ item.taskName }}</td>
        <td>
          <div *ngIf="item.dateTime">{{ item.dateTime | date: 'short' }}</div>
          <div *ngIf="item.cronExpression">{{ item.cronExpression }}</div>
        </td>
      </tr>
      </tbody>
    </table>
  </div>
  <div class="modal-footer" style="text-align:center">
    <button id="btn-cancel" type="button" class="btn btn-default" (click)="cancel()">No</button>
    <button id="btn-destroy" type="button" class="btn btn-primary" (click)="destroy(taskSchedules)">
      Delete Task Schedule(s)
    </button>
  </div>
</div>

<div *ngIf="!taskSchedules" style="padding: 3rem">
  <app-loader></app-loader>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""