angular-nav-thresholds
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -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={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); | ||
!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){var n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];if(e&&e.allocations&&e.plans&&e.level&&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&&n[a]&&(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.2", | ||
"version": "1.2.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
@@ -32,3 +32,3 @@ const find = (list, match) => { | ||
// That param is only used for zones. | ||
calculateThresholds (location, stockCount, requiredStateStoresAllocation) { | ||
calculateThresholds (location, stockCount, requiredStateStoresAllocation = {}) { | ||
if (!location || !location.allocations || !location.plans || !location.level) { | ||
@@ -38,6 +38,2 @@ return | ||
if (location.level === 'zone' && !requiredStateStoresAllocation) { | ||
return | ||
} | ||
if (!stockCount || !stockCount.allocations || !stockCount.allocations.version || | ||
@@ -68,3 +64,3 @@ !stockCount.plans || !stockCount.plans.version) { | ||
if (location.level === 'zone') { | ||
if (location.level === 'zone' && requiredStateStoresAllocation[product]) { | ||
productThresholds[threshold] += requiredStateStoresAllocation[product] | ||
@@ -71,0 +67,0 @@ } |
@@ -96,8 +96,30 @@ 'use strict' | ||
}) | ||
it('also works with zones where the thresholds are based on required allocation for zone state stores', function () { | ||
it('also works with zones', 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 } | ||
// See https://github.com/fielded/angular-nav-thresholds/issues/9 | ||
var expected = { | ||
'product:a': { | ||
min: 0, | ||
reOrder: 300, | ||
max: 600, | ||
targetPopulation: 1000 | ||
}, | ||
'product:b': { | ||
min: 0, | ||
reOrder: 600, | ||
max: 1200, | ||
targetPopulation: 2000 | ||
} | ||
} | ||
var actual = thresholdsService.calculateThresholds(zone, stockCount) | ||
expect(actual).toEqual(expected) | ||
}) | ||
it('works with zones if there is a 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 | ||
// See https://github.com/fielded/angular-nav-thresholds/issues/9 | ||
var requiredStatesStoresAllocation = { 'product:a': 20 } | ||
var expected = { | ||
'product:a': { | ||
min: 20, | ||
@@ -109,5 +131,5 @@ reOrder: 320, | ||
'product:b': { | ||
min: 50, | ||
reOrder: 650, | ||
max: 1250, | ||
min: 0, | ||
reOrder: 600, | ||
max: 1200, | ||
targetPopulation: 2000 | ||
@@ -114,0 +136,0 @@ } |
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
26670
356