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

Commit 0f34e81

Browse files
committed
chore: rebuild dist
Rebuilds dist. -- tlvince/publish-dist
1 parent e2b5aaa commit 0f34e81

File tree

2 files changed

+119
-74
lines changed

2 files changed

+119
-74
lines changed

Diff for: dist/bundle.js

+118-73
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,9 @@
33

44
angular$1 = 'default' in angular$1 ? angular$1['default'] : angular$1;
55

6-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
7-
return typeof obj;
8-
} : function (obj) {
9-
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
10-
};
11-
12-
var classCallCheck = function (instance, Constructor) {
13-
if (!(instance instanceof Constructor)) {
14-
throw new TypeError("Cannot call a class as a function");
15-
}
16-
};
6+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
177

18-
var createClass = function () {
19-
function defineProperties(target, props) {
20-
for (var i = 0; i < props.length; i++) {
21-
var descriptor = props[i];
22-
descriptor.enumerable = descriptor.enumerable || false;
23-
descriptor.configurable = true;
24-
if ("value" in descriptor) descriptor.writable = true;
25-
Object.defineProperty(target, descriptor.key, descriptor);
26-
}
27-
}
28-
29-
return function (Constructor, protoProps, staticProps) {
30-
if (protoProps) defineProperties(Constructor.prototype, protoProps);
31-
if (staticProps) defineProperties(Constructor, staticProps);
32-
return Constructor;
33-
};
34-
}();
8+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
359

3610
// TODO: replace with Array#find ponyfill
3711
var find = function find(list, match) {
@@ -52,15 +26,108 @@
5226
};
5327

