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} from '@angular/core';
21 import { animate, state, style, transition, trigger } from '@angular/animations';
22 import { FormBuilder, FormGroup, AbstractControl } from '@angular/forms';
23 import { MatTableDataSource } from '@angular/material';
25 import { defer, BehaviorSubject, Observable } from 'rxjs';
26 import { map, withLatestFrom, startWith } from 'rxjs/operators';
28 import { EIJob, EIProducer } from '../interfaces/ei.types';
29 import { EIJobDataSource } from './ei-job.datasource';
30 import { EIProducerDataSource } from './ei-producer.datasource';
31 import { UiService } from '../services/ui/ui.service';
34 constructor(public eiJob: EIJob) { }
36 isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
40 selector: 'nrcp-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 {
54 producers$: Observable<EIProducer[]>;
55 filteredProducers$: Observable<EIProducer[]>;
57 eiJobInfo = new Map<string, EIJobInfo>();
61 jobsDataSource: MatTableDataSource<EIJob>;
63 readonly jobsFormControl: AbstractControl;
66 private eiJobsDataSource: EIJobDataSource,
67 private eiProducersDataSource: EIProducerDataSource,
68 private ui: UiService,
69 private formBuilder: FormBuilder) {
71 this.formGroup = formBuilder.group({ filter: [""] });
72 this.jobsFormControl = formBuilder.group({
81 this.eiJobsDataSource.getJobs();
82 this.jobsDataSource = new MatTableDataSource(this.eiJobsDataSource.eiJobsSubject.value);
84 this.jobsFormControl.valueChanges.subscribe(value => {
85 const filter = {...value, id: value.id.trim().toLowerCase()} as string;
86 this.jobsDataSource.filter = filter;
89 this.jobsDataSource.filterPredicate = ((data, filter) => {
90 return this.isDataIncluding(data.ei_job_identity, filter.id)
91 && this.isDataIncluding(data.target_uri, filter.target_uri)
92 && this.isDataIncluding(data.owner, filter.owner)
93 && this.isDataIncluding(data.ei_type_identity, filter.typeId);
94 }) as (EIJob, string) => boolean;
96 this.producers$= this.eiProducersDataSource.loadProducers();
97 this.filteredProducers$ = defer(() => this.formGroup.get("filter")
100 withLatestFrom(this.producers$),
101 map(([val, producers]) =>
102 !val ? producers : producers.filter((x) =>
103 x.ei_producer_id.toLowerCase().includes(val))))
106 this.ui.darkModeState.subscribe((isDark) => {
107 this.darkMode = isDark;
111 isDataIncluding(data: string, filter: string) : boolean {
112 return !filter || data.toLowerCase().includes(filter);
115 getEIJobInfo(eiJob: EIJob): EIJobInfo {
116 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
118 info = new EIJobInfo(eiJob);
119 this.eiJobInfo.set(eiJob.ei_job_data, info);
124 getDisplayName(eiJob: EIJob): string {
125 if (eiJob.ei_job_identity) {
126 return eiJob.ei_job_identity;
131 getEITypeId(eiJob: EIJob): string {
132 if (eiJob.ei_type_identity) {
133 return eiJob.ei_type_identity;
135 return '< No type >';
138 getTargetUri(eiJob: EIJob): string {
139 if (eiJob.target_uri) {
140 return eiJob.target_uri;
142 return '< No target URI >';
145 isInstancesShown(eiJob: EIJob): boolean {
146 return this.getEIJobInfo(eiJob).isExpanded.getValue();
149 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
150 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
153 getEIProducerId(eiProducer: EIProducer): string {
154 if (eiProducer.ei_producer_id) {
155 return eiProducer.ei_producer_id;
160 getEIProducerTypes(eiProducer: EIProducer): string[] {
161 if (eiProducer.ei_producer_types) {
162 return eiProducer.ei_producer_types;
164 return ['< No types >'];
167 getEIProducerStatus(eiProducer: EIProducer): string {
168 if (eiProducer.status) {
169 return eiProducer.status;
171 return '< No status >';
175 this.eiJobsDataSource.getJobs();
176 this.eiProducersDataSource.loadProducers();