SO Monitoring UI
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / home / home.component.ts
1 /**
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
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
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.
16
17 SPDX-License-Identifier: Apache-2.0
18 ============LICENSE_END=========================================================
19
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com
21 */
22
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';
27
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 { ViewChild } from '@angular/core';
39 import { ElementRef } from '@angular/core';
40 import { Input } from '@angular/core';
41
42 @Component({
43   selector: 'app-home',
44   templateUrl: './home.component.html',
45   styleUrls: ['./home.component.scss'],
46   encapsulation: ViewEncapsulation.None
47 })
48
49 export class HomeComponent implements OnInit {
50
51   totalVal = 0;
52   completeVal = 0;
53   inProgressVal = 0;
54   failedVal = 0;
55   pendingVal = 0;
56   unlockedVal = 0;
57   percentageComplete = 0;
58   percentageFailed = 0;
59
60   options = [{ name: "EQUAL", value: "EQ" }, { name: "NOT EQUAL", value: "NEQ" }, { name: "LIKE", value: "LIKE" }];
61   statusOptions = [{ name: "ALL", value: "ALL" }, { name: "COMPLETE", value: "COMPLETE" }, { name: "IN_PROGRESS", value: "IN_PROGRESS" },
62   { name: "FAILED", value: "FAILED" }, { name: "PENDING", value: "PENDING" }, { name: "UNLOCKED", value: "UNLOCKED" }];
63
64   hourOptions = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
65     "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];
66
67   minuteOptions = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15",
68     "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35",
69     "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55",
70     "56", "57", "58", "59"];
71
72   processData: Process[];
73   searchData: SearchData;
74
75   startingDate: Date;
76
77   displayedColumns = ['requestId', 'serviceInstanceId', 'serviceIstanceName', 'networkId', 'requestStatus', 'serviceType', 'startTime', 'endTime'];
78
79   constructor(private route: ActivatedRoute, private data: DataService,
80     private router: Router, private popup: ToastrNotificationService) {
81     this.searchData = new SearchData();
82   }
83
84   makeCall() {
85     var search = this.searchData.getSearchRequest().subscribe((result: SearchRequest) => {
86
87       this.data.retrieveInstance(result.getFilters(), result.getStartTimeInMilliseconds(), result.getEndTimeInMilliseconds())
88         .subscribe((data: Process[]) => {
89           this.processData = data;
90           this.popup.info("Number of records found: " + data.length);
91           // Calculate Statistics for Service Statistics tab
92           this.completeVal = this.processData.filter(i => i.requestStatus === "COMPLETE").length;
93           this.inProgressVal = this.processData.filter(i => i.requestStatus === "IN_PROGRESS").length;
94           this.failedVal = this.processData.filter(i => i.requestStatus === "FAILED").length;
95           this.pendingVal = this.processData.filter(i => i.requestStatus === "PENDING").length;
96           this.unlockedVal = this.processData.filter(i => i.requestStatus === "UNLOCKED").length;
97           this.totalVal = this.processData.length;
98           this.percentageComplete = Math.round(((this.completeVal / this.totalVal) * 100) * 100) / 100;
99           this.percentageFailed = Math.round(((this.failedVal / this.totalVal) * 100) * 100) / 100;
100
101           console.log("COMPLETE: " + this.completeVal);
102           console.log("FAILED: " + this.failedVal);
103         }, error => {
104           console.log(error);
105           this.popup.error("Unable to perform search Error code:" + error.status);
106         });
107     }, error => {
108       console.log("Data validation error " + error);
109       this.popup.error(error);
110     });
111   }
112
113   getProcessIsntanceId(requestId: string) {
114     var response = this.data.getProcessInstanceId(requestId).subscribe((data) => {
115       if (data.status == 200) {
116         var processInstanceId = (data.body as ProcessInstanceId).processInstanceId;
117         this.router.navigate(['/details/' + processInstanceId]);
118       } else {
119         this.popup.error('No process instance id found: ' + requestId);
120         console.log('No process instance id found: ' + requestId);
121       }
122     });
123   }
124
125   ngOnInit() {
126
127   }
128 }