UNPKG

@hisptz/react-ui

Version:

A collection of reusable complex DHIS2 react ui components.

113 lines (88 loc) 3.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = IdentifiableObjectDataSource; exports.displayBool = displayBool; exports.displayNameLength = displayNameLength; exports.displayNameSelector = displayNameSelector; exports.getDataSourceType = getDataSourceType; exports.idOrRuleSelector = idOrRuleSelector; exports.typeOrFunctionSelector = typeOrFunctionSelector; var _lodash = _interopRequireDefault(require("lodash")); var _Models = require("../Models"); var _FormulaFunctions = require("./FormulaFunctions"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function IdentifiableObjectDataSource(engine, arrId) { //returns array of promises return arrId === null || arrId === void 0 ? void 0 : arrId.map(id => { return (0, _FormulaFunctions.getValueDataSourcePromise)(engine, id); }); } function getDataSourceType(formula) { if ((formula === null || formula === void 0 ? void 0 : formula.search("dataElements")) >= 0) { return _Models.dataSourceTypes.DATA_ELEMENT; } if ((formula === null || formula === void 0 ? void 0 : formula.search("indicators")) >= 0) { return _Models.dataSourceTypes.INDICATOR; } if ((formula === null || formula === void 0 ? void 0 : formula.search("programIndicators")) >= 0) { return _Models.dataSourceTypes.PROGRAM_INDICATOR; } if ((formula === null || formula === void 0 ? void 0 : formula.search("dataElementGroups")) >= 0) { return _Models.dataSourceTypes.DATA_ELEMENT_GROUP; } if ((formula === null || formula === void 0 ? void 0 : formula.search("indicatorGroups")) >= 0) { return _Models.dataSourceTypes.INDICATOR_GROUP; } if ((formula === null || formula === void 0 ? void 0 : formula.search("dataStore/function")) >= 0) { return _Models.dataSourceTypes.FUNCTION; } if ((formula === null || formula === void 0 ? void 0 : formula.search("dataSets")) >= 0) { return _Models.dataSourceTypes.DATASET; } } function displayNameSelector(id, obj) { if ((0, _FormulaFunctions.isPureDataElement)(id)) { return obj.displayName; } else { var _ruleObjectSelected$; const ruleId = id.split(".")[1]; const ruleObjectSelected = _lodash.default.filter(obj === null || obj === void 0 ? void 0 : obj.rules, e => { return (e === null || e === void 0 ? void 0 : e.id) === ruleId; }); //will return matched object with one element return (_ruleObjectSelected$ = ruleObjectSelected[0]) === null || _ruleObjectSelected$ === void 0 ? void 0 : _ruleObjectSelected$.name; } } function displayNameLength(name) { if ((name === null || name === void 0 ? void 0 : name.length) > 18) { return (name === null || name === void 0 ? void 0 : name.substr(0, 16)) + "..."; } else { return name; } } function idOrRuleSelector(id, obj) { if ((0, _FormulaFunctions.isPureDataElement)(id)) { return obj.id; } else { const ruleId = id.split(".")[1]; const ruleObjectSelected = _lodash.default.filter(obj === null || obj === void 0 ? void 0 : obj.rules, e => { return (e === null || e === void 0 ? void 0 : e.id) === ruleId; }); //will return matched object with one element return ruleObjectSelected[0]; } } function typeOrFunctionSelector(id, obj) { if ((0, _FormulaFunctions.isPureDataElement)(id)) { return getDataSourceType(obj.href); } else { return obj; } } function displayBool(val) { if (val) { return "Yes"; } else { return "No"; } }