1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\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
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\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
17 import { Component, Inject, OnInit } from '@angular/core';
\r
18 import { MatDialog, MatDialogRef, MAT_DIALOG_DATA, MatSnackBar } from '@angular/material';
\r
19 import { TestInstanceService } from '../../services/test-instance.service';
\r
20 import { SchedulingService } from '../../services/scheduling.service';
\r
21 import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';
\r
22 import { AlertModalComponent } from '../alert-modal/alert-modal.component';
\r
26 selector: 'app-schedule-test-modal',
\r
27 templateUrl: './schedule-test-modal.component.pug',
\r
28 styleUrls: ['./schedule-test-modal.component.scss']
\r
30 export class ScheduleTestModalComponent implements OnInit {
\r
33 public test_instances;
\r
34 public selectedTestInstance;
\r
42 public frequency = false;
\r
43 public isSelected = false;
\r
44 public scheduledJobs;
\r
48 private schedulingService: SchedulingService,
\r
49 private testInstanceService: TestInstanceService,
\r
50 public dialogRef: MatDialogRef<ScheduleTestModalComponent>,
\r
51 private snack: MatSnackBar,
\r
52 private dialog: MatDialog,
\r
53 @Inject(MAT_DIALOG_DATA) public input_data
\r
59 this.dialogRef.close();
\r
66 this.selectedTestInstance = {};
\r
67 this.startDate = null;
\r
68 this.timeToRun = null;
\r
69 this.endDate = null;
\r
70 //this.search.testInstanceName = "";
\r
71 //this.test_instances = [];
\r
73 this.schedule.testInstanceExecFreqInSeconds = '';
\r
74 this.scheduledJobs = [];
\r
75 this.loadingJobs = true;
\r
77 //console.log(this.test_instances);
\r
78 this.testInstanceService.get(this.input_data.id).subscribe(
\r
80 this.selectedTestInstance = result;
\r
84 this.schedulingService.find({$limit: -1, testInstanceId: this.input_data.id}).subscribe(
\r
86 for (let i = 0; i < result['length']; i++) {
\r
87 result[i].data.testSchedule._testInstanceStartDate = new Date(result[i].data.testSchedule._testInstanceStartDate).toLocaleString();
\r
88 if (result[i].data.testSchedule._testInstanceEndDate) {
\r
89 result[i].data.testSchedule._testInstanceEndDate = new Date(result[i].data.testSchedule._testInstanceEndDate).toLocaleString();
\r
91 this.scheduledJobs.push(result[i]);
\r
94 this.loadingJobs = false;
\r
99 convertDate(date, time = ''): Date {
\r
100 let nDate = new Date(date + '');
\r
101 return new Date(nDate.getMonth() + 1 + '/' + nDate.getDate() + '/' + nDate.getFullYear() + ' ' + time);
\r
105 this.convertDate(this.startDate, this.timeToRun);
\r
107 if (!this.selectedTestInstance || !this.startDate || !this.timeToRun) {
\r
108 this.dialog.open(AlertModalComponent, {
\r
112 message: 'Select start date/time before you create schedule!'
\r
117 if (this.frequency) {
\r
119 testInstanceId: this.selectedTestInstance._id,
\r
120 testInstanceStartDate: this.convertDate(this.startDate, this.timeToRun).toISOString(),
\r
121 testInstanceExecFreqInSeconds: this.numUnit * this.timeUnit,
\r
128 this.schedule.testInstanceEndDate = this.convertDate(this.endDate).toISOString();
\r
132 testInstanceId: this.selectedTestInstance._id,
\r
133 testInstanceStartDate: this.convertDate(this.startDate, this.timeToRun).toISOString(),
\r
137 //console.log(this.schedule);
\r
141 this.schedulingService.create(this.schedule).subscribe((result) => {
\r
142 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
145 message: 'Schedule Created!'
\r
150 this.dialog.open(AlertModalComponent, {
\r
153 message: err.message
\r
157 // console.log(this.schedule);
\r
161 var deleteJob = this.dialog.open(AlertModalComponent, {
\r
164 type: 'confirmation',
\r
165 message: 'Are you sure you want to delete this schedule?'
\r
169 deleteJob.afterClosed().subscribe(
\r
172 this.schedulingService.delete(job._id).subscribe(
\r
181 // this.testInstanceId = testInstanceId;
\r
182 // this.testInstanceStartDate = testInstanceStartDate;
\r
183 // this.testInstanceExecFreqInSeconds = testInstanceExecFreqInSeconds;
\r
184 // this.testInstanceEndDate = testInstanceEndDate;
\r
185 // this.async = async;
\r
186 // this.asyncTopic = asyncTopic;
\r
187 // this.executorId = executorId;
\r