--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';\r
+import { HttpClient } from '@angular/common/http';\r
+import { ListService } from '../../services/list.service';\r
+import { TestHeadService } from '../../services/test-head.service';\r
+import { GroupService } from '../../services/group.service';\r
+import 'codemirror/mode/yaml/yaml.js';\r
+import { MatSnackBar, MatDialog, MatDialogRef } from '@angular/material';\r
+import { AlertSnackbarComponent } from '../alert-snackbar/alert-snackbar.component';\r
+import { AlertModalComponent } from '../alert-modal/alert-modal.component';\r
+\r
+\r
+@Component({\r
+ selector: 'app-create-test-head-form',\r
+ templateUrl: './create-test-head-form.component.pug',\r
+ styleUrls: ['./create-test-head-form.component.scss']\r
+})\r
+export class CreateTestHeadFormComponent implements OnInit {\r
+ yaml;\r
+\r
+ private hasPrevCredential;\r
+\r
+ public codeConfig = {\r
+ mode: "yaml",\r
+ theme: "eclipse",\r
+ lineNumbers: true\r
+ };\r
+\r
+ @Input() public formData;\r
+ @Input() public options;\r
+\r
+ @Output() public childEvent = new EventEmitter();\r
+\r
+ //Virtual Test Head Type Options\r
+ types = [\r
+ 'Proxy',\r
+ 'Regular',\r
+ 'Script',\r
+ 'Adapter'\r
+ ]\r
+\r
+ //Implementation Language Options\r
+ langs = [\r
+ 'Java',\r
+ 'Python',\r
+ 'JavaScript/NodeJS'\r
+ ]\r
+\r
+ public vth;\r
+ public groups;\r
+\r
+ @ViewChild('testHeadForm') form: any;\r
+\r
+ constructor(public dialogRef: MatDialogRef<CreateTestHeadFormComponent>, private http: HttpClient, private list: ListService, private dialog: MatDialog, private snack: MatSnackBar, private testHead: TestHeadService, private group: GroupService) { }\r
+\r
+ ngOnInit() {\r
+ this.setNew();\r
+ if(this.formData){\r
+ this.vth = Object.assign({}, this.formData);\r
+ if(!this.vth.authorizationCredential){\r
+ this.vth.authorizationCredential = "";\r
+ this.hasPrevCredential = false;\r
+ }\r
+ else{\r
+ this.hasPrevCredential = true\r
+ }\r
+ }\r
+ }\r
+\r
+ markAsDirty(){\r
+ this.form.control.markAsDirty();\r
+ }\r
+\r
+ create(){\r
+\r
+ this.testHead.create(this.vth)\r
+ .subscribe((vth) => {\r
+ //this.list.addElement('vth', vth);\r
+ this.clear(this.form);\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message:'Test Head Created'\r
+ }\r
+ });\r
+ this.dialogRef.close();\r
+ //this.dialog.closeAll();\r
+ }, err => {\r
+ this.dialog.open(AlertModalComponent, {\r
+ data: {\r
+ type: 'alert',\r
+ message: JSON.stringify(err)\r
+ },\r
+ width: '450px'\r
+ })\r
+ });\r
+\r
+ }\r
+ //grab file\r
+ saveFileContents(){\r
+ this.getFileContents(val => {\r
+ this.vth.vthInputTemplate = val;\r
+ });\r
+ }\r
+\r
+ getFileContents(callback) {\r
+ var val = "x";\r
+ var fileToLoad = (document.getElementById('file'))['files'][0];\r
+ var fileReader = new FileReader();\r
+ if (!fileToLoad) {\r
+ return null;\r
+ }\r
+ fileReader.onload = function (event) {\r
+ //\r
+ val = event.target['result'];\r
+\r
+ //\r
+ callback(val);\r
+ }\r
+ fileReader.readAsText(fileToLoad);\r
+ }\r
+\r
+ update(){\r
+ if(!this.hasPrevCredential && this.vth.authorizationCredential == ""){\r
+ delete this.vth.authorizationCredential;\r
+ }\r
+ this.testHead.patch(this.vth)\r
+ .subscribe((vth) => {\r
+ // this.list.updateElement('vth', '_id', vth['_id'], vth);\r
+ this.childEvent.emit();\r
+ this.snack.openFromComponent(AlertSnackbarComponent, {\r
+ duration: 1500,\r
+ data: {\r
+ message:'Test Head Updated'\r
+ }\r
+ });\r
+ this.dialogRef.close();\r
+ });\r
+ }\r
+\r
+ clear(form){\r
+ this.setNew();\r
+ if(form){\r
+ form.reset();\r
+ }\r
+ this.childEvent.emit();\r
+ }\r
+\r
+ setNew(){\r
+ this.vth = {};\r
+ this.vth.vthInputTemplate = '';\r
+\r
+ //this.vth.vthOutputTemplate = '';\r
+ }\r
+}\r