File

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

Description

Provides TaskSchedule related services.

Implements

OnInit OnDestroy

Example

Metadata

selector app-tasks-schedules
styleUrls styles.scss
templateUrl ./task-schedules.component.html

Index

Properties
Methods

Constructor

constructor(modalService: BsModalService, tasksService: TasksService, notificationService: NotificationService, router: Router, loggerService: LoggerService)

Constructor

Parameters :
Name Type Optional Description
modalService BsModalService
tasksService TasksService
notificationService NotificationService
router Router
loggerService LoggerService

Methods

applyAction
applyAction(action: string, args?: any)

Apply Action

Parameters :
Name Type Optional Description
action string
args any true
Returns : void
changeCheckboxes
changeCheckboxes()

Update the list of selected checkbox

Returns : void
countSelected
countSelected()

Number of selected task definitions

Returns : number
destroySchedules
destroySchedules(taskSchedules: TaskSchedule[])

Starts the destroy the TaskSchedules in parameter by opening a confirmation modal dialog.

Parameters :
Name Type Optional Description
taskSchedules TaskSchedule[]
Returns : void
destroySelectedSchedules
destroySelectedSchedules()

Starts the destroy process of multiple TaskDefinitions by opening a confirmation modal dialog.

Returns : void
details
details(taskSchedule: TaskSchedule)

Route to TaskSchedule details page.

Parameters :
Name Type Optional Description
taskSchedule TaskSchedule
Returns : void
isSchedulesEmpty
isSchedulesEmpty()

Determine if there is no task schedule

Returns : boolean
ngOnDestroy
ngOnDestroy()

Close subscription

Returns : void
ngOnInit
ngOnInit()

Retrieves the TaskDefinitions to be displayed on the page.

Returns : void
refresh
refresh()

Initializes the taskSchedules attribute with the results from Spring Cloud Data Flow server.

Returns : void
scheduleActions
scheduleActions(index: number)

Schedule Actions

Parameters :
Name Type Optional Description
index number
Returns : {}
schedulesActions
schedulesActions()

Schedules Actions

Returns : {}
search
search(params: ListDefaultParams)

Run the search

Parameters :
Name Type Optional Description
params ListDefaultParams
Returns : void
taskDetails
taskDetails(taskSchedule: TaskSchedule)

Route to TaskSchedule details task page.

Parameters :
Name Type Optional Description
taskSchedule TaskSchedule
Returns : void
updateContext
updateContext()

Write the context in the service.

Returns : void

Properties

context
context: any
Type : any

Storage context

form
form: any
Type : any

Current forms value

isLoaded
isLoaded:
Default value : false

IsLoaded state

itemsSelected
itemsSelected: Array<string>
Type : Array<string>

Contain a key application of each selected application

listBar
listBar: ListBarComponent
Type : ListBarComponent
Decorators : ViewChild

List Bar Component

modal
modal: BsModalRef
Type : BsModalRef

Modal reference

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

Unsubscribe

params
params: ListDefaultParams
Type : ListDefaultParams

State of App List Params

taskSchedules
taskSchedules: Page<TaskSchedule>
Type : Page<TaskSchedule>

Current page of Tasks Schedules

tasksTabulation
tasksTabulation: TasksTabulationComponent
Type : TasksTabulationComponent
Decorators : ViewChild

Tabulation

import { Component, OnDestroy, OnInit } from '@angular/core';
import { Page } from '../../shared/model/page';
import { ListDefaultParams, OrderParams } from '../../shared/components/shared.interface';
import { Subject } from 'rxjs';
import { TasksService } from '../tasks.service';
import { NotificationService } from '../../shared/services/notification.service';
import { LoggerService } from '../../shared/services/logger.service';
import { Router } from '@angular/router';
import { TaskSchedule } from '../model/task-schedule';
import { map, takeUntil } from 'rxjs/operators';
import { BsModalRef, BsModalService } from 'ngx-bootstrap';
import { TaskSchedulesDestroyComponent } from '../task-schedules-destroy/task-schedules-destroy.component';
import { ViewChild } from '@angular/core';
import { ListBarComponent } from '../../shared/components/list/list-bar.component';
import { TasksTabulationComponent } from '../components/tasks-tabulation/tasks-tabulation.component';

/**
 * Provides {@link TaskSchedule} related services.
 *
 * @author Damien Vitrac
 *
 */
@Component({
  selector: 'app-tasks-schedules',
  templateUrl: './task-schedules.component.html',
  styleUrls: ['styles.scss']
})
export class TaskSchedulesComponent implements OnInit, OnDestroy {

  /**
   * Current page of Tasks Schedules
   */
  taskSchedules: Page<TaskSchedule>;

