From 69bb0fad852a8219b17b8e5694ab8c5ffe1975ab Mon Sep 17 00:00:00 2001 From: Bradley Jones Date: Thu, 15 Oct 2015 11:52:02 +0100 Subject: [PATCH] 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 --- magnum_ui/api/rest/magnum.py | 12 ++++++++++- .../baymodel/table/table.controller.js | 21 ++++++++++--------- .../containers/baymodel/table/table.html | 13 ++++++------ 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/magnum_ui/api/rest/magnum.py b/magnum_ui/api/rest/magnum.py index e7665618..3c364dc4 100644 --- a/magnum_ui/api/rest/magnum.py +++ b/magnum_ui/api/rest/magnum.py @@ -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): diff --git a/magnum_ui/static/dashboard/containers/baymodel/table/table.controller.js b/magnum_ui/static/dashboard/containers/baymodel/table/table.controller.js index 464e5aad..39c469ae 100644 --- a/magnum_ui/static/dashboard/containers/baymodel/table/table.controller.js +++ b/magnum_ui/static/dashboard/containers/baymodel/table/table.controller.js @@ -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 = {}; }) } } diff --git a/magnum_ui/static/dashboard/containers/baymodel/table/table.html b/magnum_ui/static/dashboard/containers/baymodel/table/table.html index 83707220..d4e4390f 100644 --- a/magnum_ui/static/dashboard/containers/baymodel/table/table.html +++ b/magnum_ui/static/dashboard/containers/baymodel/table/table.html @@ -43,7 +43,7 @@ Name - + ID @@ -66,13 +66,12 @@ rsp-p1 rsp-p2 are responsive priority as user resizes window. --> - + @@ -84,7 +83,7 @@ {$ bm.name $} - {$ bm.uuid $} + {$ bm.id $} {$ bm.coe $} @@ -119,7 +118,7 @@
{$ bm.name $}
ID
-
{$ bm.uuid $}
+
{$ bm.id $}
COE
{$ bm.coe $}