[UI] Support UI partial control
[validation.git] / ui / src / main / webapp / app / BluvalUI / NewSubmission / NewSubmissionController.js
  * limitations under the License.
  */
 
-var app = angular.module('AECNewSubmission');
+var app = angular.module('NewSubmission');
 app
         .controller(
-                'AECNewSubmissionController',
+                'NewSubmissionController',
                 function($scope, restAPISvc) {
 
                     initialize();
@@ -25,7 +25,7 @@ app
                     function initialize() {
                         restAPISvc
                                 .getRestAPI(
-                                        "/api/blueprintInstanceForValidation/",
+                                        "/api/v1/blueprintinstanceforvalidation/",
                                         function(data) {
                                             $scope.blueprintInstancesForValidation = data;
                                             $scope.blueprintNames = [];
@@ -41,12 +41,12 @@ app
                                                                 }
                                                             });
                                         });
-                        restAPISvc.getRestAPI("/api/timeslots/",
-                                function(data) {
-                                    $scope.timeslots = data;
-                                    $scope.declerativeTimeslots = [];
-                                    angular.forEach($scope.timeslots, function(
-                                            timeslot) {
+                        restAPISvc.getRestAPI("/api/v1/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
@@ -57,11 +57,15 @@ app
                                                 + " lab :" + timeslot.lab.lab;
                                         $scope.declerativeTimeslots.push(temp);
                                     });
-                                });
+                        });
                     }
                     $scope.selectedBluePrintNameChange = function() {
                         $scope.blueprintVersions = [];
                         $scope.blueprintLayers = [];
+                        $scope.optionals = [];
+                        $scope.selectedBlueprintVersion = {};
+                        $scope.selectedBlueprintLayer = {};
+                        $scope.selectedOptional = "";
                         angular
                                 .forEach(
                                         $scope.blueprintInstancesForValidation,
@@ -76,7 +80,13 @@ app
                                         });
                     }
                     $scope.selectedBluePrintVersionChange = function() {
+                        if (!$scope.selectedBlueprintName) {
+                            return;
+                        }
                         $scope.blueprintLayers = [];
+                        $scope.optionals = [];
+                        $scope.selectedBlueprintLayer = {};
+                        $scope.selectedOptional = "";
                         angular
                                 .forEach(
                                         $scope.blueprintInstancesForValidation,
@@ -91,30 +101,23 @@ app
                                                 }
                                             }
                                         });
+                        $scope.blueprintLayers.push("all");
+                    }
+
+                    $scope.selectedBluePrintLayerChange = function() {
+                        $scope.optionals = [ 'true', 'false' ];
                     }
 
                     $scope.submit = function() {
                         if (!$scope.selectedBlueprintName
                                 || !$scope.selectedBlueprintVersion
                                 || !$scope.selectedBlueprintLayer
+                                || !$scope.selectedOptional
                                 || !$scope.selectedDeclerativeTimeslot) {
                             confirm("You must specify all data fields");
                             return;
                         }
-                        var finalBlueprint;
                         var finalTimeslot;
-                        angular
-                                .forEach(
-                                        $scope.blueprintInstancesForValidation,
-                                        function(blueprintInstance) {
-                                            if (blueprintInstance["blueprint"]["blueprintName"] === $scope.selectedBlueprintName) {
-                                                if (blueprintInstance["version"] === $scope.selectedBlueprintVersion) {
-                                                    if (blueprintInstance["layer"] === $scope.selectedBlueprintLayer) {
-                                                        finalBlueprint = blueprintInstance;
-                                                    }
-                                                }
-                                            }
-                                        });
                         var selectedDeclerativeTimeslotId = $scope.selectedDeclerativeTimeslot
                                 .substring(
                                         $scope.selectedDeclerativeTimeslot
@@ -131,17 +134,35 @@ app
                                                 finalTimeslot = timeslot;
                                             }
                                         });
-                        var submission = {
-                            "blueprintInstanceForValidation" : finalBlueprint,
+                        var allLayers = "false";
+                        if ($scope.selectedBlueprintLayer === 'all') {
+                            allLayers = "true";
+                        }
+                        var wRobotTestResults = [];
+                        if (allLayers === "false") {
+                            wRobotTestResults = [ {
+                                "blueprintLayer" : $scope.selectedBlueprintLayer
+                            } ];
+                        }
+
+                        var validationNexusTestResult = {
+                            "blueprintName" : $scope.selectedBlueprintName,
+                            "version" : $scope.selectedBlueprintVersion,
+                            "allLayers" : allLayers,
+                            "wRobotNexusTestResults" : wRobotTestResults,
+                            "optional" : $scope.selectedOptional
+                        };
+                        var submissionData = {
+                            "validationNexusTestResult" : validationNexusTestResult,
                             "timeslot" : finalTimeslot
                         };
                         restAPISvc
                                 .postRestAPI(
-                                        "/api/submission/",
-                                        submission,
+                                        "/api/v1/submission/",
+                                        submissionData,
                                         function(data) {
                                             if (data !== undefined) {
-                                                var confirmText = "The blueprint instance for validation has been submitted successfully. Submissionn id:"
+                                                var confirmText = "The blueprint instance for validation has been submitted successfully. Submission id:"
                                                         + data.submissionId;
                                                 confirm(confirmText);
                                             } else {
@@ -151,6 +172,7 @@ app
                         $scope.selectedBlueprintName = {};
                         $scope.selectedBlueprintVersion = {};
                         $scope.selectedBlueprintLayer = {};
+                        $scope.selectedOptional = "";
                         $scope.selectedDeclerativeTimeslot = {};
                     }