--- /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, ViewContainerRef, ViewChild } from '@angular/core';\r
+import { HttpClient } from '@angular/common/http';\r
+import { routerLeftTransition } from '../../router.animations';\r
+import { ListService } from '../../shared/services/list.service';\r
+import { Router } from '@angular/router';\r
+import { MatDialog, MatTableDataSource, MatPaginator, MatSnackBar } from '@angular/material';\r
+import { ScheduleTestModalComponent } from '../../shared/modules/schedule-test-modal/schedule-test-modal.component';\r
+import { SchedulingService } from '../../shared/services/scheduling.service';\r
+import { TestInstanceService } from '../../shared/services/test-instance.service';\r
+import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';\r
+import { ViewScheduleModalComponent } from '../../shared/modules/view-schedule-modal/view-schedule-modal.component';\r
+import { AlertSnackbarComponent } from '../../shared/modules/alert-snackbar/alert-snackbar.component';\r
+\r
+@Component({\r
+ selector: 'app-scheduling',\r
+ templateUrl: './scheduling.component.pug',\r
+ styleUrls: ['./scheduling.component.scss'],\r
+ animations: [routerLeftTransition()]\r
+})\r
+\r
+export class SchedulingComponent implements OnInit {\r
+\r
+ constructor(private http: HttpClient,\r
+ private router: Router,\r
+ private viewRef: ViewContainerRef,\r
+ private list: ListService,\r
+ private schedulingService: SchedulingService,\r
+ private testInstanceService: TestInstanceService,\r
+ public dialog: MatDialog,\r
+ private snack: MatSnackBar\r
+ ) { }\r
+\r
+ public search;\r
+ public data;\r
+ public dataSource;\r
+ public displayedColumns: string[] = ['name', 'description', 'testDefinition', 'options'];\r
+ public resultsLength;\r
+ public instances;\r
+ public temp;\r
+ public count;\r
+ \r
+ @ViewChild(MatPaginator) paginator: MatPaginator;\r
+\r
+ ngOnInit() {\r
+ this.search = {};\r
+ this.search._id = "";\r
+ this.search.testInstanceName = "";\r
+ this.instances = [];\r
+ this.list.createList('schedules');\r
+ this.temp = {};\r
+ this.count = 0;\r
+\r
+ this.schedulingService.find({$limit: -1, 'data.testSchedule._testInstanceStartDate': { $ne: ['now'] }}).subscribe((list) => {\r
+ \r
+ for(var i = 0; i < Object.keys(list).length; i++){\r
+ list[i].nextRunAt = this.convertDate(list[i].nextRunAt);\r
+ list[i].lastRunAt = this.convertDate(list[i].lastRunAt);\r
+ }\r
+ this.list.changeMessage('schedules', list);\r
+ })\r
+\r
+ \r
+ this.dataSource = new MatTableDataSource();\r
+ this.dataSource.paginator = this.paginator;\r
+ \r
+ this.list.listMap['schedules'].currentList.subscribe((list) =>{\r
+ if(list){\r
+ this.dataSource.data = list;\r
+ this.resultsLength = list.length;\r
+ \r
+ \r
+ }\r
+ });\r
+ }\r
+\r
+ convertDate(str){\r
+ if(!str){\r
+ return 'none'\r
+ }\r
+ str = str.split('-')\r
+ let dayAndTime = str[2];\r
+ let day = dayAndTime.substring(0, dayAndTime.indexOf('T'));\r
+ let time = dayAndTime.substring(dayAndTime.indexOf('T')+1, dayAndTime.length-5);\r
+ return str[1] + '/' + day + '/' + str[0] + ' at ' + time + ' UTC';\r
+ }\r
+\r
+ viewSchedule(sched){\r
+ this.dialog.open(ViewScheduleModalComponent, {\r
+ width: '450px',\r
+ data: sched\r
+ });\r
+\r
+ }\r
+\r
+ deleteSchedule(sched){\r
+ const dialogRef = this.dialog.open(AlertModalComponent, {\r
+ width : '450px',\r
+ data: {\r
+ type: 'confirmation',\r
+ message: 'Are you sure you want to delete you schedule? This action cannot be undone.'\r
+ }\r
+ });\r
+ dialogRef.afterClosed().subscribe(result => {\r
+ if(result){\r
+ this.schedulingService.delete(sched._id).subscribe((result) => {\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: { \r
+ message:'Test Instance Saved'\r
+ }\r
+ });\r
+ this.list.removeElement('sched', '_id', sched._id + '');\r
+ this.list.listMap['sched'].currentList.subscribe(x => {\r
+ this.dataSource = x;\r
+ });\r
+\r
+ })\r
+ }\r
+ })\r
+ \r
+ }\r
+\r
+ createSchedule(){\r
+ const dialogRef = this.dialog.open(ScheduleTestModalComponent, {\r
+ width: '90%'\r
+ });\r
+\r
+ dialogRef.afterClosed().subscribe(result => {\r
+ /*if(result != ''){\r
+ this.test_instance_selected = result;\r
+ this.strategy_selected = true;\r
+ }else{\r
+ this.strategy_selected = false;\r
+ }*/\r
+ });\r
+ }\r
+\r
+}\r