UI initial implementation.
[validation.git] / ui / src / main / webapp / resources / js / AECNewSubmissionController.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 AECBlueprintValidationUIApp = angular
18         .module('BlueprintValidationUIManagement');
19
20 AECBlueprintValidationUIApp
21         .controller(
22                 'AECNewSubmissionController',
23                 function($scope, appContext, restAPISvc) {
24
25                     initialize();
26
27                     function initialize() {
28                         restAPISvc
29                                 .getRestAPI(
30                                         "/api/blueprintInstance/",
31                                         function(data) {
32                                             $scope.blueprintInstances = data;
33                                             $scope.blueprintNames = [];
34                                             angular
35                                                     .forEach(
36                                                             $scope.blueprintInstances,
37                                                             function(
38                                                                     blueprintInstance) {
39                                                                 if ($scope.blueprintNames
40                                                                         .indexOf(blueprintInstance["blueprint"]["blueprintName"]) === -1) {
41                                                                     $scope.blueprintNames
42                                                                             .push(blueprintInstance["blueprint"]["blueprintName"]);
43                                                                 }
44                                                             });
45                                         });
46                     }
47                     $scope.selectedBluePrintNameChange = function() {
48                         $scope.blueprintVersions = [];
49                         $scope.blueprintLayers = [];
50                         $scope.declerativeTimeslots = [];
51                         angular
52                                 .forEach(
53                                         $scope.blueprintInstances,
54                                         function(blueprintInstance) {
55                                             if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
56                                                 if ($scope.blueprintVersions
57                                                         .indexOf(blueprintInstance["version"]) === -1) {
58                                                     $scope.blueprintVersions
59                                                             .push(blueprintInstance["version"]);
60                                                 }
61                                             }
62                                         });
63                     }
64                     $scope.selectedBluePrintVersionChange = function() {
65                         $scope.blueprintLayers = [];
66                         $scope.declerativeTimeslots = [];
67                         angular
68                                 .forEach(
69                                         $scope.blueprintInstances,
70                                         function(blueprintInstance) {
71                                             if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
72                                                 if ($scope.selectedBlueprintVersion === blueprintInstance["version"]) {
73                                                     if ($scope.blueprintLayers
74                                                             .indexOf(blueprintInstance["layer"]) === -1) {
75                                                         $scope.blueprintLayers
76                                                                 .push(blueprintInstance["layer"]);
77                                                     }
78                                                 }
79                                             }
80                                         });
81                     }
82                     $scope.selectedBluePrintLayerChange = function() {
83                         $scope.declerativeTimeslots = [];
84                         angular
85                                 .forEach(
86                                         $scope.blueprintInstances,
87                                         function(blueprintInstance) {
88                                             if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
89                                                 if ($scope.selectedBlueprintVersion === blueprintInstance["version"]) {
90                                                     if ($scope.selectedBlueprintLayer === blueprintInstance["layer"]) {
91                                                         var temp = "id: "
92                                                                 + blueprintInstance["timeslot"].timeslotId
93                                                                 + " Start date and time: "
94                                                                 + blueprintInstance["timeslot"].startDateTime
95                                                                 + " duration(in sec) :"
96                                                                 + blueprintInstance["timeslot"].duration
97                                                                 + " lab :"
98                                                                 + blueprintInstance["timeslot"].lab;
99                                                         if ($scope.declerativeTimeslots
100                                                                 .indexOf(temp) === -1) {
101                                                             $scope.declerativeTimeslots
102                                                                     .push(temp);
103                                                         }
104                                                     }
105                                                 }
106                                             }
107                                         });
108                     }
109                     $scope.submit = function() {
110                         var finalBlueprint;
111                         angular
112                                 .forEach(
113                                         $scope.blueprintInstances,
114                                         function(blueprintInstance) {
115                                             if (blueprintInstance["blueprint"]["blueprintName"] === $scope.selectedBlueprintName) {
116                                                 if (blueprintInstance["version"] === $scope.selectedBlueprintVersion) {
117                                                     if (blueprintInstance["layer"] === $scope.selectedBlueprintLayer) {
118                                                         var selectedDeclerativeTimeslotId = $scope.selectedDeclerativeTimeslot
119                                                                 .substring(
120                                                                         $scope.selectedDeclerativeTimeslot
121                                                                                 .indexOf("id:") + 4,
122                                                                         $scope.selectedDeclerativeTimeslot
123                                                                                 .indexOf("Start date and time:") - 1);
124                                                         if (selectedDeclerativeTimeslotId
125                                                                 .toString()
126                                                                 .trim() === blueprintInstance["timeslot"]["timeslotId"]
127                                                                 .toString()
128                                                                 .trim()) {
129                                                             finalBlueprint = blueprintInstance;
130                                                         }
131                                                     }
132                                                 }
133                                             }
134                                         });
135                         var submission = {
136                             "blueprintInstance" : finalBlueprint
137                         };
138                         restAPISvc
139                                 .postRestAPI(
140                                         "/api/submission/",
141                                         submission,
142                                         function(data) {
143                                             if (data !== undefined) {
144                                                 confirm("Submission committed successfully");
145                                             } else {
146                                                 confirm("Error when committing the submission");
147                                             }
148                                         });
149                     }
150
151                 });