2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
20 import { Component, OnInit, ViewChild } from '@angular/core';
21 import { MatDialog } from '@angular/material/dialog';
22 import { MatSort } from '@angular/material/sort';
23 import { animate, state, style, transition, trigger } from '@angular/animations';
25 import { EIService } from '../services/ei/ei.service';
26 import { EIJob, EIProducer } from '../interfaces/ei.jobs';
27 import { EIProducerDataSource } from './ei-producer.datasource';
28 import { EIJobDataSource } from './ei-job.datasource';
29 import { NotificationService } from '../services/ui/notification.service';
30 import { BehaviorSubject, Observable } from 'rxjs';
31 import { UiService } from '../services/ui/ui.service';
34 constructor(public eiJob: EIJob) { }
36 isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
40 selector: 'rd-ei-coordinator',
41 templateUrl: './ei-coordinator.component.html',
42 styleUrls: ['./ei-coordinator.component.scss'],
44 trigger('detailExpand', [
45 state('collapsed, void', style({ height: '0px', minHeight: '0', display: 'none' })),
46 state('expanded', style({ height: '*' })),
47 transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
48 transition('expanded <=> void', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
52 export class EICoordinatorComponent implements OnInit {
55 eiJobsDataSource: EIJobDataSource;
56 eiProducersDataSource: EIProducerDataSource;
57 @ViewChild(MatSort, { static: true }) sort: MatSort;
59 eiJobInfo = new Map<string, EIJobInfo>();
63 private eiSvc: EIService,
64 private dialog: MatDialog,
65 private notificationService: NotificationService,
66 private ui: UiService) { }
69 this.eiJobsDataSource = new EIJobDataSource(this.eiSvc, this.sort, this.notificationService);
70 this.eiProducersDataSource = new EIProducerDataSource(this.eiSvc, this.sort, this.notificationService);
71 this.eiJobsDataSource.loadTable();
72 this.eiProducersDataSource.loadTable();
73 this.ui.darkModeState.subscribe((isDark) => {
74 this.darkMode = isDark;
78 toggleListInstances(eiJob: EIJob): void {
79 const info = this.getEIJobInfo(eiJob);
80 info.isExpanded.next(!info.isExpanded.getValue());
83 getEIJobInfo(eiJob: EIJob): EIJobInfo {
84 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
86 info = new EIJobInfo(eiJob);
87 this.eiJobInfo.set(eiJob.ei_job_data, info);
92 getDisplayName(eiJob: EIJob): string {
93 if (eiJob.ei_job_identity) {
94 return eiJob.ei_job_identity;
99 getEITypeId(eiJob: EIJob): string {
100 if (eiJob.ei_type_identity){
101 return eiJob.ei_type_identity;
103 return '< No type >';
106 getTargetUri(eiJob: EIJob): string {
107 if (eiJob.target_uri){
108 return eiJob.target_uri;
110 return '< No target URI >';
113 isInstancesShown(eiJob: EIJob): boolean {
114 return this.getEIJobInfo(eiJob).isExpanded.getValue();
117 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
118 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
121 getEIProducerId(eiProducer: EIProducer): string {
122 if (eiProducer.ei_producer_id){
123 return eiProducer.ei_producer_id;
128 getEIProducerTypes(eiProducer: EIProducer): string[] {
129 if (eiProducer.ei_producer_types){
130 return eiProducer.ei_producer_types;
132 return ['< No types >'];
135 getEIProducerStatus(eiProducer: EIProducer): string {
136 if (eiProducer.status){
137 return eiProducer.status;
139 return '< No status >';