diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e77e86f..b6a4bb61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,23 +1,24 @@ -7.2.12-SNAPSHOT / WIP +7.2.12-SNAPSHOT / WIP ================== Bug fixes: * [OLMIS-7931](https://openlmis.atlassian.net/browse/OLMIS-7931): Fix imports for layout-ui jenkins job * [OLMIS-8010](https://openlmis.atlassian.net/browse/OLMIS-8010): Added a condition for putAll function for local storage New Functionalities: -* [OLMIS-7976](https://openlmis.atlassian.net/browse/OLMIS-7976): Improved visual apperance of the homepage alerts component +* [OLMIS-7976](https://openlmis.atlassian.net/browse/OLMIS-7976): Improved visual apperance of the homepage alerts component New functionalities that are backwards-compatible: * [OLMIS-7987](https://openlmis.atlassian.net/browse/OLMIS-7987): Move Submit Requisitionless Orders functionalities from Angola to Core instance Improvements: * [OIS-23](https://openlmis.atlassian.net/browse/OIS-23): Add basic mixin utils for RTL support +* [OLMIS-8022](https://openlmis.atlassian.net/browse/OLMIS-8022): Improvements in app offline capabilities. 7.2.11 / 2024-04-19 ================== Bug fixes: * [OLMIS-7922](https://openlmis.atlassian.net/browse/OLMIS-7922): Fix missing loading spinner in the Data Export and Data Import pages -* [OLMIS-7903](https://openlmis.atlassian.net/browse/OLMIS-7903): Adjust BUQ colors with core UI +* [OLMIS-7903](https://openlmis.atlassian.net/browse/OLMIS-7903): Adjust BUQ colors with core UI * [OLMIS-7906](https://openlmis.atlassian.net/browse/OLMIS-7906): Adjust BUQ to core geographic levels New Functionalities: @@ -113,7 +114,7 @@ Bug fixes: Improvements: * [OLMIS-6684](https://openlmis.atlassian.net/browse/OLMIS-6684): Updated pagination component to allow providing a function to call before changing page. * Got rid of angular.copy to improve performance in some places. - + Bug fixes: * [OLMIS-6612](https://openlmis.atlassian.net/browse/OLMIS-6612): Added check whether the property exists before sorting array by given property. * [OLMIS-6740](https://openlmis.atlassian.net/browse/OLMIS-6740): Fixed wrapping text in modal body. diff --git a/src/openlmis-cached-repository/openlmis-cached-resource.js b/src/openlmis-cached-repository/openlmis-cached-resource.js index cc7e7e78..f486d041 100644 --- a/src/openlmis-cached-repository/openlmis-cached-resource.js +++ b/src/openlmis-cached-repository/openlmis-cached-resource.js @@ -97,21 +97,22 @@ database = this.database, isVersioned = this.isVersioned; - return database.allDocsByIndex(id, versionId).then(function(result) { - if (!result[0] || !versionId) { - openlmisResource.lastModified = result[0] ? result[0].lastModified : undefined; - return openlmisResource.get(id, versionId) - .then(function(response) { - isVersioned ? database.putVersioned(response.content) : database.put(response.content); - return response.content; - }, function(response) { - if (response.status === 304) { - return result[0]; - } + if (offlineService.isOffline()) { + return database.allDocsByIndex(id, versionId).then(function(result) { + return result[0]; + }); + } + return openlmisResource.get(id, versionId) + .then(function(response) { + isVersioned ? database.putVersioned(response.content) : database.put(response.content); + return response.content; + }, function(response) { + if (response.status === 304) { + return database.allDocsByIndex(id, versionId).then(function(result) { + return result[0]; }); - } - return result[0]; - }); + } + }); } return $q.reject(); } @@ -259,7 +260,15 @@ * rejected if request fails */ function getAll(params) { + if (offlineService.isOffline()) { + var deferred = $q.defer(); + this.database.getAll().then(function(response) { + deferred.resolve(response); + }, deferred.reject); + return deferred.promise; + } var config = this.config; + return this.query(params) .then(function(response) { return isPaginated(config) ? response.content : response; diff --git a/src/openlmis-cached-repository/openlmis-cached-resource.spec.js b/src/openlmis-cached-repository/openlmis-cached-resource.spec.js index d1784ff6..dfae729c 100644 --- a/src/openlmis-cached-repository/openlmis-cached-resource.spec.js +++ b/src/openlmis-cached-repository/openlmis-cached-resource.spec.js @@ -82,7 +82,6 @@ describe('OpenlmisCachedResource', function() { this.getDeferred.resolve(this.response); this.$rootScope.$apply(); - expect(this.LocalDatabase.prototype.allDocsByIndex).toHaveBeenCalled(); expect(this.LocalDatabase.prototype.putVersioned).not.toHaveBeenCalled(); expect(this.LocalDatabase.prototype.put).toHaveBeenCalled(); }); @@ -95,7 +94,6 @@ describe('OpenlmisCachedResource', function() { this.getDeferred.resolve(this.response); this.$rootScope.$apply(); - expect(this.LocalDatabase.prototype.allDocsByIndex).toHaveBeenCalled(); expect(this.LocalDatabase.prototype.putVersioned).toHaveBeenCalled(); expect(this.LocalDatabase.prototype.put).not.toHaveBeenCalled(); }); @@ -122,30 +120,6 @@ describe('OpenlmisCachedResource', function() { this.$rootScope.$apply(); expect(result.$$state.value).toEqual(this.page[0]); - expect(this.LocalDatabase.prototype.allDocsByIndex).toHaveBeenCalled(); - expect(this.LocalDatabase.prototype.putVersioned).not.toHaveBeenCalled(); - expect(this.LocalDatabase.prototype.put).not.toHaveBeenCalled(); - }); - - it('should no request if record with the specified version is in the local database', function() { - this.page = [{ - id: 'some-id', - _id: 'some-id/2', - latest: true - }, { - id: 'some-id', - _id: 'some-id/1', - latest: false - }]; - - this.openlmisCachedResource.isVersioned = true; - - this.allDocsByIndexDeferred.resolve(this.page); - var result = this.openlmisCachedResource.get(this.id, 1); - this.$rootScope.$apply(); - - expect(result.$$state.value).toEqual(this.page[0]); - expect(this.LocalDatabase.prototype.allDocsByIndex).toHaveBeenCalled(); expect(this.LocalDatabase.prototype.putVersioned).not.toHaveBeenCalled(); expect(this.LocalDatabase.prototype.put).not.toHaveBeenCalled(); }); @@ -156,8 +130,8 @@ describe('OpenlmisCachedResource', function() { this.getDeferred.reject(); this.$rootScope.$apply(); - expect(this.LocalDatabase.prototype.allDocsByIndex).toHaveBeenCalled(); expect(this.LocalDatabase.prototype.putVersioned).not.toHaveBeenCalled(); + expect(this.LocalDatabase.prototype.put).not.toHaveBeenCalled(); }); it('should reject if null was given', function() {