added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / tests / test-definition-details / test-definition-details.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, OnDestroy } from '@angular/core';\r
18 import { ActivatedRoute } from '@angular/router';\r
19 import { Subscription } from 'rxjs';\r
20 import { TestDefinitionService } from 'app/shared/services/test-definition.service';\r
21 import { TestDefinition } from 'app/shared/models/test-definition.model';\r
22 import { StatsService } from 'app/layout/components/stats/stats.service';\r
23 \r
24 @Component({\r
25   selector: 'app-test-definition-details',\r
26   templateUrl: './test-definition-details.component.pug',\r
27   styleUrls: ['./test-definition-details.component.scss']\r
28 })\r
29 export class TestDefinitionDetailsComponent implements OnInit, OnDestroy {\r
30 \r
31   private toDestroy: Array<Subscription> = [];\r
32 \r
33   public testDefinition: TestDefinition;\r
34   \r
35   constructor(\r
36     private route: ActivatedRoute, \r
37     private _testDefinition: TestDefinitionService,\r
38     public stats: StatsService\r
39   ) { }\r
40 \r
41   ngOnInit() {\r
42     this.toDestroy.push(this.route.params.subscribe(params => {\r
43       \r
44       if(params.id){\r
45         this._testDefinition.get(params.id).subscribe(\r
46           res => {\r
47             \r
48             this.testDefinition = res as TestDefinition;\r
49           },\r
50           err => {\r
51             \r
52           })\r
53 \r
54         this.getData(params.id);\r
55       }\r
56     }));\r
57   }\r
58 \r
59   get numOfVersions(){\r
60     if(this.testDefinition['bpmnInstances']){\r
61       return this.testDefinition['bpmnInstances'].length;\r
62     }\r
63     return 0;\r
64   }\r
65 \r
66   ngOnDestroy() {\r
67     this.toDestroy.forEach(elem => elem.unsubscribe());\r
68   }\r
69 \r
70   getData(testDefinitionId?){\r
71     if(!testDefinitionId){\r
72       testDefinitionId = this.testDefinition._id\r
73     }\r
74 \r
75     if(!testDefinitionId){\r
76       return;\r
77     }\r
78 \r
79     this.stats.getDefaultData(1, {\r
80       'historicTestDefinition._id': testDefinitionId,\r
81       $select: [\r
82         'startTime',\r
83         'endTime',\r
84         "historicTestDefinition._id",\r
85         "historicTestDefinition.testName",\r
86         "historicTestInstance._id",\r
87         "historicTestInstance.testInstanceName",\r
88         "testHeadResults.startTime",\r
89         "testHeadResults.endTime",\r
90         "testHeadResults.testHeadName",\r
91         "testHeadResults.testHeadId",\r
92         "testHeadResults.testHeadGroupId",\r
93         "testHeadResults.statusCode",\r
94         'testResult'\r
95       ],\r
96       $limit: -1,\r
97       $sort: {\r
98         startTime: 1\r
99       },\r
100       startTime: {\r
101         $gte: this.stats.filters.startDate,\r
102         $lte: this.stats.filters.endDate\r
103       }\r
104     });\r
105   }\r
106 \r
107 }\r