added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / components / stats / filter-modal / filter-modal.component.ts
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 import { Component, OnInit } from '@angular/core';\r
18 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';\r
19 import { FormControl } from '@angular/forms';\r
20 import * as moment from 'moment';\r
21 \r
22 import { StatsService } from '../stats.service';\r
23 import { TestDefinitionService } from 'app/shared/services/test-definition.service';\r
24 import { TestInstanceService } from 'app/shared/services/test-instance.service';\r
25 import { GroupService } from 'app/shared/services/group.service';\r
26 \r
27 @Component({\r
28   selector: 'app-filter-modal',\r
29   templateUrl: './filter-modal.component.pug',\r
30   styleUrls: ['./filter-modal.component.scss']\r
31 })\r
32 \r
33 export class FilterModalComponent implements OnInit {\r
34 \r
35   public group;\r
36   public allFilters = {\r
37     startDate: "",\r
38     endDate: ""\r
39   };\r
40   public tdFilters = {\r
41     selected: [],\r
42     startDate: "",\r
43     endDate: "",\r
44   };\r
45   public tiFilters = {\r
46     selectedTDs: [],\r
47     selectedTIs: [],\r
48     startDate: "",\r
49     endDate: "",\r
50     multiLineLimit: 5\r
51   };\r
52   public scheduleFilters = {\r
53     startDate: "",\r
54     endDate: "",\r
55     timeRangeStart: "",\r
56     timeRangeEnd: "",\r
57     selectedInstances: [],\r
58   }\r
59   // public vthFilters = {\r
60   //   selected: [],\r
61   //   startDate: "",\r
62   //   endDate: "",\r
63   // };\r
64 \r
65   public minDate;\r
66   public maxDate;\r
67 \r
68   public testDefinitions: Array<any> = [];\r
69   public testInstances: Array<any> = [];\r
70   //public scheduleInstances: Array<any> = [];\r
71   //public vths = [];\r
72 \r
73   constructor(\r
74     public dialogRef: MatDialogRef<FilterModalComponent>,\r
75     public statsService: StatsService,\r
76     public tdService: TestDefinitionService,\r
77     public groupService: GroupService,\r
78     public tiService: TestInstanceService\r
79   ) {\r
80     this.minDate = new Date(moment().subtract(1, 'year').format('L'));\r
81     this.maxDate = new Date(moment().format('L'));\r
82 \r
83   }\r
84 \r
85   ngOnInit() {\r
86     //populate the td, ti, and vth arrays up there. or import them?\r
87     this.setTDList();\r
88     this.setTIList();\r
89   }\r
90 \r
91   setTDList() {\r
92     this.tdService.find({\r
93       groupId: this.groupService.getGroup()["_id"],\r
94       $select: ['testName', 'testDescription', "_id"],\r
95       $limit: -1,\r
96       $sort:{\r
97         testName:1\r
98       }\r
99     }).subscribe(result => {\r
100       for (let index in result) {\r
101         this.testDefinitions.push({id: result[index]._id, viewValue: result[index].testName });\r
102       }\r
103     })\r
104   }\r
105 \r
106   setTIList() {\r
107     this.tiService.find({\r
108       groupId: this.groupService.getGroup()["_id"],\r
109       $select: ['testInstanceName', 'testInstanceDescription', "_id"],\r
110       $limit: -1,\r
111       $sort:{\r
112         testInstanceName:1\r
113       }\r
114     }).subscribe(result => {\r
115       //console.log(result);\r
116       for (let index in result) {\r
117         this.testInstances.push({ id: result[index]._id, viewValue: result[index].testInstanceName })\r
118       }\r
119       //this.testInstances.sort((a, b) => b.viewValue - a.viewValue);\r
120     })\r
121   }\r
122 \r
123   checkDates() {\r
124     let allSet = true;\r
125 \r
126     if (this.scheduleFilters.startDate > this.scheduleFilters.endDate) {\r
127       allSet = false;\r
128       alert("Schedule Filters: Your end date cannot be earlier than your start date.");\r
129     } else if (this.tdFilters.startDate > this.tdFilters.endDate) {\r
130       allSet = false;\r
131       alert("Test Definition Filters: Your end date cannot be earlier than your start date.");\r
132     } else if (this.tiFilters.startDate > this.tiFilters.endDate) {\r
133       allSet = false;\r
134       alert("Test Instance Filters: Your end date cannot be earlier than your start date.");\r
135     }\r
136     return allSet;\r
137   }\r
138 \r
139   onConfirm() {\r
140     if (this.checkDates() == true) {\r
141       this.close();\r
142       this.statsService.filterData(this.allFilters, this.tdFilters, this.tiFilters, this.scheduleFilters);\r
143       //console.log(this.tdFilters);\r
144     }\r
145   }\r
146 \r
147   close() {\r
148     this.dialogRef.close();\r
149   }\r
150 \r
151 }\r