added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / test-executions-catalog / test-executions-catalog.component.ts
diff --git a/otf-frontend/client/src/app/layout/test-executions-catalog/test-executions-catalog.component.ts b/otf-frontend/client/src/app/layout/test-executions-catalog/test-executions-catalog.component.ts
new file mode 100644 (file)
index 0000000..a054e59
--- /dev/null
@@ -0,0 +1,162 @@
+/*  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, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core';\r
+import { MatPaginator, MatDialog, MatTableDataSource, MatSnackBar } from '@angular/material';\r
+import { Router } from '@angular/router';\r
+import { ActivatedRoute } from '@angular/router';\r
+import { ListService } from 'app/shared/services/list.service';\r
+import { TestInstanceService } from 'app/shared/services/test-instance.service';\r
+import { AlertModalComponent } from 'app/shared/modules/alert-modal/alert-modal.component';\r
+import { TestExecutionService } from 'app/shared/services/test-execution.service';\r
+import { routerTransition } from 'app/router.animations';\r
+import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';\r
+import { TestDefinitionService } from 'app/shared/services/test-definition.service';\r
+import { GroupService } from 'app/shared/services/group.service';\r
+import { Subscription } from 'rxjs';\r
+\r
+@Component({\r
+  selector: 'app-test-executions-catalog',\r
+  templateUrl: './test-executions-catalog.component.pug',\r
+  styleUrls: ['./test-executions-catalog.component.scss'],\r
+  animations: [routerTransition()]\r
+})\r
+export class TestExecutionsCatalogComponent implements OnInit, OnDestroy {\r
+\r
+  private toDestroy: Array<Subscription> = [];\r
+  public dataSource;\r
+  public displayedColumns: string[] = ['testInstanceName', 'testInstanceDescription', 'result', 'totalTime', 'options'];\r
+  public resultsLength;\r
+  public loading = false;\r
+\r
+  @ViewChild(MatPaginator) paginator: MatPaginator;\r
+\r
+  constructor(\r
+    private list: ListService,\r
+    private testExecution: TestExecutionService,\r
+    private modal: MatDialog,\r
+    private route: ActivatedRoute,\r
+    private _groups: GroupService,\r
+    private snack: MatSnackBar\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
+      return;\r
+    }\r
+    this.loading = true;\r
+\r
+    this.dataSource = new MatTableDataSource();\r
+    this.dataSource.paginator = this.paginator;\r
+\r
+    //RG: Hard limit returns object, -1 returns array\r
+    const params = { $limit: 50, groupId: group._id, $populate: ['testInstanceId'], $sort: { startTime: -1 } }//['$limit=-1', '$populate[]=testInstanceId', '$sort[startTime]=-1'];\r
+    if (this.route.snapshot.params['filter']) {\r
+      params['testResult'] = this.route.snapshot.params['filter'].toUpperCase();\r
+    }\r
+    this.testExecution.find(params).subscribe((response) => {\r
+\r
+      let list = response;\r
+      //RG: check if hard limit if so it will be object w/ prop data\r
+      if(!Array.isArray(response) && response.hasOwnProperty('data')){\r
+        list = response['data'];\r
+      }\r
+      for (let i = 0; i < list['length']; i++) {\r
+        const tsDate = new Date(list[i]['startTime']);\r
+        const teDate = new Date(list[i]['endTime']);\r
+        list[i]['totalTime'] = (teDate.getTime() - tsDate.getTime()) / 1000;\r
+      }\r
+      this.dataSource.data = list;\r
+      this.resultsLength = this.dataSource.data.length;\r
+      this.loading = false;\r
+    });\r
+\r
+  }\r
+\r
+  applyFilter(filterValue: string) {\r
+    this.dataSource.filter = filterValue.trim().toLowerCase();\r
+  }\r
+\r
+  createTestInstance() {\r
+    // const create = this.modal.open(TestDefinition, {\r
+    //   width: '450px',\r
+    //   data: {\r
+    //     goal: 'create'\r
+    //   }\r
+    // });\r
+\r
+    // create.afterClosed().subscribe(result => {\r
+    //   this.list.listMap['vth'].currentList.subscribe(x => {\r
+    //     this.dataSource = x;\r
+    //   });\r
+    // });\r
+  }\r
+\r
+\r
+  editTestInstance(th) {\r
+    // const edit = this.modal.open(TestHeadModalComponent, {\r
+    //   width: '450px',\r
+    //   data: {\r
+    //     goal: 'edit',\r
+    //     testHead: th\r
+    //   }\r
+    // });\r
+\r
+    // edit.afterClosed().subscribe(result => {\r
+    //   console.log(result);\r
+    // });\r
+  }\r
+\r
+  deleteTestInstance(te) {\r
+    const deleter = this.modal.open(AlertModalComponent, {\r
+      width: '250px',\r
+      data: {\r
+        type: 'confirmation',\r
+        message: 'Are you sure you want to delete ' + te.testExecutionName + ' ?'\r
+      }\r
+    });\r
+\r
+    deleter.afterClosed().subscribe(result => {\r
+      if (result) {\r
+        this.testExecution.delete(te._id).subscribe(response => {\r
+          this.snack.openFromComponent(AlertSnackbarComponent, {\r
+            duration: 1500,\r
+            data: {\r
+              message: 'Test Execution Deleted'\r
+            }\r
+          });\r
+          this.list.removeElement('te', '_id', te._id + '');\r
+          this.list.listMap['te'].currentList.subscribe(x => {\r
+            this.dataSource.data = x;\r
+            this.resultsLength = x.length;\r
+          });\r
+        });\r
+      }\r
+    });\r
+  }\r
+}\r