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, andrei.barcovschi@ericsson.com
23 import { Component, OnInit, ViewChild, ElementRef, Input, ViewEncapsulation } from '@angular/core';
24 import { DataService } from '../data.service';
25 import { ActivatedRoute, Router } from "@angular/router";
26 import { BpmnInfraRequest } from '../model/bpmnInfraRequest.model';
27 import { ProcessInstanceId } from '../model/processInstanceId.model';
28 import { ToastrNotificationService } from '../toastr-notification-service.service';
29 import { MatSelectModule } from '@angular/material/select';
30 import { FormsModule, FormControl } from '@angular/forms';
31 import { SearchData } from '../model/searchData.model';
32 import { MatDatepickerModule } from '@angular/material/datepicker';
33 import { SearchRequest } from '../model/SearchRequest.model';
34 import { NgxSpinnerService } from 'ngx-spinner';
35 import { MatFormFieldModule, MatInputModule, MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
36 import { Constants } from './home.constant';
40 templateUrl: './home.component.html',
41 styleUrls: ['./home.component.scss'],
42 encapsulation: ViewEncapsulation.None
45 export class HomeComponent {
53 percentageComplete = 0;
56 percentagePending = 0;
57 percentageUnlocked = 0;
59 options = Constants.OPTIONS;
60 statusOptions = Constants.STATUS_OPTIONS;
61 hourOptions = Constants.HOUR_OPTIONS;
62 minuteOptions = Constants.MINUTE_OPTIONS;
63 displayedColumns = Constants.DISPLAYED_COLUMNS;
64 pageSizeOptions = Constants.DEFAULT_PAGE_SIZE_OPTIONS;
66 searchData: SearchData;
68 processData: MatTableDataSource<BpmnInfraRequest>;
70 @ViewChild(MatPaginator) paginator: MatPaginator;
71 @ViewChild(MatSort) sort: MatSort;
73 constructor(private route: ActivatedRoute, private data: DataService,
74 private router: Router, private popup: ToastrNotificationService,
75 private spinner: NgxSpinnerService) {
76 this.searchData = new SearchData();
82 var search = this.searchData.getSearchRequest().subscribe((result: SearchRequest) => {
84 this.data.getBpmnInfraRequest(result.getFilters(), result.getStartTimeInMilliseconds(), result.getEndTimeInMilliseconds())
85 .subscribe((data: BpmnInfraRequest[]) => {
87 var processData: BpmnInfraRequest[] = data;
88 this.processData = new MatTableDataSource<BpmnInfraRequest>(processData);
89 this.processData.sort = this.sort;
90 this.processData.paginator = this.paginator;
91 this.processData.paginator.firstPage();
93 this.popup.info("Number of records found: " + data.length)
95 // Calculate Statistics for Service Statistics tab
96 this.completeVal = processData.filter(i => i.requestStatus === "COMPLETE").length;
97 this.inProgressVal = processData.filter(i => i.requestStatus === "IN_PROGRESS").length;
98 this.failedVal = processData.filter(i => i.requestStatus === "FAILED").length;
99 this.pendingVal = processData.filter(i => i.requestStatus === "PENDING").length;
100 this.unlockedVal = processData.filter(i => i.requestStatus === "UNLOCKED").length;
101 this.totalVal = processData.length;
103 // Calculate percentages to 2 decimal places and compare to 0 to avoid NaN error
104 if (this.totalVal != 0) {
105 this.percentageComplete = Math.round(((this.completeVal / this.totalVal) * 100) * 100) / 100;
106 this.percentageFailed = Math.round(((this.failedVal / this.totalVal) * 100) * 100) / 100;
107 this.percentageInProg = Math.round(((this.inProgressVal / this.totalVal) * 100) * 100) / 100;
108 this.percentagePending = Math.round(((this.pendingVal / this.totalVal) * 100) * 100) / 100;
109 this.percentageUnlocked = Math.round(((this.unlockedVal / this.totalVal) * 100) * 100) / 100;
111 console.log("COMPLETE: " + this.completeVal);
112 console.log("FAILED: " + this.failedVal);
115 this.popup.error("Unable to perform search Error code:" + error.status);
119 console.log("Data validation error " + error);
120 this.popup.error(error);
125 getProcessInstanceId(requestId: string) {
128 var response = this.data.getProcessInstanceId(requestId).subscribe((data) => {
129 if (data.status == 200) {
131 var processInstanceId = (data.body as ProcessInstanceId).processInstanceId;
132 this.router.navigate(['/details/' + processInstanceId]);
134 this.popup.error('No process instance id found: ' + requestId);
136 console.log('No process instance id found: ' + requestId);