From 58f4fab180e956799592ef065ca79bb4c174921e Mon Sep 17 00:00:00 2001 From: Luis Daniel Castellanos Date: Thu, 1 Sep 2016 10:41:27 -0500 Subject: [PATCH] Added Regions 'drawer' to show hosts in region The list of hosts is not available in the region's drawer --- ChangeLog | 3 ++ craton_dashboard/api/craton.py | 18 +++++-- craton_dashboard/api/rest/__init__.py | 2 +- .../openstack-service-api/craton.service.js | 31 +++++++++++- .../craton.service.spec.js | 14 ++++++ .../inventory/details/drawer.html | 9 +++- .../inventory/drawer.controller.js | 47 +++++++++++++++++ .../inventory/drawer.controller.spec.js | 50 +++++++++++++++++++ .../inventory/inventory.controller.js | 15 ------ .../inventory/inventory.controller.spec.js | 22 -------- .../inventory/regions.module.js | 5 +- 11 files changed, 169 insertions(+), 47 deletions(-) create mode 100644 craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.js create mode 100644 craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.spec.js delete mode 100644 craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.js delete mode 100644 craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.spec.js diff --git a/ChangeLog b/ChangeLog index 05cea60..e0942ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ CHANGES ======= +* Added regions resource table to the Inventory panel +* Directory for i18n +* Reordered panels * Add JavaScript unit tests code base * Move the panel dashboard outside of the project section * Removed the docstrings from the start of file diff --git a/craton_dashboard/api/craton.py b/craton_dashboard/api/craton.py index c0c90e9..3d1b155 100644 --- a/craton_dashboard/api/craton.py +++ b/craton_dashboard/api/craton.py @@ -27,14 +27,18 @@ def get_auth_params_from_request(request): request.user.username, request.user.token.id, request.user.tenant_id, - base.url_for(request, 'craton') + base.url_for(request, 'fleetmanagement'), + request.session ) @memoized_with_request(get_auth_params_from_request) def cratonclient(request_auth_params): - username, token, project_id, url = request_auth_params - session = craton_session.Session(username=username, token=token) + username, token, project_id, url, session = request_auth_params + + session = craton_session.Session(session=session, + username=username, + token=token) c = craton_client.Client(session=session, url=url) return c @@ -124,8 +128,14 @@ def host_delete(request, **kwargs): pass +@memoized def host_list(request, **kwargs): - pass + project_id = getattr(kwargs, 'project_id', None) + if project_id: + delattr(kwargs, 'project_id') + return cratonclient(request).hosts.list(project_id=project_id, + **kwargs) + return [] def host_show(request, **kwargs): diff --git a/craton_dashboard/api/rest/__init__.py b/craton_dashboard/api/rest/__init__.py index 778d56e..1ec819f 100644 --- a/craton_dashboard/api/rest/__init__.py +++ b/craton_dashboard/api/rest/__init__.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -from craton_dashboard.api.rest import craton # noqa \ No newline at end of file +from craton_dashboard.api.rest import craton # noqa diff --git a/craton_dashboard/static/app/core/openstack-service-api/craton.service.js b/craton_dashboard/static/app/core/openstack-service-api/craton.service.js index 6ff7876..8b78457 100644 --- a/craton_dashboard/static/app/core/openstack-service-api/craton.service.js +++ b/craton_dashboard/static/app/core/openstack-service-api/craton.service.js @@ -38,7 +38,9 @@ function cratonAPI($q, apiService, toastService) { var service = { - getRegions: getRegions + getRegions: getRegions, + getHosts: getHosts, + getRegion: getRegion }; /** @@ -54,6 +56,33 @@ }); } + + /** + * @name getRegion + * @param identifier Region Id + * @returns {Object} api call result + */ + function getRegion(identifier) { + return apiService.get('api/craton/regions/' + identifier + '/') + .error(function error() { + toastService.add('error', gettext("Unable to get the Craton Region")); + }); + } + + /** + * @name getHosts + * @description Gets a list of hosts + * @param params {Object} query filter params + * @returns {Object} an object with 'items' + */ + function getHosts(params) { + var config = params ? {'params': params} : {}; + return apiService.get('api/craton/hosts', config) + .error(function error() { + toastService.add('error', gettext('Unable to retrieve the hosts')); + }); + } + return service; } diff --git a/craton_dashboard/static/app/core/openstack-service-api/craton.service.spec.js b/craton_dashboard/static/app/core/openstack-service-api/craton.service.spec.js index 9316ff6..4d0eb57 100644 --- a/craton_dashboard/static/app/core/openstack-service-api/craton.service.spec.js +++ b/craton_dashboard/static/app/core/openstack-service-api/craton.service.spec.js @@ -46,6 +46,20 @@ method: "get", path: "api/craton/regions", error: "Unable to get the Craton regions listing" + }, + { + func: "getRegion", + method: "get", + path: "api/craton/regions/spam/", + error: "Unable to get the Craton Region", + testInput: ["spam"] + }, + { + func: "getHosts", + method: "get", + path: "api/craton/hosts", + error: "Unable to retrieve the hosts", + data: {} } ]; diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/details/drawer.html b/craton_dashboard/static/dashboard/project/fleet_management/inventory/details/drawer.html index ca1eb28..ab18add 100644 --- a/craton_dashboard/static/dashboard/project/fleet_management/inventory/details/drawer.html +++ b/craton_dashboard/static/dashboard/project/fleet_management/inventory/details/drawer.html @@ -1,5 +1,10 @@ -
+
- + +

