From 3256fd462cf2a7a943638b8122ec7f3e818a9419 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 22 Jun 2018 10:56:02 -0400 Subject: [PATCH] LP#1768947 Offline xact presence is cached; show date Maintain an entry to the object date cache table indicating the time of the most recent offline transaction entry. This data is used on the login page to determine if offline transactions exist, so the staff logging in can be notified. We do this in lieu of checking the offline transaction table, since that table only exists in the offline UI. As a bonus, since we know the last transaction add time, display this information in the login page offline xact alert panel. Signed-off-by: Bill Erickson Signed-off-by: Jeff Davis Signed-off-by: Kathy Lussier --- Open-ILS/src/templates/staff/t_login.tt2 | 11 ++-- .../js/ui/default/staff/offline-db-worker.js | 14 ++++++ .../js/ui/default/staff/services/lovefield.js | 50 ++++++++++++++----- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/Open-ILS/src/templates/staff/t_login.tt2 b/Open-ILS/src/templates/staff/t_login.tt2 index e4d42cb30f..0f58cea8e9 100644 --- a/Open-ILS/src/templates/staff/t_login.tt2 +++ b/Open-ILS/src/templates/staff/t_login.tt2 @@ -49,9 +49,14 @@ -
-
- [% l('Unprocessed offline transactions waiting for upload') %] +
+
+
+ [% | l('{{pendingXacts | date:"short"}}') %] + Unprocessed offline transactions waiting for upload. + Last transaction added at [_1]. + [% END %] +
diff --git a/Open-ILS/web/js/ui/default/staff/offline-db-worker.js b/Open-ILS/web/js/ui/default/staff/offline-db-worker.js index 0107dfd581..6c2e1ad61c 100644 --- a/Open-ILS/web/js/ui/default/staff/offline-db-worker.js +++ b/Open-ILS/web/js/ui/default/staff/offline-db-worker.js @@ -181,6 +181,15 @@ function deleteAll(schemaName, tableName) { return info.schema.db.delete().from(info.table).exec(); } +// Delete rows from selected table where field equals value +function deleteWhereEqual(schemaName, tableName, field, value) { + var info = getTableInfo(schemaName, tableName); + if (info.error) { return Promise.reject(info.error); } + + return info.schema.db.delete().from(info.table) + .where(info.table[field].eq(value)).exec(); +} + // Resolves to true if the selected table contains any rows. function hasRows(schemaName, tableName) { @@ -370,6 +379,11 @@ function dispatchRequest(port, data) { deleteAll(data.schema, data.table).then(replySuccess, replyError); break; + case 'deleteWhereEqual': + deleteWhereEqual(data.schema, data.table, data.field, data.value) + .then(replySuccess, replyError); + break; + case 'hasRows': hasRows(data.schema, data.table).then(replySuccess, replyError); break; diff --git a/Open-ILS/web/js/ui/default/staff/services/lovefield.js b/Open-ILS/web/js/ui/default/staff/services/lovefield.js index b78d3164ed..cfd787fc36 100644 --- a/Open-ILS/web/js/ui/default/staff/services/lovefield.js +++ b/Open-ILS/web/js/ui/default/staff/services/lovefield.js @@ -83,6 +83,8 @@ angular.module('egCoreMod') // Connects if necessary to the active schemas then relays the request. service.request = function(args) { + // useful, but very chatty, leaving commented out. + // console.debug('egLovfield sending request: ', args); return service.connectToSchemas().then( function() { return service.relayRequest(args); @@ -154,19 +156,34 @@ angular.module('egCoreMod') ); } + // Remove all pending offline transactions and delete the cached + // offline transactions date to indicate no transactions remain. service.destroyPendingOfflineXacts = function () { return service.request({ schema: 'offline', table: 'OfflineXact', action: 'deleteAll' + }).then(function() { + return service.request({ + schema: 'cache', + table: 'CacheDate', + action: 'deleteWhereEqual', + field: 'type', + value: '_offlineXact' + }); }); } + // Returns the cache date when xacts exit, null otherwise. service.havePendingOfflineXacts = function () { return service.request({ - schema: 'offline', - table: 'OfflineXact', - action: 'hasRows' + schema: 'cache', + table: 'CacheDate', + action: 'selectWhereEqual', + field: 'type', + value: '_offlineXact' + }).then(function(results) { + return results[0] ? results[0].cachedate : null; }); } @@ -180,6 +197,24 @@ angular.module('egCoreMod') }); } + // Add an offline transaction and update the cache indicating + // now() as the most recent addition of an offline xact. + service.addOfflineXact = function (obj) { + return service.request({ + schema: 'offline', + table: 'OfflineXact', + action: 'insertOrReplace', + rows: [{value: obj}] + }).then(function() { + return service.request({ + schema: 'cache', + table: 'CacheDate', + action: 'insertOrReplace', + rows: [{type: '_offlineXact', cachedate : new Date()}] + }); + }); + } + service.populateBlockList = function() { return service.request({ action: 'populateBlockList', @@ -201,15 +236,6 @@ angular.module('egCoreMod') }); } - service.addOfflineXact = function (obj) { - return service.request({ - schema: 'offline', - table: 'OfflineXact', - action: 'insertOrReplace', - rows: [{value: obj}] - }); - } - service.setStatCatsCache = function (statcats) { if (lf.isOffline || !statcats || statcats.length === 0) return $q.when(); -- 2.43.2