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, AfterViewInit, OnDestroy, ViewChildren, ElementRef, QueryList } from '@angular/core';
\r
18 import { MatDialog, MatPaginator, MatSnackBar, MatTableDataSource, MatListItem } from '@angular/material';
\r
19 import { ActivatedRoute, Router } from '@angular/router';
\r
20 import { ListService } from '../../shared/services/list.service';
\r
21 import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';
\r
22 import { TestInstanceService } from '../../shared/services/test-instance.service';
\r
23 import { routerTransition } from 'app/router.animations';
\r
24 import { SchedulingService } from '../../shared/services/scheduling.service';
\r
25 import { TestInstanceModalComponent } from '../../shared/modules/test-instance-modal/test-instance-modal.component';
\r
26 import { AlertSnackbarComponent } from '../../shared/modules/alert-snackbar/alert-snackbar.component';
\r
27 import { ScheduleTestModalComponent } from '../../shared/modules/schedule-test-modal/schedule-test-modal.component';
\r
28 import { animate, state, style, transition, trigger } from '@angular/animations';
\r
29 import { TestDefinitionService } from '../../shared/services/test-definition.service';
\r
30 import { Observable, Subscription } from 'rxjs';
\r
31 import { ExecuteService } from 'app/shared/services/execute.service';
\r
32 import { GroupService } from 'app/shared/services/group.service';
\r
33 import { GridOptions } from "ag-grid-community";
\r
37 selector: 'app-test-instances-catalog',
\r
38 templateUrl: './test-instances-catalog.component.pug',
\r
39 styleUrls: ['./test-instances-catalog.component.scss'],
\r
40 animations: [routerTransition(),
\r
41 trigger('detailExpand', [
\r
42 state('collapsed', style({ height: '0px', minHeight: '0', display: 'none' })),
\r
43 state('expanded', style({ height: '*' })),
\r
44 transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
\r
48 export class TestInstancesCatalogComponent implements OnInit, AfterViewInit, OnDestroy {
\r
51 public resultsLength;
\r
52 public loading = false;
\r
55 public columnDefs = [
\r
56 {headerName: '', field: 'disabled', cellRenderer: this.disabledIndicator, width: 100, hide: false, checkboxSelection:true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true},
\r
57 {headerName: 'Name', field: 'testInstanceName', sortable: true, filter: true, resizable: true, width: 300},
\r
58 {headerName: 'Description', field: 'testInstanceDescription', sortable: true, filter: true, resizable: true, width: 100},
\r
59 {headerName: 'Id', field: '_id', sortable: true, filter: true, resizable: true, width: 200, editable: true},
\r
60 {headerName: 'Test Definition', field: 'testDefinitionId.testName', sortable: true, filter: true, resizable: true}
\r
64 public selectedRows;
\r
65 public hasSelectedRows;
\r
66 public selectedSingleRow;
\r
68 private gridColumnApi;
\r
69 public selectedUnlockedRows;
\r
72 public gridOptions: GridOptions;
\r
77 private subscriptions: Subscription[] = [];
\r
79 @ViewChild(MatPaginator) paginator: MatPaginator;
\r
83 private router: Router,
\r
84 private viewRef: ViewContainerRef,
\r
85 private testInstance: TestInstanceService,
\r
86 private modal: MatDialog,
\r
87 private schedulingService: SchedulingService,
\r
88 private snack: MatSnackBar,
\r
89 private route: ActivatedRoute,
\r
90 private testDefinitionService: TestDefinitionService,
\r
91 private _execute: ExecuteService,
\r
92 private _groups: GroupService
\r
97 this.setComponentData(this._groups.getGroup());
\r
99 this.subscriptions.push(this._groups.groupChange().subscribe(group => {
\r
100 this.setComponentData(group);
\r
104 // this.subscriptions.push(this._groups.groupChange().subscribe( group => {
\r
105 // if(!group["_id"]){
\r
106 // this.setComponentData(this._groups.getGroup());
\r
108 // this.setComponentData(group);
\r
112 this.route.queryParams.subscribe( params => {
\r
114 this.params = params;
\r
122 setComponentData(group) {
\r
127 this.loading = true;
\r
129 groupId: group['_id'],
\r
131 $populate: ['testDefinitionId'],
\r
135 $select: ['testInstanceName', 'testInstanceDescription', 'testDefinitionId.testName', 'disabled']
\r
138 if (this.route.snapshot.params['filter']) {
\r
139 params['_id'] = this.route.snapshot.params['filter'];
\r
142 this.testInstance.find(params).subscribe((list) => {
\r
143 this.resultsLength = list['length'];
\r
144 this.loading = false;
\r
145 this.rowData = list;
\r
153 ngAfterViewInit() {
\r
158 this.subscriptions.forEach(e => e.unsubscribe());
\r
163 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testInstanceName, testDefinitionId}) => ({_id, testInstanceName, testDefinitionId}));
\r
164 console.log("The new element is: "+JSON.stringify(this.selectedRows[0]._id));
\r
166 console.log("Here is the selected Row: "+JSON.stringify(this.gridApi.getSelectedRows()[0]));
\r
167 const dialogRef = this.modal.open(ScheduleTestModalComponent, {
\r
170 id: this.selectedRows[0]._id
\r
174 dialogRef.afterClosed().subscribe(result => {
\r
175 /*if(result != ''){
\r
176 this.test_instance_selected = result;
\r
177 this.strategy_selected = true;
\r
179 this.strategy_selected = false;
\r
184 executeMultipleTestInstance(){
\r
185 for(let i = 0; i < this.gridApi.getSelectedNodes().length; i++){
\r
186 this.executeTestInstance(i);
\r
190 executeTestInstance(ti) {
\r
192 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testInstanceName, testDefinitionId}) => ({_id, testInstanceName, testDefinitionId}));
\r
195 if (this.selectedRows[ti].testDefinitionId) {
\r
196 const executer = this.modal.open(AlertModalComponent, {
\r
199 type: 'confirmation',
\r
200 message: 'Are you sure you want to run ' + this.selectedRows[ti].testInstanceName + '?'
\r
204 executer.afterClosed().subscribe(result => {
\r
206 this._execute.create({
\r
207 _id: this.selectedRows[ti]._id,
\r
209 }).subscribe((result) => {
\r
210 console.log(result);
\r
212 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
215 message: 'Test Instance Executed'
\r
221 console.log(error);
\r
222 this.modal.open(AlertModalComponent, {
\r
226 message: 'Failed to execute Test Instance!\n' + JSON.stringify(error)
\r
236 createTestInstance() {
\r
237 const create = this.modal.open(TestInstanceModalComponent, {
\r
243 create.afterClosed().subscribe(result => {
\r
249 editTestInstance() {
\r
250 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testInstanceName}) => ({_id, testInstanceName}));
\r
252 const edit = this.modal.open(TestInstanceModalComponent, {
\r
254 ti: this.selectedRows[0]._id,
\r
261 edit.afterClosed().subscribe(result => {
\r
266 cloneTestInstance() {
\r
267 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testInstanceName}) => ({_id, testInstanceName}));
\r
268 this.testInstance.get(this.selectedRows[0]._id).subscribe(
\r
270 var temp = Object.assign({}, result);
\r
271 delete result['_id'];
\r
272 delete result['createdAt'];
\r
273 delete result['updatedAt'];
\r
274 if (this.selectedRows[0].testInstanceName) {
\r
275 result['testInstanceName'] = this.selectedRows[0].testInstanceName + '_Clone';
\r
277 result['testInstanceName'] = result['testInstanceName'] + '_Clone';
\r
279 this.testInstance.create(result).subscribe(
\r
281 //this.editTestInstance(resp);
\r
282 this.editTestInstance();
\r
287 result['_id'] = temp['_id'];
\r
289 //this.cloneTestInstance(result);
\r
297 deleteMultipleTestInstance(){
\r
298 for(let i = 0; i < this.gridApi.getSelectedNodes().length; i++){
\r
299 this.deleteTestInstance(i);
\r
303 deleteTestInstance(ti) {
\r
304 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testInstanceName}) => ({_id, testInstanceName}));
\r
307 const deleter = this.modal.open(AlertModalComponent, {
\r
310 type: 'confirmation',
\r
311 message: 'Are you sure you want to delete ' + this.selectedRows[ti].testInstanceName + ' ? Executions of this instance will no longer display everything.'
\r
315 deleter.afterClosed().subscribe(result => {
\r
317 this.testInstance.delete(this.selectedRows[ti]._id).subscribe(response => {
\r
318 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
321 message: 'Test Instance Deleted'
\r
326 this.setComponentData(this._groups.getGroup());
\r
333 disabledIndicator(params){
\r
335 return `<mat-icon class="mat-icon mat-icon-no-color" role="img" >
\r
336 locked</mat-icon>`;
\r
342 setParams(element) {
\r
344 if (JSON.stringify(element) == JSON.stringify({testInstanceId: this.params.testInstanceId})){
\r
349 this.router.navigate([], {
\r
350 //queryParams: {testInstanceId: element.testInstanceId, page: this.paginator.pageIndex, instancePerPage: this.paginator.pageSize }
\r
351 queryParams: {testInstanceId: element._id}
\r
356 onGridReady(params){
\r
357 this.gridApi = params.api;
\r
358 console.log(params.columnApi.autoSizeColumns)
\r
359 this.gridColumnApi = params.columnApi;
\r
361 //auto size the column widths
\r
362 this.gridColumnApi.autoSizeColumns(['name']);
\r
366 selectActiveInstance($event){
\r
367 if(this.params.testInstanceId)
\r
369 this.gridApi.forEachNode( (node, index) => {
\r
371 if(node.data._id ==this.params.testInstanceId)
\r
373 // Pre selects the row that was last selected when on the page
\r
374 node.setSelected(true, true);
\r
375 //Vertically scrolls to that row so it is visible
\r
376 this.gridApi.ensureIndexVisible(index, "middle");
\r
386 onRowSelected(event){
\r
388 this.selectedRows = this.gridApi.getSelectedRows().map(({ _id, disabled, testInstanceName }) => ({ _id, disabled, testInstanceName}));
\r
392 if(event.api.getSelectedNodes().length > 0){
\r
393 this.hasSelectedRows = true;
\r
395 //Checks for all Unlocked rows
\r
396 for (let i = 0; i < event.api.getSelectedNodes().length; i++ )
\r
398 if(!this.selectedRows[i].disabled)
\r
400 this.selectedUnlockedRows = true;
\r
403 this.selectedUnlockedRows = false;
\r
409 this.hasSelectedRows = false;
\r
410 this.selectedUnlockedRows = false;
\r
412 this.setParams({_id: null});
\r
416 //One Row was selected
\r
417 if((event.api.getSelectedNodes().length == 1)){
\r
418 this.selectedSingleRow = true;
\r
420 this.setParams({_id: this.selectedRows[0]._id});
\r
423 this.selectedSingleRow = false;
\r
424 this.setParams({_id: null});
\r