From 60bb98696ee93f979914d8e88ed4708f59fcff9c Mon Sep 17 00:00:00 2001 From: asteroide Date: Fri, 9 Jun 2017 16:18:59 +0200 Subject: Stable version Change-Id: I70001bedbdf1823cb9e8dccd545800387777201b --- .../assignments/assignments-list.tpl.html | 68 +++-- .../parameter/assignments/assignments.list.dir.js | 289 +++++++-------------- .../policy/edit/parameter/data/data-list.tpl.html | 75 ++++-- .../policy/edit/parameter/data/data.edit.dir.js | 210 +++++---------- .../policy/edit/parameter/data/data.list.dir.js | 170 +++--------- .../parameter/perimeter/perimeter-list.tpl.html | 130 ++------- .../edit/parameter/perimeter/perimeter.list.dir.js | 212 +++++---------- .../edit/parameter/rules/rules-list.tpl.html | 148 ++++++----- .../policy/edit/parameter/rules/rules.list.dir.js | 88 +++++-- .../static/app/policy/edit/policy-edit.tpl.html | 10 +- .../static/app/policy/policy.controller.list.js | 6 +- .../static/app/policy/policy.mapped.list.dir.js | 9 +- 12 files changed, 554 insertions(+), 861 deletions(-) (limited to 'moonv4/moon_gui/static/app/policy') diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html b/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html index 0f919a4a..34bbc7a8 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html @@ -17,9 +17,7 @@ Perimeter name Category name - Data name - - + Data name @@ -29,13 +27,14 @@ +
Loading
- +
@@ -63,14 +62,26 @@ - - , + + () + + + + +
+ + + +
+ + + @@ -101,7 +112,7 @@
- +
@@ -122,13 +133,11 @@ - - - - - - - + + + + + @@ -143,7 +152,7 @@
- +
@@ -169,10 +178,13 @@ + - - , + + () + + @@ -207,7 +219,7 @@
- +
@@ -228,13 +240,11 @@
Perimeter nameCategory nameData name
Perimeter nameCategory nameData name
- - - - - - - + + + + + @@ -277,8 +287,10 @@ - - , + + () + + @@ -314,7 +326,7 @@
. - +
diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js b/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js index 747fd487..22931e4d 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js @@ -1,4 +1,4 @@ -(function() { +(function () { 'use strict'; @@ -11,16 +11,16 @@ function moonAssignmentsList() { return { - templateUrl : 'html/policy/edit/parameter/assignments/assignments-list.tpl.html', - bindToController : true, - controller : moonAssignmentsListController, - controllerAs : 'list', - scope : { + templateUrl: 'html/policy/edit/parameter/assignments/assignments-list.tpl.html', + bindToController: true, + controller: moonAssignmentsListController, + controllerAs: 'list', + scope: { policy: '=', - editMode : '=' + editMode: '=' }, - restrict : 'E', - replace : true + restrict: 'E', + replace: true }; } @@ -28,9 +28,11 @@ .module('moon') .controller('moonAssignmentsListController', moonAssignmentsListController); - moonAssignmentsListController.$inject = ['$scope', '$rootScope', 'assignmentService', '$translate', 'alertService', 'policyService', 'ASSIGNMENTS_CST', 'utilService', 'metaDataService', 'perimeterService', 'dataService']; + moonAssignmentsListController.$inject = ['$scope', '$rootScope', 'assignmentsService', '$translate', 'alertService', + 'policyService', 'ASSIGNMENTS_CST', 'utilService', 'metaDataService', 'perimeterService', 'dataService']; - function moonAssignmentsListController($scope, $rootScope, assignmentService, $translate, alertService, policyService, ASSIGNMENTS_CST, utilService, metaDataService, perimeterService, dataService){ + function moonAssignmentsListController($scope, $rootScope, assignmentsService, $translate, alertService, + policyService, ASSIGNMENTS_CST, utilService, metaDataService, perimeterService, dataService) { var list = this; @@ -41,10 +43,6 @@ list.typeOfObject = ASSIGNMENTS_CST.TYPE.OBJECT; list.typeOfAction = ASSIGNMENTS_CST.TYPE.ACTION; - list.unMapSub = unMapSub; - list.unMapObj = unMapObj; - list.unMapAct = unMapAct; - list.deleteSub = deleteSub; list.deleteObj = deleteObj; list.deleteAct = deleteAct; @@ -59,7 +57,7 @@ activate(); - function activate(){ + function activate() { manageSubjects(); @@ -71,37 +69,32 @@ var rootListeners = { - 'event:deleteDataFromDataAddSuccess': $rootScope.$on('event:deleteDataFromDataAddSuccess', deletePolicy) + 'event:createAssignmentsFromAssignmentsEditSuccess': $rootScope.$on('event:createAssignmentsFromAssignmentsEditSuccess', updateList) }; - for (var unbind in rootListeners) { + _.each(rootListeners, function(unbind){ $scope.$on('$destroy', rootListeners[unbind]); - } - + }); - function manageSubjects(){ + function manageSubjects() { list.loadingSub = true; - assignmentService.subject.findAllFromPolicyWithCallback(list.policy.id, function(data){ + assignmentsService.subject.findAllFromPolicyWithCallback(list.policy.id, function (data) { - console.log('subjects'); - console.log(data); list.subjects = data; list.loadingSub = false; }); } - function manageObjects(){ + function manageObjects() { list.loadingObj = true; - assignmentService.object.findAllFromPolicyWithCallback(list.policy.id, function(data){ + assignmentsService.object.findAllFromPolicyWithCallback(list.policy.id, function (data) { - console.log('objects'); - console.log(data); list.objects = data; list.loadingObj = false; @@ -109,14 +102,12 @@ } - function manageActions(){ + function manageActions() { list.loadingAct = true; - assignmentService.action.findAllFromPolicyWithCallback(list.policy.id, function(data){ + assignmentsService.action.findAllFromPolicyWithCallback(list.policy.id, function (data) { - console.log('actions'); - console.log(data); list.actions = data; list.loadingAct = false; @@ -126,16 +117,16 @@ function getPerimeterFromAssignment(assignment, type) { - if(_.has(assignment, 'perimeter')){ + if (_.has(assignment, 'perimeter')) { return assignment.perimeter; } // if the call has not been made - if(!_.has(assignment, 'callPerimeterInProgress')){ + if (!_.has(assignment, 'callPerimeterInProgress')) { assignment.callPerimeterInProgress = true; - switch(type){ + switch (type) { case ASSIGNMENTS_CST.TYPE.SUBJECT: perimeterService.subject.findOneFromPolicyWithCallback(list.policy.id, assignment.subject_id, setPerimeterToAssignment); @@ -156,7 +147,7 @@ // if the call is in progress return false return false; - function setPerimeterToAssignment(perimeter){ + function setPerimeterToAssignment(perimeter) { assignment.callPerimeterInProgress = false; assignment.perimeter = perimeter; @@ -166,16 +157,16 @@ function getCategoryFromAssignment(data, type) { - if(_.has(data, 'category')){ + if (_.has(data, 'category')) { return data.category; } // if the call has not been made - if(!_.has(data, 'callCategoryInProgress')){ + if (!_.has(data, 'callCategoryInProgress')) { data.callCategoryInProgress = true; - switch(type){ + switch (type) { case ASSIGNMENTS_CST.TYPE.SUBJECT: metaDataService.subject.findOne(data.subject_cat_id, setCategoryToData); @@ -196,7 +187,7 @@ // if the call is in progress return false return false; - function setCategoryToData(category){ + function setCategoryToData(category) { data.callCategoryInProgress = false; data.category = category; @@ -205,32 +196,31 @@ } /** - * Prerequisite : meta Rule should be completely loaded * @param index * @param assignment * @param type */ - function getDataFromAssignmentsIndex(index, assignment, type){ + function getDataFromAssignmentsIndex(index, assignment, type) { - if(!_.has(assignment, 'assignments_value')){ + if (!_.has(assignment, 'assignments_value')) { // setting an array which will contains every value of the category - assignment.assignments_value = Array.apply(null, new Array(assignment.assignments.length)).map(function(){ + assignment.assignments_value = Array.apply(null, new Array(assignment.assignments.length)).map(function () { return { data: {} - } + }; }); } - if(_.has(assignment.assignments_value[index], 'callDataInProgress') && !assignment.assignments_value[index].callDataInProgress ){ + if (_.has(assignment.assignments_value[index], 'callDataInProgress') && !assignment.assignments_value[index].callDataInProgress) { return assignment.assignments_value[index].data; } // if the call has not been made - if(!_.has(assignment.assignments_value[index], 'callDataInProgress')){ + if (!_.has(assignment.assignments_value[index], 'callDataInProgress')) { assignment.assignments_value[index].callDataInProgress = true; - switch(type){ + switch (type) { case ASSIGNMENTS_CST.TYPE.SUBJECT: dataService.subject.data.findOne(list.policy.id, assignment.category_id, assignment.assignments[index], setDataToAssignment); @@ -251,7 +241,7 @@ // if the call is in progress return false return false; - function setDataToAssignment(data){ + function setDataToAssignment(data) { assignment.assignments_value[index].callDataInProgress = false; assignment.assignments_value[index].data = data; @@ -259,239 +249,142 @@ } } - - /** - * UnMap + * Delete */ - function unMapSub(subject){ + function deleteSub(subject, dataId) { subject.loader = true; - var policyToSend = angular.copy(list.policy); + assignmentsService.subject.delete(list.policy.id, subject.subject_id, subject.subject_cat_id, dataId, deleteSubSuccess, deleteSubError); - policyToSend.subject_categories = _.without(policyToSend.subject_categories, subject.id); + function deleteSubSuccess(data) { - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); - - function updatePolicySuccess(data){ - - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.assignments.subject.delete.success').then(function (translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findDataFromPolicy(utilService.transformOne(data, 'meta_rules')); - - activate(); + manageSubjects(); subject.loader = false; } - function updatePolicyError(reason){ + function deleteSubError(reason) { - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.assignments.subject.delete.error', { + subjectName: subject.name, + reason: reason.message + }).then(function (translatedValue) { alertService.alertError(translatedValue); }); subject.loader = false; } - } - function unMapObj(object){ + function deleteObj(object, dataId) { object.loader = true; - var policyToSend = angular.copy(list.policy); - - policyToSend.object_categories = _.without(policyToSend.object_categories, object.id); - - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); + assignmentsService.object.delete(list.policy.id, object.object_id, object.object_cat_id, dataId, deleteObjSuccess, deleteObjError); - function updatePolicySuccess(data){ + function deleteObjSuccess(data) { - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.assignments.object.delete.success').then(function (translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findDataFromPolicy(utilService.transformOne(data, 'meta_rules')); - - activate(); + manageObjects(); object.loader = false; } - function updatePolicyError(reason){ + function deleteObjError(reason) { - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.assignments.object.delete.error', { + objectName: object.name, + reason: reason.message + }).then(function (translatedValue) { alertService.alertError(translatedValue); }); object.loader = false; - } - } - function unMapAct(action){ + function deleteAct(action, dataId) { action.loader = true; - var policyToSend = angular.copy(list.policy); + assignmentsService.action.delete(list.policy.id, action.action_id, action.action_cat_id, dataId, deleteActSuccess, deleteActError); - policyToSend.action_categories = _.without(policyToSend.action_categories, action.id); + function deleteActSuccess(data) { - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); - - function updatePolicySuccess(data){ - - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.assignments.action.delete.success').then(function (translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findDataFromPolicy(utilService.transformOne(data, 'meta_rules')); - - activate(); + manageActions(); action.loader = false; } - function updatePolicyError(reason){ + function deleteActError(reason) { - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.assignments.action.delete.error', { + actionName: action.name, + reason: reason.message + }).then(function (translatedValue) { alertService.alertError(translatedValue); }); action.loader = false; } - } - /** - * Delete - */ - - function deleteSub(subject){ - - subject.loader = true; - - assignmentService.subject.delete(subject, deleteSubSuccess, deleteSubError); - - function deleteSubSuccess(data){ - - $translate('moon.policy.perimeter.subject.delete.success', { subjectName: subject.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); - - removeSubFromSubList(subject); - - subject.loader = false; - - } - - function deleteSubError(reason){ - - $translate('moon.policy.perimeter.subject.delete.error', { subjectName: subject.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); - - subject.loader = false; - - } + function getSubjects() { + return list.subjects ? list.subjects : []; } - function deleteObj(object){ - - object.loader = true; - - assignmentService.object.delete(object, deleteObjSuccess, deleteObjError); - - function deleteObjSuccess(data){ - - $translate('moon.policy.perimeter.object.delete.success', { objectName: object.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); - - removeObjFromObjList(object); - - object.loader = false; - - } - - function deleteObjError(reason){ - - $translate('moon.policy.perimeter.object.delete.error', { objectName: object.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); - - object.loader = false; - } + function getObjects() { + return list.objects ? list.objects : []; } - function deleteAct(action){ + function getActions() { + return list.actions ? list.actions : []; + } - action.loader = true; + function updateList(event, type) { - assignmentService.action.delete(action, deleteActSuccess, deleteActError); + switch(type){ - function deleteActSuccess(data){ + case ASSIGNMENTS_CST.TYPE.SUBJECT: - $translate('moon.policy.perimeter.action.delete.success', { actionName: action.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); + manageSubjects(); + break; - removeActFromActList(action); + case ASSIGNMENTS_CST.TYPE.OBJECT: - action.loader = false; + manageObjects(); + break; - } + case ASSIGNMENTS_CST.TYPE.ACTION: - function deleteActError(reason){ + manageActions(); + break; - $translate('moon.policy.perimeter.action.delete.error', { actionName: action.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); + default : - action.loader = false; + activate(); + break; } - } - - function getSubjects(){ - return list.subjects ? list.subjects : []; - } - - function getObjects(){ - return list.objects ? list.objects : []; - } - - function getActions(){ - return list.actions ? list.actions : []; - } - - function removeSubFromSubList(subject){ - list.subjects = _.without(list.subjects, subject); - } - - function removeObjFromObjList(object){ - list.objects = _.without(list.objects, object); - } - - function removeActFromActList(action){ - list.actions = _.without(list.actions, action); - } - - function deletePolicy( event, policy){ - - list.policy = policy; - - activate(); } diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html b/moonv4/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html index b2bac597..b69a4eed 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html @@ -18,7 +18,7 @@ - + @@ -40,6 +40,23 @@ + + + + + @@ -156,6 +170,21 @@ + + + + @@ -271,6 +299,21 @@ + + + + @@ -27,40 +26,15 @@ - - + @@ -80,7 +54,6 @@ - @@ -102,12 +75,13 @@
- +
+
@@ -124,10 +98,9 @@
- - + @@ -135,39 +108,14 @@ - - + @@ -184,7 +132,6 @@ - @@ -206,7 +153,7 @@
- +
@@ -228,10 +175,9 @@ - - + @@ -239,39 +185,14 @@ - - + @@ -288,7 +209,6 @@ - @@ -311,7 +231,7 @@
. - +
diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js b/moonv4/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js index 8c50b22e..dffa7783 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js @@ -22,15 +22,16 @@ restrict : 'E', replace : true }; + } angular .module('moon') .controller('moonPerimeterListController', moonPerimeterListController); - moonPerimeterListController.$inject = ['$scope', '$rootScope', 'perimeterService', '$translate', 'alertService', 'policyService', 'PERIMETER_CST', 'utilService']; + moonPerimeterListController.$inject = ['$scope', '$rootScope', 'perimeterService', '$translate', 'alertService', 'PERIMETER_CST']; - function moonPerimeterListController($scope, $rootScope, perimeterService, $translate, alertService, policyService, PERIMETER_CST, utilService){ + function moonPerimeterListController($scope, $rootScope, perimeterService, $translate, alertService, PERIMETER_CST){ var list = this; @@ -45,10 +46,6 @@ list.unMapObj = unMapObj; list.unMapAct = unMapAct; - list.deleteSub = deleteSub; - list.deleteObj = deleteObj; - list.deleteAct = deleteAct; - list.getSubjects = getSubjects; list.getObjects = getObjects; list.getActions = getActions; @@ -67,13 +64,14 @@ var rootListeners = { - 'event:deletePerimeterFromPerimeterAddSuccess': $rootScope.$on('event:deletePerimeterFromPerimeterAddSuccess', deletePolicy) + 'event:deletePerimeterFromPerimeterAddSuccess': $rootScope.$on('event:deletePerimeterFromPerimeterAddSuccess', deletePolicy), + 'event:createAssignmentsFromAssignmentsEditSuccess': $rootScope.$on('event:createAssignmentsFromAssignmentsEditSuccess', addAssignmentsToPolicy) }; - for (var unbind in rootListeners) { + _.each(rootListeners, function(unbind){ $scope.$on('$destroy', rootListeners[unbind]); - } + }); function manageSubjects(){ @@ -94,8 +92,6 @@ perimeterService.object.findAllFromPolicyWithCallback(list.policy.id, function(perimeters){ - console.log('objects'); - console.log(perimeters); list.objects = perimeters; list.loadingObj = false; @@ -109,8 +105,6 @@ perimeterService.action.findAllFromPolicyWithCallback(list.policy.id, function(perimeters){ - console.log('actions'); - console.log(perimeters); list.actions = perimeters; list.loadingAct = false; @@ -118,207 +112,113 @@ } - /** * UnMap */ - function unMapSub(subject){ + function unMapSub(perimeter){ - subject.loader = true; + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); - var policyToSend = angular.copy(list.policy); + perimeter.loader = true; - policyToSend.subject_categories = _.without(policyToSend.subject_categories, subject.id); + var perimeterToSend = angular.copy(perimeter); - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); + perimeterService.subject.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); - function updatePolicySuccess(data){ + function updatePerimeterSuccess(data){ - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findPerimeterFromPolicy(utilService.transformOne(data, 'meta_rules')); + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.SUBJECT); activate(); - subject.loader = false; - + perimeter.loader = false; } - function updatePolicyError(reason){ + function updatePerimeterError(reason){ - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { alertService.alertError(translatedValue); }); - subject.loader = false; + perimeter.loader = false; } } - function unMapObj(object){ + function unMapObj(perimeter){ - object.loader = true; + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); - var policyToSend = angular.copy(list.policy); + perimeter.loader = true; - policyToSend.object_categories = _.without(policyToSend.object_categories, object.id); + var perimeterToSend = angular.copy(perimeter); - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); + perimeterService.object.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); - function updatePolicySuccess(data){ + function updatePerimeterSuccess(data){ - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findPerimeterFromPolicy(utilService.transformOne(data, 'meta_rules')); + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.OBJECT); activate(); - object.loader = false; - + perimeter.loader = false; } - function updatePolicyError(reason){ + function updatePerimeterError(reason){ - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { alertService.alertError(translatedValue); }); - object.loader = false; + perimeter.loader = false; } } - function unMapAct(action){ + function unMapAct(perimeter){ - action.loader = true; + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); - var policyToSend = angular.copy(list.policy); + perimeter.loader = true; - policyToSend.action_categories = _.without(policyToSend.action_categories, action.id); + var perimeterToSend = angular.copy(perimeter); - policyService.update(policyToSend, updatePolicySuccess, updatePolicyError); + perimeterService.action.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); - function updatePolicySuccess(data){ + function updatePerimeterSuccess(data){ - $translate('moon.policy.metarules.update.success', { policyName: list.policy.name }).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { alertService.alertSuccess(translatedValue); }); - list.policy = policyService.findPerimeterFromPolicy(utilService.transformOne(data, 'meta_rules')); + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.ACTION); activate(); - action.loader = false; - + perimeter.loader = false; } - function updatePolicyError(reason){ + function updatePerimeterError(reason){ - $translate('moon.policy.metarules.update.error', { policyName: list.policy.name, reason: reason.message}).then( function(translatedValue) { + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { alertService.alertError(translatedValue); }); - action.loader = false; - - } - - } - - /** - * Delete - */ - - function deleteSub(subject){ - - subject.loader = true; - - perimeterService.subject.delete(subject, deleteSubSuccess, deleteSubError); - - function deleteSubSuccess(data){ - - $translate('moon.policy.perimeter.subject.delete.success', { subjectName: subject.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); - - removeSubFromSubList(subject); - - subject.loader = false; + perimeter.loader = false; } - function deleteSubError(reason){ - - $translate('moon.policy.perimeter.subject.delete.error', { subjectName: subject.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); - - subject.loader = false; - - } - } - - function deleteObj(object){ - - object.loader = true; - - perimeterService.object.delete(object, deleteObjSuccess, deleteObjError); - - function deleteObjSuccess(data){ - - $translate('moon.policy.perimeter.object.delete.success', { objectName: object.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); - - removeObjFromObjList(object); - - object.loader = false; - - } - - function deleteObjError(reason){ - - $translate('moon.policy.perimeter.object.delete.error', { objectName: object.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); - - object.loader = false; - } - } - - function deleteAct(action){ - - action.loader = true; - - perimeterService.action.delete(action, deleteActSuccess, deleteActError); - - function deleteActSuccess(data){ - - $translate('moon.policy.perimeter.action.delete.success', { actionName: action.name }).then( function(translatedValue) { - alertService.alertSuccess(translatedValue); - }); - - removeActFromActList(action); - - action.loader = false; - - } - - function deleteActError(reason){ - - $translate('moon.policy.perimeter.action.delete.error', { actionName: action.name, reason: reason.message}).then( function(translatedValue) { - alertService.alertError(translatedValue); - }); - - action.loader = false; - - } } function getSubjects(){ @@ -353,6 +253,32 @@ } + function addAssignmentsToPolicy( event, assignments, type){ + + switch (type) { + + case PERIMETER_CST.TYPE.SUBJECT: + + list.subjects.push(assignments); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + list.objects.push(assignments); + break; + + case PERIMETER_CST.TYPE.ACTION: + + list.actions.push(assignments); + break; + + default : + break; + + } + + } + } })(); \ No newline at end of file diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html b/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html index 3ec54239..76ac4365 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html @@ -1,79 +1,74 @@
-
-
+
-
Perimeter nameCategory nameData name
Perimeter nameCategory nameData name
Name Description Category
+ + + + Delete + + +
+ + + +
+ +
Actions
+ + + + Delete + + +
+ + + +
+
Actions
+ + + + Delete + + +
+ + + +
+
Id Name Description
There is no Objects
Id Name Description
There is no Actions
+
-
+

List of associated Subjects

- + + +
-
+
-
+
-
Id
-
-
Meta Rule
-
- + - - + - + - + - - - + + + - - + - - + - + + + + - - - - + - + + - - - Loading - + + + + + + + + + + + + + + +
-
Enabled
-
-
Rule
-
+
Meta Rule
+
+
Rule
+
There is no Rules +
Instruction
+
+
Actions
+
- - - Loading - +
There is no Rules
- - -
+ + + Loading + - + + + + + + + Loading + - + @@ -87,13 +82,50 @@ - +

+                        
+ + + + Delete + + +
+ + -
+ + + + + + + +
+ +
+ +

Add a Rules

+ +
- +
. - +
diff --git a/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js b/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js index 98e1d62b..5c3e7457 100644 --- a/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js +++ b/moonv4/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js @@ -28,13 +28,14 @@ .module('moon') .controller('moonRulesListController', moonRulesListController); - moonRulesListController.$inject = [ 'NgTableParams', '$filter', 'metaRuleService', 'ruleService', 'dataService']; + moonRulesListController.$inject = [ '$scope', '$rootScope', 'NgTableParams', '$filter', 'metaRuleService', 'rulesService', 'dataService', '$translate', 'alertService' ]; - function moonRulesListController( NgTableParams, $filter, metaRuleService, ruleService, dataService) { + function moonRulesListController( $scope, $rootScope, NgTableParams, $filter, metaRuleService, rulesService, dataService, $translate, alertService ) { var list = this; list.rules = []; + list.editMode = $scope.list.editMode; list.loadingRules = true; @@ -43,6 +44,7 @@ list.getRules = getRules; list.hasRules = hasRules; list.refreshRules = refreshRules; + list.deleteRules = deleteRules; list.getMetaRuleFromRule = getMetaRuleFromRule; list.getCategoryFromRuleIndex = getCategoryFromRuleIndex; @@ -55,41 +57,40 @@ function activate(){ - newRulesTable(); manageRules(); + } + var rootListeners = { + 'event:createRulesFromDataRulesSuccess': $rootScope.$on('event:createRulesFromDataRulesSuccess', addRulesToList) - function manageRules(){ + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); - ruleService.findAllFromPolicyWithCallback(list.policy.id, function(data){ + function manageRules(){ - console.log('rules'); - console.log(data); + rulesService.findAllFromPolicyWithCallback(list.policy.id, function(data){ list.rules = data; list.loadingRules = false; refreshRules(); + }); } - - - - function newRulesTable() { list.table = new NgTableParams({ page: 1, // show first page - count: 10, // count per page - sorting: { - name: 'asc' // initial sorting - } + count: 10 // count per page }, { @@ -134,7 +135,12 @@ /** - * Prerequisite : meta Rule should be completely loaded + * Prerequisite : meta Rule must be completely loader + * Depending on the meta_rule, the rule array will be filled by subject(s), object(s) or an action(s) + * the only way to know if rule[i] contains a subject/object/action is to check + * how many subject/object/action are associated to a MetaRule + * For example if the associated MetaRule contains 2 subjects, 1 object and 2 actions + * then the 2 first elements of rule array are 2 subject, the third one will be an object, and the 2 last will be action * @param index * @param rule */ @@ -145,7 +151,7 @@ rule.rule_value = Array.apply(null, new Array(rule.rule.length)).map(function(){ return { category: {} - } + }; }); } @@ -200,10 +206,11 @@ rule.rule_value[index].callCategoryInProgress = false; rule.rule_value[index].category = { name : 'ERROR' - } + }; } } + // if the call is in progress return false return false; } @@ -220,7 +227,7 @@ var ind = index + 1; - return rule.meta_rule.subject_categories.length < ind && ind <= ( rule.meta_rule.object_categories.length + rule.meta_rule.subject_categories.length ); + return rule.meta_rule.subject_categories.length < ind && ind <= ( rule.meta_rule.object_categories.length + rule.meta_rule.subject_categories.length ); } @@ -240,7 +247,6 @@ return list.getRules().length > 0; } - /** * Refresh the table */ @@ -249,6 +255,48 @@ list.table.reload(); } + function addRulesToList(event, rules){ + list.rules.push(rules); + refreshRules(); + } + + /** + * Delete + */ + function deleteRules(rules){ + + rules.loader = true; + + rulesService.delete(rules.id, list.policy.id, deleteRulesSuccess, deleteRulesError ); + + function deleteRulesSuccess(){ + + $translate('moon.policy.rules.edit.action.add.delete.success').then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeRulesFromList(rules); + refreshRules(); + + rules.loader = false; + + } + + function deleteRulesError(reason){ + + $translate('moon.policy.rules.edit.action.add.delete.success', {reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + rules.loader = false; + + } + + } + + function removeRulesFromList(rules){ + list.rules = _.without(list.rules, rules); + } } })(); \ No newline at end of file diff --git a/moonv4/moon_gui/static/app/policy/edit/policy-edit.tpl.html b/moonv4/moon_gui/static/app/policy/edit/policy-edit.tpl.html index 550d1e4c..a1a6a54a 100644 --- a/moonv4/moon_gui/static/app/policy/edit/policy-edit.tpl.html +++ b/moonv4/moon_gui/static/app/policy/edit/policy-edit.tpl.html @@ -87,7 +87,7 @@
- +
@@ -120,9 +120,9 @@
-
+
- +
@@ -157,7 +157,7 @@
- +
@@ -193,7 +193,7 @@
- +
diff --git a/moonv4/moon_gui/static/app/policy/policy.controller.list.js b/moonv4/moon_gui/static/app/policy/policy.controller.list.js index dc2db2cc..fc2c6503 100644 --- a/moonv4/moon_gui/static/app/policy/policy.controller.list.js +++ b/moonv4/moon_gui/static/app/policy/policy.controller.list.js @@ -6,9 +6,9 @@ .module('moon') .controller('PolicyListController', PolicyListController); - PolicyListController.$inject = ['$scope', 'policies', 'ngTableParams', '$filter', '$modal', '$rootScope']; + PolicyListController.$inject = ['$scope', 'policies', 'NgTableParams', '$filter', '$modal', '$rootScope']; - function PolicyListController($scope, policies, ngTableParams, $filter, $modal, $rootScope) { + function PolicyListController($scope, policies, NgTableParams, $filter, $modal, $rootScope) { var list = this; @@ -69,7 +69,7 @@ function newPoliciesTable() { - list.table = new ngTableParams({ + list.table = new NgTableParams({ page: 1, // show first page count: 10, // count per page diff --git a/moonv4/moon_gui/static/app/policy/policy.mapped.list.dir.js b/moonv4/moon_gui/static/app/policy/policy.mapped.list.dir.js index b3becde9..78bb3b8d 100644 --- a/moonv4/moon_gui/static/app/policy/policy.mapped.list.dir.js +++ b/moonv4/moon_gui/static/app/policy/policy.mapped.list.dir.js @@ -61,11 +61,13 @@ */ function loadPolicices(refresh){ + if(_.isUndefined( list.pdp.security_pipeline)){ + return; + } list.policiesId = list.pdp.security_pipeline; policyService.findSomeWithCallback(list.policiesId, function(policies){ - list.policies = policies; list.loadingPolicies = false; @@ -114,10 +116,7 @@ list.table = new NgTableParams({ page: 1, // show first page - count: 10, // count per page - sorting: { - name: 'asc' // initial sorting - } + count: 10 // count per page }, { -- cgit 1.2.3-korg