added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / virtual-test-heads / virtual-test-heads.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, Output, Input, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core';\r
18 import { HttpClient } from '@angular/common/http';\r
19 import { AppGlobals } from '../../app.global';\r
20 import { routerTransition } from '../../router.animations';\r
21 import { ListService } from '../../shared/services/list.service';\r
22 import { Router } from '@angular/router';\r
23 import { MatTableDataSource, MatPaginator, MatSort, MatDialog, MatSnackBar } from '@angular/material';\r
24 import { TestHeadService } from '../../shared/services/test-head.service';\r
25 import { TestHeadModalComponent } from '../../shared/modules/test-head-modal/test-head-modal.component';\r
26 import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';\r
27 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';\r
28 import { GroupService } from 'app/shared/services/group.service';\r
29 import { Subscription } from 'rxjs';\r
30 \r
31 @Component({\r
32   selector: 'app-virtual-test-heads',\r
33   templateUrl: './virtual-test-heads.component.pug',\r
34   providers: [AppGlobals],\r
35   styleUrls: ['./virtual-test-heads.component.scss'],\r
36   animations: [routerTransition()]\r
37 })\r
38 export class VirtualTestHeadsComponent implements OnInit, OnDestroy {\r
39 \r
40   private toDestroy: Array<Subscription> = [];\r
41   public dataSource;\r
42   public displayedColumns: string[] = ['name', 'description', 'options'];\r
43   public resultsLength;\r
44   public loading = false;\r
45 \r
46   @ViewChild(MatPaginator) paginator: MatPaginator;\r
47 \r
48   constructor(private testHead: TestHeadService,\r
49     private router: Router,\r
50     private modal: MatDialog,\r
51     private snack: MatSnackBar,\r
52     private _groups: GroupService) { }\r
53 \r
54   applyFilter(filterValue: string) {\r
55     this.dataSource.filter = filterValue.trim().toLowerCase();\r
56   }\r
57 \r
58 \r
59   ngOnInit() {\r
60     this.setComponentData(this._groups.getGroup());\r
61     this.toDestroy.push(this._groups.groupChange().subscribe(group => {\r
62       this.setComponentData(group);\r
63     }));\r
64   }\r
65 \r
66   ngOnDestroy(){\r
67     this.toDestroy.forEach(e => e.unsubscribe());\r
68   }\r
69 \r
70   setComponentData(group) {\r
71     if(group){\r
72       \r
73       this.dataSource = new MatTableDataSource();\r
74       this.dataSource.paginator = this.paginator;\r
75 \r
76       this.testHead.find({ $limit: -1, groupId: group['_id'], $sort: { createdAt: -1 } }).subscribe((list) => {\r
77         this.dataSource.data = list;\r
78         this.resultsLength = this.dataSource.data.length;\r
79         this.loading = false;\r
80       })\r
81     }\r
82   }\r
83 \r
84   createTestHead() {\r
85     const create = this.modal.open(TestHeadModalComponent, {\r
86       width: '90%',\r
87       data: {\r
88         goal: 'create'\r
89       }\r
90     })\r
91 \r
92     create.afterClosed().subscribe(result => {\r
93       this.ngOnInit();\r
94       // this.list.listMap['vth'].currentList.subscribe(x => {\r
95       //   this.dataSource.data = x;\r
96       //   this.resultsLength = this.dataSource.data.length;\r
97       // });\r
98     });\r
99   }\r
100 \r
101 \r
102   editTestHead(th) {\r
103     const edit = this.modal.open(TestHeadModalComponent, {\r
104       width: '90%',\r
105       data: {\r
106         goal: 'edit',\r
107         testHead: th\r
108       }\r
109     });\r
110 \r
111     edit.afterClosed().subscribe(result => {\r
112       this.ngOnInit();\r
113     });\r
114   }\r
115 \r
116   deleteTestHead(th) {\r
117     const deleter = this.modal.open(AlertModalComponent, {\r
118       width: '250px',\r
119       data: {\r
120         type: 'confirmation',\r
121         message: 'Are you sure you want to delete ' + th.testHeadName + '? There may be test definitions using this test head.'\r
122       }\r
123     });\r
124 \r
125     deleter.afterClosed().subscribe(result => {\r
126       if (result) {\r
127         this.testHead.delete(th._id).subscribe(response => {\r
128           this.snack.openFromComponent(AlertSnackbarComponent, {\r
129             duration: 1500,\r
130             data: {\r
131               message: 'Test Head Deleted'\r
132             }\r
133           });\r
134 \r
135           this.ngOnInit();\r
136         });\r
137       }\r
138     });\r
139   }\r
140 \r
141   navToTestHead(id){\r
142     this.router.navigate(['/test-heads', id]);\r
143   }\r
144 \r
145 }\r