}
function fetch_hold(deferred,entry) {
- egCore.pcrud.search('ahr',
+ return egCore.pcrud.search('ahr',
{ 'id' : entry.data.hold_id }, {
'flesh' : 2,
'flesh_fields' : {
},
}
).then(
- deferred.resolve, null,
function(hold) {
entry.patron_id = hold.usr().id();
entry.user = hold.usr().family_name();
}
function fetch_patron(deferred,entry) {
- egCore.pcrud.search('au',
+ return egCore.pcrud.search('au',
{ 'id' : entry.data.patron_id }, {}
).then(
- deferred.resolve, null,
function(usr) {
entry.user = usr.family_name();
deferred.notify(entry);
console.log(log_entries);
var deferred = $q.defer();
- $timeout( function() {
- log_entries.work_log.forEach(
- function(el,idx) {
- el.id = idx;
- if (el.action == 'requested_hold') {
- fetch_hold(deferred,el);
- } else if (el.action == 'registered_patron') {
- fetch_patron(deferred,el);
- } else if (el.action == 'edited_patron') {
- fetch_patron(deferred,el);
- } else if (el.action == 'paid_bill') {
- fetch_patron(deferred,el);
- } else {
- deferred.notify(el);
- }
+ var promises = [];
+ var entries = count ?
+ log_entries.work_log.slice(offset, offset + count) :
+ log_entries.work_log;
+ entries.forEach(
+ function(el,idx) {
+ el.id = idx;
+ if (el.action == 'requested_hold') {
+ promises.push(fetch_hold(deferred,el));
+ } else if (el.action == 'registered_patron') {
+ promises.push(fetch_patron(deferred,el));
+ } else if (el.action == 'edited_patron') {
+ promises.push(fetch_patron(deferred,el));
+ } else if (el.action == 'paid_bill') {
+ promises.push(fetch_patron(deferred,el));
+ } else {
+ promises.push($timeout(function() { deferred.notify(el) }));
}
- );
- });
+ }
+ );
+ $q.all(promises).then(deferred.resolve);
+
return deferred.promise;
}
console.log(log_entries);
var deferred = $q.defer();
- $timeout( function() {
- log_entries.patron_log.forEach(
- function(el,idx) {
- el.id = idx;
- if (el.action == 'requested_hold') {
- fetch_hold(deferred,el);
- } else if (el.action == 'registered_patron') {
- fetch_patron(deferred,el);
- } else if (el.action == 'edited_patron') {
- fetch_patron(deferred,el);
- } else if (el.action == 'paid_bill') {
- fetch_patron(deferred,el);
- } else {
- deferred.notify(el);
- }
+ var promises = [];
+ var entries = count ?
+ log_entries.patron_log.slice(offset, offset + count) :
+ log_entries.patron_log;
+ log_entries.patron_log.forEach(
+ function(el,idx) {
+ el.id = idx;
+ if (el.action == 'requested_hold') {
+ promises.push(fetch_hold(deferred,el));
+ } else if (el.action == 'registered_patron') {
+ promises.push(fetch_patron(deferred,el));
+ } else if (el.action == 'edited_patron') {
+ promises.push(fetch_patron(deferred,el));
+ } else if (el.action == 'paid_bill') {
+ promises.push(fetch_patron(deferred,el));
+ } else {
+ promises.push($timeout(function() { deferred.notify(el) }));
}
- );
- });
+ }
+ );
+ $q.all(promises).then(deferred.resolve);
+
return deferred.promise;
}