Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-nav-thresholds

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-nav-thresholds - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

396

dist/bundle.js

@@ -1,263 +0,227 @@

(function (angular$1) {
'use strict';
(function (angular) {
'use strict';
angular$1 = 'default' in angular$1 ? angular$1['default'] : angular$1;
angular = 'default' in angular ? angular['default'] : angular;
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; }; }();
var versionDateFormat = "YYYY-MM-DD";
var config = {
versionDateFormat: versionDateFormat
};
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }; }();
// TODO: replace with Array#find ponyfill
var find = function find(list, match) {
for (var i = 0; i < list.length; i++) {
if (match(list[i])) {
return list[i];
}
}
return undefined;
};
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var isVersion = function isVersion(version, item) {
return item.version === version;
};
// TODO: replace with Array#find ponyfill
var find = function find(list, match) {
for (var i = 0; i < list.length; i++) {
if (match(list[i])) {
return list[i];
}
}
return undefined;
};
var isId = function isId(id, item) {
return item._id === id;
};
var isVersion = function isVersion(date, version) {
var momentDate = moment().isoWeekYear(date.year).isoWeek(date.week).isoWeekday(1).startOf('day');
var momentVersionStartDate = moment(version.date, config.versionDateFormat).startOf('isoWeek').startOf('day');
return momentDate.isSameOrAfter(momentVersionStartDate);
};
// Zones config
var zonePlans = {
weeksOfStock: {
min: 0,
reOrder: 3,
max: 6
}
};
var isId = function isId(id, item) {
return item._id === id;
};
var getFactorVersion = function getFactorVersion(stockCount, factor, options) {
if (options.version === 'last') {
return options.version;
}
if (!(stockCount[factor] && stockCount[factor].version)) {
return 1;
}
return stockCount[factor].version;
};
var getFactor = function getFactor(versions, date) {
var reverseVersions = versions.slice(0).reverse();
var factor = find(reverseVersions, isVersion.bind(null, date));
// If the doc is too old to have a matching version, default to the oldest one
if (!factor) {
return versions[0];
}
return factor;
};
var getFactor = function getFactor(location, versions, version) {
if (version === 'last') {
return versions[versions.length - 1];
}
var getFactors = function getFactors(stockCount, location) {
// centralized for whenever we implement #16
var somethingIsWrong = function somethingIsWrong() {
return undefined;
};
return find(versions, isVersion.bind(null, version));
};
var getWeeklyLevels = function getWeeklyLevels() {
if (!(location.allocations && location.allocations.length)) {
somethingIsWrong();
}
var getFactors = function getFactors(stockCount, location, options) {
// centralized for whenever we implement #16
var somethingIsWrong = function somethingIsWrong() {
return undefined;
};
var allocations = getFactor(location.allocations, stockCount.date);
return allocations && allocations.weeklyLevels;
};
var getWeeklyLevels = function getWeeklyLevels() {
if (!(location.allocations && location.allocations.length)) {
somethingIsWrong();
}
var getWeeksOfStock = function getWeeksOfStock() {
if (!(location.plans && location.plans.length)) {
somethingIsWrong();
}
var allocationsVersion = getFactorVersion(stockCount, 'allocations', options);
var plans = getFactor(location.plans, stockCount.date);
return plans && plans.weeksOfStock;
};
if (typeof allocationsVersion === 'undefined') {
somethingIsWrong();
}
var getMonthlyTargetPopulations = function getMonthlyTargetPopulations() {
var monthlyTargetPopulations = void 0;
if (location.targetPopulations) {
if (!location.targetPopulations.length) {
somethingIsWrong();
}
var allocations = getFactor(location, location.allocations, allocationsVersion);
return allocations && allocations.weeklyLevels;
};
var targetPopulations = getFactor(location.targetPopulations, stockCount.date);
monthlyTargetPopulations = targetPopulations && targetPopulations.monthlyTargetPopulations;
} else {
// For backwards compatibility with the old style location docs,
// since we have no control about when the dashboards are going
// to replicate the new location docs
if (!(location.targetPopulation && location.targetPopulation.length)) {
somethingIsWrong();
}
monthlyTargetPopulations = location.targetPopulation;
}
return monthlyTargetPopulations;
};
var getWeeksOfStock = function getWeeksOfStock() {
if (location.level !== 'zone' && !(location.plans && location.plans.length)) {
somethingIsWrong();
}
return {
weeksOfStock: getWeeksOfStock(),
weeklyLevels: getWeeklyLevels(),
targetPopulations: getMonthlyTargetPopulations()
};
};
var plansVersion = getFactorVersion(stockCount, 'plans', options);
var ThresholdsService = function () {
function ThresholdsService($q, smartId, lgasService, statesService) {
_classCallCheck(this, ThresholdsService);
if (typeof plansVersion === 'undefined') {
somethingIsWrong();
}
this.$q = $q;
this.smartId = smartId;
this.lgasService = lgasService;
this.statesService = statesService;
}
var plans = zonePlans;
if (location.level !== 'zone') {
plans = getFactor(location, location.plans, plansVersion);
}
// 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.
return plans && plans.weeksOfStock;
};
var getMonthlyTargetPopulations = function getMonthlyTargetPopulations() {
var monthlyTargetPopulations = void 0;
if (location.targetPopulations) {
if (!location.targetPopulations.length) {
somethingIsWrong();
}
var targetPopulationVersion = getFactorVersion(stockCount, 'targetPopulations', options);
_createClass(ThresholdsService, [{
key: 'calculateThresholds',
value: function calculateThresholds(location, stockCount, products) {
var requiredStateStoresAllocation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (typeof targetPopulationVersion === 'undefined') {
somethingIsWrong();
}
if (!(stockCount && stockCount.date)) {
return;
}
var targetPopulations = getFactor(location, location.targetPopulations, targetPopulationVersion);
monthlyTargetPopulations = targetPopulations && targetPopulations.monthlyTargetPopulations;
} else {
// For backwards compatibility with the old style location docs,
// since we have no control about when the dashboards are going
// to replicate the new location docs
if (!(location.targetPopulation && location.targetPopulation.length)) {
somethingIsWrong();
}
monthlyTargetPopulations = location.targetPopulation;
}
return monthlyTargetPopulations;
};
if (!(location && location.level)) {
return;
}
return {
weeksOfStock: getWeeksOfStock(),
weeklyLevels: getWeeklyLevels(),
targetPopulations: getMonthlyTargetPopulations()
};
};
if (!(products && products.length)) {
return;
}
var ThresholdsService = function () {
function ThresholdsService($q, smartId, lgasService, statesService) {
_classCallCheck(this, ThresholdsService);
var _getFactors = getFactors(stockCount, location),
weeklyLevels = _getFactors.weeklyLevels,
weeksOfStock = _getFactors.weeksOfStock,
targetPopulations = _getFactors.targetPopulations;
this.$q = $q;
this.smartId = smartId;
this.lgasService = lgasService;
this.statesService = statesService;
}
if (!(weeklyLevels && weeksOfStock)) {
return;
}
// 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.
return Object.keys(weeklyLevels).reduce(function (index, productId) {
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
var level = weeklyLevels[productId] * weeksOfStock[threshold];
var product = find(products, isId.bind(null, productId));
// Default rounding used in VSPMD and highest possible presentation
var presentation = 20;
_createClass(ThresholdsService, [{
key: 'calculateThresholds',
value: function calculateThresholds(location, stockCount, products) {
var requiredStateStoresAllocation = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
if (product && product.presentation) {
// TODO: product presentations should be ints, not strings
presentation = parseInt(product.presentation, 10);
}
if (!stockCount) {
return;
}
var roundedLevel = Math.ceil(level / presentation) * presentation;
productThresholds[threshold] = roundedLevel;
if (!location && location.level) {
return;
}
if (location.level === 'zone' && requiredStateStoresAllocation[productId]) {
productThresholds[threshold] += requiredStateStoresAllocation[productId];
}
if (!products || !products.length) {
return;
}
return productThresholds;
}, {});
var _getFactors = getFactors(stockCount, location, options),
weeklyLevels = _getFactors.weeklyLevels,
weeksOfStock = _getFactors.weeksOfStock,
targetPopulations = _getFactors.targetPopulations;
if (targetPopulations) {
// old (and new?) zone docs have no target population doc
index[productId].targetPopulation = targetPopulations[productId];
}
if (!(weeklyLevels && weeksOfStock && targetPopulations)) {
return;
}
return index;
}, {});
}
}, {
key: 'getThresholdsFor',
value: function getThresholdsFor(stockCounts, products) {
var _this = this;
return Object.keys(weeklyLevels).reduce(function (index, productId) {
index[productId] = Object.keys(weeksOfStock).reduce(function (productThresholds, threshold) {
var level = weeklyLevels[productId] * weeksOfStock[threshold];
var product = find(products, isId.bind(null, productId));
// 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
var locationIdPattern = 'zone:?state:?lga';
var index = {};
var promises = {};
// Default rounding used in VSPMD and highest possible presentation
var presentation = 20;
index = stockCounts.reduce(function (index, stockCount) {
var scLocation = stockCount.location;
if (!scLocation) {
return index;
}
if (product && product.presentation) {
// TODO: product presentations should be ints, not strings
presentation = parseInt(product.presentation, 10);
}
var id = _this.smartId.idify(scLocation, locationIdPattern);
index[id] = { date: stockCount.date };
var roundedLevel = Math.ceil(level / presentation) * presentation;
productThresholds[threshold] = roundedLevel;
if (scLocation.lga) {
if (!promises.lga) {
promises.lga = _this.lgasService.list();
}
index[id].type = 'lga';
} else if (scLocation.state) {
if (!promises.state) {
promises.state = _this.statesService.list();
}
index[id].type = 'state';
}
if (location.level === 'zone' && requiredStateStoresAllocation[productId]) {
productThresholds[threshold] += requiredStateStoresAllocation[productId];
}
return index;
}, {});
return productThresholds;
}, {});
var addThresholds = function addThresholds(promisesRes) {
Object.keys(index).forEach(function (key) {
var item = index[key];
var location = find(promisesRes[item.type], isId.bind(null, key));
item.thresholds = _this.calculateThresholds(location, item, products);
delete item.type;
});
index[productId].targetPopulation = targetPopulations[productId];
return index;
};
return index;
}, {});
}
}, {
key: 'getThresholdsFor',
value: function getThresholdsFor(stockCounts, products) {
var _this = this;
return this.$q.all(promises).then(addThresholds);
}
}]);
// 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
var locationIdPattern = 'zone:?state:?lga';
var index = {};
var promises = {};
return ThresholdsService;
}();
index = stockCounts.reduce(function (index, stockCount) {
var scLocation = stockCount.location;
if (!scLocation) {
return index;
}
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService'];
var id = _this.smartId.idify(scLocation, locationIdPattern);
var allocations = stockCount.allocations || { version: 1 };
var plans = stockCount.plans || { version: 1 };
var targetPopulations = stockCount.targetPopulations || { version: 1 };
index[id] = angular.merge({}, {
allocations: allocations,
plans: plans,
targetPopulations: targetPopulations
});
angular.module('angularNavThresholds', ['angularNavData', 'ngSmartId']).service('thresholdsService', ThresholdsService);
if (scLocation.lga) {
if (!promises.lga) {
promises.lga = _this.lgasService.list();
}
index[id].type = 'lga';
} else if (scLocation.state) {
if (!promises.state) {
promises.state = _this.statesService.list();
}
index[id].type = 'state';
}
return index;
}, {});
var addThresholds = function addThresholds(promisesRes) {
Object.keys(index).forEach(function (key) {
var item = index[key];
var location = find(promisesRes[item.type], isId.bind(null, key));
item.thresholds = _this.calculateThresholds(location, item, products);
delete item.type;
});
return index;
};
return this.$q.all(promises).then(addThresholds);
}
}]);
return ThresholdsService;
}();
ThresholdsService.$inject = ['$q', 'smartId', 'lgasService', 'statesService'];
angular$1.module('angularNavThresholds', ['angularNavData', 'ngSmartId']).service('thresholdsService', ThresholdsService);
}(angular));

