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, AbstractControl } from '@angular/forms';
24 import { MatTableDataSource, MatTable } from '@angular/material';
26 import { BehaviorSubject, Observable } from 'rxjs';
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 @ViewChild(MatSort, { static: true }) sort: MatSort;
56 @ViewChild('producersTable', { static: true }) table: MatTable<Element>;
58 eiJobInfo = new Map<string, EIJobInfo>();
62 jobsDataSource: MatTableDataSource<EIJob>;
63 producersDataSource: MatTableDataSource<EIProducer>;
65 readonly jobsFormControl: AbstractControl;
66 readonly producersFormControl: AbstractControl;
69 private eiJobsDataSource: EIJobDataSource,
70 private eiProducersDataSource: EIProducerDataSource,
71 private ui: UiService,
72 private formBuilder: FormBuilder) {
73 this.formGroup = formBuilder.group({ filter: [""] });
75 this.jobsFormControl = formBuilder.group({
81 this.producersFormControl = formBuilder.group({
83 ei_producer_types: '',
89 this.eiJobsDataSource.getJobs();
90 this.producers$ = this.eiProducersDataSource.loadProducers();
91 this.jobsDataSource = new MatTableDataSource(this.eiJobsDataSource.eiJobsSubject.value);
92 this.producersDataSource = new MatTableDataSource(this.eiProducersDataSource.producerSubject.value)
94 this.jobsFormControl.valueChanges.subscribe(value => {
95 const filter = {...value, id: value.id.trim().toLowerCase()} as string;
96 this.jobsDataSource.filter = filter;
98 this.producersFormControl.valueChanges.subscribe(value => {
99 const filter = {...value, ei_producer_id: value.ei_producer_id.trim().toLowerCase()} as string;
100 this.producersDataSource.filter = filter;
103 this.jobsDataSource.filterPredicate = ((data, filter) => {
104 return this.isDataIncluding(data.ei_job_identity, filter.id)
105 && this.isDataIncluding(data.target_uri, filter.target_uri)
106 && this.isDataIncluding(data.owner, filter.owner)
107 && this.isDataIncluding(data.ei_type_identity, filter.typeId);
108 }) as (EIJob, string) => boolean;
110 this.producersDataSource.filterPredicate = ((data, filter) => {
111 return this.isDataIncluding(data.ei_producer_id, filter.ei_producer_id)
112 && this.isDataIncluding(data.ei_producer_types.join(','), filter.ei_producer_types)
113 && this.isDataIncluding(data.status, filter.status);
114 }) as (EIProducer, string) => boolean;
116 this.ui.darkModeState.subscribe((isDark) => {
117 this.darkMode = isDark;
121 isDataIncluding(data: string, filter: string) : boolean {
122 return !filter || data.toLowerCase().includes(filter);
125 getEIJobInfo(eiJob: EIJob): EIJobInfo {
126 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
128 info = new EIJobInfo(eiJob);
129 this.eiJobInfo.set(eiJob.ei_job_data, info);
134 getDisplayName(eiJob: EIJob): string {
135 if (eiJob.ei_job_identity) {
136 return eiJob.ei_job_identity;
141 getEITypeId(eiJob: EIJob): string {
142 if (eiJob.ei_type_identity) {
143 return eiJob.ei_type_identity;
145 return '< No type >';
148 getTargetUri(eiJob: EIJob): string {
149 if (eiJob.target_uri) {
150 return eiJob.target_uri;
152 return '< No target URI >';
155 isInstancesShown(eiJob: EIJob): boolean {
156 return this.getEIJobInfo(eiJob).isExpanded.getValue();
159 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
160 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
163 getEIProducerId(eiProducer: EIProducer): string {
164 if (eiProducer.ei_producer_id) {
165 return eiProducer.ei_producer_id;
170 getEIProducerTypes(eiProducer: EIProducer): string[] {
171 if (eiProducer.ei_producer_types) {
172 return eiProducer.ei_producer_types;
174 return ['< No types >'];
177 getEIProducerStatus(eiProducer: EIProducer): string {
178 if (eiProducer.status) {
179 return eiProducer.status;
181 return '< No status >';
185 this.eiJobsDataSource.getJobs();
186 this.eiProducersDataSource.loadProducers();