2 ============LICENSE_START=======================================================
3 Copyright (C) 2018 Ericsson. All rights reserved.
4 ================================================================================
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
17 SPDX-License-Identifier: Apache-2.0
18 ============LICENSE_END=========================================================
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com
23 import { Component, OnInit } from '@angular/core';
24 import { DataService } from '../data.service';
25 import { ActivatedRoute, Router } from "@angular/router";
26 import { Process } from '../model/process.model';
28 import { ProcessInstanceId } from '../model/processInstanceId.model';
29 import { ToastrNotificationService } from '../toastr-notification-service.service';
30 import { MatSelectModule } from '@angular/material/select';
31 import { ViewEncapsulation } from '@angular/core';
32 import { FormsModule } from '@angular/forms';
33 import { MatFormFieldModule, MatInputModule } from '@angular/material';
34 import { SearchData } from '../model/searchData.model';
35 import { MatDatepickerModule } from '@angular/material/datepicker';
36 import { FormControl } from '@angular/forms';
37 import { SearchRequest } from '../model/SearchRequest.model';
38 import { ElementRef } from '@angular/core';
39 import { Input } from '@angular/core';
40 import { NgxSpinnerService } from 'ngx-spinner';
44 templateUrl: './home.component.html',
45 styleUrls: ['./home.component.scss'],
46 encapsulation: ViewEncapsulation.None
49 export class HomeComponent implements OnInit {
57 percentageComplete = 0;
60 percentagePending = 0;
61 percentageUnlocked = 0;
63 options = [{ name: "EQUAL", value: "EQ" }, { name: "NOT EQUAL", value: "NEQ" }, { name: "LIKE", value: "LIKE" }];
64 statusOptions = [{ name: "ALL", value: "ALL" }, { name: "COMPLETE", value: "COMPLETE" }, { name: "IN_PROGRESS", value: "IN_PROGRESS" },
65 { name: "FAILED", value: "FAILED" }, { name: "PENDING", value: "PENDING" }, { name: "UNLOCKED", value: "UNLOCKED" }];
67 hourOptions = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
68 "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
70 minuteOptions = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
71 "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
72 "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55",
73 "56", "57", "58", "59"];
75 processData: Process[];
76 searchData: SearchData;
80 displayedColumns = ['requestId', 'serviceInstanceId', 'serviceIstanceName', 'networkId', 'requestStatus', 'serviceType', 'startTime', 'endTime'];
82 constructor(private route: ActivatedRoute, private data: DataService,
83 private router: Router, private popup: ToastrNotificationService,
84 private spinner: NgxSpinnerService) {
85 this.searchData = new SearchData();
91 var search = this.searchData.getSearchRequest().subscribe((result: SearchRequest) => {
93 this.data.retrieveInstance(result.getFilters(), result.getStartTimeInMilliseconds(), result.getEndTimeInMilliseconds())
94 .subscribe((data: Process[]) => {
96 this.processData = data;
97 this.popup.info("Number of records found: " + data.length)
99 // Calculate Statistics for Service Statistics tab
100 this.completeVal = this.processData.filter(i => i.requestStatus === "COMPLETE").length;
101 this.inProgressVal = this.processData.filter(i => i.requestStatus === "IN_PROGRESS").length;
102 this.failedVal = this.processData.filter(i => i.requestStatus === "FAILED").length;
103 this.pendingVal = this.processData.filter(i => i.requestStatus === "PENDING").length;
104 this.unlockedVal = this.processData.filter(i => i.requestStatus === "UNLOCKED").length;
105 this.totalVal = this.processData.length;
107 // Calculate percentages to 2 decimal places and compare to 0 to avoid NaN error
108 if (this.totalVal != 0) {
109 this.percentageComplete = Math.round(((this.completeVal / this.totalVal) * 100) * 100) / 100;
110 this.percentageFailed = Math.round(((this.failedVal / this.totalVal) * 100) * 100) / 100;
111 this.percentageInProg = Math.round(((this.inProgressVal / this.totalVal) * 100) * 100) / 100;
112 this.percentagePending = Math.round(((this.pendingVal / this.totalVal) * 100) * 100) / 100;
113 this.percentageUnlocked = Math.round(((this.unlockedVal / this.totalVal) * 100) * 100) / 100;
115 console.log("COMPLETE: " + this.completeVal);
116 console.log("FAILED: " + this.failedVal);
119 this.popup.error("Unable to perform search Error code:" + error.status);
123 console.log("Data validation error " + error);
124 this.popup.error(error);
129 getProcessIsntanceId(requestId: string) {
132 var response = this.data.getProcessInstanceId(requestId).subscribe((data) => {
133 if (data.status == 200) {
135 var processInstanceId = (data.body as ProcessInstanceId).processInstanceId;
136 this.router.navigate(['/details/' + processInstanceId]);
138 this.popup.error('No process instance id found: ' + requestId);
140 console.log('No process instance id found: ' + requestId);