  /**
   * List Bar Component
   */
  @ViewChild('listBar', { static: true })
  listBar: ListBarComponent;

  /**
   * Tabulation
   */
  @ViewChild('tasksTabulation', { static: false })
  tasksTabulation: TasksTabulationComponent;

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

  /**
   * Modal reference
   */
  modal: BsModalRef;

  /**
   * Current forms value
   */
  form: any = {
    checkboxes: []
  };

  /**
   * State of App List Params
   */
  params: ListDefaultParams = {
    sort: 'SCHEDULE_ID',
    order: OrderParams.ASC,
    page: 0,
    size: 100000,
    q: ''
  };

  /**
   * Contain a key application of each selected application
   * @type {Array}
   */
  itemsSelected: Array<string> = [];

  /**
   * Storage context
   */
  context: any;

  /**
   * IsLoaded state
   * @type {boolean}
   */
  isLoaded = false;

  /**
   * Constructor
   *
   * @param {BsModalService} modalService
   * @param {TasksService} tasksService
   * @param {NotificationService} notificationService
   * @param {Router} router
   * @param {LoggerService} loggerService
   */
  constructor(private modalService: BsModalService,
              private tasksService: TasksService,
              private notificationService: NotificationService,
              private router: Router,
              private loggerService: LoggerService) {
  }

  /**
   * Retrieves the {@link TaskDefinition}s to be displayed on the page.
   */
  ngOnInit() {
    this.context = this.tasksService.schedulesContext;
    this.params = { ...this.context };
    this.itemsSelected = this.context.itemsSelected || [];
    this.refresh();
  }

  /**
   * Close subscription
   */
  ngOnDestroy() {
    this.ngUnsubscribe$.next();
    this.ngUnsubscribe$.complete();
  }

  /**
   * Schedules Actions
   */
  schedulesActions() {
    return [
      {
        id: 'destroy-schedules',
        icon: 'trash',
        action: 'destroySelected',
        title: 'Destroy schedule(s)'
      },
    ];
  }

  /**
   * Schedule Actions
   * @param {number} index
   */
  scheduleActions(index: number) {
    return [
      {
        id: 'details-schedule' + index,
        icon: 'info-circle',
        action: 'details',
        title: 'Show details',
        isDefault: true
      },
      {
        divider: true
      },
      {
        id: 'destroy-schedule' + index,
        icon: 'trash',
        action: 'destroy',
        title: 'Delete schedule'
      }
    ];
  }

  /**
   * Apply Action
   * @param action
   * @param arg
   */
  applyAction(action: string, args?: any) {
    switch (action) {
      case 'details':
        this.details(args);
        break;
      case 'destroy':
        this.destroySchedules([args]);
        break;
      case 'destroySelected':
        this.destroySelectedSchedules();
        break;
    }
  }

  /**
   * Write the context in the service.
   */
  updateContext() {
    this.context.q = this.params.q;
    this.context.sort = this.params.sort;
    this.context.order = this.params.order;
    this.context.page = this.params.page;
    this.context.size = this.params.size;
    this.context.itemsSelected = this.itemsSelected;
  }

  /**
   * Initializes the taskSchedules attribute with the results from Spring Cloud Data Flow server.
   */
  refresh() {
    this.tasksService
      .getSchedules(this.params)
      .pipe(map(((page: Page<TaskSchedule>) => {
        this.form.checkboxes = page.items.map((schedule) => this.itemsSelected.indexOf(schedule.name) > -1);
        return page;
      })))
      .pipe(takeUntil(this.ngUnsubscribe$))
      .subscribe((page: Page<TaskSchedule>) => {
          if (page.items.length === 0 && this.params.page > 0) {
            this.params.page = 0;
            this.refresh();
            return;
          }
          this.isLoaded = true;
          this.taskSchedules = page;
          this.changeCheckboxes();
          this.updateContext();
        },
        error => {
          this.notificationService.error(error);
        }
      );

    if (this.tasksTabulation) {
      this.tasksTabulation.forceRefresh();
    }
  }

  /**
   * Determine if there is no task schedule
   */
  isSchedulesEmpty(): boolean {
    if (this.taskSchedules) {
      if (this.taskSchedules.totalPages < 2) {
        return this.params.q === '' && this.taskSchedules.items.length === 0;
      }
    }
    return false;
  }

  /**
   * Update the list of selected checkbox
   */
  changeCheckboxes() {
    if (!this.taskSchedules || (this.taskSchedules.items.length !== this.form.checkboxes.length)) {
      return;
    }
    const value: Array<string> = this.taskSchedules.items.map((schedule, index) => {
      if (this.form.checkboxes[index]) {
        return schedule.name;
      }
    }).filter((a) => a != null);
    this.itemsSelected = value;
    this.updateContext();
  }

