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, Input, Output, EventEmitter, ViewChild } from '@angular/core';
\r
18 import { HttpClient } from '@angular/common/http';
\r
19 import { ListService } from '../../services/list.service';
\r
20 import { TestHeadService } from '../../services/test-head.service';
\r
21 import { GroupService } from '../../services/group.service';
\r
22 import 'codemirror/mode/yaml/yaml.js';
\r
23 import { MatSnackBar, MatDialog, MatDialogRef } from '@angular/material';
\r
24 import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';
\r
25 import { AlertModalComponent } from '../alert-modal/alert-modal.component';
\r
29 selector: 'app-create-test-head-form',
\r
30 templateUrl: './create-test-head-form.component.pug',
\r
31 styleUrls: ['./create-test-head-form.component.scss']
\r
33 export class CreateTestHeadFormComponent implements OnInit {
\r
36 private hasPrevCredential;
\r
38 public codeConfig = {
\r
44 @Input() public formData;
\r
45 @Input() public options;
\r
47 @Output() public childEvent = new EventEmitter();
\r
49 //Virtual Test Head Type Options
\r
57 //Implementation Language Options
\r
67 @ViewChild('testHeadForm') form: any;
\r
69 constructor(public dialogRef: MatDialogRef<CreateTestHeadFormComponent>, private http: HttpClient, private list: ListService, private dialog: MatDialog, private snack: MatSnackBar, private testHead: TestHeadService, private group: GroupService) { }
\r
74 this.vth = Object.assign({}, this.formData);
\r
75 if(!this.vth.authorizationCredential){
\r
76 this.vth.authorizationCredential = "";
\r
77 this.hasPrevCredential = false;
\r
80 this.hasPrevCredential = true
\r
86 this.form.control.markAsDirty();
\r
91 this.testHead.create(this.vth)
\r
92 .subscribe((vth) => {
\r
93 //this.list.addElement('vth', vth);
\r
94 this.clear(this.form);
\r
95 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
98 message:'Test Head Created'
\r
101 this.dialogRef.close();
\r
102 //this.dialog.closeAll();
\r
104 this.dialog.open(AlertModalComponent, {
\r
107 message: JSON.stringify(err)
\r
115 saveFileContents(){
\r
116 this.getFileContents(val => {
\r
117 this.vth.vthInputTemplate = val;
\r
121 getFileContents(callback) {
\r
123 var fileToLoad = (document.getElementById('file'))['files'][0];
\r
124 var fileReader = new FileReader();
\r
128 fileReader.onload = function (event) {
\r
130 val = event.target['result'];
\r
135 fileReader.readAsText(fileToLoad);
\r
139 if(!this.hasPrevCredential && this.vth.authorizationCredential == ""){
\r
140 delete this.vth.authorizationCredential;
\r
142 this.testHead.patch(this.vth)
\r
143 .subscribe((vth) => {
\r
144 // this.list.updateElement('vth', '_id', vth['_id'], vth);
\r
145 this.childEvent.emit();
\r
146 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
149 message:'Test Head Updated'
\r
152 this.dialogRef.close();
\r
161 this.childEvent.emit();
\r
166 this.vth.vthInputTemplate = '';
\r
168 //this.vth.vthOutputTemplate = '';
\r