+ No items to display. +

\ No newline at end of file diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.js b/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.js new file mode 100644 index 0000000..6d52500 --- /dev/null +++ b/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.js @@ -0,0 +1,47 @@ +/** + * Copyright 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +(function() { + 'use strict'; + + angular.module('horizon.dashboard.project.fleet_management.regions') + .controller('horizon.dashboard.project.fleet_management.regions.RegionDrawerController', + RegionDrawerController); + + RegionDrawerController.$inject = [ + 'horizon.dashboard.project.fleet_management.regions.resourceType', + 'horizon.framework.conf.resource-type-registry.service', + 'horizon.app.core.openstack-service-api.craton', + '$scope' + ]; + + function RegionDrawerController(regionResourceType, registry, cratonApi, $scope) { + var ctrl = this; + + ctrl.region = $scope.item || {}; + ctrl.region.hosts = []; + ctrl.resourceType = registry.getResourceType(regionResourceType); + + getHosts(); + + function getHosts() { + cratonApi.getHosts({region_id: ctrl.region.id }).then(function resolve(data) { + ctrl.region.hosts = data.data.items; + }); + } + } + +})(); diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.spec.js b/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.spec.js new file mode 100644 index 0000000..0e2eb76 --- /dev/null +++ b/craton_dashboard/static/dashboard/project/fleet_management/inventory/drawer.controller.spec.js @@ -0,0 +1,50 @@ +/** + * Copyright 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +(function () { + 'use strict'; + + describe('horizon.dashboard.project.fleet_management.regions RegionsDrawerController', + function () { + beforeEach(module('horizon.app.core.openstack-service-api')); + beforeEach(module('horizon.framework')); + beforeEach(module('horizon.dashboard.project')); + beforeEach(module('horizon.dashboard.project.fleet_management')); + + var /*$q, $rootScope,*/ scope, cratonAPI, controller; + + beforeEach(inject( function ($injector, _$q_, _$rootScope_) { + controller = $injector.get('$controller'); + // $q = _$q_; + // $rootScope = _$rootScope_; + scope = _$rootScope_.$new(); + cratonAPI = $injector.get('horizon.app.core.openstack-service-api.craton'); + })); + + function createController() { + return controller( + 'horizon.dashboard.project.fleet_management.regions.RegionDrawerController', + {$scope: scope}); + } + + it('should call api getHosts when created', function test() { + spyOn(cratonAPI, 'getHosts').and.callThrough(); + createController(); + expect(cratonAPI.getHosts).toHaveBeenCalled(); + }); + }); + +})(); diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.js b/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.js deleted file mode 100644 index d996a1b..0000000 --- a/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright 2016 Intel Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.spec.js b/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.spec.js deleted file mode 100644 index aebe1fc..0000000 --- a/craton_dashboard/static/dashboard/project/fleet_management/inventory/inventory.controller.spec.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright 2016 Intel Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ - -(function() { - 'use strict'; - - //TODO: ADD TESTS!! - -})(); diff --git a/craton_dashboard/static/dashboard/project/fleet_management/inventory/regions.module.js b/craton_dashboard/static/dashboard/project/fleet_management/inventory/regions.module.js index ca73a53..5367ef8 100644 --- a/craton_dashboard/static/dashboard/project/fleet_management/inventory/regions.module.js +++ b/craton_dashboard/static/dashboard/project/fleet_management/inventory/regions.module.js @@ -29,7 +29,8 @@ angular .module('horizon.dashboard.project.fleet_management.regions', ['ngRoute']) - .constant('horizon.dashboard.project.fleet_management.resourceType', 'OS::Craton::Region') + .constant('horizon.dashboard.project.fleet_management.regions.resourceType', + 'OS::Craton::Region') .run(run) .config(config); @@ -37,7 +38,7 @@ 'horizon.framework.conf.resource-type-registry.service', 'horizon.app.core.openstack-service-api.craton', 'horizon.dashboard.project.fleet_management.basePath', - 'horizon.dashboard.project.fleet_management.resourceType' + 'horizon.dashboard.project.fleet_management.regions.resourceType' ]; function run(registry, craton, basePath, cratonResourceType) {