@@ -1,1 +0,1 @@

!function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var n=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),r=function(e,t){for(var n=0;n<e.length;n++)if(t(e[n]))return e[n]},a=function(e,t){return t.version===e},o=function(e,t){return t._id===e},l={weeksOfStock:{min:0,reOrder:3,max:6}},i=function(e,t,n){return"last"===n.version?n.version:e[t]&&e[t].version?e[t].version:1},s=function(e,t,n){return"last"===n?t[t.length-1]:r(t,a.bind(null,n))},u=function(e,t,n){var r=function(){},a=function(){t.allocations&&t.allocations.length||r();var a=i(e,"allocations",n);"undefined"==typeof a&&r();var o=s(t,t.allocations,a);return o&&o.weeklyLevels},o=function(){"zone"===t.level||t.plans&&t.plans.length||r();var a=i(e,"plans",n);"undefined"==typeof a&&r();var o=l;return"zone"!==t.level&&(o=s(t,t.plans,a)),o&&o.weeksOfStock},u=function(){var a=void 0;if(t.targetPopulations){t.targetPopulations.length||r();var o=i(e,"targetPopulations",n);"undefined"==typeof o&&r();var l=s(t,t.targetPopulations,o);a=l&&l.monthlyTargetPopulations}else t.targetPopulation&&t.targetPopulation.length||r(),a=t.targetPopulation;return a};return{weeksOfStock:o(),weeklyLevels:a(),targetPopulations:u()}},c=function(){function e(n,r,a,o){t(this,e),this.$q=n,this.smartId=r,this.lgasService=a,this.statesService=o}return n(e,[{key:"calculateThresholds",value:function(e,t,n){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};if(t&&(e||!e.level)&&n&&n.length){var i=u(t,e,l),s=i.weeklyLevels,c=i.weeksOfStock,v=i.targetPopulations;if(s&&c&&v)return Object.keys(s).reduce(function(t,l){return t[l]=Object.keys(c).reduce(function(t,i){var u=s[l]*c[i],v=r(n,o.bind(null,l)),f=20;v&&v.presentation&&(f=parseInt(v.presentation,10));var g=Math.ceil(u/f)*f;return t[i]=g,"zone"===e.level&&a[l]&&(t[i]+=a[l]),t},{}),t[l].targetPopulation=v[l],t},{})}}},{key:"getThresholdsFor",value:function(e,t){var n=this,a="zone:?state:?lga",l={},i={};l=e.reduce(function(e,t){var r=t.location;if(!r)return e;var o=n.smartId.idify(r,a),l=t.allocations||{version:1},s=t.plans||{version:1},u=t.targetPopulations||{version:1};return e[o]=angular.merge({},{allocations:l,plans:s,targetPopulations:u}),r.lga?(i.lga||(i.lga=n.lgasService.list()),e[o].type="lga"):r.state&&(i.state||(i.state=n.statesService.list()),e[o].type="state"),e},{});var s=function(e){return Object.keys(l).forEach(function(a){var i=l[a],s=r(e[i.type],o.bind(null,a));i.thresholds=n.calculateThresholds(s,i,t),delete i.type}),l};return this.$q.all(i).then(s)}}]),e}();c.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",c)}(angular);
!function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}e="default"in e?e.default:e;var a="YYYY-MM-DD",n={versionDateFormat:a},r=function(){function e(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,a,n){return a&&e(t.prototype,a),n&&e(t,n),t}}(),o=function(e,t){for(var a=0;a<e.length;a++)if(t(e[a]))return e[a]},i=function(e,t){var a=moment().isoWeekYear(e.year).isoWeek(e.week).isoWeekday(1).startOf("day"),r=moment(t.date,n.versionDateFormat).startOf("isoWeek").startOf("day");return a.isSameOrAfter(r)},l=function(e,t){return t._id===e},s=function(e,t){var a=e.slice(0).reverse(),n=o(a,i.bind(null,t));return n?n:e[0]},u=function(e,t){var a=function(){},n=function(){t.allocations&&t.allocations.length||a();var n=s(t.allocations,e.date);return n&&n.weeklyLevels},r=function(){t.plans&&t.plans.length||a();var n=s(t.plans,e.date);return n&&n.weeksOfStock},o=function(){var n=void 0;if(t.targetPopulations){t.targetPopulations.length||a();var r=s(t.targetPopulations,e.date);n=r&&r.monthlyTargetPopulations}else t.targetPopulation&&t.targetPopulation.length||a(),n=t.targetPopulation;return n};return{weeksOfStock:r(),weeklyLevels:n(),targetPopulations:o()}},c=function(){function e(a,n,r,o){t(this,e),this.$q=a,this.smartId=n,this.lgasService=r,this.statesService=o}return r(e,[{key:"calculateThresholds",value:function(e,t,a){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(t&&t.date&&e&&e.level&&a&&a.length){var r=u(t,e),i=r.weeklyLevels,s=r.weeksOfStock,c=r.targetPopulations;if(i&&s)return Object.keys(i).reduce(function(t,r){return t[r]=Object.keys(s).reduce(function(t,u){var c=i[r]*s[u],f=o(a,l.bind(null,r)),v=20;f&&f.presentation&&(v=parseInt(f.presentation,10));var d=Math.ceil(c/v)*v;return t[u]=d,"zone"===e.level&&n[r]&&(t[u]+=n[r]),t},{}),c&&(t[r].targetPopulation=c[r]),t},{})}}},{key:"getThresholdsFor",value:function(e,t){var a=this,n="zone:?state:?lga",r={},i={};r=e.reduce(function(e,t){var r=t.location;if(!r)return e;var o=a.smartId.idify(r,n);return e[o]={date:t.date},r.lga?(i.lga||(i.lga=a.lgasService.list()),e[o].type="lga"):r.state&&(i.state||(i.state=a.statesService.list()),e[o].type="state"),e},{});var s=function(e){return Object.keys(r).forEach(function(n){var i=r[n],s=o(e[i.type],l.bind(null,n));i.thresholds=a.calculateThresholds(s,i,t),delete i.type}),r};return this.$q.all(i).then(s)}}]),e}();c.$inject=["$q","smartId","lgasService","statesService"],e.module("angularNavThresholds",["angularNavData","ngSmartId"]).service("thresholdsService",c)}(angular);

@@ -40,2 +40,3 @@ {

"karma-phantomjs-launcher": "^1.0.0",
"moment": "^2.17.1",
"ng-smart-id": "github:fielded/ng-smart-id#4.0.3",

@@ -47,2 +48,3 @@ "phantomjs-prebuilt": "^2.1.7",

"rollup-plugin-commonjs": "^2.2.1",
"rollup-plugin-json": "^2.0.2",
"rollup-plugin-node-resolve": "^1.5.0",

@@ -77,3 +79,3 @@ "semantic-release": "^4.3.5",

],
"version": "2.2.0"
"version": "2.3.0"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc