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, ViewContainerRef, ViewChild, AfterContentInit, OnDestroy } from '@angular/core';
\r
18 import { HttpClient } from '@angular/common/http';
\r
19 import { routerTransition } from '../../router.animations';
\r
20 import { ListService } from '../../shared/services/list.service';
\r
21 import { Router } from '@angular/router';
\r
22 import { TestDefinitionService } from '../../shared/services/test-definition.service';
\r
23 import { TestInstanceService } from '../../shared/services/test-instance.service';
\r
24 import { MatTableDataSource } from '@angular/material/table';
\r
25 import { MatPaginator, MatDialog, MatSnackBar } from '@angular/material';
\r
26 import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';
\r
27 import { CreateTestComponent } from '../onboarding/create-test/create-test.component';
\r
28 import { TestDefinitionModalComponent } from 'app/shared/modules/test-definition-modal/test-definition-modal.component';
\r
29 import { ViewWorkflowModalComponent } from 'app/shared/modules/view-workflow-modal/view-workflow-modal.component';
\r
30 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';
\r
31 import { TestInstanceModalComponent } from '../../shared/modules/test-instance-modal/test-instance-modal.component';
\r
32 import { UserService } from 'app/shared/services/user.service';
\r
33 import { CookieService } from "ngx-cookie-service";
\r
34 import { GroupService } from 'app/shared/services/group.service';
\r
35 import { appInitializerFactory } from '@angular/platform-browser/src/browser/server-transition';
\r
36 import { element } from '@angular/core/src/render3/instructions';
\r
37 import { GridOptionsWrapper, RowNode, initialiseAgGridWithAngular1 } from 'ag-grid-community';
\r
38 import { every } from 'rxjs/operators';
\r
39 import { Subscription } from 'rxjs';
\r
42 selector: 'app-tests',
\r
43 templateUrl: './tests.component.pug',
\r
44 styleUrls: ['./tests.component.scss'],
\r
45 animations: [routerTransition()]
\r
47 export class TestsComponent implements OnInit, OnDestroy {
\r
49 private toDestroy: Array<Subscription> = [];
\r
52 public displayedColumns: string[] = ['lock', 'name', 'description', 'id', 'processDefinitionKey', 'options'];
\r
53 public resultsLength;
\r
54 public loading = false;
\r
59 {headerName: 'Name', field: 'testName', sortable: true, filter: true, resizable: true, checkboxSelection:true, headerCheckboxSelection: true, headerCheckboxSelectionFilteredOnly: true, width: 300},
\r
60 {headerName: 'Description', field: 'testDescription', sortable: true, filter: true, resizable: true},
\r
61 {headerName: 'Id', field: '_id', sortable: true, filter: true, resizable: true, editable: true},
\r
62 {headerName: 'Process Definition key', field: 'processDefinitionKey', sortable: true, filter: true, resizable: true},
\r
63 {headerName: '', field: 'disabled', cellRenderer: this.disabledIndicator, hide: false, width: 80}
\r
70 { _id: '5cfe7e5d6f4e5d0040a3b235', testDescription: 'For testing', testName: "testflow", processDefinitionKey: "demo"},
\r
71 { make: 'Ford', model: 'Mondeo', price: 32000 },
\r
72 { make: 'Porsche', model: 'Boxter', price: 72000 }
\r
75 public hasSelectedRows = false;
\r
76 public selectedSingleRow = false;
\r
77 public selectedUnlockedRows = true;
\r
78 public selectedLockedRows = false;
\r
81 private gridColumnApi;
\r
82 private selectedRows = {};
\r
84 @ViewChild(MatPaginator) paginator: MatPaginator;
\r
86 constructor(private http: HttpClient,
\r
87 private router: Router,
\r
88 private viewRef: ViewContainerRef,
\r
89 private testDefinition: TestDefinitionService,
\r
90 private modal: MatDialog,
\r
91 private snack: MatSnackBar,
\r
92 private user: UserService,
\r
93 private testInstanceService: TestInstanceService,
\r
94 private cookie: CookieService,
\r
95 private _groups: GroupService
\r
100 this.setComponentData(this._groups.getGroup());
\r
101 this.toDestroy.push(this._groups.groupChange().subscribe(group => {
\r
102 this.setComponentData(group);
\r
109 this.toDestroy.forEach(elem => elem.unsubscribe());
\r
112 setComponentData(group) {
\r
118 this.loading = true;
\r
120 this.dataSource = new MatTableDataSource();
\r
121 this.dataSource.paginator = this.paginator;
\r
125 this.testDefinition.find({
\r
127 groupId: group['_id'],
\r
131 $select: ['testName', 'testDescription', 'processDefinitionKey', 'bpmnInstances.isDeployed', 'disabled', 'groupId']
\r
132 }).subscribe((list) => {
\r
133 this.dataSource.data = list;
\r
134 this.resultsLength = this.dataSource.data.length;
\r
135 this.loading = false;
\r
136 // Getting row data filled with list
\r
137 this.rowData = list;
\r
141 //console.log("This is the rowdata: "+ JSON.stringify(this.rowData[1]))
\r
142 //this.rowData = [].concat.apply([], list);
\r
148 applyFilter(filterValue: string) {
\r
149 this.dataSource.filter = filterValue.trim().toLowerCase();
\r
151 //createInstance(element)
\r
155 this.selectedRows = this.gridApi.getSelectedRows().map(({ _id, testName }) => ({_id, testName}));
\r
157 const create = this.modal.open(TestInstanceModalComponent, {
\r
160 td: this.selectedRows[0]._id//element._id
\r
167 let create = this.modal.open(TestDefinitionModalComponent, {
\r
171 create.afterClosed().subscribe(res => {
\r
178 // this.modal.open(ViewWorkflowModalComponent, {
\r
181 // maxWidth: '100%',
\r
193 for(let i = 0; i < this.gridApi.getSelectedNodes().length; i++){
\r
200 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testName }) => ({_id, testName}));
\r
201 const deleter = this.modal.open(AlertModalComponent, {
\r
204 type: 'confirmation',
\r
205 message: 'Are you sure you want to delete ' + this.selectedRows[td].testName + '? Any test instances or executions using this test definition will no longer work.'
\r
209 deleter.afterClosed().subscribe(result => {
\r
211 this.testDefinition.delete(this.selectedRows[td]._id).subscribe(response => {
\r
212 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
215 message: 'Test definition was deleted'
\r
219 this.setComponentData(this._groups.getGroup());
\r
226 this.selectedRows = this.gridApi.getSelectedRows().map(({_id }) => ({_id}));
\r
227 var editor = this.modal.open(TestDefinitionModalComponent, {
\r
228 disableClose: true,
\r
230 testDefinitionId: this.selectedRows[0]._id
\r
237 for(let i = 0; i < this.gridApi.getSelectedNodes().length; i++){
\r
245 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testName, groupId, }) => ({_id, testName, groupId}));
\r
247 let user = JSON.parse(this.cookie.get('currentUser'));
\r
248 let isAdmin = false;
\r
249 for (let i = 0; i < user.groups.length; i++) {
\r
250 if (this.selectedRows[td].groupId === user.groups[i].groupId) {
\r
251 if (user.groups[i].permissions.includes("admin")) {
\r
258 this.modal.open(AlertModalComponent, {
\r
262 message: 'You do not have the correct permissions to lock/unlock test definitions.'
\r
267 this.modal.open(AlertModalComponent, {
\r
270 type: 'confirmation',
\r
271 message: 'Are you sure you want to lock ' + this.selectedRows[td].testName + '? All test instances using this test definition will be locked and no more instances can be created until unlocked.'
\r
273 }).afterClosed().subscribe((result) => {
\r
276 '_id': this.selectedRows[td]._id,
\r
279 this.testDefinition.patch(testDef).subscribe((res) => {
\r
280 this.selectedRows[td].disabled = true;
\r
281 this.testInstanceService.find({ $limit: -1, testDefinitionId: this.selectedRows[td]._id }).subscribe((result) => {
\r
285 if (result['length']) {
\r
286 for (let i = 0; i < result['length']; i++) {
\r
291 ti._id = result[i]._id;
\r
292 ti.disabled = true;
\r
295 this.testInstanceService.patch(ti).subscribe((results) => {
\r
297 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
300 message: 'Test Instance ' + results['testInstanceName'] + ' was locked'
\r
310 ti._id = result['_id'];
\r
311 this.testInstanceService.patch(ti).subscribe((results) => {
\r
312 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
315 message: 'Test Instance ' + results['testInstanceName'] + ' was locked'
\r
321 this.setComponentData(this._groups.getGroup());
\r
323 this.modal.open(AlertModalComponent, {
\r
327 message: 'Test Definition could not be locked.'
\r
339 this.setComponentData(this._groups.getGroup());
\r
343 for(let i = 0; i < this.gridApi.getSelectedNodes().length; i++){
\r
347 //unlock multiple and loop through single unlock
\r
349 this.selectedRows = this.gridApi.getSelectedRows().map(({_id, testName, groupId, }) => ({_id, testName, groupId}));
\r
350 let user = JSON.parse(this.cookie.get('currentUser'));
\r
351 let isAdmin = false;
\r
352 for (let i = 0; i < user.groups.length; i++) {
\r
353 if (this.selectedRows[td].groupId === user.groups[i].groupId) {
\r
354 if (user.groups[i].permissions.includes("admin")) {
\r
361 this.modal.open(AlertModalComponent, {
\r
365 message: 'You do not have the correct permissions to lock/unlock test definitions.'
\r
371 this.modal.open(AlertModalComponent, {
\r
374 type: 'confirmation',
\r
375 message: 'Are you sure you want to unlock ' + td.testName + '? All test instances using this test definition will be unlocked as well.'
\r
377 }).afterClosed().subscribe((result) => {
\r
380 '_id': this.selectedRows[td]._id,
\r
383 this.testDefinition.patch(testDef).subscribe((res) => {
\r
384 this.selectedRows[td].disabled = false;
\r
385 this.testInstanceService.find({ $limit: -1, testDefinitionId: this.selectedRows[td]._id }).subscribe((result) => {
\r
387 // console.log(result);
\r
388 if (result['length']) {
\r
389 for (let i = 0; i < result['length']; i++) {
\r
394 ti._id = result[i]._id;
\r
395 ti.disabled = false;
\r
396 this.testInstanceService.patch(ti).subscribe((results) => {
\r
397 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
400 message: 'Test Instance ' + results['testInstanceName'] + ' was unlocked'
\r
410 ti._id = result['_id'];
\r
412 this.testInstanceService.patch(ti).subscribe((results) => {
\r
413 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
416 message: 'Test Instance ' + results['testInstanceName'] + ' was unlocked'
\r
422 this.setComponentData(this._groups.getGroup());
\r
424 this.modal.open(AlertModalComponent, {
\r
428 message: 'Test Definition could not be locked.'
\r
438 isDeployed(element) {
\r
439 let deployed = false;
\r
440 if (element.bpmnInstances) {
\r
441 element.bpmnInstances.forEach(elem => {
\r
442 if (elem.isDeployed) {
\r
452 onRowSelected(event){
\r
454 this.selectedRows = this.gridApi.getSelectedRows().map(({ _id, disabled }) => ({ _id, disabled}));
\r
456 if(event.api.getSelectedNodes().length > 0){
\r
457 this.hasSelectedRows = true;
\r
459 //Checks for all Unlocked rows
\r
460 for (let i = 0; i < event.api.getSelectedNodes().length; i++ )
\r
463 if(!this.selectedRows[i].disabled)
\r
465 this.selectedUnlockedRows = true;
\r
468 this.selectedUnlockedRows = false;
\r
473 //Checks for all Locked rows
\r
474 for (let i = 0; i < event.api.getSelectedNodes().length; i++ )
\r
477 if(this.selectedRows[i].disabled)
\r
479 this.selectedLockedRows = true;
\r
482 this.selectedLockedRows = false;
\r
493 this.hasSelectedRows = false;
\r
494 this.selectedLockedRows = false;
\r
495 this.selectedUnlockedRows = true;
\r
498 //One Row was selected
\r
499 if((event.api.getSelectedNodes().length == 1)){
\r
500 this.selectedSingleRow = true;
\r
503 this.selectedSingleRow = false;
\r
508 onGridReady(params){
\r
509 this.gridApi = params.api;
\r
511 this.gridColumnApi = params.columnApi;
\r
513 //auto size the column widths
\r
514 this.gridColumnApi.autoSizeColumns(['name']);
\r
517 disabledIndicator(params){
\r
519 return `<mat-icon class="mat-icon mat-icon-no-color" role="img" >
\r
520 locked</mat-icon>`;
\r
527 navToDefinition(event){
\r
528 this.router.navigate(['/test-definitions', event.data._id]);
\r
531 testDefinitionModeler(){
\r
532 this.router.navigate(['/modeler'], {queryParams: {testDefinitionId: this.selectedRows[0]._id}});
\r