1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\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
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\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
17 import { Component, OnInit, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core';
\r
18 import { MatPaginator, MatDialog, MatTableDataSource, MatSnackBar } from '@angular/material';
\r
19 import { Router } from '@angular/router';
\r
20 import { ActivatedRoute } from '@angular/router';
\r
21 import { ListService } from 'app/shared/services/list.service';
\r
22 import { TestInstanceService } from 'app/shared/services/test-instance.service';
\r
23 import { AlertModalComponent } from 'app/shared/modules/alert-modal/alert-modal.component';
\r
24 import { TestExecutionService } from 'app/shared/services/test-execution.service';
\r
25 import { routerTransition } from 'app/router.animations';
\r
26 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';
\r
27 import { TestDefinitionService } from 'app/shared/services/test-definition.service';
\r
28 import { GroupService } from 'app/shared/services/group.service';
\r
29 import { Subscription } from 'rxjs';
\r
32 selector: 'app-test-executions-catalog',
\r
33 templateUrl: './test-executions-catalog.component.pug',
\r
34 styleUrls: ['./test-executions-catalog.component.scss'],
\r
35 animations: [routerTransition()]
\r
37 export class TestExecutionsCatalogComponent implements OnInit, OnDestroy {
\r
39 private toDestroy: Array<Subscription> = [];
\r
41 public displayedColumns: string[] = ['testInstanceName', 'testInstanceDescription', 'result', 'totalTime', 'options'];
\r
42 public resultsLength;
\r
43 public loading = false;
\r
45 @ViewChild(MatPaginator) paginator: MatPaginator;
\r
48 private list: ListService,
\r
49 private testExecution: TestExecutionService,
\r
50 private modal: MatDialog,
\r
51 private route: ActivatedRoute,
\r
52 private _groups: GroupService,
\r
53 private snack: MatSnackBar
\r
58 this.setComponentData(this._groups.getGroup());
\r
59 this.toDestroy.push(this._groups.groupChange().subscribe(group => {
\r
60 this.setComponentData(group);
\r
65 this.toDestroy.forEach(e => e.unsubscribe());
\r
68 setComponentData(group) {
\r
72 this.loading = true;
\r
74 this.dataSource = new MatTableDataSource();
\r
75 this.dataSource.paginator = this.paginator;
\r
77 //RG: Hard limit returns object, -1 returns array
\r
78 const params = { $limit: 50, groupId: group._id, $populate: ['testInstanceId'], $sort: { startTime: -1 } }//['$limit=-1', '$populate[]=testInstanceId', '$sort[startTime]=-1'];
\r
79 if (this.route.snapshot.params['filter']) {
\r
80 params['testResult'] = this.route.snapshot.params['filter'].toUpperCase();
\r
82 this.testExecution.find(params).subscribe((response) => {
\r
84 let list = response;
\r
85 //RG: check if hard limit if so it will be object w/ prop data
\r
86 if(!Array.isArray(response) && response.hasOwnProperty('data')){
\r
87 list = response['data'];
\r
89 for (let i = 0; i < list['length']; i++) {
\r
90 const tsDate = new Date(list[i]['startTime']);
\r
91 const teDate = new Date(list[i]['endTime']);
\r
92 list[i]['totalTime'] = (teDate.getTime() - tsDate.getTime()) / 1000;
\r
94 this.dataSource.data = list;
\r
95 this.resultsLength = this.dataSource.data.length;
\r
96 this.loading = false;
\r
101 applyFilter(filterValue: string) {
\r
102 this.dataSource.filter = filterValue.trim().toLowerCase();
\r
105 createTestInstance() {
\r
106 // const create = this.modal.open(TestDefinition, {
\r
113 // create.afterClosed().subscribe(result => {
\r
114 // this.list.listMap['vth'].currentList.subscribe(x => {
\r
115 // this.dataSource = x;
\r
121 editTestInstance(th) {
\r
122 // const edit = this.modal.open(TestHeadModalComponent, {
\r
130 // edit.afterClosed().subscribe(result => {
\r
131 // console.log(result);
\r
135 deleteTestInstance(te) {
\r
136 const deleter = this.modal.open(AlertModalComponent, {
\r
139 type: 'confirmation',
\r
140 message: 'Are you sure you want to delete ' + te.testExecutionName + ' ?'
\r
144 deleter.afterClosed().subscribe(result => {
\r
146 this.testExecution.delete(te._id).subscribe(response => {
\r
147 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
150 message: 'Test Execution Deleted'
\r
153 this.list.removeElement('te', '_id', te._id + '');
\r
154 this.list.listMap['te'].currentList.subscribe(x => {
\r
155 this.dataSource.data = x;
\r
156 this.resultsLength = x.length;
\r