Merge "Added presentation of owner of EiJob"
[portal/nonrtric-controlpanel.git] / webapp-frontend / src / app / ei-coordinator / ei-coordinator.component.ts
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 Nordix Foundation
6  * %%
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20 import { Component, OnInit, ViewChild } from '@angular/core';
21 import { MatDialog } from '@angular/material/dialog';
22 import { MatSort } from '@angular/material/sort';
23 import { animate, state, style, transition, trigger } from '@angular/animations';
24
25 import { EIService } from '../services/ei/ei.service';
26 import { EIJob, EIProducer } from '../interfaces/ei.jobs';
27 import { EIProducerDataSource } from './ei-producer.datasource';
28 import { EIJobDataSource } from './ei-job.datasource';
29 import { NotificationService } from '../services/ui/notification.service';
30 import { BehaviorSubject, Observable } from 'rxjs';
31 import { UiService } from '../services/ui/ui.service';
32
33 class EIJobInfo {
34     constructor(public eiJob: EIJob) { }
35
36     isExpanded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
37 }
38
39 @Component({
40     selector: 'rd-ei-coordinator',
41     templateUrl: './ei-coordinator.component.html',
42     styleUrls: ['./ei-coordinator.component.scss'],
43     animations: [
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)'))
49         ]),
50     ],
51 })
52 export class EICoordinatorComponent implements OnInit {
53
54
55     eiJobsDataSource: EIJobDataSource;
56     eiProducersDataSource: EIProducerDataSource;
57     @ViewChild(MatSort, { static: true }) sort: MatSort;
58
59     eiJobInfo = new Map<string, EIJobInfo>();
60     darkMode: boolean;
61
62     constructor(
63         private eiSvc: EIService,
64         private dialog: MatDialog,
65         private notificationService: NotificationService,
66         private ui: UiService) { }
67
68     ngOnInit() {
69         this.eiJobsDataSource = new EIJobDataSource(this.eiSvc, this.sort, this.notificationService);
70         this.eiProducersDataSource = new EIProducerDataSource(this.eiSvc, this.sort, this.notificationService);
71         this.eiJobsDataSource.loadTable();
72         this.eiProducersDataSource.loadTable();
73         this.ui.darkModeState.subscribe((isDark) => {
74             this.darkMode = isDark;
75         });
76     }
77
78     toggleListInstances(eiJob: EIJob): void {
79         const info = this.getEIJobInfo(eiJob);
80         info.isExpanded.next(!info.isExpanded.getValue());
81     }
82
83     getEIJobInfo(eiJob: EIJob): EIJobInfo {
84         let info: EIJobInfo = this.eiJobInfo.get(eiJob.ei_job_data);
85         if (!info) {
86             info = new EIJobInfo(eiJob);
87             this.eiJobInfo.set(eiJob.ei_job_data, info);
88         }
89         return info;
90     }
91
92     getDisplayName(eiJob: EIJob): string {
93         if (eiJob.ei_job_identity) {
94             return eiJob.ei_job_identity;
95         }
96         return '< No id >';
97     }
98
99     getEITypeId(eiJob: EIJob): string {
100         if (eiJob.ei_type_identity) {
101             return eiJob.ei_type_identity;
102         }
103         return '< No type >';
104     }
105
106     getTargetUri(eiJob: EIJob): string {
107         if (eiJob.target_uri) {
108             return eiJob.target_uri;
109         }
110         return '< No target URI >';
111     }
112
113     isInstancesShown(eiJob: EIJob): boolean {
114         return this.getEIJobInfo(eiJob).isExpanded.getValue();
115     }
116
117     getExpandedObserver(eiJob: EIJob): Observable<boolean> {
118         return this.getEIJobInfo(eiJob).isExpanded.asObservable();
119     }
120
121     getEIProducerId(eiProducer: EIProducer): string {
122         if (eiProducer.ei_producer_id) {
123             return eiProducer.ei_producer_id;
124         }
125         return '< No id>';
126     }
127
128     getEIProducerTypes(eiProducer: EIProducer): string[] {
129         if (eiProducer.ei_producer_types) {
130             return eiProducer.ei_producer_types;
131         }
132         return ['< No types >'];
133     }
134
135     getEIProducerStatus(eiProducer: EIProducer): string {
136         if (eiProducer.status) {
137             return eiProducer.status;
138         }
139         return '< No status >';
140     }
141
142     refreshTables() {
143         this.eiJobsDataSource.loadTable();
144         this.eiProducersDataSource.loadTable();
145     }
146 }