Fix select all button in table view
This patch changes to using the $scope of the directive to access the selected rows of the table. Also introduces a function to translate the 'uuid' field returned from the magnum python client to 'id', this is due to angular directives requiring a field called id in order to do selection. Closes-bug: #1506078 Change-Id: I9405f012cc18074484ee3dc19904a6ba51e9d1e7
This commit is contained in:
parent
723dcfa97d
commit
69bb0fad85
@ -20,6 +20,16 @@ from openstack_dashboard.api.rest import urls
|
||||
from openstack_dashboard.api.rest import utils as rest_utils
|
||||
|
||||
|
||||
def change_to_id(obj):
|
||||
"""Change key named 'uuid' to 'id'
|
||||
|
||||
Magnum returns objects with a field called 'uuid' many of Horizons
|
||||
directives however expect objects to have a field called 'id'.
|
||||
"""
|
||||
obj['id'] = obj.pop('uuid')
|
||||
return obj
|
||||
|
||||
|
||||
@urls.register
|
||||
class BayModels(generic.View):
|
||||
"""API for Magnum BayModels
|
||||
@ -34,7 +44,7 @@ class BayModels(generic.View):
|
||||
item under this is a BayModel.
|
||||
"""
|
||||
result = magnum.baymodel_list(request)
|
||||
return{'baymodels': [n.to_dict() for n in result]}
|
||||
return{'baymodels': [change_to_id(n.to_dict()) for n in result]}
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def delete(self, request):
|
||||
|
@ -30,14 +30,14 @@
|
||||
.controller('containersBayModelTableController', containersBayModelTableController);
|
||||
|
||||
containersBayModelTableController.$inject = [
|
||||
'$scope',
|
||||
'horizon.app.core.openstack-service-api.magnum'
|
||||
];
|
||||
|
||||
function containersBayModelTableController(magnum) {
|
||||
function containersBayModelTableController($scope, magnum) {
|
||||
var ctrl = this;
|
||||
ctrl.ibaymodels = [];
|
||||
ctrl.baymodels = [];
|
||||
ctrl.checked = {};
|
||||
|
||||
ctrl.singleDelete = singleDelete;
|
||||
ctrl.batchDelete = batchDelete;
|
||||
@ -53,25 +53,26 @@
|
||||
}
|
||||
|
||||
function singleDelete(baymodel) {
|
||||
magnum.deleteBayModel(baymodel.uuid).success(function() {
|
||||
magnum.deleteBayModel(baymodel.id).success(function() {
|
||||
ctrl.baymodels.splice(ctrl.baymodels.indexOf(baymodel),1);
|
||||
});
|
||||
}
|
||||
|
||||
function batchDelete() {
|
||||
var ids = [];
|
||||
for (var bm in ctrl.checked) {
|
||||
ids.push(bm);
|
||||
for (var id in $scope.selected) {
|
||||
if ($scope.selected[id].checked) {
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
magnum.deleteBayModels(ctrl.checked).success(function() {
|
||||
for (var bm in ctrl.checked) {
|
||||
magnum.deleteBayModels(ids).success(function() {
|
||||
for (var id in ids) {
|
||||
var todelete = ctrl.baymodels.filter(function(obj) {
|
||||
return obj.uuid == bm;
|
||||
return obj.id == ids[id];
|
||||
});
|
||||
ctrl.baymodels.splice(ctrl.baymodels.indexOf(todelete[0]),1);
|
||||
}
|
||||
ctrl.checked = {};
|
||||
$scope.selected = {};
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@
|
||||
<translate>Name</translate>
|
||||
</th>
|
||||
|
||||
<th class="rsp-p1" st-sort="uuid" >
|
||||
<th class="rsp-p1" st-sort="id" >
|
||||
<translate>ID</translate>
|
||||
</th>
|
||||
|
||||
@ -66,13 +66,12 @@
|
||||
rsp-p1 rsp-p2 are responsive priority as user resizes window.
|
||||
-->
|
||||
|
||||
<tr ng-repeat-start="bm in table.ibaymodels"
|
||||
g-repeat-start="bm in table.ibaymodels"
|
||||
nt-class="{'st-selected': table.checked[bm.uuid]">
|
||||
<tr ng-repeat-start="bm in table.ibaymodels track by bm.id"
|
||||
nt-class="{'st-selected': checked[bm.id]}">
|
||||
|
||||
<td class="select-col">
|
||||
<input type="checkbox"
|
||||
ng-model="table.checked[bm.uuid].checked"
|
||||
ng-model="selected[bm.id].checked"
|
||||
hz-select="bm">
|
||||
</td>
|
||||
|
||||
@ -84,7 +83,7 @@
|
||||
</td>
|
||||
|
||||
<td class="rsp-p1">{$ bm.name $}</td>
|
||||
<td class="rsp-p1">{$ bm.uuid $}</td>
|
||||
<td class="rsp-p1">{$ bm.id $}</td>
|
||||
<td class="rsp-p2">{$ bm.coe $}</td>
|
||||
|
||||
<td class="action-col">
|
||||
@ -119,7 +118,7 @@
|
||||
<dd>{$ bm.name $}</dd>
|
||||
|
||||
<dt><translate>ID</translate></dt>
|
||||
<dd>{$ bm.uuid $}</dd>
|
||||
<dd>{$ bm.id $}</dd>
|
||||
|
||||
<dt><translate>COE</translate></dt>
|
||||
<dd>{$ bm.coe $}</dd>
|
||||
|
Loading…
Reference in New Issue
Block a user