mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 14:11:54 +00:00
Pagination service and same is used for client pagination
This commit is contained in:
parent
b49f80da6a
commit
84f20be287
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,4 +14,5 @@ logs
|
||||
results
|
||||
npm-debug.log
|
||||
.idea/*
|
||||
image/Thumbs.db
|
||||
**/.DS_Store
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="client in clients.pageItems">
|
||||
<tr ng-repeat="client in clients.currentPageItems | filter:filterText">
|
||||
<td><a href="#/viewclient/{{client.id}}">{{client.displayName}}</a></td>
|
||||
<td><a href="#/viewclient/{{client.id}}">{{client.accountNo}}</a></td>
|
||||
<td>{{client.staffName}}</td>
|
||||
@ -24,4 +24,8 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="pager">
|
||||
<li class="previous"><a ng-click="clients.previous()" href="" ng-disabled="!clients.hasPrevious()">← Prev</a></li>
|
||||
<li class="next" ><a ng-click="clients.next()" href="" ng-disabled="!clients.hasNext()">Next →</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -1,13 +1,18 @@
|
||||
(function(module) {
|
||||
mifosX.controllers = _.extend(module, {
|
||||
ClientController: function(scope, resourceFactory) {
|
||||
ClientController: function(scope, resourceFactory , paginatorService) {
|
||||
|
||||
scope.clients = [];
|
||||
resourceFactory.clientResource.getAllClients(function(data) {
|
||||
scope.clients = data;
|
||||
});
|
||||
|
||||
var fetchFunction = function(offset, limit, callback) {
|
||||
resourceFactory.clientResource.getAllClients({offset: offset, limit: limit} , callback);
|
||||
};
|
||||
|
||||
scope.clients = paginatorService.paginate(fetchFunction, 4);
|
||||
|
||||
}
|
||||
});
|
||||
mifosX.ng.application.controller('ClientController', ['$scope', 'ResourceFactory', mifosX.controllers.ClientController]).run(function($log) {
|
||||
mifosX.ng.application.controller('ClientController', ['$scope', 'ResourceFactory', 'PaginatorService', mifosX.controllers.ClientController]).run(function($log) {
|
||||
$log.info("ClientController initialized");
|
||||
});
|
||||
}(mifosX.controllers || {}));
|
||||
|
||||
@ -20,7 +20,8 @@ define(['underscore', 'mifosX'], function() {
|
||||
'ResourceFactoryProvider',
|
||||
'HttpServiceProvider',
|
||||
'AuthenticationService',
|
||||
'SessionManager'
|
||||
'SessionManager',
|
||||
'Paginator'
|
||||
],
|
||||
directives: [
|
||||
'DataTablesDirective',
|
||||
|
||||
46
js/services/Paginator.js
Normal file
46
js/services/Paginator.js
Normal file
@ -0,0 +1,46 @@
|
||||
(function(module) {
|
||||
mifosX.services = _.extend(module, {
|
||||
PaginatorService: function(scope, httpService) {
|
||||
|
||||
this.paginate = function(fetchFunction, pageSize) {
|
||||
var paginator = {
|
||||
hasNextVar: false,
|
||||
next: function() {
|
||||
if (this.hasNextVar) {
|
||||
this.currentOffset += pageSize;
|
||||
this._load();
|
||||
}
|
||||
},
|
||||
_load: function() {
|
||||
var self = this;
|
||||
fetchFunction(this.currentOffset, pageSize + 1, function(items) {
|
||||
self.currentPageItems = items.pageItems;
|
||||
self.hasNextVar = items.pageItems.length === pageSize + 1;;
|
||||
});
|
||||
},
|
||||
hasNext: function() {
|
||||
return this.hasNextVar;
|
||||
},
|
||||
previous: function() {
|
||||
if(this.hasPrevious()) {
|
||||
this.currentOffset -= pageSize;
|
||||
this._load();
|
||||
}
|
||||
},
|
||||
hasPrevious: function() {
|
||||
return this.currentOffset !== 0;
|
||||
},
|
||||
currentPageItems: [],
|
||||
currentOffset: 0
|
||||
};
|
||||
// Load the first page
|
||||
paginator._load();
|
||||
return paginator;
|
||||
};
|
||||
|
||||
}
|
||||
});
|
||||
mifosX.ng.services.service('PaginatorService', ['$rootScope', 'HttpService', mifosX.services.PaginatorService]).run(function($log) {
|
||||
$log.info("PaginatorService initialized");
|
||||
});
|
||||
}(mifosX.services || {}));
|
||||
Loading…
Reference in New Issue
Block a user