From 6f1e2e356343e1afd90ca6a48f40f618e74fe32d Mon Sep 17 00:00:00 2001 From: Patricia Garcia Date: Tue, 4 Oct 2016 21:10:49 +0200 Subject: [PATCH 1/2] fix: not working if zone stock counts have no version Temporary fix for https://github.com/fielded/nav-integrated-national-dashboard/issues/265. It will work only while there is only one version for plans and allocations. Connects https://github.com/fielded/nav-integrated-national-dashboard/issues/265 --- src/state-indicators.service.js | 4 +++- test/state-indicators.service.spec.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/state-indicators.service.js b/src/state-indicators.service.js index f0eaeb2..0aabc14 100644 --- a/src/state-indicators.service.js +++ b/src/state-indicators.service.js @@ -85,7 +85,9 @@ class StateIndicatorsService { const location = getLocation(lgas, states, zones, stockCount) let locationThresholds if (location && location.level === 'zone') { - locationThresholds = this.thresholdsService.calculateThresholds(location, stockCount, products, requiredAllocations[location._id]) + // Temporary fix for https://github.com/fielded/nav-integrated-national-dashboard/issues/265 + // This should be removed when https://github.com/fielded/nav-etl/issues/136 is fixed + locationThresholds = this.thresholdsService.calculateThresholds(location, stockCount, products, requiredAllocations[location._id], { version: 'last' }) } else { locationThresholds = this.thresholdsService.calculateThresholds(location, stockCount, products) } diff --git a/test/state-indicators.service.spec.js b/test/state-indicators.service.spec.js index ceb3e7a..4a6c21e 100644 --- a/test/state-indicators.service.spec.js +++ b/test/state-indicators.service.spec.js @@ -382,7 +382,7 @@ describe('state indicators service', function () { stateIndicatorsService.decorateWithIndicators(stockCounts) .then(function (decoratedStockCounts) { expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(states[0], stockCounts[0], products) - expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(zones[0], stockCounts[1], products, requiredByState) + expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(zones[0], stockCounts[1], products, requiredByState, { version: 'last' }) expect(decoratedStockCounts).toEqual(expected) }) $rootScope.$digest() @@ -427,7 +427,7 @@ describe('state indicators service', function () { stateIndicatorsService.decorateWithIndicators(stockCounts) .then(function (decoratedStockCounts) { expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(states[0], stockCounts[0], products) - expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(zones[0], stockCounts[1], products, undefined) + expect(thresholdsService.calculateThresholds).toHaveBeenCalledWith(zones[0], stockCounts[1], products, undefined, { version: 'last' }) expect(decoratedStockCounts).toEqual(expected) }) $rootScope.$digest() From 9309da6e49b52239cd30b7ea979780f3c2e49d42 Mon Sep 17 00:00:00 2001 From: Patricia Garcia Date: Tue, 4 Oct 2016 21:16:27 +0200 Subject: [PATCH 2/2] chore: release 2.2.1 --- dist/bundle.js | 4 +++- dist/bundle.min.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 3e4527a..ceb1ddf 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -133,7 +133,9 @@ var location = getLocation(lgas, states, zones, stockCount); var locationThresholds = void 0; if (location && location.level === 'zone') { - locationThresholds = _this2.thresholdsService.calculateThresholds(location, stockCount, products, requiredAllocations[location._id]); + // Temporary fix for https://github.com/fielded/nav-integrated-national-dashboard/issues/265 + // This should be removed when https://github.com/fielded/nav-etl/issues/136 is fixed + locationThresholds = _this2.thresholdsService.calculateThresholds(location, stockCount, products, requiredAllocations[location._id], { version: 'last' }); } else { locationThresholds = _this2.thresholdsService.calculateThresholds(location, stockCount, products); } diff --git a/dist/bundle.min.js b/dist/bundle.min.js index 9d641b0..7c725b7 100644 --- a/dist/bundle.min.js +++ b/dist/bundle.min.js @@ -1 +1 @@ -!function(t){"use strict";t="default"in t?t["default"]:t;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n0&&(t[n]+=e[n].allocation),t},t)},a=function(){function t(e,o,r,i,c,a,s,u){n(this,t),this.$q=e,this.smartId=o,this.STOCK_STATUSES=r,this.lgasService=i,this.statesService=c,this.zonesService=a,this.thresholdsService=s,this.productListService=u}return o(t,[{key:"stateRequiredAllocationsByZone",value:function(t){var e=this;return t.reduce(function(t,n){if(n.location&&n.location.state&&!n.location.lga&&n.reStockNeeded){var o=e.smartId.idify({zone:n.location.zone},"locationId");t[o]=t[o]||{},t[o]=c(t[o],n.stock)}return t},{})}},{key:"decorateWithIndicators",value:function(t){var n=this,o=void 0,c=void 0,a=void 0,s=void 0,u=function(t,n,o,i){var c=i.location.lga,a=i.location.state;if(c)return r(t,function(t){return t.id===c});if(a)return r(n,function(t){return t.id===a});var s=function(){var t=i.location.zone;return{v:r(o,function(e){return e.id===t})}}();return"object"===("undefined"==typeof s?"undefined":e(s))?s.v:void 0},l=function(t,e){var i=u(o,c,a,e),l=void 0;l=i&&"zone"===i.level?n.thresholdsService.calculateThresholds(i,e,s,t[i._id]):n.thresholdsService.calculateThresholds(i,e,s);var d=e.stock,f=Object.keys(d).reduce(function(t,e){var n=d[e],o=void 0,i=void 0,c=void 0,a=r(s,function(t){return t._id===e});if(l&&(c=l[e])){o="overstock",n0?u+(a.presentation-f):u}}return t[e]={status:o,amount:n,allocation:i,thresholds:c},t},{});return e.stock=f,e},d=function(t){var e=function(e,n){return t.stock[n].allocation>0&&(e+=t.stock[n].allocation),e};if(t.location&&t.location.lga){var n=i(t.stock);t.reStockNeeded=!!(n.understock.length+n["re-stock"].length)}else if(t.stock){var o=Object.keys(t.stock).reduce(e,0);t.reStockNeeded=o>0}return t},f=function(t){var e=i(t.stock).unknown.length,o=i(t.stock).understock.length;return t.location&&(t.stockLevelStatus=o>=n.STOCK_STATUSES.alert.threshold?n.STOCK_STATUSES.alert.id:o>=n.STOCK_STATUSES.warning.threshold?n.STOCK_STATUSES.warning.id:e?"unknown":n.STOCK_STATUSES.ok.id),t},v=function(t){return t.stock&&Object.keys(t.stock).length},S=function(t){return t.location&&t.location.zone&&!t.location.state},h=function(t){return!S(t)},k=function(t,e,r){return o=r.lgas,c=r.states,a=r.zones||[],s=r.products,t=t.map(l.bind(null,null)).map(d),e=e.map(l.bind(null,n.stateRequiredAllocationsByZone(t))).map(d),t.concat(e).map(f)},y={lgas:this.lgasService.list(),states:this.statesService.list(),products:this.productListService.relevant()};if(t=t.filter(v),!t.length)return this.$q.when(t);var g=t.filter(S),T=t.filter(h);return g.length&&(y.zones=this.zonesService.list()),this.$q.all(y).then(k.bind(null,T,g))}}]),t}();a.$inject=["$q","smartId","STOCK_STATUSES","lgasService","statesService","zonesService","thresholdsService","productListService"],t.module("angularNavStateIndicators",["ngSmartId","angularNavData","angularNavThresholds"]).service("stateIndicatorsService",a)}(angular); \ No newline at end of file +!function(t){"use strict";t="default"in t?t["default"]:t;var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},n=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},o=function(){function t(t,e){for(var n=0;n0&&(t[n]+=e[n].allocation),t},t)},a=function(){function t(e,o,r,i,c,a,s,u){n(this,t),this.$q=e,this.smartId=o,this.STOCK_STATUSES=r,this.lgasService=i,this.statesService=c,this.zonesService=a,this.thresholdsService=s,this.productListService=u}return o(t,[{key:"stateRequiredAllocationsByZone",value:function(t){var e=this;return t.reduce(function(t,n){if(n.location&&n.location.state&&!n.location.lga&&n.reStockNeeded){var o=e.smartId.idify({zone:n.location.zone},"locationId");t[o]=t[o]||{},t[o]=c(t[o],n.stock)}return t},{})}},{key:"decorateWithIndicators",value:function(t){var n=this,o=void 0,c=void 0,a=void 0,s=void 0,u=function(t,n,o,i){var c=i.location.lga,a=i.location.state;if(c)return r(t,function(t){return t.id===c});if(a)return r(n,function(t){return t.id===a});var s=function(){var t=i.location.zone;return{v:r(o,function(e){return e.id===t})}}();return"object"===("undefined"==typeof s?"undefined":e(s))?s.v:void 0},l=function(t,e){var i=u(o,c,a,e),l=void 0;l=i&&"zone"===i.level?n.thresholdsService.calculateThresholds(i,e,s,t[i._id],{version:"last"}):n.thresholdsService.calculateThresholds(i,e,s);var d=e.stock,f=Object.keys(d).reduce(function(t,e){var n=d[e],o=void 0,i=void 0,c=void 0,a=r(s,function(t){return t._id===e});if(l&&(c=l[e])){o="overstock",n0?u+(a.presentation-f):u}}return t[e]={status:o,amount:n,allocation:i,thresholds:c},t},{});return e.stock=f,e},d=function(t){var e=function(e,n){return t.stock[n].allocation>0&&(e+=t.stock[n].allocation),e};if(t.location&&t.location.lga){var n=i(t.stock);t.reStockNeeded=!!(n.understock.length+n["re-stock"].length)}else if(t.stock){var o=Object.keys(t.stock).reduce(e,0);t.reStockNeeded=o>0}return t},f=function(t){var e=i(t.stock).unknown.length,o=i(t.stock).understock.length;return t.location&&(t.stockLevelStatus=o>=n.STOCK_STATUSES.alert.threshold?n.STOCK_STATUSES.alert.id:o>=n.STOCK_STATUSES.warning.threshold?n.STOCK_STATUSES.warning.id:e?"unknown":n.STOCK_STATUSES.ok.id),t},v=function(t){return t.stock&&Object.keys(t.stock).length},S=function(t){return t.location&&t.location.zone&&!t.location.state},h=function(t){return!S(t)},k=function(t,e,r){return o=r.lgas,c=r.states,a=r.zones||[],s=r.products,t=t.map(l.bind(null,null)).map(d),e=e.map(l.bind(null,n.stateRequiredAllocationsByZone(t))).map(d),t.concat(e).map(f)},y={lgas:this.lgasService.list(),states:this.statesService.list(),products:this.productListService.relevant()};if(t=t.filter(v),!t.length)return this.$q.when(t);var g=t.filter(S),T=t.filter(h);return g.length&&(y.zones=this.zonesService.list()),this.$q.all(y).then(k.bind(null,T,g))}}]),t}();a.$inject=["$q","smartId","STOCK_STATUSES","lgasService","statesService","zonesService","thresholdsService","productListService"],t.module("angularNavStateIndicators",["ngSmartId","angularNavData","angularNavThresholds"]).service("stateIndicatorsService",a)}(angular); \ No newline at end of file