])
.controller('OfflineCtrl',
- ['$q','$scope','$window','$location','$rootScope','egCore','egLovefield','$routeParams','$timeout','$http','ngToast','egConfirmDialog','egUnloadPrompt',
- function($q , $scope , $window , $location , $rootScope , egCore , egLovefield , $routeParams , $timeout , $http , ngToast , egConfirmDialog , egUnloadPrompt) {
+ ['$q','$scope','$window','$location','$rootScope','egCore',
+ 'egLovefield','$routeParams','$timeout','$http','ngToast',
+ 'egConfirmDialog','egUnloadPrompt','egProgressDialog',
+ function($q , $scope , $window , $location , $rootScope , egCore ,
+ egLovefield , $routeParams , $timeout , $http , ngToast ,
+ egConfirmDialog , egUnloadPrompt , egProgressDialog) {
// Immediately redirect if we're really offline
if (!$window.navigator.onLine) {
});
$scope.downloadBlockList = function () {
+ egProgressDialog.open();
var url = '/standalone/list.txt?ses='
+ egCore.auth.token()
+ '&' + new Date().getTime();
function (res) {
if (res.data) {
var lines = res.data.split('\n');
- egLovefield.destroyOfflineBlocks().then(function(){
- angular.forEach(lines, function (l) {
- var parts = l.split(' ');
- egLovefield.addOfflineBlock(parts[0], parts[1]);
- });
- return $q.when();
+ return egLovefield.destroyOfflineBlocks()
+ .then(function(){
+ return egLovefield.addOfflineBlockBatch(lines);
}).then(function(){
ngToast.create(egCore.strings.OFFLINE_BLOCKLIST_SUCCESS);
});
ngToast.warning(egCore.strings.OFFLINE_BLOCKLIST_FAIL);
egCore.audio.play('warning.offline.blocklist_fail');
}
- );
+ )['finally'](egProgressDialog.close);
}
$scope.createOfflineXactBlob = function () {
var osb = lf.schema.create('offline', 2);
+// Leaving here as an example. Note this had no impact
+// on load speed for large offline block lists.
+// osb.setPragma({enableBundledMode: true});
+
osb.createTable('Object').
addColumn('type', lf.Type.STRING). // class hint
addColumn('id', lf.Type.STRING). // obj id
});
}
+ service.addOfflineBlockBatch = function (lines) {
+ return connectOrGo().then(function() {
+
+ var rows = [];
+ var table = lf.offlineDB.getSchema().table('OfflineBlocks');
+ console.debug('compiling offline block rows');
+
+ lines.forEach(function(line) {
+ // slice/substring instead of split(' ') to handle barcodes
+ // with trailing spaces.
+ var barcode = line.slice(0, -2);
+ var reason = line.substring(line.length - 1);
+ rows.push(table.createRow({barcode: barcode, reason: reason}));
+ })
+
+ console.debug('inserting ' + rows.length + ' offline block rows');
+ return lf.offlineDB.
+ insertOrReplace().
+ into(table).
+ values(rows).
+ exec().
+ then(function() {
+ console.debug(
+ 'inserted ' + rows.length + ' offline block rows');
+ });
+ });
+ }
+
+
// Returns a promise with true for blocked, false for not blocked
service.testOfflineBlock = function (barcode) {
return connectOrGo().then(function() {