Index: CHANGELOG.md =================================================================== diff -u -N -r4cdf13d764c6f6e43e86a5c006e128905e43a8db -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- CHANGELOG.md (.../CHANGELOG.md) (revision 4cdf13d764c6f6e43e86a5c006e128905e43a8db) +++ CHANGELOG.md (.../CHANGELOG.md) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -2,4 +2,5 @@ ================== New functionality that are backwards-compatible: -* [OLMIS-7209](https://openlmis.atlassian.net/browse/OLMIS-7209): Added pending offline events service decorator which retrieves events from local storage. \ No newline at end of file +* [OLMIS-7209](https://openlmis.atlassian.net/browse/OLMIS-7209): Added pending offline events service decorator which retrieves events from local storage. +* [OLMIS-7198](https://openlmis.atlassian.net/browse/OLMIS-7198): Added the Pending Offline events screen with pending operations table. \ No newline at end of file Index: src/offline-events/event-types.constant.js =================================================================== diff -u -N -rbaa3982a72fc2fbb1fee9f02529c8ad7c4ca06d0 -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/event-types.constant.js (.../event-types.constant.js) (revision baa3982a72fc2fbb1fee9f02529c8ad7c4ca06d0) +++ src/offline-events/event-types.constant.js (.../event-types.constant.js) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -76,11 +76,11 @@ * @return {Array} the list of available event types */ function getEventTypes() { - return [ - EVENT_TYPES.ISSUE, - EVENT_TYPES.RECEIVE, - EVENT_TYPES.ADJUSTMENT - ]; + return { + ISSUE: EVENT_TYPES.ISSUE, + RECEIVE: EVENT_TYPES.RECEIVE, + ADJUSTMENT: EVENT_TYPES.ADJUSTMENT + }; } } Index: src/offline-events/event-types.constant.spec.js =================================================================== diff -u -N -ree64f444a88c37814a56087e84c5022e2ede7f3f -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/event-types.constant.spec.js (.../event-types.constant.spec.js) (revision ee64f444a88c37814a56087e84c5022e2ede7f3f) +++ src/offline-events/event-types.constant.spec.js (.../event-types.constant.spec.js) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -55,12 +55,12 @@ describe('EVENT_TYPES', function() { - it('should return a list of event types', function() { - expect(this.EVENT_TYPES.getEventTypes()).toEqual([ - 'ISSUE', - 'RECEIVE', - 'ADJUSTMENT' - ]); + it('should return a map of event types', function() { + expect(this.EVENT_TYPES.getEventTypes()).toEqual({ + ISSUE: this.EVENT_TYPES.ISSUE, + RECEIVE: this.EVENT_TYPES.RECEIVE, + ADJUSTMENT: this.EVENT_TYPES.ADJUSTMENT + }); }); }); Index: src/offline-events/events.module.js =================================================================== diff -u -N -ree64f444a88c37814a56087e84c5022e2ede7f3f -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/events.module.js (.../events.module.js) (revision ee64f444a88c37814a56087e84c5022e2ede7f3f) +++ src/offline-events/events.module.js (.../events.module.js) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -30,7 +30,8 @@ 'referencedata-program', 'referencedata-lot', 'stock-adjustment-creation', - 'stock-reason' + 'stock-reason', + 'stock-valid-destinations' ]); })(); Index: src/offline-events/events.service.js =================================================================== diff -u -N -ree64f444a88c37814a56087e84c5022e2ede7f3f -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/events.service.js (.../events.service.js) (revision ee64f444a88c37814a56087e84c5022e2ede7f3f) +++ src/offline-events/events.service.js (.../events.service.js) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -29,10 +29,11 @@ .factory('eventsService', service); service.$inject = ['localStorageService', 'currentUserService', 'EVENT_TYPES', '$q', - 'programService', 'facilityFactory', 'OrderableResource', 'lotService', 'stockReasonsFactory']; + 'facilityFactory', 'OrderableResource', 'lotService', 'stockReasonsFactory', + 'sourceDestinationService']; - function service(localStorageService, currentUserService, EVENT_TYPES, $q, - programService, facilityFactory, OrderableResource, lotService, stockReasonsFactory) { + function service(localStorageService, currentUserService, EVENT_TYPES, $q, facilityFactory, + OrderableResource, lotService, stockReasonsFactory, sourceDestinationService) { var STOCK_EVENTS = 'stockEvents'; @@ -57,65 +58,97 @@ return currentUserService.getUserInfo() .then(function(user) { - var offlineEvents = localStorageService.get(STOCK_EVENTS); + var offlineEvents = localStorageService.get(STOCK_EVENTS), + userEvents = offlineEvents ? angular.fromJson(offlineEvents)[user.id] : [], + homeFacility, + programs = [], + sources = [], + destinations = [], + validAssignmentsList = [], + orderableIds = [], + lotIds = [], + promises = []; if (!offlineEvents) { return []; } - var userEvents = angular.fromJson(offlineEvents)[user.id]; - if (!userEvents) { return []; } - var facilityIds = []; - var orderableIds = []; - var lotIds = []; - var reasonIds = []; + return facilityFactory.getUserHomeFacility().then(function(facility) { + homeFacility = facility; + programs = homeFacility.supportedPrograms; - userEvents.forEach(function(event) { - if (facilityIds.indexOf(event.facilityId) === -1) { - facilityIds.push(event.facilityId); - } + programs.forEach(function(program) { + promises.push(sourceDestinationService.getSourceAssignments( + program.id ? program.id : program, + homeFacility.id ? homeFacility.id : homeFacility + )); + promises.push(sourceDestinationService.getDestinationAssignments( + program.id ? program.id : program, + homeFacility.id ? homeFacility.id : homeFacility + )); + }); - event.lineItems.forEach(function(item) { - var facilityId = null; + return $q.all(promises).then(function(responses) { + sources = responses[0]; + destinations = responses[1]; - if (item.sourceId) { - facilityId = item.sourceId; - } + userEvents.forEach(function(event) { + event.lineItems.forEach(function(item) { - if (item.destinationId) { - facilityId = item.destinationId; - } + if (item.sourceId) { + sources.forEach(function(source) { + if (source.node.id === item.sourceId) { + validAssignmentsList.push(source); + } + }); + } - facilityIds = getIds(facilityId, facilityIds); - orderableIds = getIds(item.orderableId, orderableIds); - lotIds = getIds(item.lotId, lotIds); - reasonIds = getIds(item.reasonId, reasonIds); - }); + if (item.destinationId) { + destinations.forEach(function(destination) { + if (destination.node.id === item.destinationId) { + validAssignmentsList.push(destination); + } + }); + } - }); + orderableIds = getIds(item.orderableId, orderableIds); + lotIds = getIds(item.lotId, lotIds); + }); + }); - return $q.all([ - programService.getUserPrograms(user.id), - facilityFactory.getUserHomeFacility(), - orderableResource.query({ - id: orderableIds - }), - lotService.query({ - id: lotIds - }), - stockReasonsFactory.getReasons() - ]).then(function(responses) { - var programs = responses[0], - homeFacility = responses[1], - orderables = responses[2].content, - lots = responses[3].content, - reasons = responses[4]; + return $q.resolve({ + orderableIds: orderableIds, + lotIds: lotIds, + validAssignmentsList: validAssignmentsList, + userEvents: userEvents + }); + }) + .then(function(result) { + return $q.all([ + orderableResource.query({ + id: result.orderableIds + }), + lotService.query({ + id: result.lotIds + }), + stockReasonsFactory.getReasons(), + result.validAssignmentsList, + result.userEvents + ]).then(function(responses) { + var orderables = responses[0].content, + lots = responses[1].content, + reasons = responses[2], + validAssignmentsList = responses[3], + userEvents = responses[4]; - return combineResponses(userEvents, programs, homeFacility, orderables, lots, reasons); + return combineResponses(userEvents, programs, homeFacility, orderables, + lots, reasons, validAssignmentsList); + }); + }); }); }); } @@ -188,11 +221,16 @@ }); } - function combineResponses(offlineEvents, programs, homeFacility, orderables, lots, reasons) { + function combineResponses(offlineEvents, programs, homeFacility, orderables, lots, reasons, + validAssignmentsList) { var programsMap = prepareMap(programs), orderablesMap = prepareMap(orderables), lotsMap = prepareMap(lots), - reasonsMap = prepareMap(reasons); + reasonsMap = prepareMap(reasons), + validAssignmentsMap = validAssignmentsList.reduce(function(map, assignment) { + map[assignment.node.id] = assignment; + return map; + }, {}); return offlineEvents.map(function(event, ind) { event.ind = ind; @@ -211,11 +249,11 @@ event.lineItems = event.lineItems.map(function(item) { if (item.sourceId) { - //item.source = facilitiesMap[item.sourceId]; + item.source = validAssignmentsMap[item.sourceId]; } if (item.destinationId) { - //item.destination = facilitiesMap[item.destinationId]; + item.destination = validAssignmentsMap[item.destinationId]; } item.orderable = orderablesMap[item.orderableId]; Index: src/offline-events/events.service.spec.js =================================================================== diff -u -N -ree64f444a88c37814a56087e84c5022e2ede7f3f -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/events.service.spec.js (.../events.service.spec.js) (revision ee64f444a88c37814a56087e84c5022e2ede7f3f) +++ src/offline-events/events.service.spec.js (.../events.service.spec.js) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -47,6 +47,7 @@ this.OrderableDataBuilder = $injector.get('OrderableDataBuilder'); this.ProgramOrderableDataBuilder = $injector.get('ProgramOrderableDataBuilder'); this.ReasonDataBuilder = $injector.get('ReasonDataBuilder'); + this.sourceDestinationService = $injector.get('sourceDestinationService'); }); this.localStorageEvents = {}; @@ -137,10 +138,32 @@ this.reason3 ]; + this.validSources = [ + { + facilityTypeId: 'fac-type-id-1', + id: 'source-id-1', + name: 'source one', + programId: 'program-id-1', + facilityId: this.homeFacilityId + } + ]; + + this.validDestinations = [ + { + facilityTypeId: 'fac-type-id-1', + id: 'dest-id-1', + name: 'destination one', + programId: 'program-id-1', + facilityId: this.homeFacilityId + } + ]; + spyOn(this.OrderableResource.prototype, 'query').andReturn(this.$q.resolve(this.orderablesPage)); - spyOn(this.programService, 'getUserPrograms').andReturn(this.$q.when(this.programs)); spyOn(this.facilityFactory, 'getUserHomeFacility').andReturn(this.$q.resolve(this.homeFacility)); spyOn(this.stockReasonsFactory, 'getReasons').andReturn(this.$q.resolve(this.reasons)); + spyOn(this.sourceDestinationService, 'getSourceAssignments').andReturn(this.$q.resolve(this.validSources)); + spyOn(this.sourceDestinationService, 'getDestinationAssignments') + .andReturn(this.$q.resolve(this.validDestinations)); spyOn(this.lotService, 'query').andReturn(this.$q.when( new this.PageDataBuilder() Index: src/offline-events/offline-events.html =================================================================== diff -u -N -rbaa3982a72fc2fbb1fee9f02529c8ad7c4ca06d0 -r02fe349aa2b4296734ed8ca231b66fb5eaf3a266 --- src/offline-events/offline-events.html (.../offline-events.html) (revision baa3982a72fc2fbb1fee9f02529c8ad7c4ca06d0) +++ src/offline-events/offline-events.html (.../offline-events.html) (revision 02fe349aa2b4296734ed8ca231b66fb5eaf3a266) @@ -38,14 +38,14 @@ {{vm.getEventTypeLabel(event.eventType) | message}} ({{'offlineEvents.stockManagement' | message}})

- {{event.facility.name}}; + {{event.facility.name}}; {{event.program.name}}; {{item.orderable.fullProductName}}; {{'offlineEvents.noLots' | message}}; {{item.lot.lotCode}}; - {{'offlineEvents.issueTo' | message}}: {{item.destination.name}}; - {{'offlineEvents.receivedFrom' | message}}: {{item.source.name}}; - {{'offlineEvents.reason' | message}}: {{item.reason.name}}; + {{'offlineEvents.issueTo' | message}}: {{item.destination.name}}; + {{'offlineEvents.receivedFrom' | message}}: {{item.source.name}}; + {{'offlineEvents.reason' | message}}: {{item.reason.name}}; {{'offlineEvents.quantity' | message}}: {{item.quantity}}