Skip to content

Commit

Permalink
Merge pull request #507 from getbannerman/master
Browse files Browse the repository at this point in the history
feature(params): global default config
  • Loading branch information
Github committed Jan 16, 2015
2 parents 0b91bb2 + 9156c3f commit e72950d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/scripts/03-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
*/

/**
* @ngdoc value
* @name ngTable.value:ngTableDefaultParams
* @description Default Parameters for ngTable
*/
app.value('ngTableDefaults',{
params: {},
settings: {}
});

/**
* @ngdoc service
* @name ngTable.factory:ngTableParams
* @description Parameters manager for ngTable
*/
app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
app.factory('ngTableParams', ['$q', '$log', 'ngTableDefaults', function ($q, $log, ngTableDefaults) {
var isNumber = function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
};
Expand Down Expand Up @@ -382,6 +392,8 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
group: {},
groupBy: null
};
angular.extend(params, ngTableDefaults.params);

var settings = {
$scope: null, // set by ngTable controller
$loading: false,
Expand All @@ -393,6 +405,7 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
getGroups: this.getGroups,
getData: this.getData
};
angular.extend(settings, ngTableDefaults.settings);

this.settings(baseSettings);
this.parameters(baseParameters, true);
Expand Down
17 changes: 17 additions & 0 deletions test/tableParamsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,21 @@ describe('ngTableParams', function () {
});
params.getGroups($defer, 'age');
}));

it('ngTableParams test defaults', inject(function ($q, ngTableParams, ngTableDefaults) {
ngTableDefaults.params = {
count: 2
};
ngTableDefaults.settings = {
counts: []
};
var params = new ngTableParams();

expect(params.count()).toEqual(2);
expect(params.page()).toEqual(1);

var settings = params.settings()
expect(settings.counts.length).toEqual(0);
expect(settings.filterDelay).toEqual(750);
}));
});
3 changes: 1 addition & 2 deletions test/tableSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe('ng-table', function () {
}));

it('should show scope data', inject(function ($compile, $rootScope, ngTableParams) {
debugger;
var tbody = elm.find('tbody');
expect(tbody.length).toBe(1);

Expand All @@ -99,7 +98,7 @@ describe('ng-table', function () {

scope.tableParams.page(2);
scope.$digest();

rows = tbody.find('tr');
expect(rows.length).toBe(7);

Expand Down

0 comments on commit e72950d

Please sign in to comment.