added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / shared / modules / test-instance-modal / test-instance-modal.component.ts
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\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
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\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
15 \r
16 \r
17 import { Component, OnInit, Inject, Output, Input } from '@angular/core';\r
18 import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';\r
19 import { AppGlobals } from 'app/app.global';\r
20 import { HttpClient } from '@angular/common/http';\r
21 import { TestInstanceService } from '../../services/test-instance.service';\r
22 import { TestDefinitionService } from '../../services/test-definition.service';\r
23 \r
24 @Component({\r
25   selector: 'app-test-instance-modal',\r
26   templateUrl: './test-instance-modal.component.pug',\r
27   styleUrls: ['./test-instance-modal.component.scss']\r
28 })\r
29 export class TestInstanceModalComponent implements OnInit {\r
30 \r
31   @Output() editInstance;\r
32   public findInstance = true;\r
33   @Input() childEvent;\r
34 \r
35 \r
36   constructor(\r
37       public dialogRef: MatDialogRef<TestInstanceModalComponent>,\r
38       private http: HttpClient,\r
39       private testDefintionService: TestDefinitionService,\r
40       private testInstanceService: TestInstanceService,\r
41     @Inject(MAT_DIALOG_DATA) public inputInstanceId) { }\r
42 \r
43   ngOnInit() {\r
44     if(!this.inputInstanceId){\r
45       this.findInstance = false;\r
46     }\r
47     //if the user is creating an Instance from a test definition page. Pull all data and populate testHeads\r
48     else if(this.inputInstanceId["td"]){\r
49       this.testDefintionService.get(this.inputInstanceId.td,{$populate: ['bpmnInstances.testHeads.testHeadId']}).subscribe((result) => {\r
50         this.editInstance = {\r
51           \r
52           testDefinition: result,\r
53           isEdit: false\r
54         };\r
55         \r
56         this.findInstance = false;\r
57       });\r
58 \r
59     }\r
60     else if (this.inputInstanceId["ti"]) {\r
61       this.testInstanceService.get(this.inputInstanceId.ti, {$populate: ['testDefinitionId']}).subscribe((result) => {\r
62         \r
63         this.editInstance = {};\r
64         this.editInstance.testInstance = result;\r
65         if(this.inputInstanceId.isEdit){\r
66           this.editInstance.isEdit = true;\r
67         }else{\r
68           this.editInstance.isEdit = false;\r
69         }\r
70         this.findInstance = false;\r
71       });\r
72     }else{\r
73       this.findInstance = false\r
74     }\r
75   }\r
76 \r
77   close() {\r
78     this.dialogRef.close();\r
79   }\r
80 }