From 1100c66ce03a059ebe7ece9734e799b49b3a5a9e Mon Sep 17 00:00:00 2001 From: WuKong Date: Sat, 23 Dec 2017 21:49:35 +0100 Subject: moonv4 cleanup Change-Id: Icef927f3236d985ac13ff7376f6ce6314b2b39b0 Signed-off-by: WuKong --- .../policy/action/mapping/policy.controller.map.js | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 moon_gui/static/app/policy/action/mapping/policy.controller.map.js (limited to 'moon_gui/static/app/policy/action/mapping/policy.controller.map.js') 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 -- cgit 1.2.3-korg