diff --git a/horizon/static/framework/conf/conf.js b/horizon/static/framework/conf/conf.js index 645f5782d1..8687315ad6 100644 --- a/horizon/static/framework/conf/conf.js +++ b/horizon/static/framework/conf/conf.js @@ -20,5 +20,8 @@ .value('horizon.framework.conf.toastOptions', { 'delay': 3000, 'dimissible': ['alert-success', 'alert-info'] + }) + .value('horizon.framework.conf.tableOptions', { + 'pageSize': 20 }); })(); diff --git a/horizon/static/framework/widgets/table/hz-dynamic-table.directive.spec.js b/horizon/static/framework/widgets/table/hz-dynamic-table.directive.spec.js index 88fe276536..b25c02ad55 100644 --- a/horizon/static/framework/widgets/table/hz-dynamic-table.directive.spec.js +++ b/horizon/static/framework/widgets/table/hz-dynamic-table.directive.spec.js @@ -29,6 +29,17 @@ beforeEach(module('horizon.framework.widgets.magic-search')); beforeEach(module('horizon.framework.widgets.table')); + beforeEach(function() { + horizon.cookies = { + get: function() { + return; + } + }; + + spyOn(horizon.cookies, 'get').and.callThrough(); + + }); + beforeEach(inject(function(_$compile_, _$rootScope_) { $compile = _$compile_; $rootScope = _$rootScope_; diff --git a/horizon/static/framework/widgets/table/hz-dynamic-table.spec.js b/horizon/static/framework/widgets/table/hz-dynamic-table.spec.js index 325746b58f..684f32d82d 100644 --- a/horizon/static/framework/widgets/table/hz-dynamic-table.spec.js +++ b/horizon/static/framework/widgets/table/hz-dynamic-table.spec.js @@ -31,6 +31,17 @@ beforeEach(module('smart-table')); beforeEach(module('horizon.framework')); + beforeEach(function() { + horizon.cookies = { + get: function() { + return; + } + }; + + spyOn(horizon.cookies, 'get').and.callThrough(); + + }); + beforeEach(inject(function ($injector) { $compile = $injector.get('$compile'); $scope = $injector.get('$rootScope').$new(); diff --git a/horizon/static/framework/widgets/table/hz-table-footer.controller.js b/horizon/static/framework/widgets/table/hz-table-footer.controller.js new file mode 100644 index 0000000000..901dabc19c --- /dev/null +++ b/horizon/static/framework/widgets/table/hz-table-footer.controller.js @@ -0,0 +1,33 @@ +/* + * Copyright 2016 IBM Corp. + * Copyright 2016 99Cloud. + * + * 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.framework.widgets.table') + .controller('HzTableFooterController', HzTableFooterController); + + HzTableFooterController.$inject = [ + 'horizon.framework.conf.tableOptions' + ]; + + function HzTableFooterController(tableOptions) { + var ctrl = this; + ctrl.pageSize = horizon.cookies.get('API_RESULT_PAGE_SIZE') || tableOptions.pageSize; + } + +})(); diff --git a/horizon/static/framework/widgets/table/hz-table-footer.directive.js b/horizon/static/framework/widgets/table/hz-table-footer.directive.js index d02591763f..c8071717c0 100644 --- a/horizon/static/framework/widgets/table/hz-table-footer.directive.js +++ b/horizon/static/framework/widgets/table/hz-table-footer.directive.js @@ -57,6 +57,7 @@ */ function hzTableFooter(basePath, $compile) { var directive = { + controller: 'HzTableFooterController as ctrl', restrict: 'A', scope: { items: '=' diff --git a/horizon/static/framework/widgets/table/hz-table-footer.html b/horizon/static/framework/widgets/table/hz-table-footer.html index 69e24b57ec..9f2be0e97c 100644 --- a/horizon/static/framework/widgets/table/hz-table-footer.html +++ b/horizon/static/framework/widgets/table/hz-table-footer.html @@ -1,12 +1,11 @@ - {$ items.length|itemCount $} -
+ {$ items.length|itemCount $} + - + \ No newline at end of file diff --git a/horizon/static/framework/widgets/table/pagination.html b/horizon/static/framework/widgets/table/pagination.html new file mode 100644 index 0000000000..e690341c1e --- /dev/null +++ b/horizon/static/framework/widgets/table/pagination.html @@ -0,0 +1,13 @@ + + | + + + « Prev + + + + + Next » + + + diff --git a/horizon/static/framework/widgets/table/table.module.js b/horizon/static/framework/widgets/table/table.module.js index 41f001f950..f804b887e6 100644 --- a/horizon/static/framework/widgets/table/table.module.js +++ b/horizon/static/framework/widgets/table/table.module.js @@ -29,7 +29,7 @@ * module and jQuery (for table drawer slide animation in IE9) to be installed. */ angular - .module('horizon.framework.widgets.table', []) + .module('horizon.framework.widgets.table', ['smart-table']) /** * @ngdoc parameters @@ -53,5 +53,9 @@ CLEAR_SELECTIONS: 'hzTable:clearSelections', ROW_SELECTED: 'hzTable:rowSelected', ROW_EXPANDED: 'hzTable:rowExpanded' - }); + }) + .config(['stConfig','$windowProvider', function (stConfig, $windowProvider) { + var path = $windowProvider.$get().STATIC_URL + 'framework/widgets/table/'; + stConfig.pagination.template = path + 'pagination.html'; + }]); })(); diff --git a/horizon/static/framework/widgets/table/table.spec.js b/horizon/static/framework/widgets/table/table.spec.js index 77570ff8d5..1f3d754773 100644 --- a/horizon/static/framework/widgets/table/table.spec.js +++ b/horizon/static/framework/widgets/table/table.spec.js @@ -260,12 +260,27 @@ }); describe('hzTableFooter directive', function () { - var $scope, $compile, $element; + var $scope, $compile, $element, controllerProvider, horizonCookiesSpy; beforeEach(module('templates')); beforeEach(module('smart-table')); beforeEach(module('horizon.framework')); + beforeEach(inject(function ($controller) { + controllerProvider = $controller; + })); + + beforeEach(function() { + horizon.cookies = { + get: function() { + return; + } + }; + + horizonCookiesSpy = spyOn(horizon.cookies, 'get'); + + }); + beforeEach(inject(function ($injector) { $compile = $injector.get('$compile'); $scope = $injector.get('$rootScope').$new(); @@ -310,11 +325,25 @@ expect($element).toBeDefined(); expect($element.find('span').length).toBe(1); - expect($element.find('span').text()).toBe('3 items'); + expect($element.find('span').text()).toBe('Displaying 3 items'); }); it('includes pagination', function() { - expect($element.find('div').attr('st-items-by-page')).toEqual('20'); + expect($element.find('st-pagination').attr('st-items-by-page')).toEqual('ctrl.pageSize'); + }); + + it('gets pagination from cookies', function() { + horizonCookiesSpy.and.returnValue(10); + + var ctrl = controllerProvider('HzTableFooterController'); + expect(ctrl.pageSize).toBe(10); + }); + + it('gets pagination from config service', function() { + horizonCookiesSpy.and.callThrough(); + + var ctrl = controllerProvider('HzTableFooterController'); + expect(ctrl.pageSize).toBe(20); }); }); diff --git a/openstack_dashboard/static/dashboard/scss/_util.scss b/openstack_dashboard/static/dashboard/scss/_util.scss index 8ae5f86492..f88e32e708 100644 --- a/openstack_dashboard/static/dashboard/scss/_util.scss +++ b/openstack_dashboard/static/dashboard/scss/_util.scss @@ -64,3 +64,7 @@ input::-ms-clear, input::-ms-reveal { width: 0; height: auto; } + +[ng-click] { + cursor: pointer; +} \ No newline at end of file