  /**
   * Number of selected task definitions
   * @returns {number}
   */
  countSelected(): number {
    return this.form.checkboxes.filter((a) => a).length;
  }

  /**
   * Run the search
   */
  search(params: ListDefaultParams) {
    this.params.q = params.q;
    this.params.page = 0;
    this.refresh();
  }

  /**
   * Starts the destroy process of multiple {@link TaskDefinition}s
   * by opening a confirmation modal dialog.
   */
  destroySelectedSchedules() {
    const schedules = this.taskSchedules.items
      .filter((item) => this.itemsSelected.indexOf(item.name) > -1);
    this.destroySchedules(schedules);
  }

  /**
   * Starts the destroy the {@link TaskSchedule}s in parameter
   * by opening a confirmation modal dialog.
   * @param {TaskSchedule[]} taskSchedules
   */
  destroySchedules(taskSchedules: TaskSchedule[]) {
    if (taskSchedules.length === 0) {
      return;
    }
    this.loggerService.log(`Destroy ${taskSchedules} task schedule(s).`, taskSchedules);
    const className = taskSchedules.length > 1 ? 'modal-lg' : 'modal-md';
    this.modal = this.modalService.show(TaskSchedulesDestroyComponent, { class: className });
    this.modal.content.open({ taskSchedules: taskSchedules }).subscribe(() => {
      this.refresh();
    });
  }

  /**
   * Route to {@link TaskSchedule} details page.
   * @param {TaskSchedule} taskSchedule
   */
  details(taskSchedule: TaskSchedule) {
    this.router.navigate([`tasks/schedules/${taskSchedule.name}`]);
  }

  /**
   * Route to {@link TaskSchedule} details task page.
   * @param {TaskSchedule} taskSchedule
   */
  taskDetails(taskSchedule: TaskSchedule) {
    this.router.navigate([`tasks/definitions/${taskSchedule.taskName}`]);
  }

}
<app-tasks-tabulation #tasksTabulation>

  <div id="schedules-list" *ngIf="isLoaded && taskSchedules" dataflowLayoutType type="full">

    <app-list-bar [params]="params" [page]="taskSchedules" [countSelected]="countSelected()" #listBar
                  (refresh)="refresh()" (search)="search($event)" [actions]="schedulesActions()"
                  (action)="applyAction($event.action)">
    </app-list-bar>

    <table *ngIf="taskSchedules && (taskSchedules.items | filterSchedules: q).length > 0"
           class="table table-hover table-checkbox" id="taskSchedulesTable">
      <thead>
      <tr>
        <th style="width: 30px">
          <app-master-checkbox (change)="changeCheckboxes()" *ngIf="form?.checkboxes" [dataflowAppRoles]="['ROLE_CREATE']"
                               [items]="form.checkboxes"></app-master-checkbox>
        </th>
        <th>
          Schedule Name
        </th>
        <th>
          Task Name
        </th>
        <th nowrap="">
          Cron Expression
        </th>
        <th>&nbsp;</th>
      </tr>
      </thead>
      <tbody>
      <ng-container
        *ngFor="let item of taskSchedules.items | filterSchedules: q; index as i">
        <tr>
          <td class="cell-checkbox">
            <input [dataflowAppRoles]="['ROLE_CREATE']" type="checkbox" (change)="changeCheckboxes()"
                   [(ngModel)]="form.checkboxes[i]"/>
          </td>
          <td>
            <a class="link-schedule" (click)="details(item)" style="cursor: pointer">{{ item.name }}</a>
          </td>
          <td>
            <a class="link-task" (click)="taskDetails(item)" style="cursor: pointer">{{ item.taskName }}</a>
          </td>
          <td>
            {{ item.cronExpression }}
          </td>
          <td class="table-actions" width="10px" nowrap="">
            <app-list-row-actions [item]="item" (action)="applyAction($event.action, $event.args)"
                                  [actions]="scheduleActions(i)"></app-list-row-actions>
          </td>
        </tr>
      </ng-container>
      </tbody>
    </table>

    <app-list-empty [page]="taskSchedules" [filters]="[params.q]">
      <p>There is <strong>no task schedule</strong>.</p>
      <p [dataflowAppRoles]="['ROLE_CREATE']">
        You can <a (click)="refresh()">Refresh</a> the page
      </p>
    </app-list-empty>

    <app-list-no-result [page]="taskSchedules" [filters]="[params.q]">
      <p>
        No results found for
        <strong>'{{ params.q }}'</strong>
      </p>
      <p>
        You can <a (click)="listBar.clearSearch()">clear the search</a> or <a (click)="refresh()">Refresh</a> the page.
      </p>
    </app-list-no-result>

  </div>

</app-tasks-tabulation>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""