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, Version } 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';
24 import { FormBuilder, FormGroup } from '@angular/forms';
25 import { MatTableDataSource } from '@angular/material';
27 import { EIService } from '../services/ei/ei.service';
28 import { EIJob, EIProducer } from '../interfaces/ei.jobs';
29 import { EIProducerDataSource } from './ei-producer.datasource';
30 import { EIJobDataSource } from './ei-job.datasource';
31 import { NotificationService } from '../services/ui/notification.service';
32 import { defer, BehaviorSubject, Observable } from 'rxjs';
33 import { map, withLatestFrom, startWith, tap } from 'rxjs/operators';
34 import { UiService } from '../services/ui/ui.service';
37 constructor(public eiJob: EIJob) { }
39 isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
43 selector: 'rd-ei-coordinator',
44 templateUrl: './ei-coordinator.component.html',
45 styleUrls: ['./ei-coordinator.component.scss'],
47 trigger('detailExpand', [
48 state('collapsed, void', style({ height: '0px', minHeight: '0', display: 'none' })),
49 state('expanded', style({ height: '*' })),
50 transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
51 transition('expanded <=> void', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
55 export class EICoordinatorComponent implements OnInit {
57 eiJobsDataSource: EIJobDataSource;
58 eiProducersDataSource: EIProducerDataSource;
59 producers$: Observable<EIProducer[]>;
60 filteredProducers$: Observable<EIProducer[]>;
61 @ViewChild(MatSort, { static: true }) sort: MatSort;
63 eiJobInfo = new Map<string, EIJobInfo>();
67 eiProducersData: MatTableDataSource<EIProducerDataSource>;
71 private eiSvc: EIService,
72 private dialog: MatDialog,
73 private notificationService: NotificationService,
74 private ui: UiService,
75 private formBuilder: FormBuilder) {
76 this.formGroup = formBuilder.group({ filter: [""] });
80 this.eiJobsDataSource = new EIJobDataSource(this.eiSvc, this.sort, this.notificationService);
81 this.eiProducersDataSource = new EIProducerDataSource(this.eiSvc, this.sort, this.notificationService);
82 this.eiJobsDataSource.loadTable();
83 //this.eiProducersDataSource.loadTable();
85 this.producers$= this.eiProducersDataSource.getProducers();
86 this.filteredProducers$ = defer(() => this.formGroup.get("filter")
89 withLatestFrom(this.producers$),
90 map(([val, producers]) =>
91 !val ? producers : producers.filter((x) =>
92 x.ei_producer_id.toLowerCase().includes(val))))
95 this.ui.darkModeState.subscribe((isDark) => {
96 this.darkMode = isDark;
101 this.eiJobsDataSource.sort = this.sort;
102 this.eiProducersDataSource.sort = this.sort;
106 getEIJobInfo(eiJob: EIJob): EIJobInfo {
107 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
109 info = new EIJobInfo(eiJob);
110 this.eiJobInfo.set(eiJob.ei_job_data, info);
115 getDisplayName(eiJob: EIJob): string {
116 if (eiJob.ei_job_identity) {
117 return eiJob.ei_job_identity;
122 getEITypeId(eiJob: EIJob): string {
123 if (eiJob.ei_type_identity) {
124 return eiJob.ei_type_identity;
126 return '< No type >';
129 getTargetUri(eiJob: EIJob): string {
130 if (eiJob.target_uri) {
131 return eiJob.target_uri;
133 return '< No target URI >';
136 isInstancesShown(eiJob: EIJob): boolean {
137 return this.getEIJobInfo(eiJob).isExpanded.getValue();
140 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
141 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
144 getEIProducerId(eiProducer: EIProducer): string {
145 if (eiProducer.ei_producer_id) {
146 return eiProducer.ei_producer_id;
151 getEIProducerTypes(eiProducer: EIProducer): string[] {
152 if (eiProducer.ei_producer_types) {
153 return eiProducer.ei_producer_types;
155 return ['< No types >'];
158 getEIProducerStatus(eiProducer: EIProducer): string {
159 if (eiProducer.status) {
160 return eiProducer.status;
162 return '< No status >';
166 this.eiJobsDataSource.loadTable();
167 this.eiProducersDataSource.loadTable();