middleman-angularjs 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/middleman/angularjs.rb +0 -1
- data/lib/middleman/angularjs/version.rb +1 -1
- data/middleman-angularjs.gemspec +2 -2
- data/vendor/assets/javascripts/angular-ui.js +2 -0
- data/vendor/assets/javascripts/angular-ui/0.9/core.js +3349 -0
- data/vendor/assets/javascripts/angular-ui/0.9/tpls.js +3599 -0
- data/vendor/assets/javascripts/angular.js +7 -0
- data/vendor/assets/javascripts/angular/1.2.4/animate.js +1323 -0
- data/vendor/assets/javascripts/angular/1.2.4/cookies.js +202 -0
- data/vendor/assets/javascripts/angular/1.2.4/core.js +20311 -0
- data/vendor/assets/javascripts/angular/1.2.4/mocks.js +2115 -0
- data/vendor/assets/javascripts/angular/1.2.4/resource.js +546 -0
- data/vendor/assets/javascripts/angular/1.2.4/route.js +891 -0
- data/vendor/assets/javascripts/angular/1.2.4/sanitize.js +622 -0
- data/vendor/assets/javascripts/angular/plugins/flash.js +62 -0
- data/vendor/assets/javascripts/angular/plugins/ng-table.js +633 -0
- data/vendor/assets/javascripts/jquery.js +1 -0
- data/vendor/assets/javascripts/jquery/2.0.3.js +8829 -0
- metadata +20 -5
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
angular.module('flash', [])
|
|
2
|
+
.factory('flash', ['$rootScope', '$timeout', function($rootScope, $timeout) {
|
|
3
|
+
var messages = [];
|
|
4
|
+
|
|
5
|
+
var reset;
|
|
6
|
+
var cleanup = function() {
|
|
7
|
+
$timeout.cancel(reset);
|
|
8
|
+
reset = $timeout(function() { messages = []; });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
var emit = function() {
|
|
12
|
+
$rootScope.$emit('flash:message', messages, cleanup);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
$rootScope.$on('$locationChangeSuccess', emit);
|
|
16
|
+
|
|
17
|
+
var asMessage = function(level, text) {
|
|
18
|
+
if (!text) {
|
|
19
|
+
text = level;
|
|
20
|
+
level = 'success';
|
|
21
|
+
}
|
|
22
|
+
return { level: level, text: text };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var asArrayOfMessages = function(level, text) {
|
|
26
|
+
if (level instanceof Array) return level.map(function(message) {
|
|
27
|
+
return message.text ? message : asMessage(message);
|
|
28
|
+
});
|
|
29
|
+
return text ? [{ level: level, text: text }] : [asMessage(level)];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var flash = function(level, text, timeout) {
|
|
33
|
+
if(timeout !== undefined) {
|
|
34
|
+
$timeout(function() { emit(cleanup); }, timeout);
|
|
35
|
+
}
|
|
36
|
+
emit(messages = asArrayOfMessages(level, text));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
['error', 'warning', 'info', 'success'].forEach(function (level) {
|
|
40
|
+
flash[level] = function (text, timeout) { flash(level, text, timeout); };
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return flash;
|
|
44
|
+
}])
|
|
45
|
+
|
|
46
|
+
.directive('flashMessages', [function() {
|
|
47
|
+
var directive = { restrict: 'EA', replace: true };
|
|
48
|
+
directive.template =
|
|
49
|
+
'<div class="container" ng-show="messages"><div class="alert alert-warning">' +
|
|
50
|
+
'<ol id="flash-messages">' +
|
|
51
|
+
'<li ng-repeat="m in messages" class="{{m.level}}">{{m.text}}</li>' +
|
|
52
|
+
'</ol></div></div>';
|
|
53
|
+
|
|
54
|
+
directive.controller = ['$scope', '$rootScope', function($scope, $rootScope) {
|
|
55
|
+
$rootScope.$on('flash:message', function(_, messages, done) {
|
|
56
|
+
$scope.messages = messages;
|
|
57
|
+
done();
|
|
58
|
+
});
|
|
59
|
+
}];
|
|
60
|
+
|
|
61
|
+
return directive;
|
|
62
|
+
}]);
|
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
(function(angular, factory) {
|
|
2
|
+
if (typeof define === 'function' && define.amd) {
|
|
3
|
+
define(['angular'], function(angular) {
|
|
4
|
+
return factory(angular);
|
|
5
|
+
});
|
|
6
|
+
} else {
|
|
7
|
+
return factory(angular);
|
|
8
|
+
}
|
|
9
|
+
}(angular || null, function(angular) {
|
|
10
|
+
/**
|
|
11
|
+
* ngTable: Table + Angular JS
|
|
12
|
+
*
|
|
13
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
14
|
+
* @url https://github.com/esvit/ng-table/
|
|
15
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @ngdoc module
|
|
20
|
+
* @name ngTable
|
|
21
|
+
* @description ngTable: Table + Angular JS
|
|
22
|
+
* @example
|
|
23
|
+
<doc:example>
|
|
24
|
+
<doc:source>
|
|
25
|
+
<script>
|
|
26
|
+
var app = angular.module('myApp', ['ngTable']);
|
|
27
|
+
app.controller('MyCtrl', function($scope) {
|
|
28
|
+
$scope.users = [
|
|
29
|
+
{name: "Moroni", age: 50},
|
|
30
|
+
{name: "Tiancum", age: 43},
|
|
31
|
+
{name: "Jacob", age: 27},
|
|
32
|
+
{name: "Nephi", age: 29},
|
|
33
|
+
{name: "Enos", age: 34}
|
|
34
|
+
];
|
|
35
|
+
});
|
|
36
|
+
</script>
|
|
37
|
+
<table ng-table class="table">
|
|
38
|
+
<tr ng-repeat="user in users">
|
|
39
|
+
<td data-title="'Name'">{{user.name}}</td>
|
|
40
|
+
<td data-title="'Age'">{{user.age}}</td>
|
|
41
|
+
</tr>
|
|
42
|
+
</table>
|
|
43
|
+
</doc:source>
|
|
44
|
+
</doc:example>
|
|
45
|
+
*/
|
|
46
|
+
var app = angular.module('ngTable', []);
|
|
47
|
+
/**
|
|
48
|
+
* ngTable: Table + Angular JS
|
|
49
|
+
*
|
|
50
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
51
|
+
* @url https://github.com/esvit/ng-table/
|
|
52
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @ngdoc service
|
|
57
|
+
* @name ngTable.factory:ngTableParams
|
|
58
|
+
* @description Parameters manager for ngTable
|
|
59
|
+
*/
|
|
60
|
+
app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
|
|
61
|
+
var isNumber = function (n) {
|
|
62
|
+
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
63
|
+
};
|
|
64
|
+
var ngTableParams = function (baseParameters, baseSettings) {
|
|
65
|
+
var self = this;
|
|
66
|
+
|
|
67
|
+
this.data = [];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @ngdoc method
|
|
71
|
+
* @name ngTable.factory:ngTableParams#parameters
|
|
72
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
73
|
+
* @description Set new parameters or get current parameters
|
|
74
|
+
*
|
|
75
|
+
* @param {string} newParameters New parameters
|
|
76
|
+
* @param {string} parseParamsFromUrl Flag if parse parameters like in url
|
|
77
|
+
* @returns {Object} Current parameters or `this`
|
|
78
|
+
*/
|
|
79
|
+
this.parameters = function (newParameters, parseParamsFromUrl) {
|
|
80
|
+
parseParamsFromUrl = parseParamsFromUrl || false;
|
|
81
|
+
if (angular.isDefined(newParameters)) {
|
|
82
|
+
for (var key in newParameters) {
|
|
83
|
+
var value = newParameters[key];
|
|
84
|
+
if (parseParamsFromUrl && key.indexOf('[') >= 0) {
|
|
85
|
+
var keys = key.split(/\[(.*)\]/).reverse()
|
|
86
|
+
var lastKey = '';
|
|
87
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
88
|
+
var name = keys[i];
|
|
89
|
+
if (name !== '') {
|
|
90
|
+
var v = value;
|
|
91
|
+
value = {};
|
|
92
|
+
value[lastKey = name] = (isNumber(v) ? parseFloat(v) : v);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (lastKey === 'sorting') {
|
|
96
|
+
params[lastKey] = {};
|
|
97
|
+
}
|
|
98
|
+
params[lastKey] = angular.extend(params[lastKey] || {}, value[lastKey]);
|
|
99
|
+
} else {
|
|
100
|
+
params[key] = (isNumber(newParameters[key]) ? parseFloat(newParameters[key]) : newParameters[key]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
$log.debug && $log.debug('ngTable: set parameters', params);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
return params;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @ngdoc method
|
|
111
|
+
* @name ngTable.factory:ngTableParams#settings
|
|
112
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
113
|
+
* @description Set new settings for table
|
|
114
|
+
*
|
|
115
|
+
* @param {string} newSettings New settings or undefined
|
|
116
|
+
* @returns {Object} Current settings or `this`
|
|
117
|
+
*/
|
|
118
|
+
this.settings = function (newSettings) {
|
|
119
|
+
if (angular.isDefined(newSettings)) {
|
|
120
|
+
if (angular.isArray(newSettings.data)) {
|
|
121
|
+
//auto-set the total from passed in data
|
|
122
|
+
newSettings.total = newSettings.data.length;
|
|
123
|
+
}
|
|
124
|
+
settings = angular.extend(settings, newSettings);
|
|
125
|
+
$log.debug && $log.debug('ngTable: set settings', settings);
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
return settings;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @ngdoc method
|
|
133
|
+
* @name ngTable.factory:ngTableParams#page
|
|
134
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
135
|
+
* @description If parameter page not set return current page else set current page
|
|
136
|
+
*
|
|
137
|
+
* @param {string} page Page number
|
|
138
|
+
* @returns {Object|Number} Current page or `this`
|
|
139
|
+
*/
|
|
140
|
+
this.page = function (page) {
|
|
141
|
+
return angular.isDefined(page) ? this.parameters({'page': page}) : params.page;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @ngdoc method
|
|
146
|
+
* @name ngTable.factory:ngTableParams#total
|
|
147
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
148
|
+
* @description If parameter total not set return current quantity else set quantity
|
|
149
|
+
*
|
|
150
|
+
* @param {string} total Total quantity of items
|
|
151
|
+
* @returns {Object|Number} Current page or `this`
|
|
152
|
+
*/
|
|
153
|
+
this.total = function (total) {
|
|
154
|
+
return angular.isDefined(total) ? this.settings({'total': total}) : settings.total;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @ngdoc method
|
|
159
|
+
* @name ngTable.factory:ngTableParams#count
|
|
160
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
161
|
+
* @description If parameter count not set return current count per page else set count per page
|
|
162
|
+
*
|
|
163
|
+
* @param {string} count Count per number
|
|
164
|
+
* @returns {Object|Number} Count per page or `this`
|
|
165
|
+
*/
|
|
166
|
+
this.count = function (count) {
|
|
167
|
+
// reset to first page because can be blank page
|
|
168
|
+
return angular.isDefined(count) ? this.parameters({'count': count, 'page': 1}) : params.count;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @ngdoc method
|
|
173
|
+
* @name ngTable.factory:ngTableParams#filter
|
|
174
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
175
|
+
* @description If parameter page not set return current filter else set current filter
|
|
176
|
+
*
|
|
177
|
+
* @param {string} filter New filter
|
|
178
|
+
* @returns {Object} Current filter or `this`
|
|
179
|
+
*/
|
|
180
|
+
this.filter = function (filter) {
|
|
181
|
+
return angular.isDefined(filter) ? this.parameters({'filter': filter}) : params.filter;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @ngdoc method
|
|
186
|
+
* @name ngTable.factory:ngTableParams#sorting
|
|
187
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
188
|
+
* @description If 'sorting' parameter is not set, return current sorting. Otherwise set current sorting.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} sorting New sorting
|
|
191
|
+
* @returns {Object} Current sorting or `this`
|
|
192
|
+
*/
|
|
193
|
+
this.sorting = function (sorting) {
|
|
194
|
+
if (arguments.length == 2){
|
|
195
|
+
var sortArray = {};
|
|
196
|
+
sortArray[sorting] = arguments[1];
|
|
197
|
+
this.parameters({'sorting': sortArray});
|
|
198
|
+
return this;
|
|
199
|
+
}
|
|
200
|
+
return angular.isDefined(sorting) ? this.parameters({'sorting': sorting}) : params.sorting;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @ngdoc method
|
|
205
|
+
* @name ngTable.factory:ngTableParams#isSortBy
|
|
206
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
207
|
+
* @description Checks sort field
|
|
208
|
+
*
|
|
209
|
+
* @param {string} field Field name
|
|
210
|
+
* @param {string} direction Direction of sorting 'asc' or 'desc'
|
|
211
|
+
* @returns {Array} Return true if field sorted by direction
|
|
212
|
+
*/
|
|
213
|
+
this.isSortBy = function (field, direction) {
|
|
214
|
+
return angular.isDefined(params.sorting[field]) && params.sorting[field] == direction;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @ngdoc method
|
|
219
|
+
* @name ngTable.factory:ngTableParams#orderBy
|
|
220
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
221
|
+
* @description Return object of sorting parameters for angular filter
|
|
222
|
+
*
|
|
223
|
+
* @returns {Array} Array like: [ '-name', '+age' ]
|
|
224
|
+
*/
|
|
225
|
+
this.orderBy = function () {
|
|
226
|
+
var sorting = [];
|
|
227
|
+
for (var column in params.sorting) {
|
|
228
|
+
sorting.push((params.sorting[column] === "asc" ? "+" : "-") + column);
|
|
229
|
+
}
|
|
230
|
+
return sorting;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @ngdoc method
|
|
235
|
+
* @name ngTable.factory:ngTableParams#getData
|
|
236
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
237
|
+
* @description Called when updated some of parameters for get new data
|
|
238
|
+
*
|
|
239
|
+
* @param {Object} $defer promise object
|
|
240
|
+
* @param {Object} params New parameters
|
|
241
|
+
*/
|
|
242
|
+
this.getData = function ($defer, params) {
|
|
243
|
+
if (angular.isArray(this.data) && angular.isObject(params)) {
|
|
244
|
+
$defer.resolve(this.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
245
|
+
} else {
|
|
246
|
+
$defer.resolve([]);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @ngdoc method
|
|
252
|
+
* @name ngTable.factory:ngTableParams#getGroups
|
|
253
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
254
|
+
* @description Return groups for table grouping
|
|
255
|
+
*/
|
|
256
|
+
this.getGroups = function ($defer, column) {
|
|
257
|
+
var defer = $q.defer();
|
|
258
|
+
|
|
259
|
+
defer.promise.then(function(data) {
|
|
260
|
+
var groups = {};
|
|
261
|
+
for (var k in data) {
|
|
262
|
+
var item = data[k],
|
|
263
|
+
groupName = angular.isFunction(column) ? column(item) : item[column];
|
|
264
|
+
|
|
265
|
+
groups[groupName] = groups[groupName] || {
|
|
266
|
+
data: []
|
|
267
|
+
};
|
|
268
|
+
groups[groupName]['value'] = groupName;
|
|
269
|
+
groups[groupName].data.push(item);
|
|
270
|
+
}
|
|
271
|
+
var result = [];
|
|
272
|
+
for (var i in groups) {
|
|
273
|
+
result.push(groups[i]);
|
|
274
|
+
}
|
|
275
|
+
$log.debug && $log.debug('ngTable: refresh groups', result);
|
|
276
|
+
$defer.resolve(result);
|
|
277
|
+
});
|
|
278
|
+
this.getData(defer, self);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @ngdoc method
|
|
283
|
+
* @name ngTable.factory:ngTableParams#generatePagesArray
|
|
284
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
285
|
+
* @description Generate array of pages
|
|
286
|
+
*
|
|
287
|
+
* @param {boolean} currentPage which page must be active
|
|
288
|
+
* @param {boolean} totalItems Total quantity of items
|
|
289
|
+
* @param {boolean} pageSize Quantity of items on page
|
|
290
|
+
* @returns {Array} Array of pages
|
|
291
|
+
*/
|
|
292
|
+
this.generatePagesArray = function (currentPage, totalItems, pageSize) {
|
|
293
|
+
var maxBlocks, maxPage, maxPivotPages, minPage, numPages, pages;
|
|
294
|
+
maxBlocks = 11;
|
|
295
|
+
pages = [];
|
|
296
|
+
numPages = Math.ceil(totalItems / pageSize);
|
|
297
|
+
if (numPages > 1) {
|
|
298
|
+
pages.push({
|
|
299
|
+
type: 'prev',
|
|
300
|
+
number: Math.max(1, currentPage - 1),
|
|
301
|
+
active: currentPage > 1
|
|
302
|
+
});
|
|
303
|
+
pages.push({
|
|
304
|
+
type: 'first',
|
|
305
|
+
number: 1,
|
|
306
|
+
active: currentPage > 1
|
|
307
|
+
});
|
|
308
|
+
maxPivotPages = Math.round((maxBlocks - 5) / 2);
|
|
309
|
+
minPage = Math.max(2, currentPage - maxPivotPages);
|
|
310
|
+
maxPage = Math.min(numPages - 1, currentPage + maxPivotPages * 2 - (currentPage - minPage));
|
|
311
|
+
minPage = Math.max(2, minPage - (maxPivotPages * 2 - (maxPage - minPage)));
|
|
312
|
+
var i = minPage;
|
|
313
|
+
while (i <= maxPage) {
|
|
314
|
+
if ((i === minPage && i !== 2) || (i === maxPage && i !== numPages - 1)) {
|
|
315
|
+
pages.push({
|
|
316
|
+
type: 'more',
|
|
317
|
+
active: false
|
|
318
|
+
});
|
|
319
|
+
} else {
|
|
320
|
+
pages.push({
|
|
321
|
+
type: 'page',
|
|
322
|
+
number: i,
|
|
323
|
+
active: currentPage !== i
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
i++;
|
|
327
|
+
}
|
|
328
|
+
pages.push({
|
|
329
|
+
type: 'last',
|
|
330
|
+
number: numPages,
|
|
331
|
+
active: currentPage !== numPages
|
|
332
|
+
});
|
|
333
|
+
pages.push({
|
|
334
|
+
type: 'next',
|
|
335
|
+
number: Math.min(numPages, currentPage + 1),
|
|
336
|
+
active: currentPage < numPages
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
return pages;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @ngdoc method
|
|
344
|
+
* @name ngTable.factory:ngTableParams#url
|
|
345
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
346
|
+
* @description Return groups for table grouping
|
|
347
|
+
*
|
|
348
|
+
* @param {boolean} asString flag indicates return array of string or object
|
|
349
|
+
* @returns {Array} If asString = true will be return array of url string parameters else key-value object
|
|
350
|
+
*/
|
|
351
|
+
this.url = function (asString) {
|
|
352
|
+
asString = asString || false;
|
|
353
|
+
var pairs = (asString ? [] : {});
|
|
354
|
+
for (key in params) {
|
|
355
|
+
if (params.hasOwnProperty(key)) {
|
|
356
|
+
var item = params[key],
|
|
357
|
+
name = encodeURIComponent(key);
|
|
358
|
+
if (typeof item === "object") {
|
|
359
|
+
for (var subkey in item) {
|
|
360
|
+
if (!angular.isUndefined(item[subkey]) && item[subkey] !== "") {
|
|
361
|
+
var pname = name + "[" + encodeURIComponent(subkey) + "]";
|
|
362
|
+
if (asString) {
|
|
363
|
+
pairs.push(pname + "=" + item[subkey]);
|
|
364
|
+
} else {
|
|
365
|
+
pairs[pname] = item[subkey];
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} else if (!angular.isFunction(item) && !angular.isUndefined(item) && item !== "") {
|
|
370
|
+
if (asString) {
|
|
371
|
+
pairs.push(name + "=" + encodeURIComponent(item));
|
|
372
|
+
} else {
|
|
373
|
+
pairs[name] = encodeURIComponent(item);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return pairs;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @ngdoc method
|
|
383
|
+
* @name ngTable.factory:ngTableParams#reload
|
|
384
|
+
* @methodOf ngTable.factory:ngTableParams
|
|
385
|
+
* @description Reload table data
|
|
386
|
+
*/
|
|
387
|
+
this.reload = function() {
|
|
388
|
+
var $defer = $q.defer(),
|
|
389
|
+
self = this;
|
|
390
|
+
|
|
391
|
+
settings.$loading = true;
|
|
392
|
+
if (settings.groupBy) {
|
|
393
|
+
settings.getGroups($defer, settings.groupBy, this);
|
|
394
|
+
} else {
|
|
395
|
+
settings.getData($defer, this);
|
|
396
|
+
}
|
|
397
|
+
$log.debug && $log.debug('ngTable: reload data');
|
|
398
|
+
$defer.promise.then(function(data) {
|
|
399
|
+
settings.$loading = false;
|
|
400
|
+
$log.debug && $log.debug('ngTable: current scope', settings.$scope);
|
|
401
|
+
if (settings.groupBy) {
|
|
402
|
+
self.data = settings.$scope.$groups = data;
|
|
403
|
+
} else {
|
|
404
|
+
self.data = settings.$scope.$data = data;
|
|
405
|
+
}
|
|
406
|
+
settings.$scope.pages = self.generatePagesArray(self.page(), self.total(), self.count());
|
|
407
|
+
});
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
this.reloadPages = function () {
|
|
411
|
+
var self = this;
|
|
412
|
+
settings.$scope.pages = self.generatePagesArray(self.page(), self.total(), self.count());
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
var params = this.$params = {
|
|
416
|
+
page: 1,
|
|
417
|
+
count: 1,
|
|
418
|
+
filter: {},
|
|
419
|
+
sorting: {},
|
|
420
|
+
group: {},
|
|
421
|
+
groupBy: null
|
|
422
|
+
};
|
|
423
|
+
var settings = {
|
|
424
|
+
$scope: null, // set by ngTable controller
|
|
425
|
+
$loading: false,
|
|
426
|
+
data: null, //allows data to be set when table is initialized
|
|
427
|
+
total: 0,
|
|
428
|
+
counts: [10, 25, 50, 100],
|
|
429
|
+
getGroups: this.getGroups,
|
|
430
|
+
getData: this.getData
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
this.settings(baseSettings);
|
|
434
|
+
this.parameters(baseParameters, true);
|
|
435
|
+
return this;
|
|
436
|
+
};
|
|
437
|
+
return ngTableParams;
|
|
438
|
+
}]);
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* ngTable: Table + Angular JS
|
|
442
|
+
*
|
|
443
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
444
|
+
* @url https://github.com/esvit/ng-table/
|
|
445
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
446
|
+
*/
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* @ngdoc object
|
|
450
|
+
* @name ngTable.directive:ngTable.ngTableController
|
|
451
|
+
*
|
|
452
|
+
* @description
|
|
453
|
+
* Each {@link ngTable.directive:ngTable ngTable} directive creates an instance of `ngTableController`
|
|
454
|
+
*/
|
|
455
|
+
var ngTableController = ['$scope', 'ngTableParams', '$q', function($scope, ngTableParams, $q) {
|
|
456
|
+
$scope.$loading = false;
|
|
457
|
+
|
|
458
|
+
if (!$scope.params) {
|
|
459
|
+
$scope.params = new ngTableParams();
|
|
460
|
+
}
|
|
461
|
+
$scope.params.settings().$scope = $scope;
|
|
462
|
+
|
|
463
|
+
$scope.$watch('params.$params', function(params) {
|
|
464
|
+
$scope.params.settings().$scope = $scope;
|
|
465
|
+
$scope.params.reload();
|
|
466
|
+
}, true);
|
|
467
|
+
|
|
468
|
+
$scope.sortBy = function (column, event) {
|
|
469
|
+
var parsedSortable = $scope.parse(column.sortable);
|
|
470
|
+
if (!parsedSortable) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
var sorting = $scope.params.sorting() && $scope.params.sorting()[parsedSortable] && ($scope.params.sorting()[parsedSortable] === "desc");
|
|
474
|
+
var sortingParams = event.ctrlKey ? $scope.params.sorting() : {};
|
|
475
|
+
sortingParams[parsedSortable] = (sorting ? 'asc' : 'desc');
|
|
476
|
+
$scope.params.parameters({
|
|
477
|
+
sorting: sortingParams
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
}];
|
|
481
|
+
/**
|
|
482
|
+
* ngTable: Table + Angular JS
|
|
483
|
+
*
|
|
484
|
+
* @author Vitalii Savchuk <esvit666@gmail.com>
|
|
485
|
+
* @url https://github.com/esvit/ng-table/
|
|
486
|
+
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
|
487
|
+
*/
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* @ngdoc directive
|
|
491
|
+
* @name ngTable.directive:ngTable
|
|
492
|
+
* @restrict A
|
|
493
|
+
*
|
|
494
|
+
* @description
|
|
495
|
+
* Directive that instantiates {@link ngTable.directive:ngTable.ngTableController ngTableController}.
|
|
496
|
+
*/
|
|
497
|
+
app.directive('ngTable', ['$compile', '$q', '$parse',
|
|
498
|
+
function ($compile, $q, $parse) {
|
|
499
|
+
'use strict';
|
|
500
|
+
|
|
501
|
+
return {
|
|
502
|
+
restrict: 'A',
|
|
503
|
+
priority: 1001,
|
|
504
|
+
scope: true,
|
|
505
|
+
controller: ngTableController,
|
|
506
|
+
compile: function (element) {
|
|
507
|
+
var columns = [], i = 0, row = null;
|
|
508
|
+
|
|
509
|
+
// custom header
|
|
510
|
+
var thead = element.find('thead');
|
|
511
|
+
|
|
512
|
+
// IE 8 fix :not(.ng-table-group) selector
|
|
513
|
+
angular.forEach(angular.element(element.find('tr')), function(tr) {
|
|
514
|
+
tr = angular.element(tr);
|
|
515
|
+
if (!tr.hasClass('ng-table-group') && !row) {
|
|
516
|
+
row = tr;
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
if (!row) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
angular.forEach(row.find('td'), function (item) {
|
|
523
|
+
var el = angular.element(item);
|
|
524
|
+
if (el.attr('ignore-cell') && 'true' === el.attr('ignore-cell')) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
var parsedAttribute = function(attr, defaultValue) {
|
|
528
|
+
return function(scope) {
|
|
529
|
+
return $parse(el.attr('x-data-' + attr) || el.attr('data-' + attr) || el.attr(attr))(scope, {
|
|
530
|
+
$columns: columns
|
|
531
|
+
}) || defaultValue;
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
var parsedTitle = parsedAttribute('title', ' '),
|
|
536
|
+
headerTemplateURL = parsedAttribute('header', false),
|
|
537
|
+
filter = parsedAttribute('filter', false)(),
|
|
538
|
+
filterTemplateURL = false;
|
|
539
|
+
|
|
540
|
+
if (filter && filter.templateURL) {
|
|
541
|
+
filterTemplateURL = filter.templateURL;
|
|
542
|
+
delete filter.templateURL;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
el.attr('data-title-text', parsedTitle()); // this used in responsive table
|
|
546
|
+
columns.push({
|
|
547
|
+
id: i++,
|
|
548
|
+
title: parsedTitle,
|
|
549
|
+
sortable: parsedAttribute('sortable', false),
|
|
550
|
+
'class': el.attr('x-data-header-class') || el.attr('data-header-class') || el.attr("header-class"),
|
|
551
|
+
filter: filter,
|
|
552
|
+
filterTemplateURL: filterTemplateURL,
|
|
553
|
+
headerTemplateURL: headerTemplateURL,
|
|
554
|
+
filterData: (el.attr("filter-data") ? el.attr("filter-data") : null),
|
|
555
|
+
show: (el.attr("ng-show") ? function (scope) {
|
|
556
|
+
return $parse(el.attr("ng-show"))(scope);
|
|
557
|
+
} : function () {
|
|
558
|
+
return true;
|
|
559
|
+
})
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
return function (scope, element, attrs) {
|
|
563
|
+
scope.$loading = false;
|
|
564
|
+
scope.$columns = columns;
|
|
565
|
+
|
|
566
|
+
scope.$watch(attrs.ngTable, (function (params) {
|
|
567
|
+
if (angular.isUndefined(params)) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
scope.paramsModel = $parse(attrs.ngTable);
|
|
571
|
+
scope.params = params;
|
|
572
|
+
}), true);
|
|
573
|
+
scope.parse = function (text) {
|
|
574
|
+
return angular.isDefined(text) ? text(scope) : '';
|
|
575
|
+
};
|
|
576
|
+
if (attrs.showFilter) {
|
|
577
|
+
scope.$parent.$watch(attrs.showFilter, function (value) {
|
|
578
|
+
scope.show_filter = value;
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
angular.forEach(columns, function (column) {
|
|
582
|
+
var def;
|
|
583
|
+
if (!column.filterData) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
def = $parse(column.filterData)(scope, {
|
|
587
|
+
$column: column
|
|
588
|
+
});
|
|
589
|
+
if (!(angular.isObject(def) && angular.isObject(def.promise))) {
|
|
590
|
+
throw new Error('Function ' + column.filterData + ' must be instance of $q.defer()');
|
|
591
|
+
}
|
|
592
|
+
delete column['filterData'];
|
|
593
|
+
return def.promise.then(function (data) {
|
|
594
|
+
if (!angular.isArray(data)) {
|
|
595
|
+
data = [];
|
|
596
|
+
}
|
|
597
|
+
data.unshift({
|
|
598
|
+
title: '-',
|
|
599
|
+
id: ''
|
|
600
|
+
});
|
|
601
|
+
column.data = data;
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
if (!element.hasClass('ng-table')) {
|
|
605
|
+
scope.templates = {
|
|
606
|
+
header: (attrs.templateHeader ? attrs.templateHeader : 'ng-table/header.html'),
|
|
607
|
+
pagination: (attrs.templatePagination ? attrs.templatePagination : 'ng-table/pager.html')
|
|
608
|
+
};
|
|
609
|
+
var headerTemplate = thead.length > 0 ? thead : angular.element(document.createElement('thead')).attr('ng-include', 'templates.header');
|
|
610
|
+
var paginationTemplate = angular.element(document.createElement('div')).attr('ng-include', 'templates.pagination');
|
|
611
|
+
element.find('thead').remove();
|
|
612
|
+
var tbody = element.find('tbody');
|
|
613
|
+
element.prepend(headerTemplate);
|
|
614
|
+
$compile(headerTemplate)(scope);
|
|
615
|
+
$compile(paginationTemplate)(scope);
|
|
616
|
+
element.addClass('ng-table');
|
|
617
|
+
return element.after(paginationTemplate);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
]);
|
|
624
|
+
|
|
625
|
+
angular.module('ngTable').run(['$templateCache', function ($templateCache) {
|
|
626
|
+
$templateCache.put('ng-table/filters/select-multiple.html', '<select ng-options="data.id as data.title for data in column.data" multiple ng-multiple="true" ng-model="params.filter()[name]" ng-show="filter==\'select-multiple\'" class="filter filter-select-multiple form-control"> </select>');
|
|
627
|
+
$templateCache.put('ng-table/filters/select.html', '<select ng-options="data.id as data.title for data in column.data" ng-model="params.filter()[name]" ng-show="filter==\'select\'" class="filter filter-select form-control"> </select>');
|
|
628
|
+
$templateCache.put('ng-table/filters/text.html', '<input type="text" ng-model="params.filter()[name]" ng-if="filter==\'text\'" class="input-filter form-control"/>');
|
|
629
|
+
$templateCache.put('ng-table/header.html', '<tr> <th ng-repeat="column in $columns" ng-class="{ \'sortable\': parse(column.sortable), \'sort-asc\': params.sorting()[parse(column.sortable)]==\'asc\', \'sort-desc\': params.sorting()[parse(column.sortable)]==\'desc\' }" ng-click="sortBy(column, $event)" ng-show="column.show(this)" ng-init="template=column.headerTemplateURL(this)" class="header {{column.class}}"> <div ng-if="!template" ng-show="!template" ng-bind="parse(column.title)"></div> <div ng-if="template" ng-show="template"><div ng-include="template"></div></div> </th> </tr> <tr ng-show="show_filter" class="ng-table-filters"> <th ng-repeat="column in $columns" ng-show="column.show(this)" class="filter"> <div ng-repeat="(name, filter) in column.filter"> <div ng-if="column.filterTemplateURL" ng-show="column.filterTemplateURL"> <div ng-include="column.filterTemplateURL"></div> </div> <div ng-if="!column.filterTemplateURL" ng-show="!column.filterTemplateURL"> <div ng-include="\'ng-table/filters/\' + filter + \'.html\'"></div> </div> </div> </th> </tr>');
|
|
630
|
+
$templateCache.put('ng-table/pager.html', '<div class="ng-cloak ng-table-pager"> <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}" 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> ');
|
|
631
|
+
}]);
|
|
632
|
+
return app;
|
|
633
|
+
}));
|