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, Output, Input, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core';
\r
18 import { HttpClient } from '@angular/common/http';
\r
19 import { AppGlobals } from '../../app.global';
\r
20 import { routerTransition } from '../../router.animations';
\r
21 import { ListService } from '../../shared/services/list.service';
\r
22 import { Router } from '@angular/router';
\r
23 import { MatTableDataSource, MatPaginator, MatSort, MatDialog, MatSnackBar } from '@angular/material';
\r
24 import { TestHeadService } from '../../shared/services/test-head.service';
\r
25 import { TestHeadModalComponent } from '../../shared/modules/test-head-modal/test-head-modal.component';
\r
26 import { AlertModalComponent } from '../../shared/modules/alert-modal/alert-modal.component';
\r
27 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';
\r
28 import { GroupService } from 'app/shared/services/group.service';
\r
29 import { Subscription } from 'rxjs';
\r
32 selector: 'app-virtual-test-heads',
\r
33 templateUrl: './virtual-test-heads.component.pug',
\r
34 providers: [AppGlobals],
\r
35 styleUrls: ['./virtual-test-heads.component.scss'],
\r
36 animations: [routerTransition()]
\r
38 export class VirtualTestHeadsComponent implements OnInit, OnDestroy {
\r
40 private toDestroy: Array<Subscription> = [];
\r
42 public displayedColumns: string[] = ['name', 'description', 'options'];
\r
43 public resultsLength;
\r
44 public loading = false;
\r
46 @ViewChild(MatPaginator) paginator: MatPaginator;
\r
48 constructor(private testHead: TestHeadService,
\r
49 private router: Router,
\r
50 private modal: MatDialog,
\r
51 private snack: MatSnackBar,
\r
52 private _groups: GroupService) { }
\r
54 applyFilter(filterValue: string) {
\r
55 this.dataSource.filter = filterValue.trim().toLowerCase();
\r
60 this.setComponentData(this._groups.getGroup());
\r
61 this.toDestroy.push(this._groups.groupChange().subscribe(group => {
\r
62 this.setComponentData(group);
\r
67 this.toDestroy.forEach(e => e.unsubscribe());
\r
70 setComponentData(group) {
\r
73 this.dataSource = new MatTableDataSource();
\r
74 this.dataSource.paginator = this.paginator;
\r
76 this.testHead.find({ $limit: -1, groupId: group['_id'], $sort: { createdAt: -1 } }).subscribe((list) => {
\r
77 this.dataSource.data = list;
\r
78 this.resultsLength = this.dataSource.data.length;
\r
79 this.loading = false;
\r
85 const create = this.modal.open(TestHeadModalComponent, {
\r
92 create.afterClosed().subscribe(result => {
\r
94 // this.list.listMap['vth'].currentList.subscribe(x => {
\r
95 // this.dataSource.data = x;
\r
96 // this.resultsLength = this.dataSource.data.length;
\r
103 const edit = this.modal.open(TestHeadModalComponent, {
\r
111 edit.afterClosed().subscribe(result => {
\r
116 deleteTestHead(th) {
\r
117 const deleter = this.modal.open(AlertModalComponent, {
\r
120 type: 'confirmation',
\r
121 message: 'Are you sure you want to delete ' + th.testHeadName + '? There may be test definitions using this test head.'
\r
125 deleter.afterClosed().subscribe(result => {
\r
127 this.testHead.delete(th._id).subscribe(response => {
\r
128 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
131 message: 'Test Head Deleted'
\r
142 this.router.navigate(['/test-heads', id]);
\r