Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 37d6c38

Browse files
committed
chore: rebuild dist
Rebuilds dist. -- tlvince/publish-dist
1 parent 343ed3d commit 37d6c38

File tree

2 files changed

+195
-1
lines changed

2 files changed

+195
-1
lines changed

dist/bundle.js

Lines changed: 194 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,194 @@
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){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);
1+
(function (angular$1) {
2+
'use strict';
3+
4+
angular$1 = 'default' in angular$1 ? angular$1['default'] : angular$1;
5+
6+
var classCallCheck = function (instance, Constructor) {
7+
if (!(instance instanceof Constructor)) {
8+
throw new TypeError("Cannot call a class as a function");
9+
}
10+
};
11+
12+
var createClass = function () {
13+
function defineProperties(target, props) {
14+
for (var i = 0; i < props.length; i++) {
15+
var descriptor = props[i];
16+
descriptor.enumerable = descriptor.enumerable || false;
17+
descriptor.configurable = true;
18+
if ("value" in descriptor) descriptor.writable = true;
19+
Object.defineProperty(target, descriptor.key, descriptor);
20+
}
21+
}
22+
23+
return function (Constructor, protoProps, staticProps) {
24+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
25+
if (staticProps) defineProperties(Constructor, staticProps);
26+
return Constructor;
27+
};
28+
}();
29+
30+
// TODO: replace with Array#find ponyfill
31+
var find = function find(list, match) {
32+
for (var i = 0; i < list.length; i++) {
33+
if (match(list[i])) {
34+
return list[i];
35+
}
36+
}
37+
return undefined;
38+
};
39+
40+
var isVersion = function isVersion(version, item) {
41+
return item.version === version;
42+
};
43+
44+
var isId = function isId(id, item) {
45+
return item._id === id;
46+
};
47+
48+
// Zones config
49+
var zonesPlan = {
50+
min: 0,
51+
reOrder: 3,
52+
max: 6
53+
};
54+
55+
var ThresholdsService = function () {
56+
function ThresholdsService($q, smartId, lgasService, statesService) {
57+
classCallCheck(this, ThresholdsService);
58+
59+
this.$q = $q;
60+
this.smartId = smartId;
61+
this.lgasService = lgasService;
62+
this.statesService = statesService;
63+
}
64+
65+
// For zones the thresholds are based on the state store required allocation for
66+
// the week, that information is passed as an optional param (`requiredStateStoresAllocation`).
67+
// That param is only used for zones.
68+
69+
70+
createClass(ThresholdsService, [{
71+
key: 'calculateThresholds',
72+
value: function calculateThresholds(location, stockCount, products) {
73+
var requiredStateStoresAllocation = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
74+
75+
if (!location || !location.allocations || !location.plans || !location.level) {
76+
return;
77+
}
78+
79+
if (!stockCount || !stockCount.allocations || !stockCount.allocations.version || !stockCount.plans || !stockCount.plans.version) {
80+
return;
81+
}
82+
83+
if (!products || !products.length) {
84+
return;
85+
}
86+
87+
var allocation = find(location.allocations, isVersion.bind(null, stockCount.allocations.version));
88+
if (!(allocation && allocation.weeklyLevels)) {
89+
return;
90+
}
91+
92+
var weeklyLevels = allocation.weeklyLevels;
93+
var weeksOfStock = zonesPlan;
94+
95+
if (location.level !== 'zone') {
96+
var plan = find(location.plans, isVersion.bind(null, stockCount.plans.version));
97+
if (!(plan && plan.weeksOfStock)) {
98+
return;
99+
}
100+
weeksOfStock = plan.weeksOfStock;
101+
}
102+
103+
var thresholds = Object.keys(weeklyLevels).reduce(function (index, productId) {
104+
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
105+
var level = weeklyLevels[productId] * weeksOfStock[threshold];
106+
var product = find(products, isId.bind(null, productId));
107+
108+
// Default rounding used in VSPMD and highest possible presentation
109+
var presentation = 20;
110+
111+
if (product && product.presentation) {
112+
// TODO: product presentations should be ints, not strings
113+
presentation = parseInt(product.presentation, 10);
114+
}
115+
116+
var roundedLevel = Math.ceil(level / presentation) * presentation;
117+
productThresholds[threshold] = roundedLevel;
118+
119+
if (location.level === 'zone' && requiredStateStoresAllocation[productId]) {
120+
productThresholds[threshold] += requiredStateStoresAllocation[productId];
121+
}
122+
123+
return productThresholds;
124+
}, {});
125+
126+
if (location.targetPopulation) {
127+
index[productId].targetPopulation = location.targetPopulation[productId];
128+
}
129+
130+
return index;
131+
}, {});
132+
133+
return thresholds;
134+
}
135+
}, {
136+
key: 'getThresholdsFor',
137+
value: function getThresholdsFor(stockCounts, products) {
138+
var _this = this;
139+
140+
// TODO: make it work for zones too.
141+
// For making it work with zones, we need to take into account the amount of stock
142+
// to be allocated to the zone state stores in a particular week
143+
var locationIdPattern = 'zone:?state:?lga';
144+
var index = {};
145+
var promises = {};
146+
147+
index = stockCounts.reduce(function (index, stockCount) {
148+
var scLocation = stockCount.location;
149+
if (!scLocation) {
150+
return index;
151+
}
152+
153+
var id = _this.smartId.idify(scLocation, locationIdPattern);
154+
var allocations = stockCount.allocations || { version: 1 };
155+
var plans = stockCount.plans || { version: 1 };
156+
index[id] = angular.merge({}, { allocations: allocations, plans: plans });
157+
158+
if (scLocation.lga) {
159+
if (!promises.lga) {
160+
promises.lga = _this.lgasService.list();
161+
}
162+
index[id].type = 'lga';
163+
} else if (scLocation.state) {
164+
if (!promises.state) {
165+
promises.state = _this.statesService.list();
166+
}
167+
index[id].type = 'state';
168+
}
169+
170+
return index;
171+
}, {});
172+
173+
var addThresholds = function addThresholds(promisesRes) {
174+
Object.keys(index).forEach(function (key) {
175+
var item = index[key];
176+
var location = find(promisesRes[item.type], isId.bind(null, key));
177+
item.thresholds = _this.calculateThresholds(location, item, products);
178+
delete item.type;
179+
});
180+
181+
return index;
182+
};
183+
184+
return this.$q.all(promises).then(addThresholds);
185+
}
186+
}]);
187+
return ThresholdsService;
188+
}();
189+
190+
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService'];
191+
192+
angular$1.module('angularNavThresholds', ['angularNavData', 'ngSmartId']).service('thresholdsService', ThresholdsService);
193+
194+
}(angular));

dist/bundle.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)