--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, OnInit } from '@angular/core';\r
+import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';\r
+import { FormControl } from '@angular/forms';\r
+import * as moment from 'moment';\r
+\r
+import { StatsService } from '../stats.service';\r
+import { TestDefinitionService } from 'app/shared/services/test-definition.service';\r
+import { TestInstanceService } from 'app/shared/services/test-instance.service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+\r
+@Component({\r
+ selector: 'app-filter-modal',\r
+ templateUrl: './filter-modal.component.pug',\r
+ styleUrls: ['./filter-modal.component.scss']\r
+})\r
+\r
+export class FilterModalComponent implements OnInit {\r
+\r
+ public group;\r
+ public allFilters = {\r
+ startDate: "",\r
+ endDate: ""\r
+ };\r
+ public tdFilters = {\r
+ selected: [],\r
+ startDate: "",\r
+ endDate: "",\r
+ };\r
+ public tiFilters = {\r
+ selectedTDs: [],\r
+ selectedTIs: [],\r
+ startDate: "",\r
+ endDate: "",\r
+ multiLineLimit: 5\r
+ };\r
+ public scheduleFilters = {\r
+ startDate: "",\r
+ endDate: "",\r
+ timeRangeStart: "",\r
+ timeRangeEnd: "",\r
+ selectedInstances: [],\r
+ }\r
+ // public vthFilters = {\r
+ // selected: [],\r
+ // startDate: "",\r
+ // endDate: "",\r
+ // };\r
+\r
+ public minDate;\r
+ public maxDate;\r
+\r
+ public testDefinitions: Array<any> = [];\r
+ public testInstances: Array<any> = [];\r
+ //public scheduleInstances: Array<any> = [];\r
+ //public vths = [];\r
+\r
+ constructor(\r
+ public dialogRef: MatDialogRef<FilterModalComponent>,\r
+ public statsService: StatsService,\r
+ public tdService: TestDefinitionService,\r
+ public groupService: GroupService,\r
+ public tiService: TestInstanceService\r
+ ) {\r
+ this.minDate = new Date(moment().subtract(1, 'year').format('L'));\r
+ this.maxDate = new Date(moment().format('L'));\r
+\r
+ }\r
+\r
+ ngOnInit() {\r
+ //populate the td, ti, and vth arrays up there. or import them?\r
+ this.setTDList();\r
+ this.setTIList();\r
+ }\r
+\r
+ setTDList() {\r
+ this.tdService.find({\r
+ groupId: this.groupService.getGroup()["_id"],\r
+ $select: ['testName', 'testDescription', "_id"],\r
+ $limit: -1,\r
+ $sort:{\r
+ testName:1\r
+ }\r
+ }).subscribe(result => {\r
+ for (let index in result) {\r
+ this.testDefinitions.push({id: result[index]._id, viewValue: result[index].testName });\r
+ }\r
+ })\r
+ }\r
+\r
+ setTIList() {\r
+ this.tiService.find({\r
+ groupId: this.groupService.getGroup()["_id"],\r
+ $select: ['testInstanceName', 'testInstanceDescription', "_id"],\r
+ $limit: -1,\r
+ $sort:{\r
+ testInstanceName:1\r
+ }\r
+ }).subscribe(result => {\r
+ //console.log(result);\r
+ for (let index in result) {\r
+ this.testInstances.push({ id: result[index]._id, viewValue: result[index].testInstanceName })\r
+ }\r
+ //this.testInstances.sort((a, b) => b.viewValue - a.viewValue);\r
+ })\r
+ }\r
+\r
+ checkDates() {\r
+ let allSet = true;\r
+\r
+ if (this.scheduleFilters.startDate > this.scheduleFilters.endDate) {\r
+ allSet = false;\r
+ alert("Schedule Filters: Your end date cannot be earlier than your start date.");\r
+ } else if (this.tdFilters.startDate > this.tdFilters.endDate) {\r
+ allSet = false;\r
+ alert("Test Definition Filters: Your end date cannot be earlier than your start date.");\r
+ } else if (this.tiFilters.startDate > this.tiFilters.endDate) {\r
+ allSet = false;\r
+ alert("Test Instance Filters: Your end date cannot be earlier than your start date.");\r
+ }\r
+ return allSet;\r
+ }\r
+\r
+ onConfirm() {\r
+ if (this.checkDates() == true) {\r
+ this.close();\r
+ this.statsService.filterData(this.allFilters, this.tdFilters, this.tiFilters, this.scheduleFilters);\r
+ //console.log(this.tdFilters);\r
+ }\r
+ }\r
+\r
+ close() {\r
+ this.dialogRef.close();\r
+ }\r
+\r
+}\r