File

src/app/tasks/components/tasks-tabulation/tasks-tabulation.component.ts

Description

Component used to display the tabulation with counters.

Implements

OnInit

Example

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector app-tasks-tabulation
templateUrl tasks-tabulation.component.html

Index

Properties
Methods

Constructor

constructor(tasksService: TasksService, sharedAboutService: SharedAboutService, appsService: AppsService, router: Router)

Constructor

Parameters :
Name Type Optional Description
tasksService TasksService
sharedAboutService SharedAboutService
appsService AppsService
router Router

Methods

createTask
createTask()
Returns : void
forceRefresh
forceRefresh()
Returns : void
ngOnInit
ngOnInit()
Returns : void
refresh
refresh()
Returns : void

Properties

counters$
counters$: Observable<any>
Type : Observable<any>
hardRefresh
hardRefresh: BehaviorSubject<any>
Type : BehaviorSubject<any>
params$
params$: Observable<any>
Type : Observable<any>
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable, forkJoin, BehaviorSubject } from 'rxjs';
import { TasksService } from '../../tasks.service';
import { map, mergeMap, share } from 'rxjs/operators';
import { Page } from '../../../shared/model/page';
import { TaskDefinition } from '../../model/task-definition';
import { TaskExecution } from '../../model/task-execution';
import { TaskSchedule } from '../../model/task-schedule';
import { SharedAboutService } from '../../../shared/services/shared-about.service';
import { FeatureInfo } from '../../../shared/model/about/feature-info.model';
import { Router } from '@angular/router';
import { AppsService } from '../../../apps/apps.service';

/**
 * Component used to display the tabulation with counters.
 *
 * @author Damien Vitrac
 */
@Component({
  selector: 'app-tasks-tabulation',
  templateUrl: 'tasks-tabulation.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TasksTabulationComponent implements OnInit {

  params$: Observable<any>;

  counters$: Observable<any>;

  hardRefresh: BehaviorSubject<any> = new BehaviorSubject(new Date());

  /**
   * Constructor
   *
   * @param {TasksService} tasksService
   * @param {SharedAboutService} sharedAboutService
   * @param appsService
   * @param {Router} router
   */
  constructor(private tasksService: TasksService,
              private sharedAboutService: SharedAboutService,
              private appsService: AppsService,
              private router: Router) {
  }

  ngOnInit() {
    this.refresh();
  }

  forceRefresh() {
    this.hardRefresh.next(new Date())
  }

  refresh() {
    this.params$ = this.sharedAboutService.getFeatureInfo()
      .pipe(map((featureInfo: FeatureInfo) => ({
        schedulesEnabled: featureInfo.schedulesEnabled
      })));
    this.counters$ = this.sharedAboutService.getFeatureInfo()
      .pipe(mergeMap(
        (featureInfo: FeatureInfo) => {
          return this.hardRefresh.pipe(map((a) => {
              return featureInfo;
            }
          ));
        }
      ))
      .pipe(mergeMap(
        (featureInfo: FeatureInfo) => {
          const arr = [];
          arr.push(this.tasksService.getDefinitions({ q: '', size: 1, page: 0, sort: null, order: null }),
            this.tasksService.getExecutions({ q: '', size: 1, page: 0, sort: null, order: null }));
          if (featureInfo.schedulesEnabled) {
            arr.push(this.tasksService.getSchedules({ q: '', size: 1, page: 0, sort: null, order: null }));
          }
          return forkJoin([...arr])
            .pipe(map((counters) => {
              const result = {
                schedulesEnabled: featureInfo.schedulesEnabled,
                definitions: (counters[0] as Page<TaskDefinition>).totalElements,
                executions: (counters[1] as Page<TaskExecution>).totalElements
              };
              if (result.schedulesEnabled) {
                result['schedules'] = (counters[2] as Page<TaskSchedule>).totalElements;
              }
              return result;
            }));
        }
      ))
      .pipe(share());
  }

  createTask() {
    this.router.navigate(['/tasks/create']);
  }

}
<app-page *ngIf="params$ | async as params; else loading">

  <app-page-head>
    <app-page-head-title><strong>Tasks</strong></app-page-head-title>
    <app-page-head-actions [dataflowAppRoles]="['ROLE_CREATE']">
      <button class="btn btn-primary btn-fa" (click)="createTask()">
        <span class="fa fa-plus"></span>
        Create task(s)
      </button>
    </app-page-head-actions>
  </app-page-head>

  <div class="page-tab">
    <div class="page-tab-head">
      <ul class="nav nav-tabs">
        <li role="presentation" routerLinkActive="active">
          <a routerLink="/tasks/definitions">
            Task
            <span *ngIf="counters$ | async as counters">
              <span class="label label-count label-primary" *ngIf="counters.definitions">{{counters.definitions}}</span>
            </span>
          </a>
        </li>
        <li role="presentation" routerLinkActive="active">
          <a routerLink="/tasks/executions">
            Executions
            <span *ngIf="counters$ | async as counters">
              <span class="label label-count label-primary" *ngIf="counters.executions">{{counters.executions}}</span>
            </span>
          </a>
        </li>
        <li role="presentation" routerLinkActive="active" *ngIf="params.schedulesEnabled" [dataflowAppRoles]="['ROLE_SCHEDULE']">
          <a routerLink="/tasks/schedules">
            Schedules
            <span *ngIf="counters$ | async as counters">
              <span class="label label-count label-primary" *ngIf="counters.schedules">{{counters.schedules}}</span>
            </span>
          </a>
        </li>
      </ul>
    </div>
    <div class="tab-content">
      <div class="tab-pane in active">
        <ng-content></ng-content>
      </div>
    </div>
  </div>

</app-page>

<ng-template #loading>
  <app-loader></app-loader>
</ng-template>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""