UI adaptation for supporting ONAP portal SDK
[validation.git] / ui / src / main / webapp / app / AECBlueprintValidationUI / NewSubmission / AECNewSubmissionController.js
  * limitations under the License.
  */
 
-var AECBlueprintValidationUIApp = angular
-        .module('BlueprintValidationUIManagement');
-
-AECBlueprintValidationUIApp
+var app = angular.module('AECNewSubmission');
+app
         .controller(
                 'AECNewSubmissionController',
-                function($scope, appContext, restAPISvc) {
+                function($scope, restAPISvc) {
 
                     initialize();
 
                     function initialize() {
                         restAPISvc
                                 .getRestAPI(
-                                        "/api/blueprintInstance/",
+                                        "/api/blueprintInstanceForValidation/",
                                         function(data) {
-                                            $scope.blueprintInstances = data;
+                                            $scope.blueprintInstancesForValidation = data;
                                             $scope.blueprintNames = [];
                                             angular
                                                     .forEach(
-                                                            $scope.blueprintInstances,
+                                                            $scope.blueprintInstancesForValidation,
                                                             function(
                                                                     blueprintInstance) {
                                                                 if ($scope.blueprintNames
@@ -43,14 +41,30 @@ AECBlueprintValidationUIApp
                                                                 }
                                                             });
                                         });
+                        restAPISvc.getRestAPI("/api/timeslots/",
+                                function(data) {
+                                    $scope.timeslots = data;
+                                    $scope.declerativeTimeslots = [];
+                                    angular.forEach($scope.timeslots, function(
+                                            timeslot) {
+                                        var temp = "id: " + timeslot.timeslotId
+                                                + " Start date and time: "
+                                                + timeslot.startDateTime
+                                                /*
+                                                 * + " duration(in sec) :" +
+                                                 * blueprintInstance["timeslot"].duration
+                                                 */
+                                                + " lab :" + timeslot.lab.lab;
+                                        $scope.declerativeTimeslots.push(temp);
+                                    });
+                                });
                     }
                     $scope.selectedBluePrintNameChange = function() {
                         $scope.blueprintVersions = [];
                         $scope.blueprintLayers = [];
-                        $scope.declerativeTimeslots = [];
                         angular
                                 .forEach(
-                                        $scope.blueprintInstances,
+                                        $scope.blueprintInstancesForValidation,
                                         function(blueprintInstance) {
                                             if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
                                                 if ($scope.blueprintVersions
@@ -63,10 +77,9 @@ AECBlueprintValidationUIApp
                     }
                     $scope.selectedBluePrintVersionChange = function() {
                         $scope.blueprintLayers = [];
-                        $scope.declerativeTimeslots = [];
                         angular
                                 .forEach(
-                                        $scope.blueprintInstances,
+                                        $scope.blueprintInstancesForValidation,
                                         function(blueprintInstance) {
                                             if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
                                                 if ($scope.selectedBlueprintVersion === blueprintInstance["version"]) {
@@ -79,61 +92,41 @@ AECBlueprintValidationUIApp
                                             }
                                         });
                     }
-                    $scope.selectedBluePrintLayerChange = function() {
-                        $scope.declerativeTimeslots = [];
-                        angular
-                                .forEach(
-                                        $scope.blueprintInstances,
-                                        function(blueprintInstance) {
-                                            if ($scope.selectedBlueprintName === blueprintInstance["blueprint"]["blueprintName"]) {
-                                                if ($scope.selectedBlueprintVersion === blueprintInstance["version"]) {
-                                                    if ($scope.selectedBlueprintLayer === blueprintInstance["layer"]) {
-                                                        var temp = "id: "
-                                                                + blueprintInstance["timeslot"].timeslotId
-                                                                + " Start date and time: "
-                                                                + blueprintInstance["timeslot"].startDateTime
-                                                                + " duration(in sec) :"
-                                                                + blueprintInstance["timeslot"].duration
-                                                                + " lab :"
-                                                                + blueprintInstance["timeslot"].lab;
-                                                        if ($scope.declerativeTimeslots
-                                                                .indexOf(temp) === -1) {
-                                                            $scope.declerativeTimeslots
-                                                                    .push(temp);
-                                                        }
-                                                    }
-                                                }
-                                            }
-                                        });
-                    }
+
                     $scope.submit = function() {
                         var finalBlueprint;
+                        var finalTimeslot;
                         angular
                                 .forEach(
-                                        $scope.blueprintInstances,
+                                        $scope.blueprintInstancesForValidation,
                                         function(blueprintInstance) {
                                             if (blueprintInstance["blueprint"]["blueprintName"] === $scope.selectedBlueprintName) {
                                                 if (blueprintInstance["version"] === $scope.selectedBlueprintVersion) {
                                                     if (blueprintInstance["layer"] === $scope.selectedBlueprintLayer) {
-                                                        var selectedDeclerativeTimeslotId = $scope.selectedDeclerativeTimeslot
-                                                                .substring(
-                                                                        $scope.selectedDeclerativeTimeslot
-                                                                                .indexOf("id:") + 4,
-                                                                        $scope.selectedDeclerativeTimeslot
-                                                                                .indexOf("Start date and time:") - 1);
-                                                        if (selectedDeclerativeTimeslotId
-                                                                .toString()
-                                                                .trim() === blueprintInstance["timeslot"]["timeslotId"]
-                                                                .toString()
-                                                                .trim()) {
-                                                            finalBlueprint = blueprintInstance;
-                                                        }
+                                                        finalBlueprint = blueprintInstance;
                                                     }
                                                 }
                                             }
                                         });
+                        var selectedDeclerativeTimeslotId = $scope.selectedDeclerativeTimeslot
+                                .substring(
+                                        $scope.selectedDeclerativeTimeslot
+                                                .indexOf("id:") + 4,
+                                        $scope.selectedDeclerativeTimeslot
+                                                .indexOf("Start date and time:") - 1);
+                        angular
+                                .forEach(
+                                        $scope.timeslots,
+                                        function(timeslot) {
+                                            if (selectedDeclerativeTimeslotId
+                                                    .toString().trim() === timeslot.timeslotId
+                                                    .toString().trim()) {
+                                                finalTimeslot = timeslot;
+                                            }
+                                        });
                         var submission = {
-                            "blueprintInstance" : finalBlueprint
+                            "blueprintInstanceForValidation" : finalBlueprint,
+                            "timeslot" : finalTimeslot
                         };
                         restAPISvc
                                 .postRestAPI(