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 @ViewChild(MatSort, { static: true }) sort: MatSort;
55 @ViewChild('producersTable', { static: true }) table: MatTable<Element>;
57 eiJobInfo = new Map<string, EIJobInfo>();
61 jobsDataSource: MatTableDataSource<EIJob>;
62 producersDataSource: MatTableDataSource<EIProducer>;
64 readonly jobsFormControl: AbstractControl;
65 readonly producersFormControl: AbstractControl;
68 private eiJobsDataSource: EIJobDataSource,
69 private eiProducersDataSource: EIProducerDataSource,
70 private ui: UiService,
71 private formBuilder: FormBuilder) {
72 this.formGroup = formBuilder.group({ filter: [""] });
74 this.jobsFormControl = formBuilder.group({
80 this.producersFormControl = formBuilder.group({
82 ei_producer_types: '',
88 this.eiJobsDataSource.loadJobs();
89 this.eiProducersDataSource.loadProducers();
90 this.jobsDataSource = new MatTableDataSource(this.eiJobsDataSource.eiJobs());
91 this.producersDataSource = new MatTableDataSource(this.eiProducersDataSource.eiProducers());
93 this.jobsFormControl.valueChanges.subscribe(value => {
94 const filter = {...value, id: value.id.trim().toLowerCase()} as string;
95 this.jobsDataSource.filter = filter;
97 this.producersFormControl.valueChanges.subscribe(value => {
98 const filter = {...value, ei_producer_id: value.ei_producer_id.trim().toLowerCase()} as string;
99 this.producersDataSource.filter = filter;
102 this.jobsDataSource.filterPredicate = ((data, filter) => {
103 return this.isDataIncluding(data.ei_job_identity, filter.id)
104 && this.isDataIncluding(data.target_uri, filter.target_uri)
105 && this.isDataIncluding(data.owner, filter.owner)
106 && this.isDataIncluding(data.ei_type_identity, filter.typeId);
107 }) as (EIJob, string) => boolean;
109 this.producersDataSource.filterPredicate = ((data, filter) => {
110 return this.isDataIncluding(data.ei_producer_id, filter.ei_producer_id)
111 && this.isDataIncluding(data.ei_producer_types.join(','), filter.ei_producer_types)
112 && this.isDataIncluding(data.status, filter.status);
113 }) as (EIProducer, string) => boolean;
115 this.ui.darkModeState.subscribe((isDark) => {
116 this.darkMode = isDark;
120 isDataIncluding(data: string, filter: string) : boolean {
121 return !filter || data.toLowerCase().includes(filter);
124 getEIJobInfo(eiJob: EIJob): EIJobInfo {
125 let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
127 info = new EIJobInfo(eiJob);
128 this.eiJobInfo.set(eiJob.ei_job_data, info);
133 getDisplayName(eiJob: EIJob): string {
134 if (eiJob.ei_job_identity) {
135 return eiJob.ei_job_identity;
140 getEITypeId(eiJob: EIJob): string {
141 if (eiJob.ei_type_identity) {
142 return eiJob.ei_type_identity;
144 return '< No type >';
147 getTargetUri(eiJob: EIJob): string {
148 if (eiJob.target_uri) {
149 return eiJob.target_uri;
151 return '< No target URI >';
154 isInstancesShown(eiJob: EIJob): boolean {
155 return this.getEIJobInfo(eiJob).isExpanded.getValue();
158 getExpandedObserver(eiJob: EIJob): Observable<boolean> {
159 return this.getEIJobInfo(eiJob).isExpanded.asObservable();
162 getEIProducerId(eiProducer: EIProducer): string {
163 if (eiProducer.ei_producer_id) {
164 return eiProducer.ei_producer_id;
169 getEIProducerTypes(eiProducer: EIProducer): string[] {
170 if (eiProducer.ei_producer_types) {
171 return eiProducer.ei_producer_types;
173 return ['< No types >'];
176 getEIProducerStatus(eiProducer: EIProducer): string {
177 if (eiProducer.status) {
178 return eiProducer.status;
180 return '< No status >';
184 this.eiJobsDataSource.loadJobs();
185 this.eiProducersDataSource.loadProducers();