diff options
Diffstat (limited to 'old/moon_gui/static/app/policy')
32 files changed, 6518 insertions, 0 deletions
diff --git a/old/moon_gui/static/app/policy/action/mapping/policy-map.tpl.html b/old/moon_gui/static/app/policy/action/mapping/policy-map.tpl.html new file mode 100755 index 00000000..8b787f14 --- /dev/null +++ b/old/moon_gui/static/app/policy/action/mapping/policy-map.tpl.html @@ -0,0 +1,64 @@ +<div ng-controller="PolicyMapController as map" class="modal" tabindex="-1" data-role="modalMappingPolicy"> + + <div class="modal-dialog"> + + <div class="modal-content"> + + <div class="modal-header"> + <button type="button" class="close" ng-click="$hide()">×</button> + <h4 class="modal-title" data-translate="moon.policy.map.title" data-translate-values="{ pdpName: map.pdp.name}"></h4> + </div> + + <div class="modal-body"> + + <form class="form-horizontal" role="form" name="map.form"> + + <div class="form-group" ng-class="{'has-error': map.form.policy.$dirty && (map.form.policy.$invalid || !map.selectedPolicy)}"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.map.form.list">List of Policies</label> + + <div class="col-sm-6"> + + <ui-select ng-model="map.selectedPolicy" name="policy" required> + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="policy in map.policies"> + <div ng-bind="policy.name" ng-value="policy"></div> + </ui-select-choices> + </ui-select> + + <moon-loader ng-if="map.policiesLoading"></moon-loader> + + <div class="help-block" ng-show="map.form.policy.$dirty && (map.form.policy.$invalid || !map.selectedPolicy)"> + <small class="error" ng-show="map.form.policy.$error.required" data-translate="moon.policy.map.check.policy.required">Policy is required</small> + </div> + + </div> + + </div> + + </form> + + </div> + + <div class="modal-footer"> + <div class="btn-toolbar" style="float: right;"> + + <a href="" ng-click="$hide()" class="btn btn-default"> + <span data-translate="moon.policy.map.action.cancel">Cancel</span> + </a> + + <a href="" ng-disabled="map.mappingLoading" ng-click="map.map()" class="btn btn-warning"> + <span class="glyphicon glyphicon-link"></span> + <span data-translate="moon.policy.map.action.map">Map</span> + </a> + + <moon-loader ng-if="map.mappingLoading"></moon-loader> + + </div> + </div> + + </div> + + </div> + +</div> diff --git a/old/moon_gui/static/app/policy/action/mapping/policy-unmap.tpl.html b/old/moon_gui/static/app/policy/action/mapping/policy-unmap.tpl.html new file mode 100755 index 00000000..a2cda52a --- /dev/null +++ b/old/moon_gui/static/app/policy/action/mapping/policy-unmap.tpl.html @@ -0,0 +1,33 @@ +<div ng-controller="PolicyUnMapController as unmap" class="modal" tabindex="-1" data-role="modalUnmapPolicy"> + + <div class="modal-dialog"> + + <div class="modal-content"> + + <div class="modal-header"> + <button type="button" class="close" ng-click="$hide()">×</button> + <h4 class="modal-title" data-translate="moon.policy.unmap.title"></h4> + </div> + + <div class="modal-body"> + <span data-translate="moon.policy.unmap.content" data-translate-values="{ policyName: unmap.policy.name, pdpName: unmap.pdp.name }"></span> + </div> + + <div class="modal-footer"> + <div class="btn-toolbar" style="float: right;"> + <a href="" ng-click="$hide()" class="btn btn-default"> + <span data-translate="moon.policy.unmap.action.cancel">Cancel</span> + </a> + <a href="" ng-disabled="unmap.unMappingLoading" ng-click="unmap.unmap()" class="btn btn-warning"> + <span class="glyphicon glyphicon-transfer"></span> + <span data-translate="moon.policy.unmap.action.unmap">Unmap</span> + </a> + <moon-loader ng-if="unmap.unMappingLoading"></moon-loader> + </div> + </div> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/action/mapping/policy.controller.map.js b/old/moon_gui/static/app/policy/action/mapping/policy.controller.map.js new file mode 100755 index 00000000..6ad8caa7 --- /dev/null +++ b/old/moon_gui/static/app/policy/action/mapping/policy.controller.map.js @@ -0,0 +1,106 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyMapController', PolicyMapController); + + PolicyMapController.$inject = ['$scope', 'alertService', '$translate', 'formService', 'policyService', 'pdpService', 'utilService']; + + function PolicyMapController($scope, alertService, $translate, formService, policyService, pdpService, utilService ) { + + var map = this; + + /* + * + */ + + map.pdps = []; + + map.pdp = $scope.pdp; + + map.addPolicyToList = false; + + map.map = mapToPdp; + + activate(); + + function activate() { + + resolvePolicies(); + + } + + function resolvePolicies() { + + map.policiesLoading = true; + + policyService.findAllWithCallback(function(policies){ + map.policies = policies; + map.policiesLoading = false; + } + ); + + } + + function mapToPdp() { + + if (formService.isInvalid(map.form)) { + + formService.checkFieldsValidity(map.form); + + } else { + + map.mappingLoading = true; + + var pdpToSend = angular.copy(map.pdp); + + pdpToSend.security_pipeline.push(map.selectedPolicy.id); + + pdpService.update(pdpToSend, mapSuccess, mapError); + + } + + function mapSuccess(data) { + + var pdpReceived = utilService.transformOne(data, 'pdps'); + + + $translate('moon.policy.map.success', {pdpName: pdpReceived.name, policyName: map.selectedPolicy.name}).then(function (translatedValue) { + + alertService.alertSuccess(translatedValue); + + }); + + map.mappingLoading = false; + + $scope.$emit('event:policyMapToPdpSuccess', pdpReceived); + + } + + function mapError(response) { + + $translate('moon.policy.map.error', { + + pdpName: map.pdp.name, + policyName: map.selectedPolicy.name + + }).then(function (translatedValue) { + + alertService.alertError(translatedValue); + + }); + + map.mappingLoading = false; + + $scope.$emit('event:policyMapToPdpError'); + + } + } + + + + } + +})();
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/action/mapping/policy.controller.unmap.js b/old/moon_gui/static/app/policy/action/mapping/policy.controller.unmap.js new file mode 100755 index 00000000..d309ec0f --- /dev/null +++ b/old/moon_gui/static/app/policy/action/mapping/policy.controller.unmap.js @@ -0,0 +1,74 @@ +/** + * @author arnaud marhin<arnaud.marhin@orange.com> + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyUnMapController', PolicyUnMapController); + + PolicyUnMapController.$inject = ['$scope', '$translate', 'alertService', 'pdpService', 'utilService']; + + function PolicyUnMapController($scope, $translate, alertService, pdpService, utilService) { + + var unmap = this; + + /* + * + */ + + unmap.pdp = $scope.pdp; + unmap.policy = $scope.policy; + + unmap.unMappingLoading = false; + + unmap.unmap = unMapPolicyToPdp; + + /* + * + */ + + function unMapPolicyToPdp() { + + unmap.unMappingLoading = true; + + var pdpToUpdate = angular.copy(unmap.pdp); + + pdpToUpdate.security_pipeline = _.without(pdpToUpdate.security_pipeline, unmap.policy.id); + + pdpService.update(pdpToUpdate, unMapSuccess, unMapError); + + function unMapSuccess(data) { + + $translate('moon.policy.unmap.success', { pdpName: unmap.pdp.name, policyName: unmap.policy.name }) + .then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + unmap.unMappingLoading = false; + + $scope.$emit('event:policyUnMappedToPdpSuccess', utilService.transformOne(data, 'pdps')); + + } + + function unMapError(reason) { + + $translate('moon.policy.unmap.error', { pdpName: unmap.pdp.name, policyName: unmap.policy.name }) + .then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + unmap.unMappingLoading = false; + + $scope.$emit('event:policyUnMappedToPdpError'); + + } + + } + + } + +})(); diff --git a/old/moon_gui/static/app/policy/action/policy-add.tpl.html b/old/moon_gui/static/app/policy/action/policy-add.tpl.html new file mode 100755 index 00000000..d20c41be --- /dev/null +++ b/old/moon_gui/static/app/policy/action/policy-add.tpl.html @@ -0,0 +1,113 @@ +<div ng-controller="PolicyAddController as add" class="modal" tabindex="-1" data-role="modalAddPolicy"> + + <div class="modal-dialog"> + + <div class="modal-content"> + + <div class="modal-header"> + <button type="button" class="close" ng-click="$hide()">×</button> + <h4 class="modal-title" data-translate="moon.policy.add.title"></h4> + </div> + + <div class="modal-body"> + + <form class="form-horizontal" role="form" name="add.form"> + + <div class="form-group" ng-class="{'has-error': add.form.name.$invalid && add.form.name.$dirty}"> + + <label for="name" class="col-sm-3 control-label" data-translate="moon.policy.add.form.name">Name</label> + + <div class="col-sm-6"> + + <input name="name" id="name" class="form-control" type="text" data-ng-model="add.policy.name" required /> + + <div class="help-block" ng-show="add.form.name.$dirty && add.form.name.$invalid"> + <small class="error" ng-show="add.form.name.$error.required" data-translate="moon.policy.add.check.name.required">Name is required</small> + </div> + + </div> + + </div> + + + <div class="form-group" ng-class="{'has-error': add.form.genre.$dirty && (add.form.genre.$invalid || !add.selectedGenre)}"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.add.form.genre">Genre</label> + + <div class="col-sm-6"> + + <ui-select ng-model="add.selectedGenre" name="genre" required> + <ui-select-match placeholder="(None)">{{$select.selected}}</ui-select-match> + <ui-select-choices repeat="genre in add.genres"> + <div ng-value="genre">{{genre}}</div> + </ui-select-choices> + </ui-select> + + <div class="help-block" ng-show="add.form.genre.$dirty && (add.form.genre.$invalid || !add.selectedPolicy)"> + <small class="error" ng-show="add.form.genre.$error.required" data-translate="moon.policy.add.check.genre.required">Genre is required</small> + </div> + + </div> + + </div> + + <div class="form-group" ng-class="{'has-error': add.form.model.$dirty && (add.form.model.$invalid || !add.selectedModel)}"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.add.form.model">Models</label> + + <div class="col-sm-6"> + + <ui-select ng-model="add.selectedModel" name="model" required> + <ui-select-match placeholder="(None)">{{$select.selected.name}}</ui-select-match> + <ui-select-choices repeat="model in add.models"> + <div ng-value="model">{{model.name}}</div> + </ui-select-choices> + </ui-select> + + <moon-loader ng-if="add.modelsLoading"></moon-loader> + + <div class="help-block" ng-show="add.form.model.$dirty && (add.form.model.$invalid || !add.selectedModel)"> + <small class="error" ng-show="add.form.model.$error.required" data-translate="moon.policy.add.check.model.required">Model is required</small> + </div> + + </div> + + </div> + + + <div class="form-group"> + + <label for="description" class="col-sm-3 control-label" data-translate="moon.policy.add.form.description">Description</label> + <div class="col-sm-6"> + <textarea id="description" name="description" class="form-control" data-ng-model="add.policy.description"></textarea> + </div> + + </div> + + </form> + + </div> + + <div class="modal-footer"> + + <div class="btn-toolbar" style="float: right;"> + + <a href="" ng-click="$hide()" class="btn btn-default"> + <span data-translate="moon.policy.add.action.cancel">Cancel</span> + </a> + + <a href="" ng-disabled="add.loading" ng-click="add.create()" class="btn btn-warning"> + <span class="glyphicon glyphicon-save"></span> + <span data-translate="moon.policy.add.action.create">Create Policy</span> + </a> + <moon-loader ng-if="add.loading"></moon-loader> + + </div> + + </div> + + </div> + + </div> + +</div> diff --git a/old/moon_gui/static/app/policy/action/policy-delete.tpl.html b/old/moon_gui/static/app/policy/action/policy-delete.tpl.html new file mode 100755 index 00000000..3b5df88b --- /dev/null +++ b/old/moon_gui/static/app/policy/action/policy-delete.tpl.html @@ -0,0 +1,40 @@ +<div ng-controller="PolicyDeleteController as del" class="modal" tabindex="-1" data-role="modalDeletePolicy"> + + <div class="modal-dialog"> + + <div class="modal-content"> + + <div class="modal-header"> + <button type="button" class="close" ng-click="$hide()">×</button> + <h4 class="modal-title" data-translate="moon.policy.remove.title"></h4> + </div> + + <div class="modal-body"> + <p><span data-translate="moon.policy.remove.content.query" data-translate-values="{ policyName: del.policy.name }"></span></p> + + </div> + + <div class="modal-footer"> + + <div class="btn-toolbar" style="float: right;"> + + <a href="" ng-click="$hide()" class="btn btn-default"> + <span data-translate="moon.policy.remove.action.cancel">Cancel</span> + </a> + + <a href="" ng-disabled="del.loading" ng-click="del.remove()" class="btn btn-warning"> + <span class="glyphicon glyphicon-trash"></span> + <span data-translate="moon.policy.remove.action.delete">Delete</span> + </a> + + <moon-loader ng-if="del.loading" ></moon-loader> + + </div> + + </div> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/action/policy.controller.add.js b/old/moon_gui/static/app/policy/action/policy.controller.add.js new file mode 100755 index 00000000..0320c2e9 --- /dev/null +++ b/old/moon_gui/static/app/policy/action/policy.controller.add.js @@ -0,0 +1,113 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyAddController', PolicyAddController); + + PolicyAddController.$inject = ['$scope', '$translate', 'alertService', 'formService', 'policyService', 'utilService', 'modelService']; + + function PolicyAddController($scope, $translate, alertService, formService, policyService, utilService, modelService) { + + var add = this; + + /* + * + */ + + add.loading = false; + + add.form = {}; + + add.policy = {name: null, genre: null, description: null, model_id: null}; + + add.genres = ['admin', 'authz']; + + add.models = []; + + add.modelsLoading = true; + + add.create = createPolicy; + + + activate(); + + function activate(){ + + resolveModels(); + + } + + /* + * + */ + + function resolveModels() { + + modelService.findAllWithCallBack(resolveModelsCallback); + + } + + function resolveModelsCallback(models) { + + add.models = models; + + add.modelsLoading = false; + + } + + + function createPolicy() { + + if(formService.isInvalid(add.form)) { + + formService.checkFieldsValidity(add.form); + + } else { + + + add.loading = true; + + policyService.data.policy.create({}, { + + name: add.policy.name, + description: add.policy.description, + genre: [add.selectedGenre], + model_id: add.selectedModel.id + + }, createSuccess, createError); + + } + + function createSuccess(data) { + + var createdPolicy = utilService.transformOne(data, 'policies'); + + $translate('moon.policy.add.success', { policyName: createdPolicy.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + add.loading = false; + + $scope.$emit('event:policyCreatedSuccess', createdPolicy); + + } + + function createError(reason) { + + $translate('moon.policy.add.error', { policyName: add.model.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + add.loading = false; + + $scope.$emit('event:policyCreatedError', add.project); + + } + + } + + } + +})(); diff --git a/old/moon_gui/static/app/policy/action/policy.controller.delete.js b/old/moon_gui/static/app/policy/action/policy.controller.delete.js new file mode 100755 index 00000000..9a718ddc --- /dev/null +++ b/old/moon_gui/static/app/policy/action/policy.controller.delete.js @@ -0,0 +1,69 @@ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyDeleteController', PolicyDeleteController); + + PolicyDeleteController.$inject = ['$scope', '$translate', 'alertService', 'policyService']; + + function PolicyDeleteController($scope, $translate, alertService, policyService) { + + var del = this; + + /* + * + */ + + del.policy = $scope.policy; + del.loading = false; + + del.remove = deletePolicy; + + activate(); + + /** + * + */ + + function activate(){ + + } + + + function deletePolicy(){ + + del.loading = true; + + policyService.delete(del.policy, deleteSuccess, deleteError); + + function deleteSuccess(data) { + + $translate('moon.policy.remove.success', { policyName: del.policy.name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + del.loading = false; + + $scope.$emit('event:policyDeletedSuccess', del.policy); + + } + + function deleteError(reason) { + + $translate('moon.policy.remove.error', { policyName: del.policy.name, errorCode: reason.data.error.code, message : reason.data.error.message } ).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + del.loading = false; + + $scope.$emit('event:policyDeletedError', del.policy); + + } + + } + } + +})(); 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 diff --git a/old/moon_gui/static/app/policy/edit/parameter/data/data-edit.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/data/data-edit.tpl.html new file mode 100755 index 00000000..fae647e3 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/data/data-edit.tpl.html @@ -0,0 +1,83 @@ +<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"> + + <div class="form-group" ng-class="{'has-error': edit.form.name.$invalid && edit.form.name.$dirty}"> + + <label for="name" class="col-sm-3 control-label" + data-translate="moon.policy.data.edit.name">Name</label> + + <div class="col-sm-6"> + + <input name="name" id="name" class="form-control" type="text" data-ng-model="edit.data.name" + required/> + + <div class="help-block" ng-show="edit.form.name.$dirty && edit.form.name.$invalid"> + <small class="error" ng-show="edit.form.name.$error.required" + data-translate="moon.policy.data.edit.check.name.required">Name is required + </small> + </div> + + </div> + + </div> + + <div class="form-group"> + + <label for="description" class="col-sm-3 control-label" + data-translate="moon.policy.data.edit.description">Description</label> + <div class="col-sm-6"> + <textarea id="description" name="description" class="form-control" + data-ng-model="edit.data.description"></textarea> + </div> + + </div> + + <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.data.edit.categories">Category List </label> + + <div class="col-sm-6"> + + <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.categoriesToBeSelected"> + <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.data.edit.check.category.required">Category is required + </small> + </div> + + </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.data.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/data/data-list.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html new file mode 100755 index 00000000..b69a4eed --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/data/data-list.tpl.html @@ -0,0 +1,390 @@ +<div> + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.data.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.data.table.name">Name</th> + <th data-translate="moon.policy.data.table.description">Description</th> + <th data-translate="moon.policy.data.table.category.name">Category</th> + <th data-translate="moon.policy.data.table.action.title"></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 ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td> + + <div ng-if="!list.getCategoryFromData(value, list.typeOfSubject)"> + <moon-loader ng-if="!list.getCategoryFromData(value)" ></moon-loader> + <em data-translate="moon.policy.list.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromData(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + + <a href="" ng-if="!value.loader" ng-click="list.deleteSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + + + <!--<td> + + <div class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.policy.data.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metarules.action.unmap">Unmap</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteSub(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td>--> + + </tr> + </tbody> + + + <tbody ng-if="!list.loadingSub && list.getSubjects().length === 0"> + <tr> + <td colspan="4" data-translate="moon.policy.data.subject.notFound">There is no Subjects</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.data.subject.add.title">Add a Subject Category</h4> + + </div> + + <div class="panel-body"> + + <moon-data-edit policy="list.policy" mn-data-type="list.typeOfSubject"></moon-data-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.data.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.data.table.name">Name</th> + <th data-translate="moon.policy.data.table.description">Description</th> + <th data-translate="moon.policy.data.table.category.name">Category</th> + <th data-translate="moon.policy.data.table.action.title">Actions</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 ng-bind="value.value.name"></td> + <td ng-bind="value.value.description"></td> + <td> + + <div ng-if="!list.getCategoryFromData(value, list.typeOfObject)"> + <moon-loader ng-if="!list.getCategoryFromData(value)" ></moon-loader> + <em data-translate="moon.policy.list.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromData(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + + <a href="" ng-if="!value.loader" ng-click="list.deleteObj(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + <!--<td> + + <div class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.policy.data.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapObj(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metarules.action.unmap">Unmap</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteObj(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + </tr>--> + </tbody> + + <tbody ng-if="!list.loadingObj && list.getObjects().length === 0"> + <tr> + + <td colspan="4" data-translate="moon.policy.data.object.notFound">There is no Objects</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.data.object.add.title">Add an Object Category</h4> + + </div> + + <div class="panel-body"> + + <moon-data-edit policy="list.policy" mn-data-type="list.typeOfObject"></moon-data-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.data.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.data.table.name">Name</th> + <th data-translate="moon.policy.data.table.description">Description</th> + <th data-translate="moon.policy.data.table.category.name">Category</th> + <th data-translate="moon.policy.data.table.action.title">Actions</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 ng-bind="value.value.name"></td> + <td ng-bind="value.value.description"></td> + <td> + + <div ng-if="!list.getCategoryFromData(value, list.typeOfAction)"> + <moon-loader ng-if="!list.getCategoryFromData(value)" ></moon-loader> + <em data-translate="moon.policy.list.table.loading.category">Loading </em> + </div> + + <div ng-if="list.getCategoryFromData(value)"> + <span ng-bind="value.category.name"></span> + </div> + + </td> + + <td> + + <a href="" ng-if="!value.loader" ng-click="list.deleteSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + <!--<td> + + <div class="dropdown"> + + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.policy.data.table.action.title">Actions</span> + <span class="caret"></span> + </button> + + <ul class="dropdown-menu"> + + <li> + <a href="" ng-click="list.unMapAct(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.model.metarules.action.unmap">Unmap</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.deleteAct(value)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.policy.data.table.action.delete">Delete</span> + </a> + </li> + + </ul> + + </div> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td>--> + </tr> + </tbody> + + <tbody ng-if="!list.loadingAct && list.getActions().length === 0"> + <tr> + <td colspan="4" data-translate="moon.policy.data.action.notFound">There is no Actions</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.data.action.add.title">Add an Action Category</h4> + + </div> + + <div class="panel-body">. + + <moon-data-edit policy="list.policy" mn-data-type="list.typeOfAction"></moon-data-edit> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/data/data.edit.dir.js b/old/moon_gui/static/app/policy/edit/parameter/data/data.edit.dir.js new file mode 100755 index 00000000..2ae08177 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/data/data.edit.dir.js @@ -0,0 +1,258 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonDataEdit', moonDataEdit); + + moonDataEdit.$inject = []; + + function moonDataEdit() { + + return { + templateUrl : 'html/policy/edit/parameter/data/data-edit.tpl.html', + bindToController : true, + controller : moonDataEditController, + controllerAs : 'edit', + scope : { + //Type can be 'ACTION', 'OBJECT', 'SUBJECT' + mnDataType: '=', + policy : '=' + }, + restrict : 'E', + replace : true + }; + + } + + angular + .module('moon') + .controller('moonDataEditController', moonDataEditController); + + moonDataEditController.$inject = ['$scope', 'dataService', 'DATA_CST', 'alertService', '$translate', + 'formService', 'policyService', 'utilService', 'metaDataService', 'modelService', 'metaRuleService']; + + function moonDataEditController($scope, dataService, DATA_CST, alertService, $translate, + formService, policyService, utilService, metaDataService, modelService, metaRuleService) { + + var edit = this; + + edit.dataType = $scope.edit.mnDataType; + edit.policy = $scope.edit.policy; + + edit.fromList = false; + + edit.loading = false; + + edit.form = {}; + + edit.data = { name: null, description: null}; + + edit.list = []; + edit.categoriesToBeSelected = []; + + edit.create = createData; + + activate(); + + /* + * + */ + + function activate(){ + + loadAllCategories(); + + switch(edit.dataType){ + + case DATA_CST.TYPE.SUBJECT: + + dataService.subject.findAllFromPolicyWithCallback(edit.policy.id, callBackList); + break; + + case DATA_CST.TYPE.OBJECT: + + dataService.object.findAllFromPolicyWithCallback(edit.policy.id, callBackList); + break; + + case DATA_CST.TYPE.ACTION: + + dataService.action.findAllFromPolicyWithCallback(edit.policy.id, callBackList); + break; + + default : + + edit.list = []; + break; + + } + + function callBackList(list){ + + // For each Data, there is a check about the mapping between the Data and the policy + _.each(list, function (element) { + if (element.policy_id !== edit.policy.id) { + + edit.list.push(element); + + } + }); + + } + + } + + + function loadAllCategories(){ + + modelService.findOneWithCallback(edit.policy.model_id, function(model){ + + metaRuleService.findSomeWithCallback(model.meta_rules, function(metaRules){ + + switch(edit.dataType){ + + case DATA_CST.TYPE.SUBJECT: + var subjectCategoryList = _.reduce(metaRules, function(result, metaRule) { + return result.concat(metaRule.subject_categories); + }, []) + metaDataService.subject.findSomeWithCallback(subjectCategoryList, callBackList); + break; + + case DATA_CST.TYPE.OBJECT: + var objectCategoryList = _.reduce(metaRules, function(result, metaRule) { + return result.concat(metaRule.object_categories); + }, []) + metaDataService.object.findSomeWithCallback(objectCategoryList, callBackList); + break; + + case DATA_CST.TYPE.ACTION: + var actionCategoryList = _.reduce(metaRules, function(result, metaRule) { + return result.concat(metaRule.action_categories); + }, []) + metaDataService.action.findSomeWithCallback(actionCategoryList, callBackList); + break; + + default : + + edit.categoriesToBeSelected = []; + break; + + } + + function callBackList(list){ + + edit.categoriesToBeSelected = list; + + } + }); + + }); + + + } + + /** + * Create + */ + + function createData() { + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + } else { + + startLoading(); + + var dataToSend = angular.copy(edit.data); + + switch(edit.dataType){ + + case DATA_CST.TYPE.SUBJECT: + + dataService.subject.add(dataToSend, edit.policy.id, edit.selectedCategory.id, createSuccess, createError); + break; + + case DATA_CST.TYPE.OBJECT: + + dataService.object.add(dataToSend, edit.policy.id, edit.selectedCategory.id, createSuccess, createError); + break; + + case DATA_CST.TYPE.ACTION: + + dataService.action.add(dataToSend, edit.policy.id, edit.selectedCategory.id, createSuccess, createError); + break; + } + + } + + /** + * @param data + */ + function createSuccess(data) { + + var created = {}; + var name = ''; + + switch(edit.dataType){ + + case DATA_CST.TYPE.SUBJECT: + + created = utilService.transformOne(data['subject_data'], 'data'); + name = created.name; + break; + + case DATA_CST.TYPE.OBJECT: + + created = utilService.transformOne(data['object_data'], 'data'); + name = created.value.name; + break; + + case DATA_CST.TYPE.ACTION: + + created = utilService.transformOne(data['action_data'], 'data'); + name = created.value.name; + break; + } + + $translate('moon.policy.data.edit.create.success', { name: name }).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + $scope.$emit('event:createDataFromDataEditSuccess', created, edit.dataType); + + stopLoading(); + + edit.list.push(created); + + } + + function createError(reason) { + + $translate('moon.policy.data.edit.create.error', { name: dataToSend.name }).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + 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/data/data.list.dir.js b/old/moon_gui/static/app/policy/edit/parameter/data/data.list.dir.js new file mode 100755 index 00000000..23a7e535 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/data/data.list.dir.js @@ -0,0 +1,293 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonDataList', moonDataList); + + moonDataList.$inject = []; + + function moonDataList() { + + return { + templateUrl : 'html/policy/edit/parameter/data/data-list.tpl.html', + bindToController : true, + controller : moonDataListController, + controllerAs : 'list', + scope : { + policy: '=', + editMode : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonDataListController', moonDataListController); + + moonDataListController.$inject = ['$scope', '$rootScope', 'dataService', '$translate', 'alertService', 'DATA_CST', 'metaDataService']; + + function moonDataListController($scope, $rootScope, dataService, $translate, alertService, DATA_CST, metaDataService){ + + var list = this; + + list.policy = $scope.list.policy; + list.editMode = $scope.list.editMode; + + list.typeOfSubject = DATA_CST.TYPE.SUBJECT; + list.typeOfObject = DATA_CST.TYPE.OBJECT; + list.typeOfAction = DATA_CST.TYPE.ACTION; + + list.deleteSub = deleteSub; + list.deleteObj = deleteObj; + list.deleteAct = deleteAct; + + list.getSubjects = getSubjects; + list.getObjects = getObjects; + list.getActions = getActions; + + list.getCategoryFromData = getCategoryFromData; + + activate(); + + function activate(){ + + manageSubjects(); + + manageObjects(); + + manageActions(); + + } + + var rootListeners = { + + 'event:createDataFromDataEditSuccess': $rootScope.$on('event:createDataFromDataEditSuccess', addDataToList) + + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); + + + function manageSubjects(){ + + list.loadingSub = true; + + dataService.subject.findAllFromPolicyWithCallback(list.policy.id, function(data){ + + list.subjects = data; + list.loadingSub = false; + + }); + } + + function manageObjects(){ + + list.loadingObj = true; + + dataService.object.findAllFromPolicyWithCallback(list.policy.id, function(data){ + + list.objects = data; + list.loadingObj = false; + + }); + + } + + function manageActions(){ + + list.loadingAct = true; + + dataService.action.findAllFromPolicyWithCallback(list.policy.id, function(data){ + + list.actions = data; + list.loadingAct = false; + + }); + + } + + function getCategoryFromData(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 DATA_CST.TYPE.SUBJECT: + metaDataService.subject.findOne(data.category_id, setCategoryToData); + break; + + case DATA_CST.TYPE.OBJECT: + metaDataService.object.findOne(data.category_id, setCategoryToData); + break; + + case DATA_CST.TYPE.ACTION: + metaDataService.action.findOne(data.category_id, setCategoryToData); + break; + + } + + } + + // if the call is in progress return false + return false; + + function setCategoryToData(category){ + + data.callCategoryInProgress = false; + data.category = category; + + } + } + + /** + * Delete + */ + + function deleteSub(subject){ + + subject.loader = true; + + dataService.subject.delete(subject, list.policy.id, subject.category_id, deleteSubSuccess, deleteSubError); + + function deleteSubSuccess(data){ + + $translate('moon.policy.data.subject.delete.success', { subjectName: subject.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeSubFromSubList(subject); + + subject.loader = false; + + } + + function deleteSubError(reason){ + + $translate('moon.policy.data.subject.delete.error', { subjectName: subject.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + subject.loader = false; + + } + } + + function deleteObj(object){ + + object.loader = true; + + dataService.object.delete(object, list.policy.id, object.category_id, deleteObjSuccess, deleteObjError); + + function deleteObjSuccess(data){ + + $translate('moon.policy.data.object.delete.success', { objectName: object.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeObjFromObjList(object); + + object.loader = false; + + } + + function deleteObjError(reason){ + + $translate('moon.policy.data.object.delete.error', { objectName: object.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + object.loader = false; + } + } + + function deleteAct(action){ + + action.loader = true; + + dataService.action.delete(action, list.policy.id, action.category_id, deleteActSuccess, deleteActError); + + function deleteActSuccess(data){ + + $translate('moon.policy.data.action.delete.success', { actionName: action.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + removeActFromActList(action); + + action.loader = false; + + } + + function deleteActError(reason){ + + $translate('moon.policy.data.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 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 addDataToList( event, data, typeOfData){ + + switch(typeOfData){ + + case DATA_CST.TYPE.SUBJECT: + + list.subjects.push(data); + break; + + case DATA_CST.TYPE.OBJECT: + + list.objects.push(data); + break; + + case DATA_CST.TYPE.ACTION: + + list.actions.push(data); + break; + } + + } + + } + +})();
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter-edit.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter-edit.tpl.html new file mode 100755 index 00000000..fa2f93c0 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter-edit.tpl.html @@ -0,0 +1,166 @@ +<div> + + <div class="col-md-4 col-sm-4 col-xs-4"> + <a class="btn btn-primary" type="button" style="white-space: normal;" ng-click="edit.fromList = !edit.fromList"> + <span ng-if="!edit.fromList" data-translate="moon.policy.perimeter.edit.action.list">Add from the list</span> + <span ng-if="edit.fromList" data-translate="moon.policy.perimeter.edit.action.new">Add a new Perimeter</span> + </a> + </div> + + <div class="col-md-8 col-sm-8 col-xs-8"> + + <form name="selectMetaData" ng-if="edit.fromList" class="form-horizontal" role="form" > + + <div class="form-group" > + + <ui-select ng-model="edit.selectedPerimeter" name="object"> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aPerimeter in edit.list"> + <div ng-value="aPerimeter" ng-bind="aPerimeter.name"></div> + </ui-select-choices> + + </ui-select> + + </div> + + <div class="form-group"> + + <div class="pull-left col-md-4 col-sm-4 col-xs-4"> + + <a href="" ng-disabled="edit.loading || !edit.selectedPerimeter" ng-click="edit.deletePerimeter()" class="btn btn-warning"> + <span class="glyphicon glyphicon-trash"></span> + <span data-translate="moon.policy.perimeter.edit.action.delete">Delete</span> + </a> + + </div> + + <div class="pull-right col-md-7 col-md-offset-1 col-sm-7 col-sm-offset-1 col-xs-7 col-xs-offset-1 "> + + <a href="" ng-disabled="edit.loading || !edit.selectedPerimeter" ng-click="edit.addToPolicy()" class="btn btn-warning" style="white-space: normal;"> + <span class="glyphicon glyphicon-link"></span> + <span data-translate="moon.policy.perimeter.edit.action.add">Add the selected Perimeter</span> + </a> + + </div> + + </div> + + <moon-loader ng-if="edit.loading"></moon-loader> + + </form> + + <form ng-if="!edit.fromList" class="form-horizontal" role="form" name="edit.form"> + + <div class="form-group" ng-class="{'has-error': edit.form.name.$invalid && edit.form.name.$dirty}"> + + <label for="name" class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.name">Name</label> + + <div class="col-sm-6"> + + <input name="name" id="name" class="form-control" type="text" data-ng-model="edit.perimeter.name" required /> + + <div class="help-block" ng-show="edit.form.name.$dirty && edit.form.name.$invalid"> + <small class="error" ng-show="edit.form.name.$error.required" data-translate="moon.policy.perimeter.edit.check.name.required">Name is required</small> + </div> + + </div> + + </div> + + <div class="form-group"> + + <label for="description" class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.description">Description</label> + <div class="col-sm-6"> + <textarea id="description" name="description" class="form-control" data-ng-model="edit.perimeter.description"></textarea> + </div> + + </div> + + <!-- + <div class="form-group"> + + <label for="partnerId" class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.partnerId">Partner Id</label> + + <div class="col-sm-6"> + <input name="partnerId" id="partnerId" class="form-control" type="text" data-ng-model="edit.perimeter.partnerId" /> + </div> + + </div> + --> + + + <div class="form-group" ng-if="edit.perimeterType === edit.subjectType" ng-class="{'has-error': edit.form.email.$invalid && edit.form.email.$dirty}"> + + <label for="email" class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.email">Email</label> + + <div class="col-sm-6"> + <input name="email" id="email" class="form-control" type="email" data-ng-model="edit.perimeter.email" /> + </div> + + </div> + + + <div class="form-group" > + + <label for="policyList" class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.policies">Policy List </label> + + <div class="col-sm-5"> + + <ui-select ng-model="edit.selectedPolicy" id="policyList"> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aPolicy in edit.policiesToBeSelected"> + <div ng-value="aPolicy" ng-bind="aPolicy.name"></div> + </ui-select-choices> + + </ui-select> + + </div> + + <div class="col-sm-1 text-center"> + <a href="" ng-click="edit.addPolicyToPerimeter()"><span style="font-size:1.5em; line-height: 1.5em;" class="glyphicon glyphicon-plus-sign"></span></a> + </div> + + </div> + + <div class="form-group"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.perimeter.edit.selectedPolicies">Selected Policies</label> + + <div class="col-sm-6"> + + <ul> + + <li ng-repeat="(key, value) in edit.selectedPolicyList"> + + <span ng-bind="value.name" ></span> <a href="" ng-click="edit.removeSelectedPolicy(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.perimeter.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/perimeter/perimeter-list.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter-list.tpl.html new file mode 100755 index 00000000..a94d663e --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter-list.tpl.html @@ -0,0 +1,240 @@ +<div> + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.perimeter.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.perimeter.table.name">Name</th> + <th data-translate="moon.policy.perimeter.table.description">Description</th> + <th data-translate="moon.policy.perimeter.table.email">Email</th> + <th data-translate="moon.policy.perimeter.table.action.title"></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 ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td ng-bind="value.email"></td> + <td> + + <a href="" ng-if="!value.loader" ng-click="list.unMapSub(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.perimeter.table.action.unmap">Unmap</span> + </a> + + <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.perimeter.subject.notFound">There is no Subjects</td> + <td></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.perimeter.subject.add.title">Add a Subject Category</h4> + + </div> + + <div class="panel-body"> + + <moon-perimeter-edit policy="list.policy" perimeter-type="list.typeOfSubject"></moon-perimeter-edit> + + </div> + + </div> + + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.perimeter.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.perimeter.table.name">Name</th> + <th data-translate="moon.policy.perimeter.table.description">Description</th> + <th data-translate="moon.policy.perimeter.table.action.title"></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 ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td> + + <a href="" ng-if="!value.loader" ng-click="list.unMapObj(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.perimeter.table.action.unmap">Unmap</span> + </a> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingObj && list.getObjects().length === 0"> + <tr> + <td data-translate="moon.policy.perimeter.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.perimeter.object.add.title">Add an Object Category</h4> + + </div> + + <div class="panel-body"> + + <moon-perimeter-edit policy="list.policy" perimeter-type="list.typeOfObject"></moon-perimeter-edit> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.perimeter.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.perimeter.table.name">Name</th> + <th data-translate="moon.policy.perimeter.table.description">Description</th> + <th data-translate="moon.policy.perimeter.table.action.title"></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 ng-bind="value.name"></td> + <td ng-bind="value.description"></td> + <td> + + <a href="" ng-if="!value.loader" ng-click="list.unMapAct(value)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.perimeter.table.action.unmap">Unmap</span> + </a> + + <div ng-if="value.loader"> + + <moon-loader></moon-loader> + + </div> + + </td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingAct && list.getActions().length === 0"> + <tr> + <td data-translate="moon.policy.perimeter.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.perimeter.action.add.title">Add an Action Category</h4> + + </div> + + <div class="panel-body">. + + <moon-perimeter-edit policy="list.policy" perimeter-type="list.typeOfAction"></moon-perimeter-edit> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.edit.dir.js b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.edit.dir.js new file mode 100755 index 00000000..d72e23b7 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.edit.dir.js @@ -0,0 +1,437 @@ +(function () { + + 'use strict'; + + angular + .module('moon') + .directive('moonPerimeterEdit', moonPerimeterEdit); + + moonPerimeterEdit.$inject = []; + + function moonPerimeterEdit() { + + return { + templateUrl: 'html/policy/edit/parameter/perimeter/perimeter-edit.tpl.html', + bindToController: true, + controller: moonPerimeterEditController, + controllerAs: 'edit', + scope: { + //Type can be 'ACTION', 'OBJECT', 'SUBJECT' + perimeterType: '=', + policy: '=' + }, + restrict: 'E', + replace: true + }; + } + + + angular + .module('moon') + .controller('moonPerimeterEditController', moonPerimeterEditController); + + moonPerimeterEditController.$inject = ['$scope', '$rootScope', + 'perimeterService', 'PERIMETER_CST', 'alertService', + '$translate', 'formService', 'policyService', 'utilService']; + + function moonPerimeterEditController($scope, $rootScope, + perimeterService, PERIMETER_CST, alertService, + $translate, formService, policyService, utilService) { + + var edit = this; + + edit.perimeterType = $scope.edit.perimeterType; + // This variable is used in the view in order to display or not display email field + edit.subjectType = PERIMETER_CST.TYPE.SUBJECT; + edit.policy = $scope.edit.policy; + + edit.fromList = true; + + edit.loading = false; + + edit.form = {}; + + edit.perimeter = {name: null, description: null, partner_id: null, policy_list: [], email: null}; + + edit.list = []; + edit.policyList = []; + edit.policiesToBeSelected = []; + edit.selectedPolicyList = []; // List of Policies to be added to a new perimeter + + edit.create = createPerimeter; + edit.addToPolicy = addToPolicy; + edit.addPolicyToPerimeter = addPolicyToPerimeter; + edit.clearSelectedPolicies = clearSelectedPolicies; + edit.removeSelectedPolicy = removeSelectedPolicy; + edit.deletePerimeter = deletePerimeter; + + activate(); + + /* + * + */ + + function activate() { + + loadAllPolicies(); + + switch (edit.perimeterType) { + + case PERIMETER_CST.TYPE.SUBJECT: + + perimeterService.subject.findAllWithCallback(callBackList); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + perimeterService.object.findAllWithCallback(callBackList); + break; + + case PERIMETER_CST.TYPE.ACTION: + + perimeterService.action.findAllWithCallback(callBackList); + break; + + default : + + edit.list = []; + break; + + } + + function callBackList(list) { + + // For each Perimeter, there is a check about the mapping between the perimeter and the policy + _.each(list, function (element) { + + if (_.indexOf(element.policy_list, edit.policy.id) === -1) { + + edit.list.push(element); + + } + + }); + + } + + } + + var rootListeners = { + + 'event:unMapPerimeterFromPerimeterList': $rootScope.$on('event:unMapPerimeterFromPerimeterList', manageUnMappedPerimeter) + + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); + + + function loadAllPolicies() { + + edit.policyList = []; + + policyService.findAllWithCallback( function(data) { + + edit.policyList = data; + edit.policiesToBeSelected = angular.copy(edit.policyList); + + }); + } + + function addPolicyToPerimeter() { + + if (!edit.selectedPolicy || _.contains(edit.perimeter.policy_list, edit.selectedPolicy.id)) { + return; + } + + edit.perimeter.policy_list.push(edit.selectedPolicy.id); + edit.selectedPolicyList.push(edit.selectedPolicy); + edit.policiesToBeSelected = _.without(edit.policiesToBeSelected, edit.selectedPolicy); + + } + + function clearSelectedPolicies() { + + edit.perimeter.policy_list = []; + edit.selectedPolicyList = []; + edit.policiesToBeSelected = angular.copy(edit.policyList); + + } + + function removeSelectedPolicy(policy) { + + edit.policiesToBeSelected.push(policy); + edit.perimeter.policy_list = _.without(edit.perimeter.policy_list, policy.id); + edit.selectedPolicyList = _.without(edit.selectedPolicyList, policy); + + } + + /** + * Add + */ + + function addToPolicy() { + + if (!edit.selectedPerimeter) { + + return; + + } + + startLoading(); + + var perimeterToSend = edit.selectedPerimeter; + + perimeterToSend.policy_list.push(edit.policy.id); + + switch (edit.perimeterType) { + + case PERIMETER_CST.TYPE.SUBJECT: + + perimeterService.subject.update(perimeterToSend, updatePerimeterSuccess, updatePerimeterError); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + perimeterService.object.update(perimeterToSend, updatePerimeterSuccess, updatePerimeterError); + break; + + case PERIMETER_CST.TYPE.ACTION: + + perimeterService.action.update(perimeterToSend, updatePerimeterSuccess, updatePerimeterError); + break; + } + + + function updatePerimeterSuccess(data) { + + $translate('moon.perimeter.update.success', {policyName: perimeterToSend.name}).then(function (translatedValue) { + + alertService.alertSuccess(translatedValue); + + }); + + stopLoading(); + + } + + function updatePerimeterError(reason) { + + $translate('moon.policy.update.error', { + policyName: perimeterToSend.name, + reason: reason.message + }).then(function (translatedValue) { + + alertService.alertError(translatedValue); + + }); + + stopLoading(); + + } + + } + + /** + * Create + */ + + function createPerimeter() { + + if (formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + } else { + + startLoading(); + + var perimeterToSend = angular.copy(edit.perimeter); + + switch (edit.perimeterType) { + + case PERIMETER_CST.TYPE.SUBJECT: + + perimeterService.subject.add(perimeterToSend, createSuccess, createError); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + perimeterService.object.add(perimeterToSend, createSuccess, createError); + break; + + case PERIMETER_CST.TYPE.ACTION: + + perimeterService.action.add(perimeterToSend, createSuccess, createError); + break; + } + + } + + function createSuccess(data) { + + var created = {}; + + switch (edit.perimeterType) { + + case PERIMETER_CST.TYPE.SUBJECT: + + created = utilService.transformOne(data, 'subjects'); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + created = utilService.transformOne(data, 'objects'); + break; + + case PERIMETER_CST.TYPE.ACTION: + + created = utilService.transformOne(data, 'actions'); + break; + } + + $translate('moon.policy.perimeter.edit.create.success', {name: created.name}).then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + stopLoading(); + + /** + * If during the creating the created assignments has be mapped with the current policy, then it is not required to push the new Assignments in the list + */ + if (_.indexOf(created.policy_list, edit.policy.id) === -1) { + + edit.list.push(created); + + }else{ + + $scope.$emit('event:createAssignmentsFromAssignmentsEditSuccess', created, edit.perimeterType); + + } + + displayList(); + + clearSelectedPolicies(); + + } + + function createError(reason) { + + $translate('moon.policy.perimeter.edit.create.error', {name: perimeterToSend.name}).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + /** + * Delete + */ + function deletePerimeter() { + + if (!edit.selectedPerimeter) { + + return; + + } + + startLoading(); + + var perimeterToDelete = angular.copy(edit.selectedPerimeter); + + switch (edit.perimeterType) { + case PERIMETER_CST.TYPE.SUBJECT: + + perimeterService.subject.delete(perimeterToDelete, deleteSuccess, deleteError); + break; + + case PERIMETER_CST.TYPE.OBJECT: + + perimeterService.object.delete(perimeterToDelete, deleteSuccess, deleteError); + break; + + case PERIMETER_CST.TYPE.ACTION: + + perimeterService.action.delete(perimeterToDelete, deleteSuccess, deleteError); + break; + } + + + function deleteSuccess(data) { + + $translate('moon.policy.perimeter.edit.delete.success', {name: perimeterToDelete.name}) + .then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + policyService.findOneReturningPromise(edit.policy.id).then(function (data) { + + edit.policy = utilService.transformOne(data, 'policies'); + + cleanSelectedValue(); + activate(); + stopLoading(); + + $scope.$emit('event:deletePerimeterFromPerimeterAddSuccess', edit.policy); + + }); + + } + + function deleteError(reason) { + + $translate('moon.policy.perimeter.edit.delete.error', {name: perimeterToDelete.name}).then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + } + + function cleanSelectedValue() { + edit.list = _.without(edit.list, edit.selectedPerimeter); + delete edit.selectedPerimeter; + + } + + function startLoading() { + + edit.loading = true; + + } + + function stopLoading() { + + edit.loading = false; + + } + + function displayList() { + + edit.fromList = true; + + } + + /** + * If A perimeter has been unMapped, maybe it has to be display into the available list of Perimeter + * @param perimeter + * @param type + */ + function manageUnMappedPerimeter(event, perimeter, type){ + + if(type === edit.perimeterType && _.indexOf(perimeter.policy_list, edit.policy.id) === -1){ + + edit.list.push(perimeter); + + } + + } + + } + +})();
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js new file mode 100755 index 00000000..dffa7783 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/perimeter/perimeter.list.dir.js @@ -0,0 +1,284 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonPerimeterList', moonPerimeterList); + + moonPerimeterList.$inject = []; + + function moonPerimeterList() { + + return { + templateUrl : 'html/policy/edit/parameter/perimeter/perimeter-list.tpl.html', + bindToController : true, + controller : moonPerimeterListController, + controllerAs : 'list', + scope : { + policy: '=', + editMode : '=' + }, + restrict : 'E', + replace : true + }; + + } + + angular + .module('moon') + .controller('moonPerimeterListController', moonPerimeterListController); + + moonPerimeterListController.$inject = ['$scope', '$rootScope', 'perimeterService', '$translate', 'alertService', 'PERIMETER_CST']; + + function moonPerimeterListController($scope, $rootScope, perimeterService, $translate, alertService, PERIMETER_CST){ + + var list = this; + + list.policy = $scope.list.policy; + list.editMode = $scope.list.editMode; + + list.typeOfSubject = PERIMETER_CST.TYPE.SUBJECT; + list.typeOfObject = PERIMETER_CST.TYPE.OBJECT; + list.typeOfAction = PERIMETER_CST.TYPE.ACTION; + + list.unMapSub = unMapSub; + list.unMapObj = unMapObj; + list.unMapAct = unMapAct; + + list.getSubjects = getSubjects; + list.getObjects = getObjects; + list.getActions = getActions; + + activate(); + + function activate(){ + + manageSubjects(); + + manageObjects(); + + manageActions(); + + } + + var rootListeners = { + + 'event:deletePerimeterFromPerimeterAddSuccess': $rootScope.$on('event:deletePerimeterFromPerimeterAddSuccess', deletePolicy), + 'event:createAssignmentsFromAssignmentsEditSuccess': $rootScope.$on('event:createAssignmentsFromAssignmentsEditSuccess', addAssignmentsToPolicy) + + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); + + + function manageSubjects(){ + + list.loadingSub = true; + + perimeterService.subject.findAllFromPolicyWithCallback(list.policy.id, function(perimeters){ + + list.subjects = perimeters; + list.loadingSub = false; + + }); + } + + function manageObjects(){ + + list.loadingObj = true; + + perimeterService.object.findAllFromPolicyWithCallback(list.policy.id, function(perimeters){ + + list.objects = perimeters; + list.loadingObj = false; + + }); + + } + + function manageActions(){ + + list.loadingAct = true; + + perimeterService.action.findAllFromPolicyWithCallback(list.policy.id, function(perimeters){ + + list.actions = perimeters; + list.loadingAct = false; + + }); + + } + + /** + * UnMap + */ + + function unMapSub(perimeter){ + + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); + + perimeter.loader = true; + + var perimeterToSend = angular.copy(perimeter); + + perimeterService.subject.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); + + function updatePerimeterSuccess(data){ + + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.SUBJECT); + + activate(); + + perimeter.loader = false; + } + + function updatePerimeterError(reason){ + + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + perimeter.loader = false; + + } + + } + + function unMapObj(perimeter){ + + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); + + perimeter.loader = true; + + var perimeterToSend = angular.copy(perimeter); + + perimeterService.object.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); + + function updatePerimeterSuccess(data){ + + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.OBJECT); + + activate(); + + perimeter.loader = false; + } + + function updatePerimeterError(reason){ + + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + perimeter.loader = false; + + } + + } + + function unMapAct(perimeter){ + + perimeter.policy_list = _.without(perimeter.policy_list, list.policy.id); + + perimeter.loader = true; + + var perimeterToSend = angular.copy(perimeter); + + perimeterService.action.unMapPerimeterFromPolicy(list.policy.id , perimeter.id, updatePerimeterSuccess, updatePerimeterError); + + function updatePerimeterSuccess(data){ + + $translate('moon.policy.perimeter.update.success', { perimeterName: perimeterToSend.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + $scope.$emit('event:unMapPerimeterFromPerimeterList', perimeter, PERIMETER_CST.TYPE.ACTION); + + activate(); + + perimeter.loader = false; + } + + function updatePerimeterError(reason){ + + $translate('moon.policy.perimeter.update.error', { perimeterName: perimeter.name, reason: reason.message}).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + perimeter.loader = false; + + } + + } + + 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(); + + } + + 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/old/moon_gui/static/app/policy/edit/parameter/rules/rules-edit.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/rules/rules-edit.tpl.html new file mode 100755 index 00000000..685046a5 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/rules/rules-edit.tpl.html @@ -0,0 +1,341 @@ +<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.rules.edit.action.add.policies">Policy List</label> + + <div class="col-sm-6" > + + <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.rules.edit.action.add.check.policy.required">Policy is required</small> + </div> + + </div> + + </div> + + <div ng-if="!edit.selectedPolicy.meta_rules_values"> + <div class="col-sm-6 col-sm-offset-3"> + <moon-loader></moon-loader> + </div> + </div> + + <div ng-if="edit.selectedPolicy.meta_rules_values"> + + <!-- Select Meta Rules --> + <div class="form-group" ng-class="{'has-error': edit.form.metaRulesList.$invalid && edit.form.metaRulesList.$dirty}" > + + <label for="metaRulesList" class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.metarules">MetaRules List</label> + + <div class="col-sm-6" > + + <ui-select ng-model="edit.selectedMetaRules" name="metaRulesList" id="metaRulesList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aMetaRules in edit.selectedPolicy.meta_rules_values"> + <div ng-value="aMetaRules" ng-bind="aMetaRules.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.metaRulesList.$dirty && edit.form.metaRulesList.$invalid"> + <small class="error" ng-show="edit.form.metaRulesList.$error.required" data-translate="moon.policy.rules.edit.action.add.check.metarules.required">A MetaRules is required</small> + </div> + + </div> + + <div> + <a href="" ng-if="edit.selectedMetaRules" ng-click="edit.showDetailselectedMetaRules = !edit.showDetailselectedMetaRules"> + + <span ng-if="!edit.showDetailselectedMetaRules"> + <span data-translate="moon.policy.rules.edit.action.add.details.show">Show</span> + <span class="glyphicon glyphicon-eye-open"></span> + </span> + + <span ng-if="edit.showDetailselectedMetaRules"> + <span data-translate="moon.policy.rules.edit.action.add.details.close">Close</span> + <span class="glyphicon glyphicon-eye-close"></span> + </span> + + </a> + </div> + + </div> + + <div class="form-group" ng-if="edit.showDetailselectedMetaRules && edit.selectedMetaRules"> + <moon-meta-data-list edit-mode="edit.editMode" meta-rule="edit.selectedMetaRules" short-display="true"></moon-meta-data-list> + </div> + + <!-- Select Data --> + <div class="form-group" ng-if="edit.selectedMetaRules"> + + <div class="col-md-4"> + + <div ng-if="edit.selectedMetaRules.subject_categories.length > 0"> + + <div class="row"> + + <div ng-if="!edit.data.loadingSubjects"> + + <label for="subjectsList" class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.categories.subject" data-translate-values="{ number: edit.selectedMetaRules.subject_categories.length }">Select Subject(s)</label> + + <div class="col-sm-7" > + + <ui-select ng-model="edit.selectedSubject" name="subjectsList" id="subjectsList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.name"></ui-select-match> + <ui-select-choices repeat="aSubject in edit.data.subjectsToBeSelected"> + <div ng-value="aSubject" ng-bind="aSubject.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.subjectsList.$dirty && edit.form.subjectsList.$invalid || !edit.numberOfSelectedSubjectValid"> + <small class="error" ng-show="edit.form.subjectsList.$error.required || !edit.numberOfSelectedSubjectValid" data-translate="moon.policy.rules.edit.action.add.check.subject.required" data-translate-values="{ number: edit.selectedMetaRules.subject_categories.length }">Some subject are required</small> + </div> + + </div> + + <div class="col-sm-2 text-center"> + <a href="" ng-if="edit.selectedSubject && !edit.isNumberSelectedDataAtMaximum(edit.data.subjectCST)" + ng-click="edit.addDataToRules(edit.data.subjectCST)"><span style="font-size:1.5em; line-height: 1.5em;" class="glyphicon glyphicon-plus-sign"></span></a> + </div> + + </div> + + <div ng-if="edit.data.loadingSubjects"> + + <moon-loader></moon-loader> + + </div> + + </div> + + <div class="row" ng-if="!edit.data.loadingSubjects"> + + <div class="form-group"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.selectedSubjects">Selected Subjcet(s)</label> + + <div class="col-sm-6"> + + <ul> + + <li ng-repeat="(key, value) in edit.data.selectedSubjectsList"> + + <span ng-bind="value.name" ></span> <a href="" ng-click="edit.removeSelectedDataFromRules(value, edit.data.subjectCST)"><span style="font-size:1.5em; line-height: 1.5em" class="glyphicon glyphicon-remove"></span></a> + + </li> + + </ul> + + </div> + + </div> + + </div> + + </div> + + <div ng-if="edit.selectedMetaRules.subject_categories.length === 0"> + + </div> + + </div> + + <div class="col-md-4"> + + <div ng-if="edit.selectedMetaRules.object_categories.length > 0"> + + <div class="row"> + + <div ng-if="!edit.data.loadingObjects"> + + <label for="objectsList" class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.categories.object" data-translate-values="{ number: edit.selectedMetaRules.object_categories.length }">Select Object(s)</label> + + <div class="col-sm-7" > + + <ui-select ng-model="edit.selectedObject" name="objectsList" id="objectsList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.value.name"></ui-select-match> + <ui-select-choices repeat="aObject in edit.data.objectsToBeSelected"> + <div ng-value="aObject" ng-bind="aObject.value.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.objectsList.$dirty && edit.form.objectsList.$invalid || !edit.numberOfSelectedObjecttValid"> + <small class="error" ng-show="edit.form.objectsList.$error.required || !edit.numberOfSelectedObjecttValid" data-translate="moon.policy.rules.edit.action.add.check.object.required" data-translate-values="{ number: edit.selectedMetaRules.object_categories.length }">Some objects are required</small> + </div> + + </div> + + <div class="col-sm-2 text-center"> + <a href="" ng-if="edit.selectedObject && !edit.isNumberSelectedDataAtMaximum(edit.data.objectCST)" + ng-click="edit.addDataToRules(edit.data.objectCST)"><span style="font-size:1.5em; line-height: 1.5em;" class="glyphicon glyphicon-plus-sign"></span></a> + </div> + + </div> + + <div ng-if="edit.data.loadingObjects"> + + <moon-loader></moon-loader> + + </div> + + </div> + + <div class="row" ng-if="!edit.data.loadingObjects"> + + <div class="form-group"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.selectedObjects">Selected Objcet(s)</label> + + <div class="col-sm-6"> + + <ul> + + <li ng-repeat="(key, value) in edit.data.selectedObjectsList"> + + <span ng-bind="value.value.name" ></span> <a href="" ng-click="edit.removeSelectedDataFromRules(value, edit.data.objectCST)"><span style="font-size:1.5em; line-height: 1.5em" class="glyphicon glyphicon-remove"></span></a> + + </li> + + </ul> + + </div> + </div> + + </div> + + </div> + + <div ng-if="edit.selectedMetaRules.object_categories.length === 0"> + + </div> + + </div> + + <div class="col-md-4"> + + <div ng-if="edit.selectedMetaRules.action_categories.length > 0"> + + <div class="row"> + + <div ng-if="!edit.data.loadingActions"> + + <label for="actionsList" class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.categories.action" data-translate-values="{ number: edit.selectedMetaRules.action_categories.length }">Select Action(s)</label> + + <div class="col-sm-7" > + + <ui-select ng-model="edit.selectedAction" name="actionsList" id="actionsList" required> + + <ui-select-match placeholder="(None)" ng-bind="$select.selected.value.name"></ui-select-match> + <ui-select-choices repeat="aAction in edit.data.actionsToBeSelected"> + <div ng-value="aAction" ng-bind="aAction.value.name"></div> + </ui-select-choices> + + </ui-select> + + <div class="help-block" ng-show="edit.form.actionsList.$dirty && edit.form.actionsList.$invalid || !edit.numberOfSelectedActionsValid"> + <small class="error" ng-show="edit.form.actionsList.$error.required || !edit.numberOfSelectedActionsValid" data-translate="moon.policy.rules.edit.action.add.check.action.required" data-translate-values="{ number: edit.selectedMetaRules.action_categories.length }">Some action are required</small> + </div> + </div> + + <div class="col-sm-2 text-center"> + <a href="" ng-if="edit.selectedAction && !edit.isNumberSelectedDataAtMaximum(edit.data.actionCST)" + ng-click="edit.addDataToRules(edit.data.actionCST)"><span style="font-size:1.5em; line-height: 1.5em;" class="glyphicon glyphicon-plus-sign"></span></a> + </div> + + </div> + + <div ng-if="edit.data.loadingActions"> + + <moon-loader></moon-loader> + + </div> + + </div> + + <div class="row" ng-if="!edit.data.loadingActions"> + + <div class="form-group"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.selectedActions">Selected Action(s)</label> + + <div class="col-sm-6"> + + <ul> + + <li ng-repeat="(key, value) in edit.data.selectedActionsList"> + + <span ng-bind="value.value.name" ></span> <a href="" ng-click="edit.removeSelectedDataFromRules(value, edit.data.actionCST)"><span style="font-size:1.5em; line-height: 1.5em" class="glyphicon glyphicon-remove"></span></a> + + </li> + + </ul> + + </div> + </div> + + </div> + + </div> + + <div ng-if="edit.selectedMetaRules.action_categories.length === 0"> + + </div> + + </div> + + </div> + + <div class="form-group" ng-class="{'has-error': edit.form.instructions.$invalid && edit.form.instructions.$dirty || !edit.instructionsValid}"> + + <label for="instructions" class="col-sm-3 control-label" data-translate="moon.policy.rules.edit.action.add.instructions">Instruction</label> + + <div class="col-sm-6"> + <textarea id="instructions" name="instructions" class="form-control" ng-model="edit.rules.instructions" rows="6" required></textarea> + <div class="help-block" ng-show="edit.form.instructions.$dirty && edit.form.instructions.$invalid || !edit.instructionsValid "> + <small class="error" data-translate="moon.policy.rules.edit.action.add.check.instructions.required">An instructions is required</small> + </div> + </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.rules.edit.action.create">Create</span> + </a> + + <moon-loader ng-if="edit.loading"></moon-loader> + + </div> + + </div> + + </div> + + </form> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html b/old/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html new file mode 100755 index 00000000..7f556f93 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/rules/rules-list.tpl.html @@ -0,0 +1,134 @@ +<div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <h4 data-translate="moon.policy.rules.edit.title">List of associated Subjects</h4> + + </div> + + <div class="panel-body"> + + <div class="table-responsive" data-role="table"> + + <table class="table table-striped table-hover" ng-table="list.table"> + + <thead> + + <tr> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('description', 'asc'), 'sort-desc': list.table.isSortBy('description', 'desc') }" + ng-click="list.table.sorting('description', list.table.isSortBy('description', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.rules.list.table.metaRule">Meta Rule</div> + </th> + + <th class="customTables sortable"> + <div data-translate="moon.policy.rules.list.table.rule">Rule</div> + </th> + + <th class="customTables sortable"> + <div data-translate="moon.policy.rules.list.table.instructions">Instruction</div> + </th> + + <th class="customTables sortable"> + <div data-translate="moon.policy.rules.list.table.action.title">Actions</div> + </th> + </tr> + + </thead> + + <moon-loader ng-if="list.loadingRules"></moon-loader> + + <tbody ng-if="!list.loadingRules && !list.hasRules()"> + <tr> + <td colspan="4"><span data-translate="moon.policy.rules.list.table.notFound">There is no Rules</span></td> + </tr> + </tbody> + + <tbody ng-if="!list.loadingRules && list.hasRules()"> + + <tr ng-repeat="aRule in $data | filter:list.search.find | orderBy:sort:reverse"> + <td> + <span ng-if="!list.getMetaRuleFromRule(aRule)"> + <moon-loader ng-if="!list.getMetaRuleFromRule(aRule)" ></moon-loader> + <em data-translate="moon.policy.rules.list.table.loading.metaRule">Loading </em> + </span> + + <span ng-if="list.getMetaRuleFromRule(aRule)"> + <span ng-bind="aRule.meta_rule.name"></span> + </span> + </td> + + <td> + + <span ng-if="!list.getMetaRuleFromRule(aRule)"> + <moon-loader ng-if="!list.getMetaRuleFromRule(aRule)" ></moon-loader> + <em data-translate="moon.policy.rules.list.table.loading.metaRule">Loading </em> + </span> + + <span ng-if="list.getMetaRuleFromRule(aRule)" ng-repeat="(key, value) in aRule.rule"> + + <span ng-if="!list.getCategoryFromRuleIndex(key, aRule)"> + <moon-loader ng-if="!list.getCategoryFromRuleIndex(key, aRule)" ></moon-loader> + </span> + + <span ng-if="list.getCategoryFromRuleIndex(key, aRule)"> + <span ng-if="aRule.rule_value[key].category.name" ng-bind="aRule.rule_value[key].category.name"></span> + <span ng-if="aRule.rule_value[key].category.value.name" ng-bind="aRule.rule_value[key].category.value.name"></span> + <span ng-if="key < aRule.rule.length-1">,</span> + </span> + + </span> + + </td> + + <td> + <pre ng-bind="aRule.instructions | json "></pre> + </td> + + <td> + + <a href="" ng-if="!aRule.loader" ng-click="list.deleteRules(aRule)" > + <span class="glyphicon glyphicon-transfer"></span> + <span class="control-label" data-translate="moon.policy.rules.list.table.action.delete">Delete</span> + </a> + + <div ng-if="aRule.loader"> + + <moon-loader></moon-loader> + + </div> + + </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.rules.edit.action.add.title">Add a Rule</h4> + + </div> + + <div class="panel-body">. + + <moon-rules-edit policy="list.policy"></moon-rules-edit> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/rules/rules.edit.dir.js b/old/moon_gui/static/app/policy/edit/parameter/rules/rules.edit.dir.js new file mode 100755 index 00000000..b7bb7614 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/rules/rules.edit.dir.js @@ -0,0 +1,537 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonRulesEdit', moonRulesEdit); + + moonRulesEdit.$inject = []; + + function moonRulesEdit() { + + return { + templateUrl : 'html/policy/edit/parameter/rules/rules-edit.tpl.html', + bindToController : true, + controller : moonRulesEditController, + controllerAs : 'edit', + scope : { + policy : '=' + }, + restrict : 'E', + replace : true + }; + + } + + angular + .module('moon') + .controller('moonRulesEditController', moonRulesEditController); + + moonRulesEditController.$inject = ['$scope', 'rulesService', 'alertService', '$translate', + 'formService', 'policyService', 'utilService', 'metaRuleService', 'metaDataService', 'modelService', 'dataService', 'DATA_CST']; + + function moonRulesEditController($scope, rulesService, alertService, $translate, + formService, policyService, utilService, metaRuleService, metaDataService, modelService, dataService, DATA_CST) { + + var edit = this; + + edit.policy = $scope.edit.policy; + edit.editMode = true; + + edit.fromList = false; + + edit.loading = false; + + edit.form = {}; + edit.showDetailselectedMetaRules = false; + + edit.list = []; + edit.policyList = []; + + edit.categories = { + subject : [], + loadingSubjects: true, + object : [], + loadingObjects: true, + action : [], + loadingActions : true + }; + + edit.data = {}; // this object is filled in declareDataObject(): + + edit.create = createRules; + edit.addDataToRules = addDataToRules; + edit.removeSelectedDataFromRules = removeSelectedDataFromRules; + edit.isNumberSelectedDataAtMaximum = isNumberSelectedDataAtMaximum; + + //this variable is related to checks on Instruction field which is in JSON + edit.instructionsValid = true; + edit.numberOfSelectedSubjectValid = true; + edit.numberOfSelectedObjecttValid = true; + edit.numberOfSelectedActionsValid = true; + + activate(); + + /* + * + */ + function activate(){ + + edit.rules = {meta_rule_id: null, rule: [], policy_id: null, instructions: '[{"decision": "grant"}]', enabled: true}; + declareDataObject(); + loadAllPolicies(); + clearSelectedMetaRules(); + + } + + function loadAllPolicies() { + + edit.policyList = []; + + policyService.findAllWithCallback( function(data) { + + _.each(data, function(element){ + + if(element.id === edit.policy.id){ + edit.selectedPolicy = element; + } + + }); + + edit.policyList = data; + + }); + } + + $scope.$watch('edit.selectedPolicy', function(newValue){ + + clearSelectedMetaRules(); + + if(!_.isUndefined(newValue)){ + + loadRelatedMetaRules(); + + } + + }); + + $scope.$watch('edit.selectedMetaRules', function(newValue){ + + clearSelectedData(); + + edit.categories = { + subject : [], + loadingSubjects: true, + object : [], + loadingObjects: true, + action : [], + loadingActions : true + }; + + declareDataObject(); + + if(!_.isUndefined(newValue)){ + + loadRelatedCategoriesAndData(newValue.subject_categories, newValue.object_categories, newValue.action_categories); + + } + + }); + + /** + * To get the related MetaRules, it is required to : + * - Get the model related to the policy + * - Get the metaRules associated to the model + * - Get the MetaData associated to the metaRules + */ + function loadRelatedMetaRules() { + + edit.selectedPolicy.meta_rules_values = undefined; + + modelService.findOneWithCallback(edit.selectedPolicy.model_id, function(model){ + + metaRuleService.findSomeWithCallback(model.meta_rules, function(metaRules){ + + edit.selectedPolicy.meta_rules_values = metaRules; + + }); + + }); + + } + + /** + * Load categories from arrays of id in args + * @param subjectsCategories, list of subject id related to the metaRule + * @param objectCategories, list of object id related to the metaRule + * @param actionsCategories, list of action id related to the metaRule + */ + function loadRelatedCategoriesAndData(subjectsCategories, objectCategories, actionsCategories){ + + metaDataService.subject.findSomeWithCallback(subjectsCategories, function(list){ + + edit.categories.subject = list; + edit.categories.loadingSubjects = false; + + _.each(edit.categories.subject, function(aSubject){ + + dataService.subject.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, aSubject.id, function(subjects){ + + edit.data.subject = subjects; + edit.data.loadingSubjects = false; + edit.data.subjectsToBeSelected = angular.copy(edit.data.subject); + + }); + + }); + + }); + + metaDataService.object.findSomeWithCallback(objectCategories, function(list){ + + edit.categories.object = list; + edit.categories.loadingObjects = false; + + _.each(edit.categories.object, function(aObject){ + + dataService.object.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, aObject.id, function(objects){ + + edit.data.object = objects; + edit.data.loadingObjects = false; + edit.data.objectsToBeSelected = angular.copy(edit.data.object); + + }); + + }); + + }); + + metaDataService.action.findSomeWithCallback(actionsCategories, function(list){ + + edit.categories.action = list; + edit.categories.loadingActions = false; + + _.each(edit.categories.action, function(aAction){ + + dataService.action.findAllFromCategoriesWithCallback(edit.selectedPolicy.id, aAction.id, function(actions){ + + edit.data.action = actions; + edit.data.loadingActions = false; + edit.data.actionsToBeSelected = angular.copy(edit.data.action); + + }); + + }); + + }); + + } + + /** + * createRules, create Rules depending of what has been filled in the view + */ + function createRules() { + + edit.instructionsValid = true; + edit.numberOfSelectedSubjectValid = true; + edit.numberOfSelectedObjecttValid = true; + edit.numberOfSelectedActionsValid = true; + + manageInstructionContent(); + // bellow function is called here in order to display errors into the view + manageNumberOfSelectedData(); + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + //manageNumberOfSelectedData is call again in order to check if errors have been display into the view + }else if(edit.instructionsValid && manageNumberOfSelectedData()){ + + startLoading(); + buildRulesArray(); + + edit.rules.meta_rule_id = edit.selectedMetaRules.id; + edit.rules.policy_id = edit.selectedPolicy.id; + + var rulesToSend = angular.copy(edit.rules); + rulesToSend.instructions = JSON.parse(edit.rules.instructions); + + rulesService.add(rulesToSend, edit.policy.id, createSuccess, createError); + } + + + function createSuccess(data) { + + var created = utilService.transformOne(data, 'rules'); + + $translate('moon.policy.rules.edit.action.add.create.success').then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + $scope.$emit('event:createRulesFromDataRulesSuccess', created); + + activate(); + + stopLoading(); + + } + + function createError(reason) { + + $translate('moon.policy.rules.edit.action.add.create.error').then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + stopLoading(); + + } + + } + + /** + * if instructions attribute is not good then edit.instructionsValid is set to false + * it will allow the view to display an error + */ + function manageInstructionContent(){ + + if (!isInstructionValid(edit.rules.instructions)){ + + edit.instructionsValid = false; + + }else{ + + edit.instructionsValid = true; + + } + } + + /** + * return true if the user has selected the number required of Selected Data (subject, object or action) + * if one is missing then return false + * it will also set numberOfSelected(Subject/Object/Action)Valid to true or false in order to display errors form in the view + * @returns {boolean} + */ + function manageNumberOfSelectedData(){ + + isNumberSelectedDataAtMaximum(DATA_CST.TYPE.SUBJECT) ? + edit.numberOfSelectedSubjectValid = true: edit.numberOfSelectedSubjectValid = false; + isNumberSelectedDataAtMaximum(DATA_CST.TYPE.OBJECT) ? + edit.numberOfSelectedObjecttValid = true: edit.numberOfSelectedObjecttValid = false; + isNumberSelectedDataAtMaximum(DATA_CST.TYPE.ACTION) ? + edit.numberOfSelectedActionsValid = true: edit.numberOfSelectedActionsValid = false; + + return edit.numberOfSelectedSubjectValid && edit.numberOfSelectedObjecttValid && edit.numberOfSelectedActionsValid; + } + + /** + * Check if the variables in param is not undefined and if it is a JSON + * It is used for instructions attribute of a Rules object + * @param str + * @returns {boolean|*} + */ + function isInstructionValid(str){ + + return !_.isUndefined(str) && isJsonString(str); + + } + + function isJsonString(str) { + + var item = null; + + try { + item = JSON.parse(str); + } catch (e) { + + return false; + } + + if (typeof item === 'object' && item !== null) { + + return true; + } + + return false; + } + + function startLoading(){ + + edit.loading = true; + + } + + function stopLoading(){ + + edit.loading = false; + + } + + /** + * allow to clear selected values in the form + */ + function clearSelectedMetaRules(){ + + edit.selectedMetaRules = undefined; + + clearSelectedData(); + + } + + function clearSelectedData(){ + + edit.selectedSubject = undefined; + edit.selectedObject = undefined; + edit.selectedAction = undefined; + + } + + /** + * check if the number of Selected Data is equal to the number of categories associated to the metaRule + * @param typeCST : 'SUBJECT', 'OBJECT', 'ACTION' + * @returns {boolean} + */ + function isNumberSelectedDataAtMaximum(typeCST){ + + if(!edit.selectedMetaRules){ + return false; + } + + switch (typeCST) { + + case DATA_CST.TYPE.SUBJECT: + + return edit.data.selectedSubjectsList.length === edit.selectedMetaRules.subject_categories.length; + + case DATA_CST.TYPE.OBJECT: + + return edit.data.selectedObjectsList.length === edit.selectedMetaRules.object_categories.length; + + case DATA_CST.TYPE.ACTION: + + return edit.data.selectedActionsList.length === edit.selectedMetaRules.action_categories.length; + } + } + + /** + * Add a data to an array of selected value (SUBJECT/OBJECT/ACTION) + * those arrays will used in the create function in order to filled the rule attribute of a rules object + * it will remove the selected value from the possible value to be selected once the data is added + * @param typeCST + */ + function addDataToRules(typeCST){ + + switch (typeCST) { + case DATA_CST.TYPE.SUBJECT: + + if (!edit.selectedSubject || isNumberSelectedDataAtMaximum(typeCST) + || _.contains(edit.data.selectedSubjectsList, edit.selectedSubject)) { + return; + } + + edit.data.selectedSubjectsList.push(edit.selectedSubject); + edit.data.subjectsToBeSelected = _.without(edit.data.subjectsToBeSelected, edit.selectedSubject); + + break; + case DATA_CST.TYPE.OBJECT: + + if (!edit.selectedObject || isNumberSelectedDataAtMaximum(typeCST) + || _.contains(edit.data.selectedObjectsList, edit.selectedObject)) { + return; + } + + edit.data.selectedObjectsList.push(edit.selectedObject); + edit.data.objectsToBeSelected = _.without(edit.data.objectsToBeSelected, edit.selectedObject); + + break; + + case DATA_CST.TYPE.ACTION: + if (!edit.selectedAction || isNumberSelectedDataAtMaximum(typeCST) + || _.contains(edit.data.selectedActionsList, edit.selectedAction)) { + return; + } + + edit.data.selectedActionsList.push(edit.selectedAction); + edit.data.actionsToBeSelected = _.without(edit.data.actionsToBeSelected, edit.selectedAction); + + break; + } + + } + + /** + * Remove a selected value, + * refresh the list of possible value to be selected with the removed selected value + * @param data + * @param typeCST + */ + function removeSelectedDataFromRules(data, typeCST) { + + switch (typeCST) { + + case DATA_CST.TYPE.SUBJECT: + + edit.data.subjectsToBeSelected.push(data); + edit.data.selectedSubjectsList = _.without(edit.data.selectedSubjectsList, data); + break; + + case DATA_CST.TYPE.OBJECT: + + edit.data.objectsToBeSelected.push(data); + edit.data.selectedObjectsList = _.without(edit.data.selectedObjectsList, data); + break; + + case DATA_CST.TYPE.ACTION: + + edit.data.actionsToBeSelected.push(data); + edit.data.selectedActionsList = _.without(edit.data.selectedActionsList, data); + break; + } + + } + + /** + * fill edit.rules.rule array with the selected data + * it will first add subject list, object list and then action list + */ + function buildRulesArray(){ + + _.each(edit.data.selectedSubjectsList, pushInRulesTab); + _.each(edit.data.selectedObjectsList, pushInRulesTab); + _.each(edit.data.selectedActionsList, pushInRulesTab); + + function pushInRulesTab(elem){ + edit.rules.rule.push(elem.id); + } + } + + /** + * Declare the data object which contains attributes related to data, + * values to be selected, values selected, loader... + */ + function declareDataObject(){ + + edit.data = { + subject : [], // List of subjects related to the policy + loadingSubjects: true, // allow to know if a call to the API is in progress + subjectsToBeSelected : [], // List of subjects the user can select + selectedSubjectsList: [], // List of subjects selected by the user from subjectsToBeSelected + subjectCST : DATA_CST.TYPE.SUBJECT, + object : [], + loadingObjects: true, + objectsToBeSelected: [], + selectedObjectsList: [], + objectCST : DATA_CST.TYPE.OBJECT, + action : [], + loadingActions : true, + actionsToBeSelected : [], + selectedActionsList: [], + actionCST : DATA_CST.TYPE.ACTION + } + + } + + } + +})();
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js b/old/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js new file mode 100755 index 00000000..5c3e7457 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/parameter/rules/rules.list.dir.js @@ -0,0 +1,302 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonRulesList', moonRulesList); + + moonRulesList.$inject = []; + + function moonRulesList() { + + return { + templateUrl : 'html/policy/edit/parameter/rules/rules-list.tpl.html', + bindToController : true, + controller : moonRulesListController, + controllerAs : 'list', + scope : { + policy: '=', + editMode : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonRulesListController', moonRulesListController); + + moonRulesListController.$inject = [ '$scope', '$rootScope', 'NgTableParams', '$filter', 'metaRuleService', 'rulesService', 'dataService', '$translate', 'alertService' ]; + + function moonRulesListController( $scope, $rootScope, NgTableParams, $filter, metaRuleService, rulesService, dataService, $translate, alertService ) { + + var list = this; + + list.rules = []; + list.editMode = $scope.list.editMode; + + list.loadingRules = true; + + list.table = {}; + + list.getRules = getRules; + list.hasRules = hasRules; + list.refreshRules = refreshRules; + list.deleteRules = deleteRules; + + list.getMetaRuleFromRule = getMetaRuleFromRule; + list.getCategoryFromRuleIndex = getCategoryFromRuleIndex; + + list.isRuleIndexSubjectCategory = isRuleIndexSubjectCategory; + list.isRuleIndexObjectCategory = isRuleIndexObjectCategory; + list.isRuleIndexActionCategory = isRuleIndexActionCategory; + + activate(); + + function activate(){ + + newRulesTable(); + + manageRules(); + + } + + var rootListeners = { + + 'event:createRulesFromDataRulesSuccess': $rootScope.$on('event:createRulesFromDataRulesSuccess', addRulesToList) + + }; + + _.each(rootListeners, function(unbind){ + $scope.$on('$destroy', rootListeners[unbind]); + }); + + function manageRules(){ + + 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 + + }, { + + total: function () { return list.getRules().length; }, // length of data + getData: function($defer, params) { + + var orderedData = params.sorting() ? $filter('orderBy')(list.getRules(), params.orderBy()) : list.getRules(); + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + + }, + $scope: { $data: {} } + + }); + + return list.table; + + } + + function getMetaRuleFromRule(rule) { + + if(_.has(rule, 'meta_rule')){ + return rule.meta_rule; + } + + // if the call has not been made + if(!_.has(rule, 'callMetaRuleInProgress')){ + + rule.callMetaRuleInProgress = true; + + metaRuleService.findOneWithCallback(rule.meta_rule_id, function(meta_rule){ + + rule.callMetaRuleInProgress = false; + rule.meta_rule = meta_rule; + + }); + + } + + // if the call is in progress return false + return false; + } + + + /** + * 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 + */ + function getCategoryFromRuleIndex(index, rule){ + + if(!_.has(rule, 'rule_value')){ + // setting an array which will contains every value of the category + rule.rule_value = Array.apply(null, new Array(rule.rule.length)).map(function(){ + return { + category: {} + }; + }); + } + + if(_.has(rule.rule_value[index], 'callCategoryInProgress') && !rule.rule_value[index].callCategoryInProgress ){ + return rule.rule_value[index].category; + } + + // if the call has not been made + if(!_.has(rule.rule_value[index], 'callCategoryInProgress')){ + + rule.rule_value[index].callCategoryInProgress = true; + + var categoryId = 0; + + if(list.isRuleIndexSubjectCategory(index, rule)){ + + categoryId = rule.meta_rule.subject_categories[index]; + + dataService.subject.data.findOne(list.policy.id, categoryId, rule.rule[index], function(category){ + + rule.rule_value[index].callCategoryInProgress = false; + rule.rule_value[index].category = category; + + }); + + }else if(list.isRuleIndexObjectCategory(index, rule)){ + + + categoryId = rule.meta_rule.object_categories[index - rule.meta_rule.subject_categories.length ]; + + dataService.object.data.findOne(list.policy.id, categoryId, rule.rule[index], function(category){ + + rule.rule_value[index].callCategoryInProgress = false; + rule.rule_value[index].category = category; + + }); + + + }else if(list.isRuleIndexActionCategory(index, rule)){ + + categoryId = rule.meta_rule.action_categories[index - rule.meta_rule.subject_categories.length - rule.meta_rule.object_categories.length ]; + + dataService.action.data.findOne(list.policy.id, categoryId, rule.rule[index], function(category){ + + rule.rule_value[index].callCategoryInProgress = false; + rule.rule_value[index].category = category; + + }); + + }else{ + + rule.rule_value[index].callCategoryInProgress = false; + rule.rule_value[index].category = { + name : 'ERROR' + }; + } + + } + + // if the call is in progress return false + return false; + } + + function isRuleIndexSubjectCategory(index, rule){ + + var ind = index + 1; + + return ind <= rule.meta_rule.subject_categories.length; + + } + + function isRuleIndexObjectCategory(index, rule){ + + 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 ); + + } + + function isRuleIndexActionCategory(index, rule){ + + var ind = index + 1; + + return ( rule.meta_rule.object_categories.length + rule.meta_rule.subject_categories.length ) < ind && ind <= ( rule.meta_rule.object_categories.length + rule.meta_rule.subject_categories.length + rule.meta_rule.action_categories.length); + + } + + function getRules() { + return (list.rules) ? list.rules : []; + } + + function hasRules() { + return list.getRules().length > 0; + } + + /** + * Refresh the table + */ + function refreshRules(){ + list.table.total(list.rules.length); + 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/old/moon_gui/static/app/policy/edit/policy-edit-basic.tpl.html b/old/moon_gui/static/app/policy/edit/policy-edit-basic.tpl.html new file mode 100755 index 00000000..f55c1d05 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/policy-edit-basic.tpl.html @@ -0,0 +1,89 @@ +<div class="row"> + + <form class="form-horizontal" role="form" name="edit.form"> + + <div class="form-group"> + + <label for="id" class="col-sm-3 control-label" data-translate="moon.policy.edit.basic.form.id">Id</label> + + <div class="col-sm-6"> + + <input name="id" id="id" disabled class="form-control" type="text" data-ng-model="edit.policyToEdit.id" required /> + + </div> + + </div> + + <div class="form-group" ng-class="{'has-error': edit.form.name.$invalid && edit.form.name.$dirty}"> + + <label for="name" class="col-sm-3 control-label" data-translate="moon.policy.edit.basic.form.name">Name</label> + + <div class="col-sm-6"> + + <input name="name" id="name" class="form-control" type="text" data-ng-model="edit.policyToEdit.name" required /> + + <div class="help-block" ng-show="edit.form.name.$dirty && edit.form.name.$invalid"> + <small class="error" ng-show="edit.form.name.$error.required" data-translate="moon.policy.edit.basic.check.name.required">Name is required</small> + </div> + + </div> + + </div> + + + <div class="form-group" ng-class="{'has-error': edit.form.model.$dirty && (edit.form.model.$invalid || !edit.selectedModel)}"> + + <label class="col-sm-3 control-label" data-translate="moon.policy.edit.basic.form.model">Models</label> + + <div class="col-sm-6"> + + <ui-select ng-model="edit.selectedModel" name="model" required> + <ui-select-match placeholder="(None)">{{$select.selected.name}}</ui-select-match> + <ui-select-choices repeat="model in edit.models"> + <div ng-value="model">{{model.name}}</div> + </ui-select-choices> + </ui-select> + + <moon-loader ng-if="edit.modelsLoading"></moon-loader> + + <div class="help-block" ng-show="edit.form.model.$dirty && (edit.form.model.$invalid || !edit.selectedModel)"> + <small class="error" ng-show="edit.form.model.$error.required" data-translate="moon.policy.edit.basic.check.model.required">Model is required</small> + </div> + + </div> + + </div> + + <div class="form-group"> + + <label for="description" class="col-sm-3 control-label" data-translate="moon.policy.edit.basic.form.description">Description</label> + <div class="col-sm-6"> + <textarea id="description" name="description" class="form-control" data-ng-model="edit.policyToEdit.description"></textarea> + </div> + + </div> + + <div class="form-group"> + + <div class="col-sm-2 col-sm-offset-3"> + + <a href="" ng-disabled="edit.loading" ng-click="edit.init()" class="btn btn-default"> + <span data-translate="moon.policy.edit.basic.action.init">Init</span> + </a> + </div> + + <div class="col-sm-4 col-sm-offset-2"> + + <a href="" ng-disabled="edit.loading" ng-click="edit.editPolicy()" class="btn btn-warning"> + <span class="glyphicon glyphicon-save"></span> + <span data-translate="moon.policy.edit.basic.action.update">Update</span> + </a> + + <moon-loader ng-if="edit.loading"></moon-loader> + </div> + + </div> + + </form> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/edit/policy-edit.tpl.html b/old/moon_gui/static/app/policy/edit/policy-edit.tpl.html new file mode 100755 index 00000000..60841168 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/policy-edit.tpl.html @@ -0,0 +1,202 @@ +<div class="container"> + + <div class="row"> + <h3 class="pull-left" data-translate="moon.policy.edit.title" data-translate-values="{ policyName: edit.policy.name }">Edit</h3> + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <span data-translate="moon.policy.edit.basic.title" >Basic Information</span> + <a href="" ng-click="edit.editBasic = !edit.editBasic"> + <span data-translate="moon.policy.edit.update">Update</span> + <span class="glyphicon glyphicon-cog"></span> + </a> + + </div> + + <div class="panel-body"> + + <div ng-if="edit.editBasic"> + <moon-policy-edit-basic policy="edit.policy"></moon-policy-edit-basic> + </div> + + <div ng-if="!edit.editBasic"> + + <dl class="dl-horizontal"> + + <dt data-translate="moon.policy.edit.basic.form.id">Id</dt> + <dd ng-bind="edit.policy.id"></dd> + + <dt data-translate="moon.policy.edit.basic.form.name">Name</dt> + <dd ng-bind="edit.policy.name"></dd> + + <dt data-translate="moon.policy.edit.basic.form.genre">Genre</dt> + <dd ng-bind="edit.policy.genre"></dd> + + <dt data-translate="moon.policy.edit.basic.form.model">Model</dt> + <dd> + + <span ng-if="edit.loadingModel"> + <moon-loader ng-if="edit.loadingModel"></moon-loader> + </span> + <span ng-if="!edit.loadingModel"> + <span ng-bind="edit.policy.model.name" ></span> + </span> + + </dd> + + <dt data-translate="moon.policy.edit.basic.form.description">Description</dt> + <dd ng-bind="edit.policy.description"></dd> + + </dl> + + </div> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <span data-translate="moon.policy.edit.perimeter.title" >Perimeters</span> + + <a href="" ng-click="edit.showPart('showPerimeters')"> + + <span ng-if="!edit.showPerimeters"> + <span data-translate="moon.policy.edit.show.open">Show</span> + <span class="glyphicon glyphicon-eye-open"></span> + </span> + + <span ng-if="edit.showPerimeters"> + <span data-translate="moon.policy.edit.show.close">Show</span> + <span class="glyphicon glyphicon-eye-close"></span> + </span> + + </a> + + <!--<a href="" ng-if="edit.showPerimeters"> + <span data-translate="moon.policy.edit.update">Update</span> + <span class="glyphicon glyphicon-cog"></span> + </a>--> + + </div> + + <div class="panel-body" ng-if="edit.showPerimeters"> + + <moon-perimeter-list edit-mode="true" policy="edit.policy" ></moon-perimeter-list> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <span data-translate="moon.policy.edit.data.title" >Data</span> + + <a href="" ng-click="edit.showPart('showData')"> + + <span ng-if="!edit.showData"> + <span data-translate="moon.policy.edit.show.open">Show</span> + <span class="glyphicon glyphicon-eye-open"></span> + </span> + + <span ng-if="edit.showData"> + <span data-translate="moon.policy.edit.show.close">Show</span> + <span class="glyphicon glyphicon-eye-close"></span> + </span> + + </a> + + <!--<a href="" ng-if="edit.showData"> + <span data-translate="moon.policy.edit.update">Update</span> + <span class="glyphicon glyphicon-cog"></span> + </a>--> + + </div> + + <div class="panel-body" ng-if="edit.showData" > <!-- --> + + <moon-data-list edit-mode="true" policy="edit.policy" ></moon-data-list> + + </div> + + </div> + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <span data-translate="moon.policy.edit.rules.title" >Rules</span> + + <a href="" ng-click="edit.showPart('showRules')"> + + <span ng-if="!edit.showRules"> + <span data-translate="moon.policy.edit.show.open">Show</span> + <span class="glyphicon glyphicon-eye-open"></span> + </span> + + <span ng-if="edit.showRules"> + <span data-showRules="moon.policy.edit.show.close">Close</span> + <span class="glyphicon glyphicon-eye-close"></span> + </span> + + </a> + + <!--<a href="" ng-if="edit.showRules"> + <span data-translate="moon.policy.edit.update">Update</span> + <span class="glyphicon glyphicon-cog"></span> + </a>--> + + </div> + + <div class="panel-body" ng-if="edit.showRules"> + + <moon-rules-list edit-mode="true" policy="edit.policy" ></moon-rules-list> + + </div> + + </div> + + + <div class="panel panel-default"> + + <div class="panel-heading"> + + <span data-translate="moon.policy.edit.assignments.title" >Assignments</span> + + <a href="" ng-click="edit.showPart('showAssignments')"> + + <span ng-if="!edit.showAssignments"> + <span data-translate="moon.policy.edit.show.open">Show</span> + <span class="glyphicon glyphicon-eye-open"></span> + </span> + + <span ng-if="edit.showAssignments"> + <span data-showRules="moon.policy.edit.show.close">Close</span> + <span class="glyphicon glyphicon-eye-close"></span> + </span> + + </a> + + <!--<a href="" ng-if="edit.showRules"> + <span data-translate="moon.policy.edit.update">Update</span> + <span class="glyphicon glyphicon-cog"></span> + </a>--> + + </div> + + <div class="panel-body" ng-if="edit.showAssignments"> + + <moon-assignments-list edit-mode="true" policy="edit.policy" ></moon-assignments-list> + + </div> + + </div> + +</div> diff --git a/old/moon_gui/static/app/policy/edit/policy.controller.edit.js b/old/moon_gui/static/app/policy/edit/policy.controller.edit.js new file mode 100755 index 00000000..cd6e429b --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/policy.controller.edit.js @@ -0,0 +1,88 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyEditController', PolicyEditController); + + PolicyEditController.$inject = ['$scope', '$rootScope', 'policy', 'modelService']; + + function PolicyEditController($scope, $rootScope, policy, modelService) { + + var edit = this; + + edit.policy = policy; + + edit.editBasic = false; + + edit.showPerimeters = false; + edit.showData = false; + edit.showRules = false; + edit.showAssignments = false; + + edit.showPart = showPart; + + + activate(); + + function showPart(partName) { + var state = edit[partName]; + + edit.showPerimeters = false; + edit.showData = false; + edit.showRules = false; + edit.showAssignments = false; + + edit[partName] = !state; + } + + + function activate(){ + + manageModel(); + + } + + function manageModel(){ + + edit.loadingModel = true; + + modelService.findOneWithCallback( edit.policy.model_id, function(model){ + + edit.loadingModel = false; + edit.policy.model = model; + + }); + + } + + /* + * ---- events + */ + var rootListeners = { + + 'event:policyUpdatedSuccess': $rootScope.$on('event:policyUpdatedSuccess', policyUpdatedSuccess) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + /** + * When the model is updated, this function refresh the current model with the new changes + * @param event + * @param policy + */ + function policyUpdatedSuccess(event, policy){ + + edit.policy = policy; + + manageModel(); + + } + + } + +})(); diff --git a/old/moon_gui/static/app/policy/edit/policy.edit.basic.dir.js b/old/moon_gui/static/app/policy/edit/policy.edit.basic.dir.js new file mode 100755 index 00000000..c32d9e69 --- /dev/null +++ b/old/moon_gui/static/app/policy/edit/policy.edit.basic.dir.js @@ -0,0 +1,134 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonPolicyEditBasic', moonPolicyEditBasic); + + moonPolicyEditBasic.$inject = []; + + function moonPolicyEditBasic() { + + return { + templateUrl : 'html/policy/edit/policy-edit-basic.tpl.html', + bindToController : true, + controller : moonPolicyEditBasicController, + controllerAs : 'edit', + scope : { + policy : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonPolicyEditBasicController', moonPolicyEditBasicController); + + moonPolicyEditBasicController.$inject = ['$scope', 'policyService', 'formService', 'alertService', '$translate', 'utilService', 'modelService']; + + function moonPolicyEditBasicController($scope, policyService, formService, alertService, $translate, utilService, modelService){ + + var edit = this; + + edit.editPolicy = editPolicy; + edit.init = init; + + edit.form = {}; + edit.modelsLoading = true; + + + activate(); + + function activate(){ + + edit.policy = $scope.edit.policy; + + edit.policyToEdit = angular.copy(edit.policy); + + console.log(edit.policyToEdit); + + resolveModels(); + + } + + /* + * + */ + + function resolveModels() { + + modelService.findAllWithCallBack(resolveModelsCallback); + + } + + function resolveModelsCallback(models) { + + edit.models = models; + + _.each(models, function(model){ + + if(model.id === edit.policy.model_id){ + edit.selectedModel = model; + } + + }); + + edit.modelsLoading = false; + + } + + + function editPolicy(){ + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + }else{ + + edit.loading = true; + + delete edit.policyToEdit.model; + + edit.policyToEdit.model_id = edit.selectedModel.id; + + policyService.update(edit.policyToEdit, updateSuccess, updateError); + + } + + function updateSuccess(data) { + + var updatedPolicy = utilService.transformOne(data, 'policies'); + + $translate('moon.policy.edit.basic.success', { policyName: updatedPolicy.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + edit.loading = false; + + $scope.$emit('event:policyUpdatedSuccess', updatedPolicy); + + } + + function updateError(reason) { + + $translate('moon.policy.edit.basic.error', { policyName: edit.policy.name }).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + edit.loading = false; + + } + } + + function init(){ + + edit.policyToEdit = angular.copy(edit.policy); + + } + } + +})(); diff --git a/old/moon_gui/static/app/policy/policy-list.tpl.html b/old/moon_gui/static/app/policy/policy-list.tpl.html new file mode 100755 index 00000000..aeb90f0b --- /dev/null +++ b/old/moon_gui/static/app/policy/policy-list.tpl.html @@ -0,0 +1,131 @@ +<div class="container"> + + <div> + <form class="form-inline pull-right"> + <div class="form-group"> + <div> + <input id="searcPolicy" data-ng-model="list.search.query" type="text" class="form-control" placeholder="{{'moon.policy.list.search.placeholder' | translate}}" /> + </div> + </div> + <div class="form-group"> + <div> + <button type="submit" class="btn btn-danger" data-ng-click="list.search.reset()" data-translate="moon.policy.list.search.reset">Reset</button> + </div> + </div> + </form> + </div> + + <div> </div> + <div> </div> + <div> </div> + + + <div class="row" > + + <div class="table-responsive" data-role="table"> + + <table class="table table-striped table-hover" ng-table="list.table"> + + <colgroup> + <col class="col-md-4" /> + <col class="col-md-2" /> + <col class="col-md-2" /> + <col class="col-md-1" /> + </colgroup> + + <thead> + + <tr> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('name', 'asc'), 'sort-desc': list.table.isSortBy('name', 'desc') }" + ng-click="list.table.sorting('name', list.table.isSortBy('name', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.name">Name</div> + </th> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('genre', 'asc'), 'sort-desc': list.table.isSortBy('genre', 'desc') }" + ng-click="list.table.sorting('genre', list.table.isSortBy('genre', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.genre">Genre</div> + </th> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('description', 'asc'), 'sort-desc': list.table.isSortBy('description', 'desc') }" + ng-click="list.table.sorting('description', list.table.isSortBy('description', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.description">Description</div> + </th> + + <th class="customTables sortable"> + <div data-translate="moon.policy.list.action.title">Actions</div> + </th> + + </tr> + + </thead> + + <tbody ng-if="!list.hasPolicies()"> + <tr> + <td colspan="12"><span data-translate="moon.policy.list.table.notFound">There is no policy</span></td> + </tr> + </tbody> + + <tbody ng-if="list.hasPolicies()"> + + <tr ng-repeat="policy in $data | filter:list.search.find | orderBy:sort:reverse"> + + <td ng-bind="policy.name"></td> + + <td ng-bind="policy.genre"></td> + + <td ng-bind="policy.description"></td> + + <td> + <div class="dropdown"> + <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown"> + <span data-translate="moon.policy.list.action.title">Actions</span> + <span class="caret"></span> + </button> + <ul class="dropdown-menu"> + + <li> + <a href="" ui-sref="moon.policy.edit({id: policy.id})"> + <span class="glyphicon glyphicon-cog"></span> + <span class="control-label" data-translate="moon.policy.list.action.edit">Edit</span> + </a> + </li> + + <li class="divider"></li> + + <li> + <a href="" ng-click="list.del.showModal(policy)"> + <span class="glyphicon glyphicon-trash"></span> + <span class="control-label" data-translate="moon.policy.list.action.delete">Delete</span> + </a> + </li> + + </ul> + </div> + </td> + + </tr> + + </tbody> + + </table> + + </div> + + <div class="container"> + + <div class="form-inline form-group"> + <a href="" ng-click="list.add.showModal()" class="btn btn-default"> + <span class="glyphicon glyphicon-plus-sign"></span> + <span data-translate="moon.policy.list.action.add">Add Model</span> + </a> + </div> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/policy-mapped-list.tpl.html b/old/moon_gui/static/app/policy/policy-mapped-list.tpl.html new file mode 100755 index 00000000..127dae3b --- /dev/null +++ b/old/moon_gui/static/app/policy/policy-mapped-list.tpl.html @@ -0,0 +1,88 @@ +<div class="container"> + + <div class="row" ng-if="list.loadingPolicies"> + <moon-loader ng-if="list.loadingPolicies"></moon-loader> + </div> + + <div class="row" ng-if="!list.loadingPolicies" > + + <div class="table-responsive" data-role="table"> + + <table class="table table-striped table-hover" ng-table="list.table"> + + <colgroup> + <col class="col-md-4" /> + <col class="col-md-2" /> + <col class="col-md-2" /> + <col class="col-md-1" /> + </colgroup> + + <thead> + + <tr> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('name', 'asc'), 'sort-desc': list.table.isSortBy('name', 'desc') }" + ng-click="list.table.sorting('name', list.table.isSortBy('name', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.name">Name</div> + </th> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('genre', 'asc'), 'sort-desc': list.table.isSortBy('genre', 'desc') }" + ng-click="list.table.sorting('genre', list.table.isSortBy('genre', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.genre">Genre</div> + </th> + + <th class="customTables sortable" + ng-class="{ 'sort-asc': list.table.isSortBy('description', 'asc'), 'sort-desc': list.table.isSortBy('description', 'desc') }" + ng-click="list.table.sorting('description', list.table.isSortBy('description', 'asc') ? 'desc' : 'asc')"> + <div data-translate="moon.policy.list.table.description">Description</div> + </th> + + <th class="customTables sortable"> + <div data-translate="moon.policy.list.action.title">Actions</div> + </th> + </tr> + + </thead> + + <tbody ng-if="!list.hasPolicies()"> + <tr> + <td colspan="12"><span data-translate="moon.policy.list.table.notFound">There is no policy</span></td> + </tr> + </tbody> + + <tbody ng-if="list.hasPolicies()"> + + <tr ng-repeat="policy in $data | filter:list.search.find | orderBy:sort:reverse"> + <td ng-bind="policy.name"></td> + <td ng-bind="policy.genre"></td> + <td ng-bind="policy.description"></td> + <td> + <a href="" ng-click="list.unmap.showModal(policy)"> + <span class="glyphicon glyphicon-transfer"></span> + <em data-translate="moon.policy.list.action.unmap">Unmap</em> + </a> + </td> + </tr> + + </tbody> + + </table> + + </div> + + <div class="container"> + + <div class="form-inline form-group"> + <a href="" ng-click="list.map.showModal()" class="btn btn-default"> + <span class="glyphicon glyphicon-link"></span> + <em data-translate="moon.policy.list.action.map">Map a Policy to PDP</em> + </a> + </div> + + </div> + + </div> + +</div>
\ No newline at end of file diff --git a/old/moon_gui/static/app/policy/policy.controller.list.js b/old/moon_gui/static/app/policy/policy.controller.list.js new file mode 100755 index 00000000..fc2c6503 --- /dev/null +++ b/old/moon_gui/static/app/policy/policy.controller.list.js @@ -0,0 +1,175 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PolicyListController', PolicyListController); + + PolicyListController.$inject = ['$scope', 'policies', 'NgTableParams', '$filter', '$modal', '$rootScope']; + + function PolicyListController($scope, policies, NgTableParams, $filter, $modal, $rootScope) { + + var list = this; + + list.policies = policies; + + list.getPolicies = getPolicies; + list.hasPolicies = hasPolicies; + list.addPolicy = addPolicy; + list.refreshPolicies = refreshPolicies; + list.deletePolicy = deletePolicy; + + list.table = {}; + + list.search = { query: '', + find: searchPolicy, + reset: searchReset }; + + list.add = { modal: $modal({ template: 'html/policy/action/policy-add.tpl.html', show: false }), + showModal: showAddModal }; + + list.del = { modal: $modal({ template: 'html/policy/action/policy-delete.tpl.html', show: false }), + showModal: showDeleteModal }; + + activate(); + + function activate(){ + + newPoliciesTable(); + + } + + + /* + * ---- events + */ + + var rootListeners = { + + 'event:policyCreatedSuccess': $rootScope.$on('event:policyCreatedSuccess', policyCreatedSuccess), + 'event:policyCreatedError': $rootScope.$on('event:policyCreatedError', policyCreatedError), + + 'event:policyDeletedSuccess': $rootScope.$on('event:policyDeletedSuccess', policyDeletedSuccess), + 'event:policyDeletedError': $rootScope.$on('event:policyDeletedError', policyDeletedError) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + function getPolicies() { + return (list.policies) ? list.policies : []; + } + + function hasPolicies() { + return list.getPolicies().length > 0; + } + + function newPoliciesTable() { + + list.table = new NgTableParams({ + + page: 1, // show first page + count: 10, // count per page + sorting: { + name: 'asc', + genre: 'asc' + } + + }, { + + total: function () { return list.getPolicies().length; }, // length of data + getData: function($defer, params) { + + var orderedData = params.sorting() ? $filter('orderBy')(list.getPolicies(), params.orderBy()) : list.getPolicies(); + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + + }, + $scope: { $data: {} } + + }); + + return list.table; + + } + + + /* + * ---- search + */ + + function searchPolicy(policy){ + return (policy.name.indexOf(list.search.query) !== -1 || policy.genre.indexOf(list.search.query) !== -1 || policy.description.indexOf(list.search.query) !== -1); + } + + function searchReset() { + list.search.query = ''; + } + + /* + * ---- add + */ + function showAddModal() { + list.add.modal.$promise.then(list.add.modal.show); + } + + function policyCreatedSuccess(event, pdp) { + + list.addPolicy(pdp); + list.refreshPolicies(); + + list.add.modal.hide(); + + } + + function policyCreatedError(event, pdp) { + list.add.modal.hide(); + } + + function addPolicy(policy) { + list.policies.push(policy); + } + + function refreshPolicies() { + + list.table.total(list.policies.length); + list.table.reload(); + + } + + /* + * ---- delete + */ + + function showDeleteModal(policy) { + + list.del.modal.$scope.policy = policy; + list.del.modal.$promise.then(list.del.modal.show); + + } + + function deletePolicy(policy) { + + list.policies = _.chain(list.policies).reject({id: policy.id}).value(); + + } + + function policyDeletedSuccess(event, policy) { + + list.deletePolicy(policy); + list.refreshPolicies(); + + list.del.modal.hide(); + + } + + function policyDeletedError(event, policy) { + list.del.modal.hide(); + } + + + } + +})(); diff --git a/old/moon_gui/static/app/policy/policy.mapped.list.dir.js b/old/moon_gui/static/app/policy/policy.mapped.list.dir.js new file mode 100755 index 00000000..78bb3b8d --- /dev/null +++ b/old/moon_gui/static/app/policy/policy.mapped.list.dir.js @@ -0,0 +1,202 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonPolicyMappedList', moonPolicyMappedList); + + moonPolicyMappedList.$inject = []; + + function moonPolicyMappedList() { + + return { + templateUrl : 'html/policy/policy-mapped-list.tpl.html', + bindToController : true, + controller : moonPolicyMappedListController, + controllerAs : 'list', + scope : { + pdp : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonPolicyMappedListController', moonPolicyMappedListController); + + moonPolicyMappedListController.$inject = ['$scope', '$rootScope', 'NgTableParams', '$modal', '$filter', 'policyService']; + + function moonPolicyMappedListController($scope, $rootScope, NgTableParams, $modal, $filter, policyService){ + + var list = this; + + list.table = {}; + + + list.pdp = $scope.list.pdp; + + list.getPolicies = getPolicies; + list.hasPolicies = hasPolicies; + list.refreshPolicies = refreshPolicies; + + list.loadingPolicies = true; + + list.policies = []; + + + activate(); + + function activate() { + + loadPolicices(false); + + } + + /** + * + * @param refresh boolean, if !refresh then newPolicYtable will be called, if refresh, then refreshPolicies is called + */ + 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; + + if(refresh){ + + refreshPolicies(); + + }else{ + + newMPolicyTable(); + + } + + }); + + } + + list.map = { modal: $modal({ template: 'html/policy/action/mapping/policy-map.tpl.html', show: false }), + showModal: showMapModal }; + + list.unmap = { modal: $modal({ template: 'html/policy/action/mapping/policy-unmap.tpl.html', show: false }), + showModal: showUnmapModal }; + + /* + * ---- events + */ + var rootListeners = { + + 'event:policyMapToPdpSuccess': $rootScope.$on('event:policyMapToPdpSuccess', policyMapToPdpSuccess), + 'event:policyMapToPdpError': $rootScope.$on('event:policyMapToPdpError', policyMapToPdpError), + + 'event:policyUnMappedToPdpSuccess': $rootScope.$on('event:policyUnMappedToPdpSuccess', policyUnmappedSuccess), + 'event:policyUnMappedToPdpError': $rootScope.$on('event:policyUnMappedToPdpError', policyUnmappedError) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + + + function newMPolicyTable() { + + list.table = new NgTableParams({ + + page: 1, // show first page + count: 10 // count per page + + }, { + + total: function () { return list.getPolicies().length; }, // length of data + getData: function($defer, params) { + + var orderedData = params.sorting() ? $filter('orderBy')(list.getPolicies(), params.orderBy()) : list.getPolicies(); + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + + }, + $scope: { $data: {} } + + }); + + return list.table; + + } + + + function getPolicies() { + return (list.policies) ? list.policies : []; + } + + function hasPolicies() { + return list.getPolicies().length > 0; + } + + function refreshPolicies(){ + + list.table.total(list.getPolicies().length); + list.table.reload(); + + } + + function showMapModal(){ + list.map.modal.$scope.pdp = list.pdp; + list.map.modal.$promise.then(list.map.modal.show); + } + + function showUnmapModal(policy){ + + list.unmap.modal.$scope.pdp = list.pdp; + list.unmap.modal.$scope.policy = policy; + + list.unmap.modal.$promise.then(list.unmap.modal.show); + + } + + function policyMapToPdpSuccess(event, pdp){ + + list.pdp = pdp; + + loadPolicices(true); + + list.map.modal.hide(); + + } + + + function policyMapToPdpError(event) { + + list.map.modal.hide(); + + } + + function policyUnmappedSuccess(event, pdp) { + + list.pdp = pdp; + + loadPolicices(true); + + list.unmap.modal.hide(); + + } + + function policyUnmappedError(event) { + list.unmap.modal.hide(); + } + + + } + +})(); |