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 { 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 } from 'rxjs/operators';
29 import { EIJob, EIProducer } from '../interfaces/ei.types';
30 import { EIJobDataSource } from './ei-job.datasource';
31 import { EIProducerDataSource } from './ei-producer.datasource';
32 import { UiService } from '../services/ui/ui.service';
35 constructor(public eiJob: EIJob) { }
37 isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
41 selector: 'rd-ei-coordinator',
42 templateUrl: './ei-coordinator.component.html',
43 styleUrls: ['./ei-coordinator.component.scss'],
45 trigger('detailExpand', [
46 state('collapsed, void', style({ height: '0px', minHeight: '0', display: 'none' })),
47 state('expanded', style({ height: '*' })),
48 transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
49 transition('expanded <=> void', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)'))
53 export class EICoordinatorComponent implements OnInit {
55 producers$: Observable<EIProducer[]>;
56 filteredProducers$: Observable<EIProducer[]>;
57 @ViewChild(MatSort, { static: true }) sort: MatSort;
59 eiJobInfo = new Map<string, EIJobInfo>();
63 eiProducersData: MatTableDataSource<EIProducerDataSource>;
66 private eiJobsDataSource: EIJobDataSource,
67 private eiProducersDataSource: EIProducerDataSource,
68 private ui: UiService,
69 private formBuilder: FormBuilder) {
70 this.formGroup = formBuilder.group({ filter: [""] });
74 this.eiJobsDataSource.getJobs();
76 this.producers$= this.eiProducersDataSource.loadProducers();
77 this.filteredProducers$ = defer(() => this.formGroup.get("filter")
80 withLatestFrom(this.producers$),
81 map(([val, producers]) =>
82 !val ? producers : producers.filter((x) =>
83 x.ei_producer_id.toLowerCase().includes(val))))
86 this.ui.darkModeState.subscribe((isDark) => {
87 this.darkMode = isDark;
91 getEIJobInfo(eiJob: EIJob): EIJobInfo {
92 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
94 info = new EIJobInfo(eiJob);
95 this.eiJobInfo.set(eiJob.ei_job_data, info);
100 getDisplayName(eiJob: EIJob): string {
101 if (eiJob.ei_job_identity) {
102 return eiJob.ei_job_identity;
107 getEITypeId(eiJob: EIJob): string {
108 if (eiJob.ei_type_identity) {
109 return eiJob.ei_type_identity;
111 return '< No type >';
114 getTargetUri(eiJob: EIJob): string {
115 if (eiJob.target_uri) {
116 return eiJob.target_uri;
118 return '< No target URI >';
121 isInstancesShown(eiJob: EIJob): boolean {
122 return this.getEIJobInfo(eiJob).isExpanded.getValue();
125 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
126 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
129 getEIProducerId(eiProducer: EIProducer): string {
130 if (eiProducer.ei_producer_id) {
131 return eiProducer.ei_producer_id;
136 getEIProducerTypes(eiProducer: EIProducer): string[] {
137 if (eiProducer.ei_producer_types) {
138 return eiProducer.ei_producer_types;
140 return ['< No types >'];
143 getEIProducerStatus(eiProducer: EIProducer): string {
144 if (eiProducer.status) {
145 return eiProducer.status;
147 return '< No status >';
151 this.eiJobsDataSource.getJobs();
152 this.eiProducersDataSource.loadProducers();