Skip to content

Commit

Permalink
Merge branch '639-add-web-avps-for-pools'
Browse files Browse the repository at this point in the history
  • Loading branch information
plajjan committed Oct 31, 2014
2 parents 47d9980 + 28bfb0a commit 4d123b8
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
7 changes: 6 additions & 1 deletion nipap-www/nipapwww/controllers/xhr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
41 changes: 40 additions & 1 deletion nipap-www/nipapwww/public/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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){
Expand Down Expand Up @@ -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) {
Expand All @@ -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',
Expand Down Expand Up @@ -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){
Expand Down
40 changes: 40 additions & 0 deletions nipap-www/nipapwww/public/templates/pool_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,46 @@ <h3 ng-show="method == 'add'" class="options-group-heading">Properties of new po
</dl>
</div>

<div class="rule"></div>

<div class="option">
<dl>
<dt>
Extra Attributes
</dt>
<dd>
<table style="width: 100%;">
<tbody>
<tr ng-repeat="avp in pool.avps">
<td class="col-md-4" style="padding: 0;">
<input type="text" style="width: 90%;" ng-model="avp.attribute"> <b>=</b>
</td>
<td class="col-md-7" style="padding: 0;">
<input type="text" style="width: 100%;" ng-model="avp.value">
</td>
<td class="col-md-1" style="padding-top: 3px; padding-bottom: 3px;">
<button type="button" class="btn btn-xs btn-danger" ng-click="removeAvp(avp)">
<span class="glyphicon glyphicon-minus"></span> Remove
</button>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td></td>
<td></td>
<td style="padding-top: 5px;">
<button type="button" class="btn btn-xs btn-success" ng-click="addAvp()">
<span class="glyphicon glyphicon-plus"></span> Add attribute
</button>
</td>
</tfoot>
</table>
</dd>
</dl>
</div>


<div class="rule" ng-show="method == 'edit'"></div>

<div class="option">
Expand Down

0 comments on commit 4d123b8

Please sign in to comment.