added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / virtual-test-heads / virtual-test-heads.component.ts
diff --git a/otf-frontend/client/src/app/layout/virtual-test-heads/virtual-test-heads.component.ts b/otf-frontend/client/src/app/layout/virtual-test-heads/virtual-test-heads.component.ts
new file mode 100644 (file)
index 0000000..0853862
--- /dev/null
@@ -0,0 +1,145 @@
+/*  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, Output, Input, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core';\r
+import { HttpClient } from '@angular/common/http';\r
+import { AppGlobals } from '../../app.global';\r
+import { routerTransition } from '../../router.animations';\r
+import { ListService } from '../../shared/services/list.service';\r
+import { Router } from '@angular/router';\r
+import { MatTableDataSource, MatPaginator, MatSort, MatDialog, MatSnackBar } from '@angular/material';\r
+import { TestHeadService } from '../../shared/services/test-head.service';\r
+import { TestHeadModalComponent } from '../../shared/modules/test-head-modal/test-head-modal.component';\r
+import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';\r
+import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { Subscription } from 'rxjs';\r
+\r
+@Component({\r
+  selector: 'app-virtual-test-heads',\r
+  templateUrl: './virtual-test-heads.component.pug',\r
+  providers: [AppGlobals],\r
+  styleUrls: ['./virtual-test-heads.component.scss'],\r
+  animations: [routerTransition()]\r
+})\r
+export class VirtualTestHeadsComponent implements OnInit, OnDestroy {\r
+\r
+  private toDestroy: Array<Subscription> = [];\r
+  public dataSource;\r
+  public displayedColumns: string[] = ['name', 'description', 'options'];\r
+  public resultsLength;\r
+  public loading = false;\r
+\r
+  @ViewChild(MatPaginator) paginator: MatPaginator;\r
+\r
+  constructor(private testHead: TestHeadService,\r
+    private router: Router,\r
+    private modal: MatDialog,\r
+    private snack: MatSnackBar,\r
+    private _groups: GroupService) { }\r
+\r
+  applyFilter(filterValue: string) {\r
+    this.dataSource.filter = filterValue.trim().toLowerCase();\r
+  }\r
+\r
+\r
+  ngOnInit() {\r
+    this.setComponentData(this._groups.getGroup());\r
+    this.toDestroy.push(this._groups.groupChange().subscribe(group => {\r
+      this.setComponentData(group);\r
+    }));\r
+  }\r
+\r
+  ngOnDestroy(){\r
+    this.toDestroy.forEach(e => e.unsubscribe());\r
+  }\r
+\r
+  setComponentData(group) {\r
+    if(group){\r
+      \r
+      this.dataSource = new MatTableDataSource();\r
+      this.dataSource.paginator = this.paginator;\r
+\r
+      this.testHead.find({ $limit: -1, groupId: group['_id'], $sort: { createdAt: -1 } }).subscribe((list) => {\r
+        this.dataSource.data = list;\r
+        this.resultsLength = this.dataSource.data.length;\r
+        this.loading = false;\r
+      })\r
+    }\r
+  }\r
+\r
+  createTestHead() {\r
+    const create = this.modal.open(TestHeadModalComponent, {\r
+      width: '90%',\r
+      data: {\r
+        goal: 'create'\r
+      }\r
+    })\r
+\r
+    create.afterClosed().subscribe(result => {\r
+      this.ngOnInit();\r
+      // this.list.listMap['vth'].currentList.subscribe(x => {\r
+      //   this.dataSource.data = x;\r
+      //   this.resultsLength = this.dataSource.data.length;\r
+      // });\r
+    });\r
+  }\r
+\r
+\r
+  editTestHead(th) {\r
+    const edit = this.modal.open(TestHeadModalComponent, {\r
+      width: '90%',\r
+      data: {\r
+        goal: 'edit',\r
+        testHead: th\r
+      }\r
+    });\r
+\r
+    edit.afterClosed().subscribe(result => {\r
+      this.ngOnInit();\r
+    });\r
+  }\r
+\r
+  deleteTestHead(th) {\r
+    const deleter = this.modal.open(AlertModalComponent, {\r
+      width: '250px',\r
+      data: {\r
+        type: 'confirmation',\r
+        message: 'Are you sure you want to delete ' + th.testHeadName + '? There may be test definitions using this test head.'\r
+      }\r
+    });\r
+\r
+    deleter.afterClosed().subscribe(result => {\r
+      if (result) {\r
+        this.testHead.delete(th._id).subscribe(response => {\r
+          this.snack.openFromComponent(AlertSnackbarComponent, {\r
+            duration: 1500,\r
+            data: {\r
+              message: 'Test Head Deleted'\r
+            }\r
+          });\r
+\r
+          this.ngOnInit();\r
+        });\r
+      }\r
+    });\r
+  }\r
+\r
+  navToTestHead(id){\r
+    this.router.navigate(['/test-heads', id]);\r
+  }\r
+\r
+}\r