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 { Sort } from '@angular/material/sort';
22 import { FormBuilder, FormGroup, AbstractControl } from '@angular/forms';
23 import { MatTableDataSource } from '@angular/material/table';
25 import { EIJob } from '../interfaces/ei.types';
26 import { EIJobDataSource } from './ei-job.datasource';
27 import { UiService } from '../services/ui/ui.service';
28 import { ProducersListComponent } from './producers-list/producers-list.component';
31 selector: 'nrcp-ei-coordinator',
32 templateUrl: './ei-coordinator.component.html',
33 styleUrls: ['./ei-coordinator.component.scss']
35 export class EICoordinatorComponent implements OnInit {
39 jobsDataSource: MatTableDataSource<EIJob> = new MatTableDataSource<EIJob>();
41 readonly jobsFormControl: AbstractControl;
44 private producersList: ProducersListComponent,
45 private eiJobsDataSource: EIJobDataSource,
46 private ui: UiService,
47 private formBuilder: FormBuilder) {
48 this.formGroup = formBuilder.group({ filter: [""] });
50 this.jobsFormControl = formBuilder.group({
59 this.eiJobsDataSource.loadJobs();
61 this.eiJobsDataSource.eiJobsSubject().subscribe((data) => {
62 this.jobsDataSource.data = data;
65 this.jobsFormControl.valueChanges.subscribe(value => {
66 const filter = {...value, id: value.id.trim().toLowerCase()} as string;
67 this.jobsDataSource.filter = filter;
70 this.jobsDataSource.filterPredicate = ((data: EIJob, filter) => {
71 return this.isDataIncluding(data.ei_job_identity, filter.id)
72 && this.isDataIncluding(data.target_uri, filter.targetUri)
73 && this.isDataIncluding(data.owner, filter.owner)
74 && this.isDataIncluding(data.ei_type_identity, filter.typeId);
75 }) as (data: EIJob, filter: any) => boolean;
77 this.ui.darkModeState.subscribe((isDark) => {
78 this.darkMode = isDark;
83 const data = this.jobsDataSource.data
84 data.sort((a: EIJob, b: EIJob) => {
85 const isAsc = sort.direction === 'asc';
86 switch (sort.active) {
87 case 'id': return this.compare(a.ei_job_identity, b.ei_job_identity, isAsc);
88 case 'typeId': return this.compare(a.ei_type_identity, b.ei_type_identity, isAsc);
89 case 'owner': return this.compare(a.owner, b.owner, isAsc);
90 case 'targetUri': return this.compare(a.target_uri, b.owner, isAsc);
94 this.jobsDataSource.data = data;
97 compare(a: any, b: any, isAsc: boolean) {
98 return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
101 stopSort(event: any){
102 event.stopPropagation();
105 isDataIncluding(data: string, filter: string) : boolean {
106 return !filter || data.toLowerCase().includes(filter);
109 getJobTypeId(eiJob: EIJob): string {
110 if (eiJob.ei_type_identity) {
111 return eiJob.ei_type_identity;
113 return '< No type >';
116 getJobOwner(eiJob: EIJob): string {
120 return '< No owner >';
123 this.eiJobsDataSource.loadJobs();
124 this.eiJobsDataSource.eiJobsSubject().subscribe((data) => {
125 this.jobsDataSource.data = data;
128 this.producersList.refresh();