5428
// Zones config
55-
var zonesPlan = {
56-
min: 0,
57-
reOrder: 3,
58-
max: 6
29+
var zonePlans = {
30+
weeksOfStock: {
31+
min: 0,
32+
reOrder: 3,
33+
max: 6
34+
}
35+
};
36+
37+
var getFactorVersion = function getFactorVersion(stockCount, factor, options) {
38+
if (options.version === 'last') {
39+
return options.version;
40+
}
41+
if (!(stockCount[factor] && stockCount[factor].version)) {
42+
return 1;
43+
}
44+
return stockCount[factor].version;
45+
};
46+
47+
var getFactor = function getFactor(location, versions, version) {
48+
if (version === 'last') {
49+
return versions[versions.length - 1];
50+
}
51+
52+
return find(versions, isVersion.bind(null, version));
53+
};
54+
55+
var getFactors = function getFactors(stockCount, location, options) {
56+
// centralized for whenever we implement #16
57+
var somethingIsWrong = function somethingIsWrong() {
58+
return undefined;
59+
};
60+
61+
var getWeeklyLevels = function getWeeklyLevels() {
62+
if (!(location.allocations && location.allocations.length)) {
63+
somethingIsWrong();
64+
}
65+
66+
var allocationsVersion = getFactorVersion(stockCount, 'allocations', options);
67+
68+
if (typeof allocationsVersion === 'undefined') {
69+
somethingIsWrong();
70+
}
71+
72+
var allocations = getFactor(location, location.allocations, allocationsVersion);
73+
return allocations && allocations.weeklyLevels;
74+
};
75+
76+
var getWeeksOfStock = function getWeeksOfStock() {
77+
if (location.level !== 'zone' && !(location.plans && location.plans.length)) {
78+
somethingIsWrong();
79+
}
80+
81+
var plansVersion = getFactorVersion(stockCount, 'plans', options);
82+
83+
if (typeof plansVersion === 'undefined') {
84+
somethingIsWrong();
85+
}
86+
87+
var plans = zonePlans;
88+
if (location.level !== 'zone') {
89+
plans = getFactor(location, location.plans, plansVersion);
90+
}
91+
92+
return plans && plans.weeksOfStock;
93+
};
94+
95+
var getMonthlyTargetPopulations = function getMonthlyTargetPopulations() {
96+
var monthlyTargetPopulations = void 0;
97+
if (location.targetPopulations) {
98+
if (!location.targetPopulations.length) {
99+
somethingIsWrong();
100+
}
101+
var targetPopulationVersion = getFactorVersion(stockCount, 'targetPopulations', options);
102+
103+
if (typeof targetPopulationVersion === 'undefined') {
104+
somethingIsWrong();
105+
}
106+
107+
var targetPopulations = getFactor(location, location.targetPopulations, targetPopulationVersion);
108+
monthlyTargetPopulations = targetPopulations && targetPopulations.monthlyTargetPopulations;
109+
} else {
110+
// For backwards compatibility with the old style location docs,
111+
// since we have no control about when the dashboards are going
112+
// to replicate the new location docs
113+
if (!(location.targetPopulation && location.targetPopulation.length)) {
114+
somethingIsWrong();
115+
}
116+
monthlyTargetPopulations = location.targetPopulation;
117+
}
118+
return monthlyTargetPopulations;
119+
};
120+
121+
return {
122+
weeksOfStock: getWeeksOfStock(),
123+
weeklyLevels: getWeeklyLevels(),
124+
targetPopulations: getMonthlyTargetPopulations()
125+
};
59126
};
60127

61128
var ThresholdsService = function () {
62129
function ThresholdsService($q, smartId, lgasService, statesService) {
63-
classCallCheck(this, ThresholdsService);
130+
_classCallCheck(this, ThresholdsService);
64131

65132
this.$q = $q;
66133
this.smartId = smartId;
@@ -73,58 +140,34 @@
73140
// That param is only used for zones.
74141

75142

76-
createClass(ThresholdsService, [{
143+
_createClass(ThresholdsService, [{
77144
key: 'calculateThresholds',
78145
value: function calculateThresholds(location, stockCount, products) {
79-
var requiredStateStoresAllocation = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
80-
var options = arguments.length <= 4 || arguments[4] === undefined ? {} : arguments[4];
81-
82-
if (!location || !location.allocations || !location.allocations.length || !location.plans || !location.plans.length || !location.level) {
83-
return;
84-
}
146+
var requiredStateStoresAllocation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
147+
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
85148

86149
if (!stockCount) {
87150
return;
88151
}
89152

90-
if (options.version !== 'last' && !(stockCount.allocations && _typeof(stockCount.allocations.version) !== undefined && stockCount.plans && _typeof(stockCount.plans.version) !== undefined)) {
153+
if (!location && location.level) {
91154
return;
92155
}
93156

94157
if (!products || !products.length) {
95158
return;
96159
}
97160

98-
var allocation = void 0;
99-
if (options.version === 'last') {
100-
allocation = location.allocations[location.allocations.length - 1];
101-
} else {
102-
allocation = find(location.allocations, isVersion.bind(null, stockCount.allocations.version));
103-
}
161+
var _getFactors = getFactors(stockCount, location, options),
162+
weeklyLevels = _getFactors.weeklyLevels,
163+
weeksOfStock = _getFactors.weeksOfStock,
164+
targetPopulations = _getFactors.targetPopulations;
104165

105-
if (!(allocation && allocation.weeklyLevels)) {
166+
if (!(weeklyLevels && weeksOfStock && targetPopulations)) {
106167
return;
107168
}
108169

109-
var weeklyLevels = allocation.weeklyLevels;
110-
111-
var weeksOfStock = zonesPlan;
112-
113-
if (location.level !== 'zone') {
114-
var plan = void 0;
115-
if (options.version === 'last') {
116-
plan = location.plans[location.plans.length - 1];
117-
} else {
118-
plan = find(location.plans, isVersion.bind(null, stockCount.plans.version));
119-
}
120-
121-
if (!(plan && plan.weeksOfStock)) {
122-
return;
123-
}
124-
weeksOfStock = plan.weeksOfStock;
125-
}
126-
127-
var thresholds = Object.keys(weeklyLevels).reduce(function (index, productId) {
170+
return Object.keys(weeklyLevels).reduce(function (index, productId) {
128171
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
129172
var level = weeklyLevels[productId] * weeksOfStock[threshold];
130173
var product = find(products, isId.bind(null, productId));
@@ -147,14 +190,10 @@
147190
return productThresholds;
148191
}, {});
149192

150-
if (location.targetPopulation) {
151-
index[productId].targetPopulation = location.targetPopulation[productId];
152-
}
193+
index[productId].targetPopulation = targetPopulations[productId];
153194

154195
return index;
155196
}, {});
156-
157-
return thresholds;
158197
}
159198
}, {
160199
key: 'getThresholdsFor',
@@ -177,7 +216,12 @@
177216
var id = _this.smartId.idify(scLocation, locationIdPattern);
178217
var allocations = stockCount.allocations || { version: 1 };
179218
var plans = stockCount.plans || { version: 1 };
180-
index[id] = angular.merge({}, { allocations: allocations, plans: plans });
219+
var targetPopulations = stockCount.targetPopulations || { version: 1 };
220+
index[id] = angular.merge({}, {
221+
allocations: allocations,
222+
plans: plans,
223+
targetPopulations: targetPopulations
224+
});
181225

182226
if (scLocation.lga) {
183227
if (!promises.lga) {
@@ -208,6 +252,7 @@
208252
return this.$q.all(promises).then(addThresholds);
209253
}
210254
}]);
255+
211256
return ThresholdsService;
212257
}();
213258

Diff for: dist/bundle.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)