@grafit/era-dependencies 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -0
- package/vendor/fonts/FontAwesome.otf +0 -0
- package/vendor/fonts/fontawesome-webfont.eot +0 -0
- package/vendor/fonts/fontawesome-webfont.svg +685 -0
- package/vendor/fonts/fontawesome-webfont.ttf +0 -0
- package/vendor/fonts/fontawesome-webfont.woff +0 -0
- package/vendor/fonts/fontawesome-webfont.woff2 +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.eot +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.svg +288 -0
- package/vendor/fonts/glyphicons-halflings-regular.ttf +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.woff +0 -0
- package/vendor/fonts/glyphicons-halflings-regular.woff2 +0 -0
- package/vendor/scripts/angular/angular-cookies.js +322 -0
- package/vendor/scripts/angular/angular-file-upload.js +2087 -0
- package/vendor/scripts/angular/angular-filter.js +2287 -0
- package/vendor/scripts/angular/angular-locale_ru-ru.js +143 -0
- package/vendor/scripts/angular/angular-route.js +1069 -0
- package/vendor/scripts/angular/angular-sanitize.js +738 -0
- package/vendor/scripts/angular/angular-ui-router-0.2.18.js +4539 -0
- package/vendor/scripts/angular/angular.js +31768 -0
- package/vendor/scripts/angular/datetimepicker.js +578 -0
- package/vendor/scripts/angular/datetimepicker.templates.js +30 -0
- package/vendor/scripts/angular/mask.min.js +7 -0
- package/vendor/scripts/angular/ng-table.js +1518 -0
- package/vendor/scripts/angular/select.js +2356 -0
- package/vendor/scripts/angular/ui-bootstrap-tpls-2.1.3.js +7536 -0
- package/vendor/scripts/angular/uploader.js +3 -0
- package/vendor/scripts/bootbox.js +985 -0
- package/vendor/scripts/bootstrap.js +2377 -0
- package/vendor/scripts/es6-shim.js +3837 -0
- package/vendor/scripts/highchart/highcharts-more.src.js +3165 -0
- package/vendor/scripts/highchart/highstock.src.js +32008 -0
- package/vendor/scripts/highchart/modules/boost.src.js +2721 -0
- package/vendor/scripts/highchart/modules/exporting.src.js +951 -0
- package/vendor/scripts/jquery/jquery.js +11008 -0
- package/vendor/scripts/jquery.datetimepicker.full.js +2911 -0
- package/vendor/scripts/keycloak.js +2382 -0
- package/vendor/scripts/lodash.js +16733 -0
- package/vendor/scripts/moment-with-locales.js +12251 -0
- package/vendor/scripts/moment.js +4234 -0
- package/vendor/scripts/old/datepicker-ru.js +38 -0
- package/vendor/scripts/old/jquery-ui-1.11.1.js +16375 -0
- package/vendor/scripts/old/jquery.form.js +1278 -0
- package/vendor/scripts/perfect-scrollbar.js +1549 -0
- package/vendor/scripts/pickmeup/pickmeup-locales.js +11 -0
- package/vendor/scripts/pickmeup/pickmeup.js +1383 -0
- package/vendor/scripts/quill.js +9676 -0
- package/vendor/scripts/socket.io.min.js +3 -0
- package/vendor/scripts/textAngular/angular-spectrum-colorpicker.min.js +2 -0
- package/vendor/scripts/textAngular/spectrum.min.js +1 -0
- package/vendor/scripts/textAngular/textAngular-dropdownToggle.js +38 -0
- package/vendor/scripts/textAngular/textAngular-rangy.min.js +478 -0
- package/vendor/scripts/textAngular/textAngular-sanitize.min.js +322 -0
- package/vendor/scripts/textAngular/textAngular.min.js +1481 -0
- package/vendor/scripts/textAngular/textAngularSetup.js +1013 -0
- package/vendor/styles/bootstrap-theme.css +587 -0
- package/vendor/styles/bootstrap-theme.css.map +1 -0
- package/vendor/styles/bootstrap-theme.min.css +6 -0
- package/vendor/styles/bootstrap-theme.min.css.map +1 -0
- package/vendor/styles/bootstrap.css +6757 -0
- package/vendor/styles/bootstrap.css.map +1 -0
- package/vendor/styles/bootstrap.min.css +6 -0
- package/vendor/styles/bootstrap.min.css.map +1 -0
- package/vendor/styles/datetimepicker.css +115 -0
- package/vendor/styles/font-awesome.css +2199 -0
- package/vendor/styles/jquery.datetimepicker.min.css +1 -0
- package/vendor/styles/ng-table.css +136 -0
- package/vendor/styles/normalize.css +424 -0
- package/vendor/styles/perfect-scrollbar.css +165 -0
- package/vendor/styles/pickmeup.css +137 -0
- package/vendor/styles/spectrum.min.css +1 -0
- package/vendor/styles/textAngular.css +193 -0
|
@@ -0,0 +1,1518 @@
|
|
|
1
|
+
(function(angular, factory) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
if (typeof define === 'function' && define.amd) {
|
|
5
|
+
define(['angular'], function(angular) {
|
|
6
|
+
return factory(angular);
|
|
7
|
+
});
|
|
8
|
+
} else {
|
|
9
|
+
return factory(angular);
|
|
10
|
+
}
|
|
11
|
+
}(window.angular || null, function(angular) {
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* ngTable: Table + Angular JS
|
|
16
|
+
*
|
|
17
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
18
|
+
* @url https://github.com/esvit/ng-table/
|
|
19
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @ngdoc module
|
|
24
|
+
* @name ngTable
|
|
25
|
+
* @description ngTable: Table + Angular JS
|
|
26
|
+
* @example
|
|
27
|
+
<doc:example>
|
|
28
|
+
<doc:source>
|
|
29
|
+
<script>
|
|
30
|
+
var app = angular.module('myApp', ['ngTable']);
|
|
31
|
+
app.controller('MyCtrl', function($scope) {
|
|
32
|
+
$scope.users = [
|
|
33
|
+
{name: "Moroni", age: 50},
|
|
34
|
+
{name: "Tiancum", age: 43},
|
|
35
|
+
{name: "Jacob", age: 27},
|
|
36
|
+
{name: "Nephi", age: 29},
|
|
37
|
+
{name: "Enos", age: 34}
|
|
38
|
+
];
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
<table ng-table class="table">
|
|
42
|
+
<tr ng-repeat="user in users">
|
|
43
|
+
<td data-title="'Name'">{{user.name}}</td>
|
|
44
|
+
<td data-title="'Age'">{{user.age}}</td>
|
|
45
|
+
</tr>
|
|
46
|
+
</table>
|
|
47
|
+
</doc:source>
|
|
48
|
+
</doc:example>
|
|
49
|
+
*/
|
|
50
|
+
var app = angular.module('ngTable', []);
|
|
51
|
+
/**
|
|
52
|
+
* ngTable: Table + Angular JS
|
|
53
|
+
*
|
|
54
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
55
|
+
* @url https://github.com/esvit/ng-table/
|
|
56
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
(function(){
|
|
60
|
+
'use strict';
|
|
61
|
+
|
|
62
|
+
angular.module('ngTable')
|
|
63
|
+
.factory('ngTableEventsChannel', ngTableEventsChannel);
|
|
64
|
+
|
|
65
|
+
ngTableEventsChannel.$inject = ['$rootScope'];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @ngdoc service
|
|
69
|
+
* @name ngTableEventsChannel
|
|
70
|
+
* @description strongly typed pub/sub for `NgTableParams`
|
|
71
|
+
*
|
|
72
|
+
* Supported events:
|
|
73
|
+
*
|
|
74
|
+
* * afterCreated - raised when a new instance of `NgTableParams` has finished being constructed
|
|
75
|
+
* * afterReloadData - raised when the `reload` event has finished loading new data
|
|
76
|
+
* * datasetChanged - raised when `settings` receives a new data array
|
|
77
|
+
* * pagesChanged - raised when a new pages array has been generated
|
|
78
|
+
*/
|
|
79
|
+
function ngTableEventsChannel($rootScope){
|
|
80
|
+
|
|
81
|
+
var events = {};
|
|
82
|
+
events = addChangeEvent('afterCreated', events);
|
|
83
|
+
events = addChangeEvent('afterReloadData', events);
|
|
84
|
+
events = addChangeEvent('datasetChanged', events);
|
|
85
|
+
events = addChangeEvent('pagesChanged', events);
|
|
86
|
+
return events;
|
|
87
|
+
|
|
88
|
+
//////////
|
|
89
|
+
|
|
90
|
+
function addChangeEvent(eventName, target){
|
|
91
|
+
var fnName = eventName.charAt(0).toUpperCase() + eventName.substring(1);
|
|
92
|
+
var event = {};
|
|
93
|
+
event['on' + fnName] = createEventSubscriptionFn(eventName);
|
|
94
|
+
event['publish' + fnName] = createPublishEventFn(eventName);
|
|
95
|
+
return angular.extend(target, event);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createEventSubscriptionFn(eventName){
|
|
99
|
+
|
|
100
|
+
return function subscription(handler/*[, eventSelector or $scope][, eventSelector]*/){
|
|
101
|
+
var eventSelector = angular.identity;
|
|
102
|
+
var scope = $rootScope;
|
|
103
|
+
|
|
104
|
+
if (arguments.length === 2){
|
|
105
|
+
if (angular.isFunction(arguments[1].$new)) {
|
|
106
|
+
scope = arguments[1];
|
|
107
|
+
} else {
|
|
108
|
+
eventSelector = arguments[1]
|
|
109
|
+
}
|
|
110
|
+
} else if (arguments.length > 2){
|
|
111
|
+
scope = arguments[1];
|
|
112
|
+
eventSelector = arguments[2];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// shorthand for subscriber to only receive events from a specific publisher instance
|
|
116
|
+
if (angular.isObject(eventSelector)) {
|
|
117
|
+
var requiredPublisher = eventSelector;
|
|
118
|
+
eventSelector = function(publisher){
|
|
119
|
+
return publisher === requiredPublisher;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return scope.$on('ngTable:' + eventName, function(event, params/*, ...args*/){
|
|
124
|
+
// don't send events published by the internal NgTableParams created by ngTableController
|
|
125
|
+
if (params.isNullInstance) return;
|
|
126
|
+
|
|
127
|
+
var eventArgs = rest(arguments, 2);
|
|
128
|
+
var fnArgs = [params].concat(eventArgs);
|
|
129
|
+
if (eventSelector.apply(this, fnArgs)){
|
|
130
|
+
handler.apply(this, fnArgs);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function createPublishEventFn(eventName){
|
|
137
|
+
return function publish(/*args*/){
|
|
138
|
+
var fnArgs = ['ngTable:' + eventName].concat(Array.prototype.slice.call(arguments));
|
|
139
|
+
$rootScope.$broadcast.apply($rootScope, fnArgs);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function rest(array, n) {
|
|
144
|
+
return Array.prototype.slice.call(array, n == null ? 1 : n);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
})();
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* ngTable: Table + Angular JS
|
|
151
|
+
*
|
|
152
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
153
|
+
* @url https://github.com/esvit/ng-table/
|
|
154
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
(function(){
|
|
158
|
+
'use strict';
|
|
159
|
+
|
|
160
|
+
angular.module('ngTable')
|
|
161
|
+
.provider('ngTableFilterConfig', ngTableFilterConfigProvider);
|
|
162
|
+
|
|
163
|
+
ngTableFilterConfigProvider.$inject = [];
|
|
164
|
+
|
|
165
|
+
function ngTableFilterConfigProvider(){
|
|
166
|
+
var config;
|
|
167
|
+
var defaultConfig = {
|
|
168
|
+
defaultBaseUrl: 'ng-table/filters/',
|
|
169
|
+
defaultExt: '.html',
|
|
170
|
+
aliasUrls: {}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
this.$get = ngTableFilterConfig;
|
|
174
|
+
this.resetConfigs = resetConfigs;
|
|
175
|
+
this.setConfig = setConfig;
|
|
176
|
+
|
|
177
|
+
init();
|
|
178
|
+
|
|
179
|
+
/////////
|
|
180
|
+
|
|
181
|
+
function init(){
|
|
182
|
+
resetConfigs();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function resetConfigs(){
|
|
186
|
+
config = defaultConfig;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function setConfig(customConfig){
|
|
190
|
+
var mergeConfig = angular.extend({}, config, customConfig);
|
|
191
|
+
mergeConfig.aliasUrls = angular.extend({}, config.aliasUrls, customConfig.aliasUrls);
|
|
192
|
+
config = mergeConfig;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/////////
|
|
196
|
+
|
|
197
|
+
ngTableFilterConfig.$inject = [];
|
|
198
|
+
|
|
199
|
+
function ngTableFilterConfig(){
|
|
200
|
+
|
|
201
|
+
var publicConfig;
|
|
202
|
+
|
|
203
|
+
var service = {
|
|
204
|
+
config: publicConfig,
|
|
205
|
+
getTemplateUrl: getTemplateUrl,
|
|
206
|
+
getUrlForAlias: getUrlForAlias
|
|
207
|
+
};
|
|
208
|
+
Object.defineProperty(service, "config", {
|
|
209
|
+
get: function(){
|
|
210
|
+
return publicConfig = publicConfig || angular.copy(config);
|
|
211
|
+
},
|
|
212
|
+
enumerable: true
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return service;
|
|
216
|
+
|
|
217
|
+
/////////
|
|
218
|
+
|
|
219
|
+
function getTemplateUrl(filterValue, filterKey){
|
|
220
|
+
if (filterValue.indexOf('/') !== -1){
|
|
221
|
+
return filterValue;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return service.getUrlForAlias(filterValue, filterKey);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function getUrlForAlias(aliasName/*, filterKey*/){
|
|
228
|
+
return config.aliasUrls[aliasName] || config.defaultBaseUrl + aliasName + config.defaultExt;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* ngTable: Table + Angular JS
|
|
236
|
+
*
|
|
237
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
238
|
+
* @url https://github.com/esvit/ng-table/
|
|
239
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
(function(){
|
|
243
|
+
'use strict';
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
angular.module('ngTable')
|
|
247
|
+
.provider('ngTableDefaultGetData', ngTableDefaultGetDataProvider);
|
|
248
|
+
|
|
249
|
+
ngTableDefaultGetDataProvider.$inject = [];
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @ngdoc provider
|
|
253
|
+
* @name ngTableDefaultGetDataProvider
|
|
254
|
+
* @description Allows for the configuration of the {@link ngTable.ngTableDefaultGetData ngTableDefaultGetData}
|
|
255
|
+
* service.
|
|
256
|
+
*
|
|
257
|
+
* Set filterFilterName to the name of a angular filter that knows how to take `NgTableParams.filter()`
|
|
258
|
+
* to restrict an array of data.
|
|
259
|
+
*
|
|
260
|
+
* Set sortingFilterName to the name of a angular filter that knows how to take `NgTableParams.orderBy()`
|
|
261
|
+
* to sort an array of data.
|
|
262
|
+
*
|
|
263
|
+
* Out of the box the `ngTableDefaultGetData` service will be configured to use the angular `filter` and `orderBy`
|
|
264
|
+
* filters respectively
|
|
265
|
+
*/
|
|
266
|
+
function ngTableDefaultGetDataProvider(){
|
|
267
|
+
var provider = this;
|
|
268
|
+
provider.$get = ngTableDefaultGetData;
|
|
269
|
+
provider.filterFilterName = 'filter';
|
|
270
|
+
provider.sortingFilterName = 'orderBy';
|
|
271
|
+
|
|
272
|
+
///////////
|
|
273
|
+
|
|
274
|
+
ngTableDefaultGetData.$inject = ['$filter'];
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @ngdoc service
|
|
278
|
+
* @name ngTableDefaultGetData
|
|
279
|
+
* @description A default implementation of the getData function that will apply the `filter`, `orderBy` and
|
|
280
|
+
* paging values from the `NgTableParams` instance supplied to the data array supplied.
|
|
281
|
+
*
|
|
282
|
+
* The outcome will be to return the resulting array and to assign the total item count after filtering
|
|
283
|
+
* to the `total` of the `NgTableParams` instance supplied
|
|
284
|
+
*/
|
|
285
|
+
function ngTableDefaultGetData($filter) {
|
|
286
|
+
|
|
287
|
+
return getData;
|
|
288
|
+
|
|
289
|
+
function getData(data, params) {
|
|
290
|
+
if (data == null){
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
var fData = params.hasFilter() ? $filter(provider.filterFilterName)(data, params.filter(true)) : data;
|
|
295
|
+
var orderBy = params.orderBy();
|
|
296
|
+
var orderedData = orderBy.length ? $filter(provider.sortingFilterName)(fData, orderBy) : fData;
|
|
297
|
+
var pagedData = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
|
|
298
|
+
params.total(orderedData.length); // set total for recalc pagination
|
|
299
|
+
return pagedData;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
})();
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* ngTable: Table + Angular JS
|
|
307
|
+
*
|
|
308
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
309
|
+
* @url https://github.com/esvit/ng-table/
|
|
310
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
(function(){
|
|
314
|
+
'use strict';
|
|
315
|
+
|
|
316
|
+
// todo: remove shim after an acceptable depreciation period
|
|
317
|
+
|
|
318
|
+
angular.module('ngTable')
|
|
319
|
+
.factory('ngTableGetDataBcShim', ngTableGetDataBcShim);
|
|
320
|
+
|
|
321
|
+
ngTableGetDataBcShim.$inject = ['$q'];
|
|
322
|
+
|
|
323
|
+
function ngTableGetDataBcShim($q){
|
|
324
|
+
|
|
325
|
+
return createWrapper;
|
|
326
|
+
|
|
327
|
+
function createWrapper(getDataFn){
|
|
328
|
+
return function getDataShim(/*args*/){
|
|
329
|
+
var $defer = $q.defer();
|
|
330
|
+
var pData = getDataFn.apply(this, [$defer].concat(Array.prototype.slice.call(arguments)));
|
|
331
|
+
if (!pData) {
|
|
332
|
+
// If getData resolved the $defer, and didn't promise us data,
|
|
333
|
+
// create a promise from the $defer. We need to return a promise.
|
|
334
|
+
pData = $defer.promise;
|
|
335
|
+
}
|
|
336
|
+
return pData;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
})();
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* ngTable: Table + Angular JS
|
|
344
|
+
*
|
|
345
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
346
|
+
* @url https://github.com/esvit/ng-table/
|
|
347
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
348
|
+
*/
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @ngdoc object
|
|
352
|
+
* @name ngTableDefaultParams
|
|
353
|
+
* @module ngTable
|
|
354
|
+
* @description Default Parameters for ngTable
|
|
355
|
+
*/
|
|
356
|
+
app.value('ngTableDefaults', {
|
|
357
|
+
params: {},
|
|
358
|
+
settings: {}
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* @ngdoc service
|
|
363
|
+
* @name NgTableParams
|
|
364
|
+
* @module ngTable
|
|
365
|
+
* @description Parameters manager for ngTable
|
|
366
|
+
*/
|
|
367
|
+
|
|
368
|
+
app.factory('NgTableParams', ['$q', '$log', 'ngTableDefaults', 'ngTableGetDataBcShim', 'ngTableDefaultGetData', 'ngTableEventsChannel', function($q, $log, ngTableDefaults, ngTableGetDataBcShim, ngTableDefaultGetData, ngTableEventsChannel) {
|
|
369
|
+
var isNumber = function(n) {
|
|
370
|
+
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
371
|
+
};
|
|
372
|
+
var NgTableParams = function(baseParameters, baseSettings) {
|
|
373
|
+
|
|
374
|
+
// the ngTableController "needs" to create a dummy/null instance and it's important to know whether an instance
|
|
375
|
+
// is one of these
|
|
376
|
+
if (typeof baseParameters === "boolean"){
|
|
377
|
+
this.isNullInstance = true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
var self = this,
|
|
381
|
+
committedParams,
|
|
382
|
+
isCommittedDataset = false,
|
|
383
|
+
log = function() {
|
|
384
|
+
if (settings.debugMode && $log.debug) {
|
|
385
|
+
$log.debug.apply(this, arguments);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
this.data = [];
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* @ngdoc method
|
|
393
|
+
* @name NgTableParams#parameters
|
|
394
|
+
* @description Set new parameters or get current parameters
|
|
395
|
+
*
|
|
396
|
+
* @param {string} newParameters New parameters
|
|
397
|
+
* @param {string} parseParamsFromUrl Flag if parse parameters like in url
|
|
398
|
+
* @returns {Object} Current parameters or `this`
|
|
399
|
+
*/
|
|
400
|
+
this.parameters = function(newParameters, parseParamsFromUrl) {
|
|
401
|
+
parseParamsFromUrl = parseParamsFromUrl || false;
|
|
402
|
+
if (angular.isDefined(newParameters)) {
|
|
403
|
+
for (var key in newParameters) {
|
|
404
|
+
var value = newParameters[key];
|
|
405
|
+
if (parseParamsFromUrl && key.indexOf('[') >= 0) {
|
|
406
|
+
var keys = key.split(/\[(.*)\]/).reverse()
|
|
407
|
+
var lastKey = '';
|
|
408
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
409
|
+
var name = keys[i];
|
|
410
|
+
if (name !== '') {
|
|
411
|
+
var v = value;
|
|
412
|
+
value = {};
|
|
413
|
+
value[lastKey = name] = (isNumber(v) ? parseFloat(v) : v);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (lastKey === 'sorting') {
|
|
417
|
+
params[lastKey] = {};
|
|
418
|
+
}
|
|
419
|
+
params[lastKey] = angular.extend(params[lastKey] || {}, value[lastKey]);
|
|
420
|
+
} else {
|
|
421
|
+
params[key] = (isNumber(newParameters[key]) ? parseFloat(newParameters[key]) : newParameters[key]);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
log('ngTable: set parameters', params);
|
|
425
|
+
return this;
|
|
426
|
+
}
|
|
427
|
+
return params;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @ngdoc method
|
|
432
|
+
* @name NgTableParams#settings
|
|
433
|
+
* @description Set new settings for table
|
|
434
|
+
*
|
|
435
|
+
* @param {string} newSettings New settings or undefined
|
|
436
|
+
* @returns {Object} Current settings or `this`
|
|
437
|
+
*/
|
|
438
|
+
this.settings = function(newSettings) {
|
|
439
|
+
if (angular.isDefined(newSettings)) {
|
|
440
|
+
if (angular.isArray(newSettings.data)) {
|
|
441
|
+
//auto-set the total from passed in data
|
|
442
|
+
newSettings.total = newSettings.data.length;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// todo: remove the backwards compatibility shim and the following two if blocks
|
|
446
|
+
if (newSettings.getData && newSettings.getData.length > 1){
|
|
447
|
+
// support the old getData($defer, params) api
|
|
448
|
+
newSettings.getDataFnAdaptor = ngTableGetDataBcShim;
|
|
449
|
+
}
|
|
450
|
+
if (newSettings.getGroups && newSettings.getGroups.length > 2){
|
|
451
|
+
// support the old getGroups($defer, grouping, params) api
|
|
452
|
+
newSettings.getGroupsFnAdaptor = ngTableGetDataBcShim;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
var originalDataset = settings.data;
|
|
456
|
+
settings = angular.extend(settings, newSettings);
|
|
457
|
+
|
|
458
|
+
// note: using != as want null and undefined to be treated the same
|
|
459
|
+
var hasDatasetChanged = newSettings.hasOwnProperty('data') && (newSettings.data != originalDataset);
|
|
460
|
+
if (hasDatasetChanged) {
|
|
461
|
+
if (isCommittedDataset){
|
|
462
|
+
this.page(1); // reset page as a new dataset has been supplied
|
|
463
|
+
}
|
|
464
|
+
isCommittedDataset = false;
|
|
465
|
+
ngTableEventsChannel.publishDatasetChanged(this, newSettings.data, originalDataset);
|
|
466
|
+
}
|
|
467
|
+
log('ngTable: set settings', settings);
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
return settings;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @ngdoc method
|
|
475
|
+
* @name NgTableParams#page
|
|
476
|
+
* @description If parameter page not set return current page else set current page
|
|
477
|
+
*
|
|
478
|
+
* @param {string} page Page number
|
|
479
|
+
* @returns {Object|Number} Current page or `this`
|
|
480
|
+
*/
|
|
481
|
+
this.page = function(page) {
|
|
482
|
+
return angular.isDefined(page) ? this.parameters({
|
|
483
|
+
'page': page
|
|
484
|
+
}) : params.page;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @ngdoc method
|
|
489
|
+
* @name NgTableParams#total
|
|
490
|
+
* @description If parameter total not set return current quantity else set quantity
|
|
491
|
+
*
|
|
492
|
+
* @param {string} total Total quantity of items
|
|
493
|
+
* @returns {Object|Number} Current page or `this`
|
|
494
|
+
*/
|
|
495
|
+
this.total = function(total) {
|
|
496
|
+
return angular.isDefined(total) ? this.settings({
|
|
497
|
+
'total': total
|
|
498
|
+
}) : settings.total;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* @ngdoc method
|
|
503
|
+
* @name NgTableParams#count
|
|
504
|
+
* @description If parameter count not set return current count per page else set count per page
|
|
505
|
+
*
|
|
506
|
+
* @param {string} count Count per number
|
|
507
|
+
* @returns {Object|Number} Count per page or `this`
|
|
508
|
+
*/
|
|
509
|
+
this.count = function(count) {
|
|
510
|
+
// reset to first page because can be blank page
|
|
511
|
+
return angular.isDefined(count) ? this.parameters({
|
|
512
|
+
'count': count,
|
|
513
|
+
'page': 1
|
|
514
|
+
}) : params.count;
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* @ngdoc method
|
|
519
|
+
* @name NgTableParams#filter
|
|
520
|
+
* @description If 'filter' parameter not set return current filter else set current filter
|
|
521
|
+
*
|
|
522
|
+
* Note: when assigning a new filter, {@link NgTableParams#page page} will be set to 1
|
|
523
|
+
*
|
|
524
|
+
* @param {Object|Boolean} filter 'object': new filter to assign or
|
|
525
|
+
* 'true': to return the current filter minus any insignificant values (null, undefined and empty string); or
|
|
526
|
+
* 'falsey': to return the current filter "as is"
|
|
527
|
+
* @returns {Object} Current filter or `this`
|
|
528
|
+
*/
|
|
529
|
+
this.filter = function(filter) {
|
|
530
|
+
if (angular.isDefined(filter) && angular.isObject(filter)) {
|
|
531
|
+
return this.parameters({
|
|
532
|
+
'filter': filter,
|
|
533
|
+
'page': 1
|
|
534
|
+
});
|
|
535
|
+
} else if (filter === true){
|
|
536
|
+
var keys = Object.keys(params.filter);
|
|
537
|
+
var significantFilter = {};
|
|
538
|
+
for (var i=0; i < keys.length; i++){
|
|
539
|
+
var filterValue = params.filter[keys[i]];
|
|
540
|
+
if (filterValue != null && filterValue !== '') {
|
|
541
|
+
significantFilter[keys[i]] = filterValue;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return significantFilter;
|
|
545
|
+
} else {
|
|
546
|
+
return params.filter;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* @ngdoc method
|
|
552
|
+
* @name NgTableParams#sorting
|
|
553
|
+
* @description If 'sorting' parameter is not set, return current sorting. Otherwise set current sorting.
|
|
554
|
+
*
|
|
555
|
+
* @param {string} sorting New sorting
|
|
556
|
+
* @returns {Object} Current sorting or `this`
|
|
557
|
+
*/
|
|
558
|
+
this.sorting = function(sorting) {
|
|
559
|
+
if (arguments.length == 2) {
|
|
560
|
+
var sortArray = {};
|
|
561
|
+
sortArray[sorting] = arguments[1];
|
|
562
|
+
this.parameters({
|
|
563
|
+
'sorting': sortArray
|
|
564
|
+
});
|
|
565
|
+
return this;
|
|
566
|
+
}
|
|
567
|
+
return angular.isDefined(sorting) ? this.parameters({
|
|
568
|
+
'sorting': sorting
|
|
569
|
+
}) : params.sorting;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @ngdoc method
|
|
574
|
+
* @name NgTableParams#isSortBy
|
|
575
|
+
* @description Checks sort field
|
|
576
|
+
*
|
|
577
|
+
* @param {string} field Field name
|
|
578
|
+
* @param {string} direction Optional direction of sorting ('asc' or 'desc')
|
|
579
|
+
* @returns {Array} Return true if field sorted by direction
|
|
580
|
+
*/
|
|
581
|
+
this.isSortBy = function(field, direction) {
|
|
582
|
+
if(direction !== undefined) {
|
|
583
|
+
return angular.isDefined(params.sorting[field]) && params.sorting[field] == direction;
|
|
584
|
+
} else {
|
|
585
|
+
return angular.isDefined(params.sorting[field]);
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* @ngdoc method
|
|
591
|
+
* @name NgTableParams#orderBy
|
|
592
|
+
* @description Return object of sorting parameters for angular filter
|
|
593
|
+
*
|
|
594
|
+
* @returns {Array} Array like: [ '-name', '+age' ]
|
|
595
|
+
*/
|
|
596
|
+
this.orderBy = function() {
|
|
597
|
+
var sorting = [];
|
|
598
|
+
for (var column in params.sorting) {
|
|
599
|
+
sorting.push((params.sorting[column] === "asc" ? "+" : "-") + column);
|
|
600
|
+
}
|
|
601
|
+
return sorting;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* @ngdoc method
|
|
606
|
+
* @name NgTableParams#getData
|
|
607
|
+
* @description Called when updated some of parameters for get new data
|
|
608
|
+
*
|
|
609
|
+
* @param {Object} params New parameters
|
|
610
|
+
*/
|
|
611
|
+
this.getData = function(params) {
|
|
612
|
+
// note: this === settings
|
|
613
|
+
return ngTableDefaultGetData(this.data, params);
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* @ngdoc method
|
|
618
|
+
* @name NgTableParams#getGroups
|
|
619
|
+
* @description Return groups for table grouping
|
|
620
|
+
*/
|
|
621
|
+
this.getGroups = function(column) {
|
|
622
|
+
return runGetData().then(function(data) {
|
|
623
|
+
var groups = {};
|
|
624
|
+
angular.forEach(data, function(item) {
|
|
625
|
+
var groupName = angular.isFunction(column) ? column(item) : item[column];
|
|
626
|
+
|
|
627
|
+
groups[groupName] = groups[groupName] || {
|
|
628
|
+
data: []
|
|
629
|
+
};
|
|
630
|
+
groups[groupName]['value'] = groupName;
|
|
631
|
+
groups[groupName].data.push(item);
|
|
632
|
+
});
|
|
633
|
+
var result = [];
|
|
634
|
+
for (var i in groups) {
|
|
635
|
+
result.push(groups[i]);
|
|
636
|
+
}
|
|
637
|
+
log('ngTable: refresh groups', result);
|
|
638
|
+
return result;
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* @ngdoc method
|
|
644
|
+
* @name NgTableParams#generatePagesArray
|
|
645
|
+
* @description Generate array of pages
|
|
646
|
+
*
|
|
647
|
+
* When no arguments supplied, the current parameter state of this `NgTableParams` instance will be used
|
|
648
|
+
*
|
|
649
|
+
* @param {boolean} currentPage which page must be active
|
|
650
|
+
* @param {boolean} totalItems Total quantity of items
|
|
651
|
+
* @param {boolean} pageSize Quantity of items on page
|
|
652
|
+
* @param {number} maxBlocks Quantity of blocks for pagination
|
|
653
|
+
* @returns {Array} Array of pages
|
|
654
|
+
*/
|
|
655
|
+
this.generatePagesArray = function(currentPage, totalItems, pageSize, maxBlocks) {
|
|
656
|
+
if (!arguments.length){
|
|
657
|
+
currentPage = this.page();
|
|
658
|
+
totalItems = this.total();
|
|
659
|
+
pageSize = this.count();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
var maxPage, maxPivotPages, minPage, numPages, pages;
|
|
663
|
+
maxBlocks = maxBlocks && maxBlocks < 6 ? 6 : maxBlocks;
|
|
664
|
+
|
|
665
|
+
pages = [];
|
|
666
|
+
numPages = Math.ceil(totalItems / pageSize);
|
|
667
|
+
if (numPages > 1) {
|
|
668
|
+
pages.push({
|
|
669
|
+
type: 'prev',
|
|
670
|
+
number: Math.max(1, currentPage - 1),
|
|
671
|
+
active: currentPage > 1
|
|
672
|
+
});
|
|
673
|
+
pages.push({
|
|
674
|
+
type: 'first',
|
|
675
|
+
number: 1,
|
|
676
|
+
active: currentPage > 1,
|
|
677
|
+
current: currentPage === 1
|
|
678
|
+
});
|
|
679
|
+
maxPivotPages = Math.round((settings.paginationMaxBlocks - settings.paginationMinBlocks) / 2);
|
|
680
|
+
minPage = Math.max(2, currentPage - maxPivotPages);
|
|
681
|
+
maxPage = Math.min(numPages - 1, currentPage + maxPivotPages * 2 - (currentPage - minPage));
|
|
682
|
+
minPage = Math.max(2, minPage - (maxPivotPages * 2 - (maxPage - minPage)));
|
|
683
|
+
var i = minPage;
|
|
684
|
+
while (i <= maxPage) {
|
|
685
|
+
if ((i === minPage && i !== 2) || (i === maxPage && i !== numPages - 1)) {
|
|
686
|
+
pages.push({
|
|
687
|
+
type: 'more',
|
|
688
|
+
active: false
|
|
689
|
+
});
|
|
690
|
+
} else {
|
|
691
|
+
pages.push({
|
|
692
|
+
type: 'page',
|
|
693
|
+
number: i,
|
|
694
|
+
active: currentPage !== i,
|
|
695
|
+
current: currentPage === i
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
i++;
|
|
699
|
+
}
|
|
700
|
+
pages.push({
|
|
701
|
+
type: 'last',
|
|
702
|
+
number: numPages,
|
|
703
|
+
active: currentPage !== numPages,
|
|
704
|
+
current: currentPage === numPages
|
|
705
|
+
});
|
|
706
|
+
pages.push({
|
|
707
|
+
type: 'next',
|
|
708
|
+
number: Math.min(numPages, currentPage + 1),
|
|
709
|
+
active: currentPage < numPages
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
return pages;
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* @ngdoc method
|
|
717
|
+
* @name NgTableParams#isDataReloadRequired
|
|
718
|
+
* @description Return true when a change to this `NgTableParams` instance should require the reload method
|
|
719
|
+
* to be run so as to ensure the data presented to the user reflects the `NgTableParams`
|
|
720
|
+
*/
|
|
721
|
+
this.isDataReloadRequired = function(){
|
|
722
|
+
// note: using != as want to treat null and undefined the same
|
|
723
|
+
return !isCommittedDataset || !angular.equals(params, committedParams);
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* @ngdoc method
|
|
728
|
+
* @name NgTableParams#hasFilter
|
|
729
|
+
* @description Determines if NgTableParams#filter has significant filter value(s)
|
|
730
|
+
* (any value except null, undefined, or empty string)
|
|
731
|
+
* @returns {Boolean} true when NgTableParams#filter has at least one significant field value
|
|
732
|
+
*/
|
|
733
|
+
this.hasFilter = function(){
|
|
734
|
+
return Object.keys(this.filter(true)).length > 0;
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* @ngdoc method
|
|
739
|
+
* @name NgTableParams#hasFilterChanges
|
|
740
|
+
* @description Return true when a change to `NgTableParams.filters`require the reload method
|
|
741
|
+
* to be run so as to ensure the data presented to the user reflects these filters
|
|
742
|
+
*/
|
|
743
|
+
this.hasFilterChanges = function(){
|
|
744
|
+
return !angular.equals((params && params.filter), (committedParams && committedParams.filter));
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* @ngdoc method
|
|
749
|
+
* @name NgTableParams#url
|
|
750
|
+
* @description Return groups for table grouping
|
|
751
|
+
*
|
|
752
|
+
* @param {boolean} asString flag indicates return array of string or object
|
|
753
|
+
* @returns {Array} If asString = true will be return array of url string parameters else key-value object
|
|
754
|
+
*/
|
|
755
|
+
this.url = function(asString) {
|
|
756
|
+
asString = asString || false;
|
|
757
|
+
var pairs = (asString ? [] : {});
|
|
758
|
+
for (var key in params) {
|
|
759
|
+
if (params.hasOwnProperty(key)) {
|
|
760
|
+
var item = params[key],
|
|
761
|
+
name = encodeURIComponent(key);
|
|
762
|
+
if (typeof item === "object") {
|
|
763
|
+
for (var subkey in item) {
|
|
764
|
+
if (!angular.isUndefined(item[subkey]) && item[subkey] !== "") {
|
|
765
|
+
var pname = name + "[" + encodeURIComponent(subkey) + "]";
|
|
766
|
+
if (asString) {
|
|
767
|
+
pairs.push(pname + "=" + item[subkey]);
|
|
768
|
+
} else {
|
|
769
|
+
pairs[pname] = item[subkey];
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
} else if (!angular.isFunction(item) && !angular.isUndefined(item) && item !== "") {
|
|
774
|
+
if (asString) {
|
|
775
|
+
pairs.push(name + "=" + encodeURIComponent(item));
|
|
776
|
+
} else {
|
|
777
|
+
pairs[name] = encodeURIComponent(item);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
return pairs;
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* @ngdoc method
|
|
787
|
+
* @name NgTableParams#reload
|
|
788
|
+
* @description Reload table data
|
|
789
|
+
*/
|
|
790
|
+
this.reload = function() {
|
|
791
|
+
var self = this,
|
|
792
|
+
pData = null;
|
|
793
|
+
|
|
794
|
+
settings.$loading = true;
|
|
795
|
+
|
|
796
|
+
committedParams = angular.copy(params);
|
|
797
|
+
isCommittedDataset = true;
|
|
798
|
+
|
|
799
|
+
if (settings.groupBy) {
|
|
800
|
+
pData = runInterceptorPipeline(runGetGroups);
|
|
801
|
+
} else {
|
|
802
|
+
pData = runInterceptorPipeline(runGetData);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
log('ngTable: reload data');
|
|
806
|
+
|
|
807
|
+
var oldData = self.data;
|
|
808
|
+
return pData.then(function(data) {
|
|
809
|
+
settings.$loading = false;
|
|
810
|
+
self.data = data;
|
|
811
|
+
// note: I think it makes sense to publish this event even when data === oldData
|
|
812
|
+
// subscribers can always set a filter to only receive the event when data !== oldData
|
|
813
|
+
ngTableEventsChannel.publishAfterReloadData(self, data, oldData);
|
|
814
|
+
self.reloadPages();
|
|
815
|
+
|
|
816
|
+
// todo: remove after acceptable depreciation period
|
|
817
|
+
if (settings.$scope) {
|
|
818
|
+
settings.$scope.$emit('ngTableAfterReloadData');
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return data;
|
|
822
|
+
}).catch(function(reason){
|
|
823
|
+
committedParams = null;
|
|
824
|
+
isCommittedDataset = false;
|
|
825
|
+
// "rethrow"
|
|
826
|
+
return $q.reject(reason);
|
|
827
|
+
});
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
this.reloadPages = (function() {
|
|
831
|
+
var currentPages;
|
|
832
|
+
return function(){
|
|
833
|
+
var oldPages = currentPages;
|
|
834
|
+
var newPages = self.generatePagesArray(self.page(), self.total(), self.count());
|
|
835
|
+
if (!angular.equals(oldPages, newPages)){
|
|
836
|
+
currentPages = newPages;
|
|
837
|
+
ngTableEventsChannel.publishPagesChanged(this, newPages, oldPages);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
})();
|
|
841
|
+
|
|
842
|
+
function runGetData(){
|
|
843
|
+
var getDataFn = settings.getDataFnAdaptor(settings.getData);
|
|
844
|
+
return $q.when(getDataFn.call(settings, self));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function runGetGroups(){
|
|
848
|
+
var getGroupsFn = settings.getGroupsFnAdaptor(settings.getGroups);
|
|
849
|
+
return $q.when(getGroupsFn.call(settings, settings.groupBy, self));
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
function runInterceptorPipeline(fetchFn){
|
|
853
|
+
var interceptors = settings.interceptors || [];
|
|
854
|
+
|
|
855
|
+
return interceptors.reduce(function(result, interceptor){
|
|
856
|
+
var thenFn = (interceptor.response && interceptor.response.bind(interceptor)) || $q.when;
|
|
857
|
+
var rejectFn = (interceptor.responseError && interceptor.responseError.bind(interceptor)) || $q.reject;
|
|
858
|
+
return result.then(function(data){
|
|
859
|
+
return thenFn(data, self);
|
|
860
|
+
}, function(reason){
|
|
861
|
+
return rejectFn(reason, self);
|
|
862
|
+
});
|
|
863
|
+
}, fetchFn());
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
var params = {
|
|
867
|
+
page: 1,
|
|
868
|
+
count: 1,
|
|
869
|
+
filter: {},
|
|
870
|
+
sorting: {},
|
|
871
|
+
group: {},
|
|
872
|
+
groupBy: null
|
|
873
|
+
};
|
|
874
|
+
angular.extend(params, ngTableDefaults.params);
|
|
875
|
+
|
|
876
|
+
var settings = {
|
|
877
|
+
// todo: remove $scope after acceptable depreciation period as no longer required
|
|
878
|
+
$scope: null, // set by ngTable controller
|
|
879
|
+
$loading: false,
|
|
880
|
+
data: null, //allows data to be set when table is initialized
|
|
881
|
+
total: 0,
|
|
882
|
+
defaultSort: 'desc',
|
|
883
|
+
filterDelay: 750,
|
|
884
|
+
counts: [10, 25, 50, 100],
|
|
885
|
+
interceptors: [],
|
|
886
|
+
paginationMaxBlocks: 11,
|
|
887
|
+
paginationMinBlocks: 5,
|
|
888
|
+
sortingIndicator: 'span',
|
|
889
|
+
getDataFnAdaptor: angular.identity,
|
|
890
|
+
getGroupsFnAdaptor: angular.identity,
|
|
891
|
+
getGroups: this.getGroups,
|
|
892
|
+
getData: this.getData
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
this.settings(ngTableDefaults.settings);
|
|
896
|
+
this.settings(baseSettings);
|
|
897
|
+
this.parameters(baseParameters, true);
|
|
898
|
+
|
|
899
|
+
ngTableEventsChannel.publishAfterCreated(this);
|
|
900
|
+
|
|
901
|
+
return this;
|
|
902
|
+
};
|
|
903
|
+
return NgTableParams;
|
|
904
|
+
}]);
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* @ngdoc service
|
|
908
|
+
* @name ngTableParams
|
|
909
|
+
* @description Backwards compatible shim for lowercase 'n' in NgTableParams
|
|
910
|
+
*/
|
|
911
|
+
app.factory('ngTableParams', ['NgTableParams', function(NgTableParams) {
|
|
912
|
+
return NgTableParams;
|
|
913
|
+
}]);
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* ngTable: Table + Angular JS
|
|
917
|
+
*
|
|
918
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
919
|
+
* @url https://github.com/esvit/ng-table/
|
|
920
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
921
|
+
*/
|
|
922
|
+
|
|
923
|
+
(function(){
|
|
924
|
+
'use strict';
|
|
925
|
+
|
|
926
|
+
angular.module('ngTable')
|
|
927
|
+
.controller('ngTableFilterRowController', ngTableFilterRowController);
|
|
928
|
+
|
|
929
|
+
ngTableFilterRowController.$inject = ['$scope', 'ngTableFilterConfig'];
|
|
930
|
+
|
|
931
|
+
function ngTableFilterRowController($scope, ngTableFilterConfig){
|
|
932
|
+
|
|
933
|
+
$scope.config = ngTableFilterConfig;
|
|
934
|
+
}
|
|
935
|
+
})();
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* ngTable: Table + Angular JS
|
|
939
|
+
*
|
|
940
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
941
|
+
* @url https://github.com/esvit/ng-table/
|
|
942
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
943
|
+
*/
|
|
944
|
+
|
|
945
|
+
(function(){
|
|
946
|
+
'use strict';
|
|
947
|
+
|
|
948
|
+
angular.module('ngTable')
|
|
949
|
+
.controller('ngTableSorterRowController', ngTableSorterRowController);
|
|
950
|
+
|
|
951
|
+
ngTableSorterRowController.$inject = ['$scope'];
|
|
952
|
+
|
|
953
|
+
function ngTableSorterRowController($scope){
|
|
954
|
+
|
|
955
|
+
$scope.sortBy = sortBy;
|
|
956
|
+
|
|
957
|
+
///////////
|
|
958
|
+
|
|
959
|
+
function sortBy($column, event) {
|
|
960
|
+
var parsedSortable = $column.sortable && $column.sortable();
|
|
961
|
+
if (!parsedSortable) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
var defaultSort = $scope.params.settings().defaultSort;
|
|
965
|
+
var inverseSort = (defaultSort === 'asc' ? 'desc' : 'asc');
|
|
966
|
+
var sorting = $scope.params.sorting() && $scope.params.sorting()[parsedSortable] && ($scope.params.sorting()[parsedSortable] === defaultSort);
|
|
967
|
+
var sortingParams = (event.ctrlKey || event.metaKey) ? $scope.params.sorting() : {};
|
|
968
|
+
sortingParams[parsedSortable] = (sorting ? inverseSort : defaultSort);
|
|
969
|
+
$scope.params.parameters({
|
|
970
|
+
sorting: sortingParams
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
})();
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* ngTable: Table + Angular JS
|
|
978
|
+
*
|
|
979
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
980
|
+
* @url https://github.com/esvit/ng-table/
|
|
981
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
982
|
+
*/
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* @ngdoc object
|
|
986
|
+
* @name ngTableController
|
|
987
|
+
*
|
|
988
|
+
* @description
|
|
989
|
+
* Each {@link ngTable ngTable} directive creates an instance of `ngTableController`
|
|
990
|
+
*/
|
|
991
|
+
app.controller('ngTableController', ['$scope', 'NgTableParams', '$timeout', '$parse', '$compile', '$attrs', '$element',
|
|
992
|
+
'ngTableColumn', 'ngTableEventsChannel',
|
|
993
|
+
function($scope, NgTableParams, $timeout, $parse, $compile, $attrs, $element, ngTableColumn, ngTableEventsChannel) {
|
|
994
|
+
var isFirstTimeLoad = true;
|
|
995
|
+
$scope.$filterRow = {};
|
|
996
|
+
$scope.$loading = false;
|
|
997
|
+
|
|
998
|
+
// until such times as the directive uses an isolated scope, we need to ensure that the check for
|
|
999
|
+
// the params field only consults the "own properties" of the $scope. This is to avoid seeing the params
|
|
1000
|
+
// field on a $scope higher up in the prototype chain
|
|
1001
|
+
if (!$scope.hasOwnProperty("params")) {
|
|
1002
|
+
$scope.params = new NgTableParams(true);
|
|
1003
|
+
}
|
|
1004
|
+
$scope.params.settings().$scope = $scope;
|
|
1005
|
+
|
|
1006
|
+
var delayFilter = (function() {
|
|
1007
|
+
var timer = 0;
|
|
1008
|
+
return function(callback, ms) {
|
|
1009
|
+
$timeout.cancel(timer);
|
|
1010
|
+
timer = $timeout(callback, ms);
|
|
1011
|
+
};
|
|
1012
|
+
})();
|
|
1013
|
+
|
|
1014
|
+
function onDataReloadStatusChange (newStatus/*, oldStatus*/) {
|
|
1015
|
+
if (!newStatus) {
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
$scope.params.settings().$scope = $scope;
|
|
1020
|
+
|
|
1021
|
+
var currentParams = $scope.params;
|
|
1022
|
+
|
|
1023
|
+
if (currentParams.hasFilterChanges()) {
|
|
1024
|
+
var applyFilter = function () {
|
|
1025
|
+
currentParams.page(1);
|
|
1026
|
+
currentParams.reload();
|
|
1027
|
+
};
|
|
1028
|
+
if (currentParams.settings().filterDelay) {
|
|
1029
|
+
delayFilter(applyFilter, currentParams.settings().filterDelay);
|
|
1030
|
+
} else {
|
|
1031
|
+
applyFilter();
|
|
1032
|
+
}
|
|
1033
|
+
} else {
|
|
1034
|
+
currentParams.reload();
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
// watch for when a new NgTableParams is bound to the scope
|
|
1039
|
+
// CRITICAL: the watch must be for reference and NOT value equality; this is because NgTableParams maintains
|
|
1040
|
+
// the current data page as a field. Checking this for value equality would be terrible for performance
|
|
1041
|
+
// and potentially cause an error if the items in that array has circular references
|
|
1042
|
+
$scope.$watch('params', function(newParams, oldParams){
|
|
1043
|
+
if (newParams === oldParams || !newParams) {
|
|
1044
|
+
return;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
newParams.reload();
|
|
1048
|
+
}, false);
|
|
1049
|
+
|
|
1050
|
+
$scope.$watch('params.isDataReloadRequired()', onDataReloadStatusChange);
|
|
1051
|
+
|
|
1052
|
+
this.compileDirectiveTemplates = function () {
|
|
1053
|
+
if (!$element.hasClass('ng-table')) {
|
|
1054
|
+
$scope.templates = {
|
|
1055
|
+
header: ($attrs.templateHeader ? $attrs.templateHeader : 'ng-table/header.html'),
|
|
1056
|
+
pagination: ($attrs.templatePagination ? $attrs.templatePagination : 'ng-table/pager.html')
|
|
1057
|
+
};
|
|
1058
|
+
$element.addClass('ng-table');
|
|
1059
|
+
var headerTemplate = null;
|
|
1060
|
+
|
|
1061
|
+
// $element.find('> thead').length === 0 doesn't work on jqlite
|
|
1062
|
+
var theadFound = false;
|
|
1063
|
+
angular.forEach($element.children(), function(e) {
|
|
1064
|
+
if (e.tagName === 'THEAD') {
|
|
1065
|
+
theadFound = true;
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
if (!theadFound) {
|
|
1069
|
+
headerTemplate = angular.element(document.createElement('thead')).attr('ng-include', 'templates.header');
|
|
1070
|
+
$element.prepend(headerTemplate);
|
|
1071
|
+
}
|
|
1072
|
+
var paginationTemplate = angular.element(document.createElement('div')).attr({
|
|
1073
|
+
'ng-table-pagination': 'params',
|
|
1074
|
+
'template-url': 'templates.pagination'
|
|
1075
|
+
});
|
|
1076
|
+
$element.after(paginationTemplate);
|
|
1077
|
+
if (headerTemplate) {
|
|
1078
|
+
$compile(headerTemplate)($scope);
|
|
1079
|
+
}
|
|
1080
|
+
$compile(paginationTemplate)($scope);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
|
|
1084
|
+
this.loadFilterData = function ($columns) {
|
|
1085
|
+
angular.forEach($columns, function ($column) {
|
|
1086
|
+
var def;
|
|
1087
|
+
def = $column.filterData($scope, {
|
|
1088
|
+
$column: $column
|
|
1089
|
+
});
|
|
1090
|
+
if (!def) {
|
|
1091
|
+
delete $column.filterData;
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// if we're working with a deferred object, let's wait for the promise
|
|
1096
|
+
if ((angular.isObject(def) && angular.isObject(def.promise))) {
|
|
1097
|
+
delete $column.filterData;
|
|
1098
|
+
return def.promise.then(function(data) {
|
|
1099
|
+
// our deferred can eventually return arrays, functions and objects
|
|
1100
|
+
if (!angular.isArray(data) && !angular.isFunction(data) && !angular.isObject(data)) {
|
|
1101
|
+
// if none of the above was found - we just want an empty array
|
|
1102
|
+
data = [];
|
|
1103
|
+
} else if (angular.isArray(data)) {
|
|
1104
|
+
data.unshift({
|
|
1105
|
+
title: '',
|
|
1106
|
+
id: ''
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
$column.data = data;
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
// otherwise, we just return what the user gave us. It could be a function, array, object, whatever
|
|
1113
|
+
else {
|
|
1114
|
+
return $column.data = def;
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
this.buildColumns = function (columns) {
|
|
1120
|
+
return columns.map(function(col){
|
|
1121
|
+
return ngTableColumn.buildColumn(col, $scope)
|
|
1122
|
+
})
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1125
|
+
this.parseNgTableDynamicExpr = function (attr) {
|
|
1126
|
+
if (!attr || attr.indexOf(" with ") > -1) {
|
|
1127
|
+
var parts = attr.split(/\s+with\s+/);
|
|
1128
|
+
return {
|
|
1129
|
+
tableParams: parts[0],
|
|
1130
|
+
columns: parts[1]
|
|
1131
|
+
};
|
|
1132
|
+
} else {
|
|
1133
|
+
throw new Error('Parse error (expected example: ng-table-dynamic=\'tableParams with cols\')');
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
this.setupBindingsToInternalScope = function(tableParamsExpr){
|
|
1138
|
+
|
|
1139
|
+
// note: this we're setting up watches to simulate angular's isolated scope bindings
|
|
1140
|
+
|
|
1141
|
+
// note: is REALLY important to watch for a change to the ngTableParams *reference* rather than
|
|
1142
|
+
// $watch for value equivalence. This is because ngTableParams references the current page of data as
|
|
1143
|
+
// a field and it's important not to watch this
|
|
1144
|
+
var tableParamsGetter = $parse(tableParamsExpr);
|
|
1145
|
+
$scope.$watch(tableParamsGetter, (function (params) {
|
|
1146
|
+
if (angular.isUndefined(params)) {
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
$scope.paramsModel = tableParamsGetter;
|
|
1150
|
+
$scope.params = params;
|
|
1151
|
+
}), false);
|
|
1152
|
+
|
|
1153
|
+
if ($attrs.showFilter) {
|
|
1154
|
+
$scope.$parent.$watch($attrs.showFilter, function(value) {
|
|
1155
|
+
$scope.show_filter = value;
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
if ($attrs.disableFilter) {
|
|
1159
|
+
$scope.$parent.$watch($attrs.disableFilter, function(value) {
|
|
1160
|
+
$scope.$filterRow.disabled = value;
|
|
1161
|
+
});
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
function commonInit(){
|
|
1168
|
+
ngTableEventsChannel.onAfterReloadData(bindDataToScope, $scope, isMyPublisher);
|
|
1169
|
+
ngTableEventsChannel.onPagesChanged(bindPagesToScope, $scope, isMyPublisher);
|
|
1170
|
+
|
|
1171
|
+
function bindDataToScope(params, newDatapage){
|
|
1172
|
+
if (params.settings().groupBy) {
|
|
1173
|
+
$scope.$groups = newDatapage;
|
|
1174
|
+
} else {
|
|
1175
|
+
$scope.$data = newDatapage;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function bindPagesToScope(params, newPages){
|
|
1180
|
+
$scope.pages = newPages
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
function isMyPublisher(publisher){
|
|
1184
|
+
return $scope.params === publisher;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
commonInit();
|
|
1189
|
+
}]);
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* @ngdoc service
|
|
1194
|
+
* @name ngTableColumn
|
|
1195
|
+
* @module ngTable
|
|
1196
|
+
* @description
|
|
1197
|
+
* Service to construct a $column definition used by {@link ngTable ngTable} directive
|
|
1198
|
+
*/
|
|
1199
|
+
app.factory('ngTableColumn', [function () {
|
|
1200
|
+
|
|
1201
|
+
var defaults = {
|
|
1202
|
+
'class': function(){ return ''; },
|
|
1203
|
+
filter: function(){ return false; },
|
|
1204
|
+
filterData: angular.noop,
|
|
1205
|
+
headerTemplateURL: function(){ return false; },
|
|
1206
|
+
headerTitle: function(){ return ''; },
|
|
1207
|
+
sortable: function(){ return false; },
|
|
1208
|
+
show: function(){ return true; },
|
|
1209
|
+
title: function(){ return ''; },
|
|
1210
|
+
titleAlt: function(){ return ''; }
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* @ngdoc method
|
|
1215
|
+
* @name ngTableColumn#buildColumn
|
|
1216
|
+
* @description Creates a $column for use within a header template
|
|
1217
|
+
*
|
|
1218
|
+
* @param {Object} column an existing $column or simple column data object
|
|
1219
|
+
* @param {Scope} defaultScope the $scope to supply to the $column getter methods when not supplied by caller
|
|
1220
|
+
* @returns {Object} a $column object
|
|
1221
|
+
*/
|
|
1222
|
+
function buildColumn(column, defaultScope){
|
|
1223
|
+
// note: we're not modifying the original column object. This helps to avoid unintended side affects
|
|
1224
|
+
var extendedCol = Object.create(column);
|
|
1225
|
+
for (var prop in defaults) {
|
|
1226
|
+
if (extendedCol[prop] === undefined) {
|
|
1227
|
+
extendedCol[prop] = defaults[prop];
|
|
1228
|
+
}
|
|
1229
|
+
if(!angular.isFunction(extendedCol[prop])){
|
|
1230
|
+
// wrap raw field values with "getter" functions
|
|
1231
|
+
// - this is to ensure consistency with how ngTable.compile builds columns
|
|
1232
|
+
// - note that the original column object is being "proxied"; this is important
|
|
1233
|
+
// as it ensure that any changes to the original object will be returned by the "getter"
|
|
1234
|
+
(function(prop1){
|
|
1235
|
+
extendedCol[prop1] = function(){
|
|
1236
|
+
return column[prop1];
|
|
1237
|
+
};
|
|
1238
|
+
})(prop);
|
|
1239
|
+
}
|
|
1240
|
+
(function(prop1){
|
|
1241
|
+
// satisfy the arguments expected by the function returned by parsedAttribute in the ngTable directive
|
|
1242
|
+
var getterFn = extendedCol[prop1];
|
|
1243
|
+
extendedCol[prop1] = function(){
|
|
1244
|
+
if (arguments.length === 0){
|
|
1245
|
+
return getterFn.call(column, defaultScope);
|
|
1246
|
+
} else {
|
|
1247
|
+
return getterFn.apply(column, arguments);
|
|
1248
|
+
}
|
|
1249
|
+
};
|
|
1250
|
+
})(prop);
|
|
1251
|
+
}
|
|
1252
|
+
return extendedCol;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
return {
|
|
1256
|
+
buildColumn: buildColumn
|
|
1257
|
+
};
|
|
1258
|
+
}]);
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* ngTable: Table + Angular JS
|
|
1262
|
+
*
|
|
1263
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
1264
|
+
* @url https://github.com/esvit/ng-table/
|
|
1265
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
1266
|
+
*/
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* @ngdoc directive
|
|
1270
|
+
* @name ngTable
|
|
1271
|
+
* @module ngTable
|
|
1272
|
+
* @restrict A
|
|
1273
|
+
*
|
|
1274
|
+
* @description
|
|
1275
|
+
* Directive that instantiates {@link ngTableController ngTableController}.
|
|
1276
|
+
*/
|
|
1277
|
+
app.directive('ngTable', ['$q', '$parse',
|
|
1278
|
+
function($q, $parse) {
|
|
1279
|
+
'use strict';
|
|
1280
|
+
|
|
1281
|
+
return {
|
|
1282
|
+
restrict: 'A',
|
|
1283
|
+
priority: 1001,
|
|
1284
|
+
scope: true,
|
|
1285
|
+
controller: 'ngTableController',
|
|
1286
|
+
compile: function(element) {
|
|
1287
|
+
var columns = [],
|
|
1288
|
+
i = 0,
|
|
1289
|
+
row = null;
|
|
1290
|
+
|
|
1291
|
+
// IE 8 fix :not(.ng-table-group) selector
|
|
1292
|
+
angular.forEach(angular.element(element.find('tr')), function(tr) {
|
|
1293
|
+
tr = angular.element(tr);
|
|
1294
|
+
if (!tr.hasClass('ng-table-group') && !row) {
|
|
1295
|
+
row = tr;
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
if (!row) {
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
angular.forEach(row.find('td'), function(item) {
|
|
1302
|
+
var el = angular.element(item);
|
|
1303
|
+
if (el.attr('ignore-cell') && 'true' === el.attr('ignore-cell')) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
var getAttrValue = function(attr){
|
|
1308
|
+
return el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr);
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
var parsedAttribute = function(attr) {
|
|
1312
|
+
var expr = getAttrValue(attr);
|
|
1313
|
+
if (!expr){
|
|
1314
|
+
return undefined;
|
|
1315
|
+
}
|
|
1316
|
+
return function(scope, locals) {
|
|
1317
|
+
return $parse(expr)(scope, angular.extend(locals || {}, {
|
|
1318
|
+
$columns: columns
|
|
1319
|
+
}));
|
|
1320
|
+
};
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
var titleExpr = getAttrValue('title-alt') || getAttrValue('title');
|
|
1324
|
+
if (titleExpr){
|
|
1325
|
+
el.attr('data-title-text', '{{' + titleExpr + '}}'); // this used in responsive table
|
|
1326
|
+
}
|
|
1327
|
+
// NOTE TO MAINTAINERS: if you add extra fields to a $column be sure to extend ngTableColumn with
|
|
1328
|
+
// a corresponding "safe" default
|
|
1329
|
+
columns.push({
|
|
1330
|
+
id: i++,
|
|
1331
|
+
title: parsedAttribute('title'),
|
|
1332
|
+
titleAlt: parsedAttribute('title-alt'),
|
|
1333
|
+
headerTitle: parsedAttribute('header-title'),
|
|
1334
|
+
sortable: parsedAttribute('sortable'),
|
|
1335
|
+
'class': parsedAttribute('header-class'),
|
|
1336
|
+
filter: parsedAttribute('filter'),
|
|
1337
|
+
headerTemplateURL: parsedAttribute('header'),
|
|
1338
|
+
filterData: parsedAttribute('filter-data'),
|
|
1339
|
+
show: (el.attr("ng-if") ? function (scope) {
|
|
1340
|
+
return $parse(el.attr("ng-if"))(scope);
|
|
1341
|
+
} : undefined)
|
|
1342
|
+
});
|
|
1343
|
+
});
|
|
1344
|
+
return function(scope, element, attrs, controller) {
|
|
1345
|
+
scope.$columns = columns = controller.buildColumns(columns);
|
|
1346
|
+
|
|
1347
|
+
controller.setupBindingsToInternalScope(attrs.ngTable);
|
|
1348
|
+
controller.loadFilterData(columns);
|
|
1349
|
+
controller.compileDirectiveTemplates();
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
]);
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* @ngdoc directive
|
|
1358
|
+
* @name ngTableDynamic
|
|
1359
|
+
* @module ngTable
|
|
1360
|
+
* @restrict A
|
|
1361
|
+
*
|
|
1362
|
+
* @description
|
|
1363
|
+
* A dynamic version of the {@link ngTable ngTable} directive that accepts a dynamic list of columns
|
|
1364
|
+
* definitions to render
|
|
1365
|
+
*/
|
|
1366
|
+
app.directive('ngTableDynamic', ['$parse', function ($parse){
|
|
1367
|
+
|
|
1368
|
+
return {
|
|
1369
|
+
restrict: 'A',
|
|
1370
|
+
priority: 1001,
|
|
1371
|
+
scope: true,
|
|
1372
|
+
controller: 'ngTableController',
|
|
1373
|
+
compile: function(tElement) {
|
|
1374
|
+
var row;
|
|
1375
|
+
|
|
1376
|
+
// IE 8 fix :not(.ng-table-group) selector
|
|
1377
|
+
angular.forEach(angular.element(tElement.find('tr')), function(tr) {
|
|
1378
|
+
tr = angular.element(tr);
|
|
1379
|
+
if (!tr.hasClass('ng-table-group') && !row) {
|
|
1380
|
+
row = tr;
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
if (!row) {
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
angular.forEach(row.find('td'), function(item) {
|
|
1388
|
+
var el = angular.element(item);
|
|
1389
|
+
var getAttrValue = function(attr){
|
|
1390
|
+
return el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr);
|
|
1391
|
+
};
|
|
1392
|
+
|
|
1393
|
+
// this used in responsive table
|
|
1394
|
+
var titleExpr = getAttrValue('title');
|
|
1395
|
+
if (!titleExpr){
|
|
1396
|
+
el.attr('data-title-text', '{{$columns[$index].titleAlt(this) || $columns[$index].title(this)}}');
|
|
1397
|
+
}
|
|
1398
|
+
var showExpr = el.attr('ng-if');
|
|
1399
|
+
if (!showExpr){
|
|
1400
|
+
el.attr('ng-if', '$columns[$index].show(this)');
|
|
1401
|
+
}
|
|
1402
|
+
});
|
|
1403
|
+
return function (scope, element, attrs, controller) {
|
|
1404
|
+
var expr = controller.parseNgTableDynamicExpr(attrs.ngTableDynamic);
|
|
1405
|
+
|
|
1406
|
+
controller.setupBindingsToInternalScope(expr.tableParams);
|
|
1407
|
+
controller.compileDirectiveTemplates();
|
|
1408
|
+
|
|
1409
|
+
scope.$watchCollection(expr.columns, function (newCols/*, oldCols*/) {
|
|
1410
|
+
scope.$columns = controller.buildColumns(newCols);
|
|
1411
|
+
controller.loadFilterData(scope.$columns);
|
|
1412
|
+
});
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
}]);
|
|
1417
|
+
|
|
1418
|
+
(function(){
|
|
1419
|
+
'use strict';
|
|
1420
|
+
|
|
1421
|
+
angular.module('ngTable')
|
|
1422
|
+
.directive('ngTableFilterRow', ngTableFilterRow);
|
|
1423
|
+
|
|
1424
|
+
ngTableFilterRow.$inject = [];
|
|
1425
|
+
|
|
1426
|
+
function ngTableFilterRow(){
|
|
1427
|
+
var directive = {
|
|
1428
|
+
restrict: 'E',
|
|
1429
|
+
replace: true,
|
|
1430
|
+
templateUrl: 'ng-table/filterRow.html',
|
|
1431
|
+
scope: true,
|
|
1432
|
+
controller: 'ngTableFilterRowController'
|
|
1433
|
+
};
|
|
1434
|
+
return directive;
|
|
1435
|
+
}
|
|
1436
|
+
})();
|
|
1437
|
+
|
|
1438
|
+
(function(){
|
|
1439
|
+
'use strict';
|
|
1440
|
+
|
|
1441
|
+
angular.module('ngTable')
|
|
1442
|
+
.directive('ngTableSorterRow', ngTableSorterRow);
|
|
1443
|
+
|
|
1444
|
+
ngTableSorterRow.$inject = [];
|
|
1445
|
+
|
|
1446
|
+
function ngTableSorterRow(){
|
|
1447
|
+
var directive = {
|
|
1448
|
+
restrict: 'E',
|
|
1449
|
+
replace: true,
|
|
1450
|
+
templateUrl: 'ng-table/sorterRow.html',
|
|
1451
|
+
scope: true,
|
|
1452
|
+
controller: 'ngTableSorterRowController'
|
|
1453
|
+
};
|
|
1454
|
+
return directive;
|
|
1455
|
+
}
|
|
1456
|
+
})();
|
|
1457
|
+
|
|
1458
|
+
/**
|
|
1459
|
+
* ngTable: Table + Angular JS
|
|
1460
|
+
*
|
|
1461
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
1462
|
+
* @url https://github.com/esvit/ng-table/
|
|
1463
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
1464
|
+
*/
|
|
1465
|
+
|
|
1466
|
+
/**
|
|
1467
|
+
* @ngdoc directive
|
|
1468
|
+
* @name ngTablePagination
|
|
1469
|
+
* @module ngTable
|
|
1470
|
+
* @restrict A
|
|
1471
|
+
*/
|
|
1472
|
+
app.directive('ngTablePagination', ['$compile', 'ngTableEventsChannel',
|
|
1473
|
+
function($compile, ngTableEventsChannel) {
|
|
1474
|
+
'use strict';
|
|
1475
|
+
|
|
1476
|
+
return {
|
|
1477
|
+
restrict: 'A',
|
|
1478
|
+
scope: {
|
|
1479
|
+
'params': '=ngTablePagination',
|
|
1480
|
+
'templateUrl': '='
|
|
1481
|
+
},
|
|
1482
|
+
replace: false,
|
|
1483
|
+
link: function(scope, element/*, attrs*/) {
|
|
1484
|
+
|
|
1485
|
+
ngTableEventsChannel.onAfterReloadData(function(pubParams) {
|
|
1486
|
+
scope.pages = pubParams.generatePagesArray();
|
|
1487
|
+
}, scope, function(pubParams){
|
|
1488
|
+
return pubParams === scope.params;
|
|
1489
|
+
});
|
|
1490
|
+
|
|
1491
|
+
scope.$watch('templateUrl', function(templateUrl) {
|
|
1492
|
+
if (angular.isUndefined(templateUrl)) {
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1495
|
+
var template = angular.element(document.createElement('div'));
|
|
1496
|
+
template.attr({
|
|
1497
|
+
'ng-include': 'templateUrl'
|
|
1498
|
+
});
|
|
1499
|
+
element.append(template);
|
|
1500
|
+
$compile(template)(scope);
|
|
1501
|
+
});
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
]);
|
|
1506
|
+
|
|
1507
|
+
angular.module('ngTable').run(['$templateCache', function ($templateCache) {
|
|
1508
|
+
$templateCache.put('ng-table/filterRow.html', '<tr ng-show="show_filter" class="ng-table-filters"> <th data-title-text="{{$column.titleAlt(this) || $column.title(this)}}" ng-repeat="$column in $columns" ng-if="$column.show(this)" class="filter"> <div ng-repeat="(name, filter) in $column.filter(this)"> <div ng-include="config.getTemplateUrl(filter)"></div> </div> </th> </tr> ');
|
|
1509
|
+
$templateCache.put('ng-table/filters/number.html', '<input type="number" name="{{name}}" ng-disabled="$filterRow.disabled" ng-model="params.filter()[name]" class="input-filter form-control"/> ');
|
|
1510
|
+
$templateCache.put('ng-table/filters/select-multiple.html', '<select ng-options="data.id as data.title for data in $column.data" ng-disabled="$filterRow.disabled" multiple ng-multiple="true" ng-model="params.filter()[name]" class="filter filter-select-multiple form-control" name="{{name}}"> </select> ');
|
|
1511
|
+
$templateCache.put('ng-table/filters/select.html', '<select ng-options="data.id as data.title for data in $column.data" ng-disabled="$filterRow.disabled" ng-model="params.filter()[name]" class="filter filter-select form-control" name="{{name}}"> <option style="display:none" value=""></option> </select> ');
|
|
1512
|
+
$templateCache.put('ng-table/filters/text.html', '<input type="text" name="{{name}}" ng-disabled="$filterRow.disabled" ng-model="params.filter()[name]" class="input-filter form-control"/> ');
|
|
1513
|
+
$templateCache.put('ng-table/header.html', '<ng-table-sorter-row></ng-table-sorter-row> <ng-table-filter-row></ng-table-filter-row> ');
|
|
1514
|
+
$templateCache.put('ng-table/pager.html', '<div class="ng-cloak ng-table-pager" ng-if="params.data.length"> <div ng-if="params.settings().counts.length" class="ng-table-counts btn-group pull-right"> <button ng-repeat="count in params.settings().counts" type="button" ng-class="{\'active\':params.count()==count}" ng-click="params.count(count)" class="btn btn-default"> <span ng-bind="count"></span> </button> </div> <ul class="pagination ng-table-pagination"> <li ng-class="{\'disabled\': !page.active && !page.current, \'active\': page.current}" ng-repeat="page in pages" ng-switch="page.type"> <a ng-switch-when="prev" ng-click="params.page(page.number)" href="">«</a> <a ng-switch-when="first" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="page" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="more" ng-click="params.page(page.number)" href="">…</a> <a ng-switch-when="last" ng-click="params.page(page.number)" href=""><span ng-bind="page.number"></span></a> <a ng-switch-when="next" ng-click="params.page(page.number)" href="">»</a> </li> </ul> </div> ');
|
|
1515
|
+
$templateCache.put('ng-table/sorterRow.html', '<tr> <th title="{{$column.headerTitle(this)}}" ng-repeat="$column in $columns" ng-class="{ \'sortable\': $column.sortable(this), \'sort-asc\': params.sorting()[$column.sortable(this)]==\'asc\', \'sort-desc\': params.sorting()[$column.sortable(this)]==\'desc\' }" ng-click="sortBy($column, $event)" ng-if="$column.show(this)" ng-init="template=$column.headerTemplateURL(this)" class="header {{$column.class(this)}}"> <div ng-if="!template" class="ng-table-header" ng-class="{\'sort-indicator\': params.settings().sortingIndicator==\'div\'}"> <span ng-bind="$column.title(this)" ng-class="{\'sort-indicator\': params.settings().sortingIndicator==\'span\'}"></span> </div> <div ng-if="template" ng-include="template"></div> </th> </tr> ');
|
|
1516
|
+
}]);
|
|
1517
|
+
return app;
|
|
1518
|
+
}));
|