diff options
author | WuKong <rebirthmonkey@gmail.com> | 2017-12-23 21:49:35 +0100 |
---|---|---|
committer | WuKong <rebirthmonkey@gmail.com> | 2017-12-23 21:49:58 +0100 |
commit | 1100c66ce03a059ebe7ece9734e799b49b3a5a9e (patch) | |
tree | a057e7e7511f6675a9327b79e6919f07c5f89f07 /moon_gui/static/app/policy/action | |
parent | 7a4dfdde6314476ae2a1a1c881ff1e3c430f790e (diff) |
moonv4 cleanup
Change-Id: Icef927f3236d985ac13ff7376f6ce6314b2b39b0
Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moon_gui/static/app/policy/action')
8 files changed, 612 insertions, 0 deletions
diff --git a/moon_gui/static/app/policy/action/mapping/policy-map.tpl.html b/moon_gui/static/app/policy/action/mapping/policy-map.tpl.html new file mode 100755 index 00000000..8b787f14 --- /dev/null +++ b/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/moon_gui/static/app/policy/action/mapping/policy-unmap.tpl.html b/moon_gui/static/app/policy/action/mapping/policy-unmap.tpl.html new file mode 100755 index 00000000..a2cda52a --- /dev/null +++ b/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/moon_gui/static/app/policy/action/mapping/policy.controller.map.js b/moon_gui/static/app/policy/action/mapping/policy.controller.map.js new file mode 100755 index 00000000..6ad8caa7 --- /dev/null +++ b/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/moon_gui/static/app/policy/action/mapping/policy.controller.unmap.js b/moon_gui/static/app/policy/action/mapping/policy.controller.unmap.js new file mode 100755 index 00000000..d309ec0f --- /dev/null +++ b/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/moon_gui/static/app/policy/action/policy-add.tpl.html b/moon_gui/static/app/policy/action/policy-add.tpl.html new file mode 100755 index 00000000..d20c41be --- /dev/null +++ b/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/moon_gui/static/app/policy/action/policy-delete.tpl.html b/moon_gui/static/app/policy/action/policy-delete.tpl.html new file mode 100755 index 00000000..3b5df88b --- /dev/null +++ b/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/moon_gui/static/app/policy/action/policy.controller.add.js b/moon_gui/static/app/policy/action/policy.controller.add.js new file mode 100755 index 00000000..0320c2e9 --- /dev/null +++ b/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/moon_gui/static/app/policy/action/policy.controller.delete.js b/moon_gui/static/app/policy/action/policy.controller.delete.js new file mode 100755 index 00000000..9a718ddc --- /dev/null +++ b/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); + + } + + } + } + +})(); |