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, OnInit, ViewContainerRef, ViewChild } from '@angular/core';
\r
18 import { HttpClient } from '@angular/common/http';
\r
19 import { routerLeftTransition } from '../../router.animations';
\r
20 import { ListService } from '../../shared/services/list.service';
\r
21 import { Router } from '@angular/router';
\r
22 import { MatDialog, MatTableDataSource, MatPaginator, MatSnackBar } from '@angular/material';
\r
23 import { ScheduleTestModalComponent } from '../../shared/modules/schedule-test-modal/schedule-test-modal.component';
\r
24 import { SchedulingService } from '../../shared/services/scheduling.service';
\r
25 import { TestInstanceService } from '../../shared/services/test-instance.service';
\r
26 import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';
\r
27 import { ViewScheduleModalComponent } from '../../shared/modules/view-schedule-modal/view-schedule-modal.component';
\r
28 import { AlertSnackbarComponent } from '../../shared/modules/alert-snackbar/alert-snackbar.component';
\r
31 selector: 'app-scheduling',
\r
32 templateUrl: './scheduling.component.pug',
\r
33 styleUrls: ['./scheduling.component.scss'],
\r
34 animations: [routerLeftTransition()]
\r
37 export class SchedulingComponent implements OnInit {
\r
39 constructor(private http: HttpClient,
\r
40 private router: Router,
\r
41 private viewRef: ViewContainerRef,
\r
42 private list: ListService,
\r
43 private schedulingService: SchedulingService,
\r
44 private testInstanceService: TestInstanceService,
\r
45 public dialog: MatDialog,
\r
46 private snack: MatSnackBar
\r
52 public displayedColumns: string[] = ['name', 'description', 'testDefinition', 'options'];
\r
53 public resultsLength;
\r
58 @ViewChild(MatPaginator) paginator: MatPaginator;
\r
62 this.search._id = "";
\r
63 this.search.testInstanceName = "";
\r
64 this.instances = [];
\r
65 this.list.createList('schedules');
\r
69 this.schedulingService.find({$limit: -1, 'data.testSchedule._testInstanceStartDate': { $ne: ['now'] }}).subscribe((list) => {
\r
71 for(var i = 0; i < Object.keys(list).length; i++){
\r
72 list[i].nextRunAt = this.convertDate(list[i].nextRunAt);
\r
73 list[i].lastRunAt = this.convertDate(list[i].lastRunAt);
\r
75 this.list.changeMessage('schedules', list);
\r
79 this.dataSource = new MatTableDataSource();
\r
80 this.dataSource.paginator = this.paginator;
\r
82 this.list.listMap['schedules'].currentList.subscribe((list) =>{
\r
84 this.dataSource.data = list;
\r
85 this.resultsLength = list.length;
\r
96 str = str.split('-')
\r
97 let dayAndTime = str[2];
\r
98 let day = dayAndTime.substring(0, dayAndTime.indexOf('T'));
\r
99 let time = dayAndTime.substring(dayAndTime.indexOf('T')+1, dayAndTime.length-5);
\r
100 return str[1] + '/' + day + '/' + str[0] + ' at ' + time + ' UTC';
\r
103 viewSchedule(sched){
\r
104 this.dialog.open(ViewScheduleModalComponent, {
\r
111 deleteSchedule(sched){
\r
112 const dialogRef = this.dialog.open(AlertModalComponent, {
\r
115 type: 'confirmation',
\r
116 message: 'Are you sure you want to delete you schedule? This action cannot be undone.'
\r
119 dialogRef.afterClosed().subscribe(result => {
\r
121 this.schedulingService.delete(sched._id).subscribe((result) => {
\r
122 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
125 message:'Test Instance Saved'
\r
128 this.list.removeElement('sched', '_id', sched._id + '');
\r
129 this.list.listMap['sched'].currentList.subscribe(x => {
\r
130 this.dataSource = x;
\r
140 const dialogRef = this.dialog.open(ScheduleTestModalComponent, {
\r
144 dialogRef.afterClosed().subscribe(result => {
\r
145 /*if(result != ''){
\r
146 this.test_instance_selected = result;
\r
147 this.strategy_selected = true;
\r
149 this.strategy_selected = false;
\r