diff options
author | 2020-06-03 10:06:52 +0200 | |
---|---|---|
committer | 2020-06-03 10:06:52 +0200 | |
commit | 7bb53c64da2dcf88894bfd31503accdd81498f3d (patch) | |
tree | 4310e12366818af27947b5e2c80cb162da93a4b5 /old/moon_gui/static/app/policy/edit/parameter/assignments | |
parent | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff) |
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com>
Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'old/moon_gui/static/app/policy/edit/parameter/assignments')
4 files changed, 1332 insertions, 0 deletions
diff --git a/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-edit.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-edit.tpl.html new file mode 100755 index 00000000..9069dcd0 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-edit.tpl.html @@ -0,0 +1,165 @@ +<div> + + <div class="col-md-12 col-sm-12 col-xs-12"> + + <form ng-if="!edit.fromList" class="form-horizontal" role="form" name="edit.form"> + + <!-- Select Policy --> + <div class="form-group" ng-class="{'has-error': edit.form.policyList.$invalid && edit.form.policyList.$dirty}" > + + <label for="policyList" class="col-sm-3 control-label" data-translate="moon.policy.assignments.edit.policies">Policy List</label> + + <div class="col-sm-6" ng-if="edit.loadingPolicies" > + <moon-loader></moon-loader> + </div> + + <div class="col-sm-6" ng-if="!edit.loadingPolicies" > + + <ui-select ng-model="edit.selectedPolicy" name="policyList" id="policyList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aPolicy in edit.policyList"> + <div ng-value="aPolicy" ng-bind="aPolicy.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.policyList.$dirty && edit.form.policyList.$invalid"> + <small class="error" ng-show="edit.form.policyList.$error.required" data-translate="moon.policy.assignments.edit.check.policy.required">Policy is required</small> + </div> + + </div> + + </div> + + <!-- Select Perimeter --> + <div class="form-group" ng-class="{'has-error': edit.form.perimeterList.$invalid && edit.form.perimeterList.$dirty}" > + + <label for="perimeterList" class="col-sm-3 control-label" data-translate="moon.policy.assignments.edit.perimeters">Perimeter List</label> + + <div class="col-sm-6" ng-if="edit.loadingPerimeters" > + <moon-loader></moon-loader> + </div> + + <div class="col-sm-6" ng-if="!edit.loadingPerimeters" > + + <ui-select ng-model="edit.selectedPerimeter" name="perimeterList" id="perimeterList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aPerimeter in edit.perimeterList"> + <div ng-value="aPerimeter" ng-bind="aPerimeter.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.perimeterList.$dirty && edit.form.perimeterList.$invalid"> + <small class="error" ng-show="edit.form.perimeterList.$error.required" data-translate="moon.policy.assignments.edit.check.perimeter.required">Perimeter is required</small> + </div> + + </div> + + </div> + + <!-- Select Category --> + <div class="form-group" ng-class="{'has-error': edit.form.categoryList.$invalid && edit.form.categoryList.$dirty}" > + + <label for="categoryList" class="col-sm-3 control-label" data-translate="moon.policy.assignments.edit.categories">Category List</label> + + <div class="col-sm-6" ng-if="edit.loadingCategories" > + <moon-loader></moon-loader> + </div> + + <div class="col-sm-6" ng-if="!edit.loadingCategories" > + + <ui-select ng-model="edit.selectedCategory" name="categoryList" id="categoryList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aCategory in edit.categoryList"> + <div ng-value="aCategory" ng-bind="aCategory.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.categoryList.$dirty && edit.form.categoryList.$invalid"> + <small class="error" ng-show="edit.form.categoryList.$error.required" data-translate="moon.policy.assignments.edit.check.category.required">Category is required</small> + </div> + + </div> + + </div> + + <!-- Select Data --> + <div class="form-group" ng-if="edit.selectedCategory" ng-class="{'has-error': edit.form.dataList.$invalid && edit.form.dataList.$dirty}" > + + <label for="dataList" class="col-sm-3 control-label" data-translate="moon.policy.assignments.edit.data">Data List</label> + + <div class="col-sm-6" ng-if="edit.loadingData" > + <moon-loader></moon-loader> + </div> + + <div class="col-sm-4" ng-if="!edit.loadingData" > + + <ui-select ng-model="edit.selectedData" name="dataList" id="dataList"> + + <ui-select-match placeholder="(None)" ng-bind="edit.getName($select.selected)"></ui-select-match> + <ui-select-choices repeat="aData in edit.dataToBeSelected"> + <div ng-value="aData" ng-bind="edit.getName(aData)"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.dataList.$dirty && edit.form.dataList.$invalid || !edit.assignementsAttributeValid"> + <small class="error" ng-show="edit.form.dataList.$error.required || !edit.assignementsAttributeValid" data-translate="moon.policy.assignments.edit.check.data.required">Data is required</small> + </div> + + </div> + + <div class="col-sm-2 text-center"> + <a href="" ng-if="edit.selectedData" + ng-click="edit.addSelectedData()"><span style="font-size:1.5em; line-height: 1.5em;" class="glyphicon glyphicon-plus-sign"></span></a> + </div> + + </div> + + <!-- Selected DataList --> + <div class="form-group" ng-if="!edit.loadingData"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.assignments.edit.selectedData">Selected Data)</label> + + <div class="col-sm-6"> + + <ul> + + <li ng-repeat="(key, value) in edit.selectedDataList"> + + <span ng-bind="edit.getName(value)" ></span> <a href="" ng-click="edit.removeSelectedData(value)"><span style="font-size:1.5em; line-height: 1.5em" class="glyphicon glyphicon-remove"></span></a> + + </li> + + </ul> + + </div> + + </div> + + <div class="form-group"> + + <div class="pull-right"> + + <a href="" ng-disabled="edit.loading" ng-click="edit.create()" class="btn btn-warning"> + <span class="glyphicon glyphicon-save"></span> + <span data-translate="moon.policy.assignments.edit.action.create">Create</span> + </a> + + <moon-loader ng-if="edit.loading"></moon-loader> + + </div> + + </div> + + + </form> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html new file mode 100755 index 00000000..34bbc7a8 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments-list.tpl.html @@ -0,0 +1,335 @@ +<div> + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.subject.title">List of associated Subjects</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.policy.assignments.table.perimeter.name">Perimeter name</th> + <th data-translate="moon.policy.assignments.table.category.name">Category name</th> + <th data-translate="moon.policy.assignments.table.data.name">Data name</th></tr> + </thead> + + <moon-loader ng-if="list.loadingSub"></moon-loader> + + <tbody ng-if="!list.loadingSub && list.getSubjects().length > 0"> + + <tr ng-repeat="(key, value) in list.subjects"> + + <td> + + <div ng-if="!list.getPerimeterFromAssignment(value, list.typeOfSubject)"> + <moon-loader ng-if="!list.getPerimeterFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.perimeter">Loading </em> + </div> + + <div ng-if="list.getPerimeterFromAssignment(value)"> + <span ng-bind="value.perimeter.name"></span> + </div> + + </td> + + <td> + + <div ng-if="!list.getCategoryFromAssignment(value, list.typeOfSubject)"> + <moon-loader ng-if="!list.getCategoryFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromAssignment(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + + <span ng-repeat="(index, id) in value.assignments"> + + <span ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfSubject)"> + <moon-loader ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfSubject)" ></moon-loader> + </span> + + <span ng-if="list.getDataFromAssignmentsIndex(index, value, list.typeOfSubject)"> + <span ng-bind="value.assignments_value[index].data.name"></span> + <a href="" ng-if="!value.loader" ng-click="list.deleteSub(value, value.assignments_value[index].data.id)" > + <span>(</span><span class="glyphicon glyphicon-transfer"></span><span>)</span> + </a> + <span ng-if="index < value.assignments.length-1">, </span> + </span> + + </span> + + </td> + + <td> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + + </tr> + </tbody> + + + <tbody ng-if="!list.loadingSub && list.getSubjects().length === 0"> + <tr> + <td data-translate="moon.policy.assignments.subject.notFound">There is no Subjects</td> + <td></td> + <td></td> + </tr> + </tbody> + + </table> + + </div> + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.subject.add.title">Add a Subject Category</h4> + + </div> + + <div class="panel-body"> + + <moon-assignments-edit policy="list.policy" assignments-type="list.typeOfSubject"></moon-assignments-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.object.title">List associated of Objects</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.policy.assignments.table.perimeter.name">Perimeter name</th> + <th data-translate="moon.policy.assignments.table.category.name">Category name</th> + <th data-translate="moon.policy.assignments.table.data.name">Data name</th> + </tr> + </thead> + + <moon-loader ng-if="list.loadingObj"></moon-loader> + + <tbody ng-if="!list.loadingObj && list.getObjects().length > 0"> + <tr ng-repeat="(key, value) in list.objects"> + <td> + + <div ng-if="!list.getPerimeterFromAssignment(value, list.typeOfObject)"> + <moon-loader ng-if="!list.getPerimeterFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.perimeter">Loading </em> + </div> + + <div ng-if="list.getPerimeterFromAssignment(value)"> + <span ng-bind="value.perimeter.name"></span> + </div> + + </td> + + <td> + + <div ng-if="!list.getCategoryFromAssignment(value, list.typeOfObject)"> + <moon-loader ng-if="!list.getCategoryFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromAssignment(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + <span ng-repeat="(index, id) in value.assignments"> + + <span ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfObject)"> + <moon-loader ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfObject)" ></moon-loader> + </span> + + <span ng-if="list.getDataFromAssignmentsIndex(index, value, list.typeOfObject)"> + + <span ng-if="value.assignments_value[index].data.name" ng-bind="value.assignments_value[index].data.name"></span> + <span ng-if="value.assignments_value[index].data.value.name" ng-bind="value.assignments_value[index].data.value.name"></span> + <a href="" ng-if="!value.loader" ng-click="list.deleteObj(value, value.assignments_value[index].data.id)" > + <span>(</span><span class="glyphicon glyphicon-transfer"></span><span>)</span> + </a> + <span ng-if="index < value.assignments.length-1">, </span> + </span> + + </span> + </td> + + </tr> + </tbody> + + <tbody ng-if="!list.loadingObj && list.getObjects().length === 0"> + <tr> + <td data-translate="moon.policy.assignments.object.notFound">There is no Objects</td> + <td></td> + <td></td> + </tr> + </tbody> + + </table> + + </div> + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.object.add.title">Add an Object Category</h4> + + </div> + + <div class="panel-body"> + + <moon-assignments-edit policy="list.policy" assignments-type="list.typeOfObject"></moon-assignments-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.action.title">List associated of Actions</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive"> + + <table class="table table-striped"> + + <thead> + <tr> + <th data-translate="moon.policy.assignments.table.perimeter.name">Perimeter name</th> + <th data-translate="moon.policy.assignments.table.category.name">Category name</th> + <th data-translate="moon.policy.assignments.table.data.name">Data name</th> + </tr> + </thead> + + <moon-loader ng-if="list.loadingAct"></moon-loader> + + <tbody ng-if="!list.loadingAct && list.getActions().length > 0"> + <tr ng-repeat="(key, value) in list.actions"> + + <td> + <div ng-if="!list.getPerimeterFromAssignment(value, list.typeOfAction)"> + <moon-loader ng-if="!list.getPerimeterFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.perimeter">Loading </em> + </div> + + <div ng-if="list.getPerimeterFromAssignment(value)"> + <span ng-bind="value.perimeter.name"></span> + </div> + </td> + + <td> + + <div ng-if="!list.getCategoryFromAssignment(value, list.typeOfAction)"> + <moon-loader ng-if="!list.getCategoryFromAssignment(value)" ></moon-loader> + <em data-translate="moon.policy.assignments.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromAssignment(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + + <span ng-repeat="(index, id) in value.assignments"> + + <span ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfAction)"> + <moon-loader ng-if="!list.getDataFromAssignmentsIndex(index, value, list.typeOfAction)" ></moon-loader> + </span> + + <span ng-if="list.getDataFromAssignmentsIndex(index, value, list.typeOfAction)"> + <span ng-if="value.assignments_value[index].data.name" ng-bind="value.assignments_value[index].data.name"></span> + <span ng-if="value.assignments_value[index].data.value.name" ng-bind="value.assignments_value[index].data.value.name"></span> + <a href="" ng-if="!value.loader" ng-click="list.deleteAct(value, value.assignments_value[index].data.id)" > + <span>(</span><span class="glyphicon glyphicon-transfer"></span><span>)</span> + </a> + <span ng-if="index < value.assignments.length-1">, </span> + </span> + + </span> + + </td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingAct && list.getActions().length === 0"> + <tr> + <td data-translate="moon.policy.assignments.action.notFound">There is no Actions</td> + <td></td> + <td></td> + </tr> + </tbody> + + </table> + + </div> + + + </div> + + </div> + + <div ng-if="list.editMode" class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.assignments.action.add.title">Add an Action Category</h4> + + </div> + + <div class="panel-body">. + + <moon-assignments-edit policy="list.policy" assignments-type="list.typeOfAction"></moon-assignments-edit> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.edit.dir.js b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.edit.dir.js new file mode 100755 index 00000000..5297eccb --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.edit.dir.js @@ -0,0 +1,439 @@ +(function () { + + 'use strict'; + + angular + .module('moon') + .directive('moonAssignmentsEdit', moonAssignmentsEdit); + + moonAssignmentsEdit.$inject = []; + + function moonAssignmentsEdit() { + + return { + templateUrl: 'html/policy/edit/parameter/assignments/assignments-edit.tpl.html', + bindToController: true, + controller: moonAssignmentsEditController, + controllerAs: 'edit', + scope: { + //Type can be 'ACTION', 'OBJECT', 'SUBJECT' + assignmentsType: '=', + policy: '=' + }, + restrict: 'E', + replace: true + }; + } + + angular + .module('moon') + .controller('moonAssignmentsEditController', moonAssignmentsEditController); + + moonAssignmentsEditController.$inject = ['$scope', 'assignmentsService', 'alertService', '$translate', 'formService', + 'policyService', 'utilService', 'perimeterService', 'ASSIGNMENTS_CST', + 'metaDataService', 'dataService']; + + function moonAssignmentsEditController($scope, assignmentsService, alertService, $translate, formService, + policyService, utilService, perimeterService, ASSIGNMENTS_CST, + metaDataService, dataService ) { + + var edit = this; + + edit.assignmentsType = $scope.edit.assignmentsType; + edit.policy = $scope.edit.policy; + + edit.laoading = false; + + edit.form = {}; + + edit.policyList = []; + edit.loadingPolicies = true; + + edit.categoryList = []; + edit.loadingCategories = true; + + edit.perimeterList = []; + edit.loadingPerimeters = true; + + edit.dataList = []; + edit.dataToBeSelected = []; + edit.selectedDataList = []; + edit.loadingData = true; + + edit.assignementsAttributeValid = true; + + edit.addSelectedData = addSelectedData; + edit.removeSelectedData = removeSelectedData; + edit.getName = getName; + edit.create = createAssignments; + + activate(); + + /* + * + */ + + function activate() { + + edit.assignments = {id: null, category_id: null, data_id: null, policy_id: null}; + + loadAllPolicies(); + loadAllCategories(); + + } + + function createAssignments() { + + edit.assignementsAttributeValid = true; + + manageSelectedDataListy(); + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + }else if(edit.assignementsAttributeValid){ + + startLoading(); + + var throwEvent = false; + edit.assignments.id = edit.selectedPerimeter.id; + edit.assignments.category_id = edit.selectedCategory.id; + edit.assignments.policy_id = edit.selectedPolicy.id; + + var selectedDataListTemp = angular.copy(edit.selectedDataList); + + _.each(selectedDataListTemp, function(elem){ + + edit.assignments.data_id = elem.id; + + var assignmentsToSend = angular.copy(edit.assignments); + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + assignmentsService.subject.add(assignmentsToSend, edit.policy.id, createSuccess, createError); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + assignmentsService.object.add(assignmentsToSend, edit.policy.id, createSuccess, createError); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + assignmentsService.action.add(assignmentsToSend, edit.policy.id, createSuccess, createError); + break; + + default : + + break; + + } + + }); + + throwEvent = true; + + } + + function createSuccess(data) { + + var created = {}; + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + created = utilService.transformOne(data, 'subject_assignments'); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + created = utilService.transformOne(data, 'object_assignments'); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + created = utilService.transformOne(data, 'action_assignments'); + break; + + default: + + break; + + } + + $translate('moon.policy.assignments.edit.create.success').then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + if(throwEvent && created.policy_id === edit.policy.id){ + + $scope.$emit('event:createAssignmentsFromAssignmentsEditSuccess', edit.assignmentsType); + + activate(); + + stopLoading(); + + }else if(throwEvent){ + + activate(); + + stopLoading(); + + } + + } + + function createError(reason) { + + $translate('moon.policy.rules.edit.action.add.create.error').then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + $scope.$watch('edit.selectedPolicy', function(newValue){ + + if(!_.isUndefined(newValue)){ + + loadRelatedPerimeters(); + + } + + }); + + + $scope.$watch('edit.selectedCategory', function(newValue){ + + clearSelectedCategories(); + + if(!_.isUndefined(newValue)){ + + loadRelatedData(newValue.id); + + } + + }); + + function loadAllPolicies() { + + edit.policyList = []; + edit.loadingPolicies = true; + + policyService.findAllWithCallback( function(data) { + + _.each(data, function(element){ + + if(element.id === edit.policy.id){ + edit.selectedPolicy = element; + } + + }); + + edit.policyList = data; + edit.loadingPolicies = false; + + }); + } + + function loadRelatedPerimeters(){ + + edit.perimeterList = []; + edit.loadingPerimeters = true; + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + perimeterService.subject.findAllFromPolicyWithCallback(edit.selectedPolicy.id, callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + perimeterService.object.findAllFromPolicyWithCallback(edit.selectedPolicy.id,callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + perimeterService.action.findAllFromPolicyWithCallback(edit.selectedPolicy.id, callBackList); + break; + + default : + + edit.perimeterList = []; + edit.loadingPerimeters = false; + break; + + } + + function callBackList(list){ + + edit.perimeterList = list; + + edit.loadingPerimeters = false; + + } + } + + function loadAllCategories(){ + + edit.categoryList = []; + edit.loadingCategories = true; + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + metaDataService.subject.findAllWithCallback(callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + metaDataService.object.findAllWithCallback(callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + metaDataService.action.findAllWithCallback(callBackList); + break; + + default : + + edit.categoryList = []; + edit.loadingCategories = false; + break; + + } + + function callBackList(list){ + + edit.categoryList = list; + edit.loadingCategories = false; + + } + } + + function loadRelatedData(categoryId){ + + edit.dataList = []; + edit.dataToBeSelected = []; + edit.selectedDataList = []; + edit.loadingData = true; + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + dataService.subject.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, categoryId, callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + dataService.object.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, categoryId, callBackList); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + dataService.action.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, categoryId, callBackList); + break; + + default : + + edit.loadingData = false; + break; + + } + + function callBackList(list){ + + edit.dataList = list; + edit.dataToBeSelected = angular.copy(edit.dataList); + edit.selectedDataList = []; + edit.loadingData = false; + + } + + } + + function addSelectedData(){ + + edit.dataToBeSelected = _.without(edit.dataToBeSelected, edit.selectedData); + edit.selectedDataList.push(edit.selectedData); + clearSelectedCategories(); + + } + + function removeSelectedData(data){ + + edit.dataToBeSelected.push(data); + edit.selectedDataList = _.without(edit.selectedDataList, data); + + } + + function clearSelectedCategories(){ + + edit.selectedData = undefined; + + } + + function getName(assignment){ + + if(_.isUndefined(assignment)) return '(None)'; + + switch(edit.assignmentsType){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + return assignment.name; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + return assignment.value.name; + + + case ASSIGNMENTS_CST.TYPE.ACTION: + + return assignment.value.name; + + default : + + return assignment.name; + + } + + } + + function manageSelectedDataListy(){ + + if (edit.selectedDataList.length >= 1 ){ + + edit.assignementsAttributeValid = true; + + }else{ + + edit.assignementsAttributeValid = false; + + } + } + + function startLoading(){ + + edit.loading = true; + + } + + function stopLoading(){ + + edit.loading = false; + + } + } + +})();
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js new file mode 100755 index 00000000..22931e4d --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/assignments/assignments.list.dir.js @@ -0,0 +1,393 @@ +(function () { + + 'use strict'; + + angular + .module('moon') + .directive('moonAssignmentsList', moonAssignmentsList); + + moonAssignmentsList.$inject = []; + + function moonAssignmentsList() { + + return { + templateUrl: 'html/policy/edit/parameter/assignments/assignments-list.tpl.html', + bindToController: true, + controller: moonAssignmentsListController, + controllerAs: 'list', + scope: { + policy: '=', + editMode: '=' + }, + restrict: 'E', + replace: true + }; + } + + angular + .module('moon') + .controller('moonAssignmentsListController', moonAssignmentsListController); + + moonAssignmentsListController.$inject = ['$scope', '$rootScope', 'assignmentsService', '$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; + + list.policy = $scope.list.policy; + list.editMode = $scope.list.editMode; + + list.typeOfSubject = ASSIGNMENTS_CST.TYPE.SUBJECT; + list.typeOfObject = ASSIGNMENTS_CST.TYPE.OBJECT; + list.typeOfAction = ASSIGNMENTS_CST.TYPE.ACTION; + + list.deleteSub = deleteSub; + list.deleteObj = deleteObj; + list.deleteAct = deleteAct; + + list.getSubjects = getSubjects; + list.getObjects = getObjects; + list.getActions = getActions; + + list.getCategoryFromAssignment = getCategoryFromAssignment; + list.getPerimeterFromAssignment = getPerimeterFromAssignment; + list.getDataFromAssignmentsIndex = getDataFromAssignmentsIndex; + + activate(); + + function activate() { + + manageSubjects(); + + manageObjects(); + + manageActions(); + + } + + var rootListeners = { + + 'event:createAssignmentsFromAssignmentsEditSuccess': $rootScope.$on('event:createAssignmentsFromAssignmentsEditSuccess', updateList) + + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); + + function manageSubjects() { + + list.loadingSub = true; + + assignmentsService.subject.findAllFromPolicyWithCallback(list.policy.id, function (data) { + + list.subjects = data; + list.loadingSub = false; + + }); + } + + function manageObjects() { + + list.loadingObj = true; + + assignmentsService.object.findAllFromPolicyWithCallback(list.policy.id, function (data) { + + list.objects = data; + list.loadingObj = false; + + }); + + } + + function manageActions() { + + list.loadingAct = true; + + assignmentsService.action.findAllFromPolicyWithCallback(list.policy.id, function (data) { + + list.actions = data; + list.loadingAct = false; + + }); + + } + + function getPerimeterFromAssignment(assignment, type) { + + if (_.has(assignment, 'perimeter')) { + return assignment.perimeter; + } + + // if the call has not been made + if (!_.has(assignment, 'callPerimeterInProgress')) { + + assignment.callPerimeterInProgress = true; + + switch (type) { + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + perimeterService.subject.findOneFromPolicyWithCallback(list.policy.id, assignment.subject_id, setPerimeterToAssignment); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + perimeterService.object.findOneFromPolicyWithCallback(list.policy.id, assignment.object_id, setPerimeterToAssignment); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + perimeterService.action.findOneFromPolicyWithCallback(list.policy.id, assignment.action_id, setPerimeterToAssignment); + break; + + } + + } + + // if the call is in progress return false + return false; + + function setPerimeterToAssignment(perimeter) { + + assignment.callPerimeterInProgress = false; + assignment.perimeter = perimeter; + + } + } + + function getCategoryFromAssignment(data, type) { + + if (_.has(data, 'category')) { + return data.category; + } + + // if the call has not been made + if (!_.has(data, 'callCategoryInProgress')) { + + data.callCategoryInProgress = true; + + switch (type) { + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + metaDataService.subject.findOne(data.subject_cat_id, setCategoryToData); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + metaDataService.object.findOne(data.object_cat_id, setCategoryToData); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + metaDataService.action.findOne(data.action_cat_id, setCategoryToData); + break; + + } + + } + + // if the call is in progress return false + return false; + + function setCategoryToData(category) { + + data.callCategoryInProgress = false; + data.category = category; + + } + } + + /** + * @param index + * @param assignment + * @param type + */ + function getDataFromAssignmentsIndex(index, assignment, type) { + + 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 () { + return { + data: {} + }; + }); + } + + 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')) { + + assignment.assignments_value[index].callDataInProgress = true; + + switch (type) { + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + dataService.subject.data.findOne(list.policy.id, assignment.category_id, assignment.assignments[index], setDataToAssignment); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + dataService.object.data.findOne(list.policy.id, assignment.category_id, assignment.assignments[index], setDataToAssignment); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + dataService.action.data.findOne(list.policy.id, assignment.category_id, assignment.assignments[index], setDataToAssignment); + break; + + } + + } + + // if the call is in progress return false + return false; + + function setDataToAssignment(data) { + + assignment.assignments_value[index].callDataInProgress = false; + assignment.assignments_value[index].data = data; + + } + } + + /** + * Delete + */ + + function deleteSub(subject, dataId) { + + subject.loader = true; + + assignmentsService.subject.delete(list.policy.id, subject.subject_id, subject.subject_cat_id, dataId, deleteSubSuccess, deleteSubError); + + function deleteSubSuccess(data) { + + $translate('moon.policy.assignments.subject.delete.success').then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + manageSubjects(); + + subject.loader = false; + + } + + function deleteSubError(reason) { + + $translate('moon.policy.assignments.subject.delete.error', { + subjectName: subject.name, + reason: reason.message + }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + subject.loader = false; + + } + } + + function deleteObj(object, dataId) { + + object.loader = true; + + assignmentsService.object.delete(list.policy.id, object.object_id, object.object_cat_id, dataId, deleteObjSuccess, deleteObjError); + + function deleteObjSuccess(data) { + + $translate('moon.policy.assignments.object.delete.success').then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + manageObjects(); + + object.loader = false; + + } + + function deleteObjError(reason) { + + $translate('moon.policy.assignments.object.delete.error', { + objectName: object.name, + reason: reason.message + }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + object.loader = false; + } + } + + function deleteAct(action, dataId) { + + action.loader = true; + + assignmentsService.action.delete(list.policy.id, action.action_id, action.action_cat_id, dataId, deleteActSuccess, deleteActError); + + function deleteActSuccess(data) { + + $translate('moon.policy.assignments.action.delete.success').then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + manageActions(); + + action.loader = false; + + } + + function deleteActError(reason) { + + $translate('moon.policy.assignments.action.delete.error', { + actionName: action.name, + reason: reason.message + }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + action.loader = false; + + } + } + + function getSubjects() { + return list.subjects ? list.subjects : []; + } + + function getObjects() { + return list.objects ? list.objects : []; + } + + function getActions() { + return list.actions ? list.actions : []; + } + + function updateList(event, type) { + + switch(type){ + + case ASSIGNMENTS_CST.TYPE.SUBJECT: + + manageSubjects(); + break; + + case ASSIGNMENTS_CST.TYPE.OBJECT: + + manageObjects(); + break; + + case ASSIGNMENTS_CST.TYPE.ACTION: + + manageActions(); + break; + + default : + + activate(); + break; + + } + + } + + } + +})();
\ No newline at end of file |