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 { MatSort } from '@angular/material/sort';
22 import { animate, state, style, transition, trigger } from '@angular/animations';
23 import { FormBuilder, FormGroup } from '@angular/forms';
24 import { MatTableDataSource } from '@angular/material';
26 import { defer, BehaviorSubject, Observable } from 'rxjs';
27 import { map, withLatestFrom, startWith, tap } from 'rxjs/operators';
29 import { EIService } from '../services/ei/ei.service';
30 import { EIJob, EIProducer } from '../interfaces/ei.jobs';
31 import { EIProducerDataSource } from './ei-producer.datasource';
32 import { EIJobDataSource } from './ei-job.datasource';
33 import { NotificationService } from '../services/ui/notification.service';
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>;
70 private eiSvc: EIService,
71 private notificationService: NotificationService,
72 private ui: UiService,
73 private formBuilder: FormBuilder) {
74 this.formGroup = formBuilder.group({ filter: [""] });
78 this.eiJobsDataSource = new EIJobDataSource(this.eiSvc, this.sort, this.notificationService);
79 this.eiProducersDataSource = new EIProducerDataSource(this.eiSvc, this.sort, this.notificationService);
80 this.eiJobsDataSource.loadTable();
81 //this.eiProducersDataSource.loadTable();
83 this.producers$= this.eiProducersDataSource.getProducers();
84 this.filteredProducers$ = defer(() => this.formGroup.get("filter")
87 withLatestFrom(this.producers$),
88 map(([val, producers]) =>
89 !val ? producers : producers.filter((x) =>
90 x.ei_producer_id.toLowerCase().includes(val))))
93 this.ui.darkModeState.subscribe((isDark) => {
94 this.darkMode = isDark;
98 getEIJobInfo(eiJob: EIJob): EIJobInfo {
99 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
101 info = new EIJobInfo(eiJob);
102 this.eiJobInfo.set(eiJob.ei_job_data, info);
107 getDisplayName(eiJob: EIJob): string {
108 if (eiJob.ei_job_identity) {
109 return eiJob.ei_job_identity;
114 getEITypeId(eiJob: EIJob): string {
115 if (eiJob.ei_type_identity) {
116 return eiJob.ei_type_identity;
118 return '< No type >';
121 getTargetUri(eiJob: EIJob): string {
122 if (eiJob.target_uri) {
123 return eiJob.target_uri;
125 return '< No target URI >';
128 isInstancesShown(eiJob: EIJob): boolean {
129 return this.getEIJobInfo(eiJob).isExpanded.getValue();
132 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
133 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
136 getEIProducerId(eiProducer: EIProducer): string {
137 if (eiProducer.ei_producer_id) {
138 return eiProducer.ei_producer_id;
143 getEIProducerTypes(eiProducer: EIProducer): string[] {
144 if (eiProducer.ei_producer_types) {
145 return eiProducer.ei_producer_types;
147 return ['< No types >'];
150 getEIProducerStatus(eiProducer: EIProducer): string {
151 if (eiProducer.status) {
152 return eiProducer.status;
154 return '< No status >';
158 this.eiJobsDataSource.loadTable();
159 this.eiProducersDataSource.loadTable();