Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAM-55: optimize login - improve local storage operations #145

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions src/referencedata-orderable-fulfills/orderable-fulfills.run.js

This file was deleted.

108 changes: 0 additions & 108 deletions src/referencedata-orderable-fulfills/orderable-fulfills.run.spec.js

This file was deleted.

12 changes: 8 additions & 4 deletions src/stock-adjustment-creation/source-destination.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,21 @@
}

function cacheSources(sources, facilityId) {
sources.forEach(function(source) {
var sourcesToStore = sources.map(function(source) {
source.facilityId = facilityId;
offlineSources.put(source);
return source;
});

offlineSources.putAll(sourcesToStore);
}

function cacheDestinations(destinations, facilityId) {
destinations.forEach(function(destination) {
var destinationsToStore = destinations.map(function(destination) {
destination.facilityId = facilityId;
offlineDestinations.put(destination);
return destination;
});

offlineDestinations.putAll(destinationsToStore);
}

function clearSourcesCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('sourceDestinationService', function() {

beforeEach(function() {
this.offlineService = jasmine.createSpyObj('offlineService', ['isOffline', 'checkConnection']);
this.storage = jasmine.createSpyObj('offlineStorage', ['put', 'search', 'getAll']);
this.storage = jasmine.createSpyObj('offlineStorage', ['put', 'putAll', 'search', 'getAll']);

var storage = this.storage,
offlineService = this.offlineService;
Expand Down
35 changes: 20 additions & 15 deletions src/stock-reason/stock-reasons.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,22 @@
function getReasons(programIds, facilityType, reasonType) {
return $q.resolve(getReasonsPromise(programIds, facilityType, reasonType)
.then(function(reasonAssignments) {
return reasonAssignments
var filteredReasons = reasonAssignments
.filter(function(reasonAssignment) {
return !reasonAssignment.hidden;
})
.reduce(function(result, reasonAssignment) {
if (result.indexOf(reasonAssignment.reason) < 0) {
result.push(reasonAssignment.reason);
}
if (!offlineService.isOffline()) {
cacheReasons(reasonAssignment, programIds, facilityType);
}
return result;
}, []);

if (!offlineService.isOffline()) {
cacheReasons(filteredReasons, programIds, facilityType);
}

return filteredReasons;
}));
}

Expand All @@ -183,18 +186,20 @@
});
}

function cacheReasons(reasonAssignment, programIds, facilityType) {
var reason = angular.copy(reasonAssignment.reason);
var reasonToCache = {
id: reasonAssignment.id,
programId: programIds,
facilityType: facilityType,
reasonType: reason.reasonType,
reason: reason,
hidden: reasonAssignment.hidden
};
function cacheReasons(filteredReasons, programIds, facilityType) {
var reasonsToCache = filteredReasons.map(function(reason) {
var reasonCopy = angular.copy(reason);
return {
id: reason.id,
programId: programIds,
facilityType: facilityType,
reasonType: reasonCopy.reasonType,
reason: reasonCopy,
hidden: reason.hidden
};
});

offlineReasons.put(reasonToCache);
offlineReasons.putAll(reasonsToCache);
}

function clearReasonsCache() {
Expand Down
2 changes: 1 addition & 1 deletion src/stock-reason/stock-reasons.factory.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('stockReasonsFactory', function() {
beforeEach(function() {
module('stock-reasons-modal', function($provide) {
validReasonResourceMock = jasmine.createSpyObj('validReasonResource', ['query']);
reasonsStorage = jasmine.createSpyObj('offlineReasons', ['search', 'getAll', 'put']);
reasonsStorage = jasmine.createSpyObj('offlineReasons', ['search', 'getAll', 'putAll', 'put']);
reasonsStorage.getAll.andReturn([false]);

$provide.factory('ValidReasonResource', function() {
Expand Down
53 changes: 0 additions & 53 deletions src/stock-valid-destinations/destination-cache.run.js

This file was deleted.

Loading
Loading