--- /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, Inject, OnInit } from '@angular/core';\r
+import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatSnackBar } from '@angular/material';\r
+import { TestInstanceService } from '../../services/test-instance.service';\r
+import { SchedulingService } from '../../services/scheduling.service';\r
+import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';\r
+import { AlertModalComponent } from '../alert-modal/alert-modal.component';\r
+\r
+\r
+@Component({\r
+ selector: 'app-schedule-test-modal',\r
+ templateUrl: './schedule-test-modal.component.pug',\r
+ styleUrls: ['./schedule-test-modal.component.scss']\r
+})\r
+export class ScheduleTestModalComponent implements OnInit {\r
+\r
+ public data;\r
+ public test_instances;\r
+ public selectedTestInstance;\r
+ public schedule;\r
+ public search;\r
+ public timeUnit;\r
+ public timeToRun;\r
+ public numUnit;\r
+ public startDate;\r
+ public endDate;\r
+ public frequency = false;\r
+ public isSelected = false;\r
+ public scheduledJobs;\r
+ public loadingJobs;\r
+\r
+ constructor(\r
+ private schedulingService: SchedulingService,\r
+ private testInstanceService: TestInstanceService,\r
+ public dialogRef: MatDialogRef<ScheduleTestModalComponent>,\r
+ private snack: MatSnackBar,\r
+ private dialog: MatDialog,\r
+ @Inject(MAT_DIALOG_DATA) public input_data\r
+ ) {\r
+\r
+ }\r
+\r
+ onNoClick(): void {\r
+ this.dialogRef.close();\r
+ }\r
+\r
+ ngOnInit() {\r
+ this.timeUnit = 60;\r
+ this.numUnit = 0;\r
+ this.search = {};\r
+ this.selectedTestInstance = {};\r
+ this.startDate = null;\r
+ this.timeToRun = null;\r
+ this.endDate = null;\r
+ //this.search.testInstanceName = ""; \r
+ //this.test_instances = [];\r
+ this.schedule = {};\r
+ this.schedule.testInstanceExecFreqInSeconds = '';\r
+ this.scheduledJobs = [];\r
+ this.loadingJobs = true;\r
+\r
+ //console.log(this.test_instances);\r
+ this.testInstanceService.get(this.input_data.id).subscribe(\r
+ result => {\r
+ this.selectedTestInstance = result;\r
+ }\r
+ );\r
+\r
+ this.schedulingService.find({$limit: -1, testInstanceId: this.input_data.id}).subscribe(\r
+ result => {\r
+ for (let i = 0; i < result['length']; i++) {\r
+ result[i].data.testSchedule._testInstanceStartDate = new Date(result[i].data.testSchedule._testInstanceStartDate).toLocaleString();\r
+ if (result[i].data.testSchedule._testInstanceEndDate) {\r
+ result[i].data.testSchedule._testInstanceEndDate = new Date(result[i].data.testSchedule._testInstanceEndDate).toLocaleString();\r
+ }\r
+ this.scheduledJobs.push(result[i]);\r
+\r
+ }\r
+ this.loadingJobs = false;\r
+ }\r
+ );\r
+ }\r
+\r
+ convertDate(date, time = ''): Date {\r
+ let nDate = new Date(date + '');\r
+ return new Date(nDate.getMonth() + 1 + '/' + nDate.getDate() + '/' + nDate.getFullYear() + ' ' + time);\r
+ }\r
+\r
+ createSchedule() {\r
+ this.convertDate(this.startDate, this.timeToRun);\r
+\r
+ if (!this.selectedTestInstance || !this.startDate || !this.timeToRun) {\r
+ this.dialog.open(AlertModalComponent, {\r
+ width: '450px',\r
+ data: {\r
+ type: 'Alert',\r
+ message: 'Select start date/time before you create schedule!'\r
+ }\r
+ });\r
+ return;\r
+ }\r
+ if (this.frequency) {\r
+ this.schedule = {\r
+ testInstanceId: this.selectedTestInstance._id,\r
+ testInstanceStartDate: this.convertDate(this.startDate, this.timeToRun).toISOString(),\r
+ testInstanceExecFreqInSeconds: this.numUnit * this.timeUnit,\r
+ async: false,\r
+ asyncTopic: ''\r
+ };\r
+ \r
+\r
+ if(this.endDate){\r
+ this.schedule.testInstanceEndDate = this.convertDate(this.endDate).toISOString();\r
+ }\r
+ } else {\r
+ this.schedule = {\r
+ testInstanceId: this.selectedTestInstance._id,\r
+ testInstanceStartDate: this.convertDate(this.startDate, this.timeToRun).toISOString(),\r
+ async: false,\r
+ asyncTopic: ''\r
+ };\r
+ //console.log(this.schedule);\r
+ \r
+ }\r
+\r
+ this.schedulingService.create(this.schedule).subscribe((result) => {\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message: 'Schedule Created!'\r
+ }\r
+ });\r
+ this.ngOnInit();\r
+ }, err => {\r
+ this.dialog.open(AlertModalComponent, {\r
+ data: {\r
+ type: "alert", \r
+ message: err.message\r
+ }\r
+ })\r
+ })\r
+ // console.log(this.schedule);\r
+ }\r
+\r
+ deleteJob(job) {\r
+ var deleteJob = this.dialog.open(AlertModalComponent, {\r
+ width: '250px',\r
+ data: {\r
+ type: 'confirmation',\r
+ message: 'Are you sure you want to delete this schedule?'\r
+ }\r
+ });\r
+\r
+ deleteJob.afterClosed().subscribe(\r
+ result => {\r
+ if (result) {\r
+ this.schedulingService.delete(job._id).subscribe(\r
+ result => {\r
+ this.ngOnInit();\r
+ }\r
+ );\r
+ }\r
+ }\r
+ );\r
+ }\r
+ // this.testInstanceId = testInstanceId;\r
+ // this.testInstanceStartDate = testInstanceStartDate;\r
+ // this.testInstanceExecFreqInSeconds = testInstanceExecFreqInSeconds;\r
+ // this.testInstanceEndDate = testInstanceEndDate;\r
+ // this.async = async;\r
+ // this.asyncTopic = asyncTopic;\r
+ // this.executorId = executorId;\r
+\r
+\r
+}\r