angular-nav-thresholds
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -1,1 +0,1 @@ | ||
!function(e){"use strict";e="default"in e?e.default:e;var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),a=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return e[n]},r=function(e,t){return t.version===e},l=function(e,t){return t._id===e},i=function(){function e(n,a,r,l){t(this,e),this.$q=n,this.smartId=a,this.lgasService=r,this.statesService=l}return n(e,[{key:"calculateThresholds",value:function(e,t){if(e&&e.allocations&&e.plans&&t&&t.allocations&&t.allocations.version&&t.plans&&t.plans.version){var n=a(e.allocations,r.bind(null,t.allocations.version));if(n&&n.weeklyLevels){var l=a(e.plans,r.bind(null,t.plans.version));if(l&&l.weeksOfStock){var i=n.weeklyLevels,s=l.weeksOfStock,o=Object.keys(i).reduce(function(t,n){return t[n]=Object.keys(s).reduce(function(e,t){return e[t]=Math.round(i[n]*s[t]),e},{}),e.targetPopulation&&(t[n].targetPopulation=e.targetPopulation[n]),t},{});return o}}}}},{key:"getThresholdsFor",value:function(e){var t=this,n="zone:?state:?lga",r={},i={};r=e.reduce(function(e,a){var r=a.location;if(!r)return e;var l=t.smartId.idify(r,n),s=a.allocations||{version:1},o=a.plans||{version:1};return e[l]=angular.merge({},{allocations:s,plans:o}),r.lga?(i.lga||(i.lga=t.lgasService.list()),e[l].type="lga"):r.state&&(i.state||(i.state=t.statesService.list()),e[l].type="state"),e},{});var s=function(e){return Object.keys(r).forEach(function(n){var i=r[n],s=a(e[i.type],l.bind(null,n));i.thresholds=t.calculateThresholds(s,i),delete i.type}),r};return this.$q.all(i).then(s)}}]),e}();i.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",i)}(angular); | ||
!function(e){"use strict";e="default"in e?e.default:e;var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}return function(t,n,a){return n&&e(t.prototype,n),a&&e(t,a),t}}(),a=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return e[n]},r=function(e,t){return t.version===e},l=function(e,t){return t._id===e},i={min:0,reOrder:3,max:6},o=function(){function e(n,a,r,l){t(this,e),this.$q=n,this.smartId=a,this.lgasService=r,this.statesService=l}return n(e,[{key:"calculateThresholds",value:function(e,t,n){if(e&&e.allocations&&e.plans&&e.level&&("zone"!==e.level||n)&&t&&t.allocations&&t.allocations.version&&t.plans&&t.plans.version){var l=a(e.allocations,r.bind(null,t.allocations.version));if(l&&l.weeklyLevels){var o=l.weeklyLevels,s=i;if("zone"!==e.level){var u=a(e.plans,r.bind(null,t.plans.version));if(!u||!u.weeksOfStock)return;s=u.weeksOfStock}var c=Object.keys(o).reduce(function(t,a){return t[a]=Object.keys(s).reduce(function(t,r){return t[r]=Math.round(o[a]*s[r]),"zone"===e.level&&(t[r]+=n[a]),t},{}),e.targetPopulation&&(t[a].targetPopulation=e.targetPopulation[a]),t},{});return c}}}},{key:"getThresholdsFor",value:function(e){var t=this,n="zone:?state:?lga",r={},i={};r=e.reduce(function(e,a){var r=a.location;if(!r)return e;var l=t.smartId.idify(r,n),o=a.allocations||{version:1},s=a.plans||{version:1};return e[l]=angular.merge({},{allocations:o,plans:s}),r.lga?(i.lga||(i.lga=t.lgasService.list()),e[l].type="lga"):r.state&&(i.state||(i.state=t.statesService.list()),e[l].type="state"),e},{});var o=function(e){return Object.keys(r).forEach(function(n){var i=r[n],o=a(e[i.type],l.bind(null,n));i.thresholds=t.calculateThresholds(o,i),delete i.type}),r};return this.$q.all(i).then(o)}}]),e}();o.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",o)}(angular); |
{ | ||
"name": "angular-nav-thresholds", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
@@ -14,2 +14,9 @@ const find = (list, match) => { | ||
// Zones config | ||
const zonesPlan = { | ||
min: 0, | ||
reOrder: 3, | ||
max: 6 | ||
} | ||
class ThresholdsService { | ||
@@ -23,7 +30,14 @@ constructor ($q, smartId, lgasService, statesService) { | ||
calculateThresholds (location, stockCount) { | ||
if (!location || !location.allocations || !location.plans) { | ||
// For zones the thresholds are based on the state store required allocation for | ||
// the week, that information is passed as an optional param (`requiredStateStoresAllocation`). | ||
// That param is only used for zones. | ||
calculateThresholds (location, stockCount, requiredStateStoresAllocation) { | ||
if (!location || !location.allocations || !location.plans || !location.level) { | ||
return | ||
} | ||
if (location.level === 'zone' && !requiredStateStoresAllocation) { | ||
return | ||
} | ||
if (!stockCount || !stockCount.allocations || !stockCount.allocations.version || | ||
@@ -38,17 +52,29 @@ !stockCount.plans || !stockCount.plans.version) { | ||
} | ||
const plan = find(location.plans, isVersion.bind(null, stockCount.plans.version)) | ||
if (!(plan && plan.weeksOfStock)) { | ||
return | ||
} | ||
const weeklyLevels = allocation.weeklyLevels | ||
const weeksOfStock = plan.weeksOfStock | ||
let weeksOfStock = zonesPlan | ||
if (location.level !== 'zone') { | ||
const plan = find(location.plans, isVersion.bind(null, stockCount.plans.version)) | ||
if (!(plan && plan.weeksOfStock)) { | ||
return | ||
} | ||
weeksOfStock = plan.weeksOfStock | ||
} | ||
let thresholds = Object.keys(weeklyLevels).reduce((index, product) => { | ||
index[product] = Object.keys(weeksOfStock).reduce((productThresholds, threshold) => { | ||
productThresholds[threshold] = Math.round(weeklyLevels[product] * weeksOfStock[threshold]) | ||
if (location.level === 'zone') { | ||
productThresholds[threshold] += requiredStateStoresAllocation[product] | ||
} | ||
return productThresholds | ||
}, {}) | ||
if (location.targetPopulation) { | ||
index[product].targetPopulation = location.targetPopulation[product] | ||
} | ||
return index | ||
@@ -61,3 +87,5 @@ }, {}) | ||
getThresholdsFor (stockCounts) { | ||
// TODO: make it work for zones too | ||
// TODO: make it work for zones too. | ||
// For making it work with zones, we need to take into account the amount of stock | ||
// to be allocated to the zone state stores in a particular week | ||
const locationIdPattern = 'zone:?state:?lga' | ||
@@ -64,0 +92,0 @@ let index = {} |
@@ -34,2 +34,3 @@ 'use strict' | ||
var location = { | ||
level: 'lga', | ||
allocations: [ | ||
@@ -94,4 +95,25 @@ { version: 1, | ||
var actual = thresholdsService.calculateThresholds(location, stockCount) | ||
expect(expected).toEqual(actual) | ||
expect(actual).toEqual(expected) | ||
}) | ||
it('also works with zones where the thresholds are based on required allocation for zone state stores', function () { | ||
var zone = angular.extend({}, location, { level: 'zone' }) | ||
// Note: `plans.weeksOfStock` is ignored (at least for now) in the case of zone stores | ||
var requiredStatesStoresAllocation = { 'product:a': 20, 'product:b': 50 } | ||
var expected = { | ||
'product:a': { | ||
min: 20, | ||
reOrder: 320, | ||
max: 620, | ||
targetPopulation: 1000 | ||
}, | ||
'product:b': { | ||
min: 50, | ||
reOrder: 650, | ||
max: 1250, | ||
targetPopulation: 2000 | ||
} | ||
} | ||
var actual = thresholdsService.calculateThresholds(zone, stockCount, requiredStatesStoresAllocation) | ||
expect(actual).toEqual(expected) | ||
}) | ||
}) | ||
@@ -128,3 +150,3 @@ | ||
.then(function (thresholds) { | ||
expect(expected).toEqual(thresholds) | ||
expect(thresholds).toEqual(expected) | ||
}) | ||
@@ -131,0 +153,0 @@ $rootScope.$digest() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25953
337