added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / scheduling / scheduling.component.ts
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\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
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\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
15 \r
16 \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
29 \r
30 @Component({\r
31   selector: 'app-scheduling',\r
32   templateUrl: './scheduling.component.pug',\r
33   styleUrls: ['./scheduling.component.scss'],\r
34   animations: [routerLeftTransition()]\r
35 })\r
36 \r
37 export class SchedulingComponent implements OnInit {\r
38 \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
47     ) { }\r
48 \r
49   public search;\r
50   public data;\r
51   public dataSource;\r
52   public displayedColumns: string[] = ['name', 'description', 'testDefinition', 'options'];\r
53   public resultsLength;\r
54   public instances;\r
55   public temp;\r
56   public count;\r
57   \r
58   @ViewChild(MatPaginator) paginator: MatPaginator;\r
59 \r
60   ngOnInit() {\r
61     this.search = {};\r
62     this.search._id = "";\r
63     this.search.testInstanceName = "";\r
64     this.instances = [];\r
65     this.list.createList('schedules');\r
66     this.temp = {};\r
67     this.count = 0;\r
68 \r
69     this.schedulingService.find({$limit: -1, 'data.testSchedule._testInstanceStartDate': { $ne: ['now'] }}).subscribe((list) => {\r
70       \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
74         }\r
75         this.list.changeMessage('schedules', list);\r
76     })\r
77 \r
78     \r
79     this.dataSource = new MatTableDataSource();\r
80     this.dataSource.paginator = this.paginator;\r
81     \r
82     this.list.listMap['schedules'].currentList.subscribe((list) =>{\r
83       if(list){\r
84         this.dataSource.data = list;\r
85         this.resultsLength = list.length;\r
86         \r
87        \r
88       }\r
89     });\r
90   }\r
91 \r
92   convertDate(str){\r
93     if(!str){\r
94       return 'none'\r
95     }\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
101   }\r
102 \r
103   viewSchedule(sched){\r
104     this.dialog.open(ViewScheduleModalComponent, {\r
105       width: '450px',\r
106       data: sched\r
107     });\r
108 \r
109   }\r
110 \r
111   deleteSchedule(sched){\r
112     const dialogRef = this.dialog.open(AlertModalComponent, {\r
113       width : '450px',\r
114       data: {\r
115         type: 'confirmation',\r
116         message: 'Are you sure you want to delete you schedule? This action cannot be undone.'\r
117       }\r
118     });\r
119     dialogRef.afterClosed().subscribe(result => {\r
120       if(result){\r
121         this.schedulingService.delete(sched._id).subscribe((result) => {\r
122           this.snack.openFromComponent(AlertSnackbarComponent, {\r
123             duration: 1500,\r
124             data: { \r
125               message:'Test Instance Saved'\r
126             }\r
127           });\r
128           this.list.removeElement('sched', '_id', sched._id + '');\r
129           this.list.listMap['sched'].currentList.subscribe(x => {\r
130               this.dataSource = x;\r
131           });\r
132 \r
133         })\r
134       }\r
135     })\r
136     \r
137   }\r
138 \r
139   createSchedule(){\r
140     const dialogRef = this.dialog.open(ScheduleTestModalComponent, {\r
141       width: '90%'\r
142     });\r
143 \r
144     dialogRef.afterClosed().subscribe(result => {\r
145       /*if(result != ''){\r
146         this.test_instance_selected = result;\r
147         this.strategy_selected = true;\r
148       }else{\r
149         this.strategy_selected = false;\r
150       }*/\r
151     });\r
152   }\r
153 \r
154 }\r