Merge "UI adaptation for supporting ONAP portal SDK"
[validation.git] / ui / src / main / webapp / app / AECBlueprintValidationUI / GetBySubmissionId / AECGetBySubmissionIdController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var app = angular.module('AECGetBySubmissionId');
18 app
19         .controller(
20                 'AECGetBySubmissionIdController',
21                 function($scope, restAPISvc) {
22
23                     initialize();
24
25                     function initialize() {
26                         $scope.results = [];
27                         $scope.resultsLayers = [];
28                         $scope.resultsLayerTestSuitesNames = [];
29                         $scope.selectedRobotTestResult = [];
30                         restAPISvc
31                                 .getRestAPI(
32                                         "/api/submission/",
33                                         function(data) {
34                                             $scope.submissions = data;
35                                             $scope.submissionsForDisplay = [];
36                                             angular
37                                                     .forEach(
38                                                             $scope.submissions,
39                                                             function(
40                                                                     submissionData) {
41                                                                 var temp = "id: "
42                                                                         + submissionData.submissionId
43                                                                         + " blueprint: "
44                                                                         + submissionData.blueprintInstanceForValidation.blueprint.blueprintName
45                                                                         + " version: "
46                                                                         + submissionData.blueprintInstanceForValidation.version
47                                                                         + " layer: "
48                                                                         + submissionData.blueprintInstanceForValidation.layer
49                                                                         + " lab: "
50                                                                         + submissionData.timeslot.lab.lab
51                                                                         + " Start date and time: "
52                                                                         + submissionData.timeslot.startDateTime
53                                                                 /*
54                                                                  * + " duration: " +
55                                                                  * submissionData.blueprintInstanceForValidation.timeslot.duration
56                                                                  */;
57                                                                 $scope.submissionsForDisplay
58                                                                         .push(temp);
59                                                             });
60                                         });
61                     }
62                     $scope.selectedSubmissionChange = function(
63                             selectedSubmission) {
64                         $scope.results = [];
65                         $scope.resultsLayers = [];
66                         $scope.resultsLayerTestSuitesNames = [];
67                         $scope.selectedRobotTestResult = [];
68                         var id = selectedSubmission.substring(
69                                 selectedSubmission.indexOf("id:") + 4,
70                                 selectedSubmission.indexOf("blueprint") - 1);
71                         restAPISvc
72                                 .getRestAPI(
73                                         "/api/results/getBySubmissionId/" + id,
74                                         function(data) {
75                                             if (data !== undefined) {
76                                                 $scope.results = data;
77                                                 angular
78                                                         .forEach(
79                                                                 $scope.results,
80                                                                 function(result) {
81                                                                     $scope.resultsLayers
82                                                                             .push(result.blueprintLayer);
83                                                                 });
84                                             } else {
85                                                 confirm("Error when committing the submission");
86                                             }
87                                         });
88                     }
89
90                     $scope.selectedResultsLayerChange = function(selectedLayer) {
91                         $scope.resultsLayerTestSuitesNames = [];
92                         $scope.robotTestResults = [];
93                         $scope.selectedRobotTestResult = [];
94                         var selectedLayerResult = [];
95                         angular.forEach($scope.results, function(result) {
96                             if (result.blueprintLayer === selectedLayer) {
97                                 selectedLayerResult = result;
98                             }
99                         });
100                         $scope.robotTestResults = selectedLayerResult.robotTestResults;
101                         angular.forEach($scope.robotTestResults, function(
102                                 robotTestResult) {
103                             $scope.resultsLayerTestSuitesNames
104                                     .push(robotTestResult.name);
105                         });
106                     }
107
108                     $scope.selectedTestSuitesNameChange = function(
109                             selectedTestSuiteName) {
110                         angular
111                                 .forEach(
112                                         $scope.robotTestResults,
113                                         function(robotTestResult) {
114                                             if (robotTestResult.name.trim() === selectedTestSuiteName
115                                                     .trim()) {
116                                                 $scope.selectedRobotTestResult = robotTestResult;
117                                             }
118                                         });
119                     }
120
121                 });