Fixed the Policy API issues and Bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / webapp / app / policyApp / policy-models / Editor / PolicyTemplateController / DecisionPolicyController.js
index f5932e2..e7858d7 100644 (file)
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
-angular.module('abs').controller('decisionPolicyController', function ($scope, PolicyAppService, modalService, $modal, Notification) {
+angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
     $("#dialog").hide();
+    
+    $scope.policyNavigator;
     $scope.savebutton = true;
-    $scope.finalPath = null;
+    $scope.refreshCheck = false;
+    
+    $scope.refresh = function(){
+       if($scope.refreshCheck){
+               $scope.policyNavigator.refresh();
+       }
+       $scope.modal('createNewPolicy', true);
+       $scope.temp.policy = "";
+    };
+    
+    $scope.modal = function(id, hide) {
+        return $('#' + id).modal(hide ? 'hide' : 'show');
+    };
 
        if($scope.temp.policy.ruleProvider==undefined){
                $scope.temp.policy.ruleProvider="Custom";
@@ -76,6 +90,11 @@ angular.module('abs').controller('decisionPolicyController', function ($scope, P
     }
     
     $scope.saveDecisionPolicy = function(policy){
+       if(policy.itemContent != undefined){
+               $scope.refreshCheck = true; 
+               $scope.policyNavigator = policy.itemContent;
+               policy.itemContent = "";
+       }
        $scope.savebutton = false;
         console.log(policy);
         var uuu = "policycreation/save_policy";
@@ -144,19 +163,29 @@ angular.module('abs').controller('decisionPolicyController', function ($scope, P
    
     if(!$scope.temp.policy.editPolicy  && !$scope.temp.policy.readOnly){
        $scope.temp.policy.attributes = [];
-         $scope.temp.policy.settings = [];
-        $scope.temp.policy.ruleAlgorithmschoices = [];
-    }else{
+       $scope.temp.policy.settings = [];
+       $scope.temp.policy.ruleAlgorithmschoices = [];
+       if(!$scope.temp.policy.yamlparams){
+               $scope.temp.policy.yamlparams = {};
+       }
+       if(!$scope.temp.policy.yamlparams.blackList){
+               $scope.temp.policy.yamlparams.blackList = [];
+       }
+    }else if($scope.temp.policy.ruleProvider=="Custom"){
           if($scope.temp.policy.attributes.length == 0){
                   $scope.temp.policy.attributes = [];
           }
           if($scope.temp.policy.settings.length == 0){
                   $scope.temp.policy.settings = [];
           }
-          if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
+          if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
                   $scope.temp.policy.ruleAlgorithmschoices = [];
           }
-   }
+    }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
+       if($scope.temp.policy.yamlparams.blackList.length==0){
+               $scope.temp.policy.yamlparams.blackList = [];
+       }
+    }
     $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
     $scope.addNewChoice = function() {
       var newItemNo = $scope.temp.policy.attributes.length+1;
@@ -178,6 +207,14 @@ angular.module('abs').controller('decisionPolicyController', function ($scope, P
       $scope.temp.policy.settings.splice(lastItem);
     };
     
+    $scope.addNewBL = function() {
+       $scope.temp.policy.yamlparams.blackList.push('');
+    };
+    $scope.removeBL = function() {
+       var lastItem = $scope.temp.policy.yamlparams.blackList.length-1;
+       $scope.temp.policy.yamlparams.blackList.splice(lastItem);
+    };
+    
     $scope.ItemNo = 0;
     $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
     
@@ -206,4 +243,4 @@ angular.module('abs').controller('decisionPolicyController', function ($scope, P
                $scope.temp.policy.attributes = [];
        }
     };
-});
\ No newline at end of file
+}]);
\ No newline at end of file