From 28bfb0a8402655b5b7af3b54aea354adf36a7a22 Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Mon, 27 Oct 2014 17:38:21 +0100 Subject: [PATCH] www: add AVPs for pools This adds the ability to add, modify and remove AVPs for pools in the web UI. Fixes #639 --- nipap-www/nipapwww/controllers/xhr.py | 7 +++- nipap-www/nipapwww/public/controllers.js | 41 ++++++++++++++++++- .../nipapwww/public/templates/pool_form.html | 40 ++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/nipap-www/nipapwww/controllers/xhr.py b/nipap-www/nipapwww/controllers/xhr.py index 6e84eeba6..2a91989a4 100644 --- a/nipap-www/nipapwww/controllers/xhr.py +++ b/nipap-www/nipapwww/controllers/xhr.py @@ -257,6 +257,8 @@ def add_pool(self): p.ipv6_default_prefix_length = request.params['ipv6_default_prefix_length'] if 'tags' in request.params: p.tags = json.loads(request.params['tags']) + if 'avps' in request.params: + p.avps = json.loads(request.params['avps']) try: p.save() @@ -291,6 +293,8 @@ def edit_pool(self, id): p.ipv6_default_prefix_length = None if 'tags' in request.params: p.tags = json.loads(request.params['tags']) + if 'avps' in request.params: + p.avps = json.loads(request.params['avps']) try: p.save() @@ -862,7 +866,8 @@ def default(self, obj): 'used_addresses_v4': obj.used_addresses_v4, 'used_addresses_v6': obj.used_addresses_v6, 'free_addresses_v4': obj.free_addresses_v4, - 'free_addresses_v6': obj.free_addresses_v6 + 'free_addresses_v6': obj.free_addresses_v6, + 'avps': obj.avps } elif isinstance(obj, Prefix): diff --git a/nipap-www/nipapwww/public/controllers.js b/nipap-www/nipapwww/public/controllers.js index 8d645fac0..c86cda22e 100644 --- a/nipap-www/nipapwww/public/controllers.js +++ b/nipap-www/nipapwww/public/controllers.js @@ -829,9 +829,21 @@ nipapAppControllers.controller('PoolAddController', function ($scope, $http) { 'tags': [], 'default_type': null, 'ipv4_default_prefix_length': null, - 'ipv6_default_prefix_length': null + 'ipv6_default_prefix_length': null, + 'avps': [] }; + // add another empty "extra attribute" (AVP) input row + $scope.addAvp = function() { + $scope.pool.avps.push({ 'attribute': '', 'value': '' }); + } + + // remove AVP row + $scope.removeAvp = function(avp) { + var index = $scope.pool.avps.indexOf(avp); + $scope.pool.avps.splice( index, 1 ); + } + /* * Submit pool form - add pool */ @@ -846,6 +858,13 @@ nipapAppControllers.controller('PoolAddController', function ($scope, $http) { // Rewrite tags list to match what's expected by the XHR functions query_data.tags = JSON.stringify($scope.pool.tags.map(function (elem) { return elem.text; })); + // Mangle avps + query_data.avps = {}; + $scope.pool.avps.forEach(function(avp) { + query_data.avps[avp.attribute] = avp.value; + }); + query_data.avps = JSON.stringify(query_data.avps); + // Send query! $http.get('/xhr/add_pool', { 'params': query_data }) .success(function (data){ @@ -877,6 +896,17 @@ nipapAppControllers.controller('PoolEditController', function ($scope, $routePar }; $scope.pool_prefixes = []; + // add another empty "extra attribute" (AVP) input row + $scope.addAvp = function() { + $scope.pool.avps.push({ 'attribute': '', 'value': '' }); + } + + // remove AVP row + $scope.removeAvp = function(avp) { + var index = $scope.pool.avps.indexOf(avp); + $scope.pool.avps.splice( index, 1 ); + } + // Fetch VRF to edit from backend $http.get('/xhr/list_pool', { 'params': { 'id': $routeParams.pool_id, } }) .success(function (data) { @@ -891,6 +921,8 @@ nipapAppControllers.controller('PoolEditController', function ($scope, $routePar // format as tags-input pool.tags = Object.keys(pool.tags).map(function (elem) { return { 'text': elem }; } ); + pool.avps = Object.keys(pool.avps).sort().map(function (key) { return { 'attribute': key, 'value': pool.avps[key] }; } ); + // Fetch pool's VRF if (pool.vrf_id !== null) { $http.get('/xhr/smart_search_vrf', @@ -1012,6 +1044,13 @@ nipapAppControllers.controller('PoolEditController', function ($scope, $routePar // Rewrite tags list to match what's expected by the XHR functions query_data.tags = JSON.stringify($scope.pool.tags.map(function (elem) { return elem.text; })); + // Mangle avps + query_data.avps = {}; + $scope.prefix.avps.forEach(function(avp) { + query_data.avps[avp.attribute] = avp.value; + }); + query_data.avps = JSON.stringify(query_data.avps); + // Send query! $http.get('/xhr/edit_pool/' + $scope.pool.id, { 'params': query_data }) .success(function (data){ diff --git a/nipap-www/nipapwww/public/templates/pool_form.html b/nipap-www/nipapwww/public/templates/pool_form.html index 10cc2ba60..b057671e8 100644 --- a/nipap-www/nipapwww/public/templates/pool_form.html +++ b/nipap-www/nipapwww/public/templates/pool_form.html @@ -128,6 +128,46 @@

Properties of new po +
+ +
+
+
+ Extra Attributes +
+
+ + + + + + + + + + + + + + +
+ = + + + + +
+ +
+
+
+
+ +