UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

323 lines (303 loc) 13.1 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ 'use strict'; var index = require('./index-B0SElCD3.js'); var map = require('./map-DS77TM7_.js'); var sortBy = require('./sortBy-Qx6X8Z-M.js'); var _baseMap = require('./_baseMap-JOWSgF8Y.js'); var _getTag = require('./_getTag-BnylOe-u.js'); var groupBy = require('./groupBy-CvyCo_8L.js'); require('./_hasPath-Da_vD6kJ.js'); require('./isArray-D5T3FFPp.js'); require('./isObjectLike-DYIul5Fz.js'); require('./global-C03WvntH.js'); require('./_isIndex-B1e9x--S.js'); require('./isLength-CPPfDVFI.js'); require('./isObject-BbrqXeY4.js'); require('./_setToString-CLmf6rll.js'); require('./_getAllKeys-BC9TlVD6.js'); require('./_defineProperty-iQdktGFd.js'); require('./_baseAssignValue-ccaUD9ve.js'); /** * The base implementation of `_.findIndex` and `_.findLastIndex` without * support for iteratee shorthands. * * @private * @param {Array} array The array to inspect. * @param {Function} predicate The function invoked per iteration. * @param {number} fromIndex The index to search from. * @param {boolean} [fromRight] Specify iterating from right to left. * @returns {number} Returns the index of the matched value, else `-1`. */ function baseFindIndex(array, predicate, fromIndex, fromRight) { var length = array.length, index = fromIndex + (-1); while ((++index < length)) { if (predicate(array[index], index, array)) { return index; } } return -1; } /** * The base implementation of `_.isNaN` without support for number objects. * * @private * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. */ function baseIsNaN(value) { return value !== value; } /** * A specialized version of `_.indexOf` which performs strict equality * comparisons of values, i.e. `===`. * * @private * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. */ function strictIndexOf(array, value, fromIndex) { var index = fromIndex - 1, length = array.length; while (++index < length) { if (array[index] === value) { return index; } } return -1; } /** * The base implementation of `_.indexOf` without `fromIndex` bounds checks. * * @private * @param {Array} array The array to inspect. * @param {*} value The value to search for. * @param {number} fromIndex The index to search from. * @returns {number} Returns the index of the matched value, else `-1`. */ function baseIndexOf(array, value, fromIndex) { return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex); } /** * A specialized version of `_.includes` for arrays without support for * specifying an index to search from. * * @private * @param {Array} [array] The array to inspect. * @param {*} target The value to search for. * @returns {boolean} Returns `true` if `target` is found, else `false`. */ function arrayIncludes(array, value) { var length = array == null ? 0 : array.length; return !!length && baseIndexOf(array, value, 0) > -1; } /** * This method returns `undefined`. * * @static * @memberOf _ * @since 2.3.0 * @category Util * @example * * _.times(2, _.noop); * // => [undefined, undefined] */ function noop() { // No operation performed. } /** Used as references for various `Number` constants. */ var INFINITY = 1 / 0; /** * Creates a set object of `values`. * * @private * @param {Array} values The values to add to the set. * @returns {Object} Returns the new set. */ var createSet = !(_getTag.Set && (1 / _baseMap.setToArray(new _getTag.Set([,-0]))[1]) == INFINITY) ? noop : function(values) { return new _getTag.Set(values); }; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; /** * The base implementation of `_.uniqBy` without support for iteratee shorthands. * * @private * @param {Array} array The array to inspect. * @param {Function} [iteratee] The iteratee invoked per element. * @param {Function} [comparator] The comparator invoked per element. * @returns {Array} Returns the new duplicate free array. */ function baseUniq(array, iteratee, comparator) { var index = -1, includes = arrayIncludes, length = array.length, isCommon = true, result = [], seen = result; if (length >= LARGE_ARRAY_SIZE) { var set = createSet(array); if (set) { return _baseMap.setToArray(set); } isCommon = false; includes = _baseMap.cacheHas; seen = new _baseMap.SetCache; } else { seen = result; } outer: while (++index < length) { var value = array[index], computed = value; value = (value !== 0) ? value : 0; if (isCommon && computed === computed) { var seenIndex = seen.length; while (seenIndex--) { if (seen[seenIndex] === computed) { continue outer; } } result.push(value); } else if (!includes(seen, computed, comparator)) { if (seen !== result) { seen.push(computed); } result.push(value); } } return result; } /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) * for equality comparisons, in which only the first occurrence of each element * is kept. The order of result values is determined by the order they occur * in the array. * * @static * @memberOf _ * @since 0.1.0 * @category Array * @param {Array} array The array to inspect. * @returns {Array} Returns the new duplicate free array. * @example * * _.uniq([2, 1, 2]); * // => [2, 1] */ function uniq(array) { return (array && array.length) ? baseUniq(array) : []; } const areaCss = "slot-fb[hidden],slot[hidden]{display:initial !important}.details{padding:3rem 0 0 0}.details lar-button-group{-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}.actions{min-height:60px}lar-list-item{background-color:var(--lar-background-color-step-100, rgb(25.5, 25.5, 25.5)) !important;color:var(--lar-text-color, #fff) !important}.spacer{margin-top:1.5rem;margin-bottom:1.5rem}.circle{background-color:var(--lar-background-color-step-200, #333333) !important;border-radius:50%;display:inline-block;padding:0.5rem;width:2rem;height:2rem;margin-right:1rem}.circle lar-icon{display:block;width:100%;height:100%}.zone-list h4{margin:0;padding:0}.zone-list h4 lar-badge{margin-top:0.2rem;margin-right:0.3rem;font-weight:normal}.zone-selectors{text-align:center;margin-bottom:1rem}.zone-selectors lar-button{margin:0.2rem}.zone-list lar-badge{margin-top:0.3rem}lar-button.zone-group{--lar-button-font-size-small:.95rem;--lar-button-padding-top-small:.4rem;--lar-button-padding-bottom-small:.4rem;--lar-button-padding-left-small:.4rem;--lar-button-padding-right-small:.4rem}.center{text-align:center}"; const AreaBypass = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.output = index.createEvent(this, "output"); this.bypassZones = []; this.zonesList = []; this.troubleList = []; } togglePyPassZone(zone) { const bypassedIndex = this.bypassZones.indexOf(zone.id); if (bypassedIndex > -1) { this.bypassZones.splice(bypassedIndex, 1); } else { this.bypassZones.push(zone.id); } index.forceUpdate(this.el); } bypassAutoSelect(group, fault) { if ((group === undefined || group === null || group === '') && !fault) { // no group or fault - clear selection this.bypassZones = []; return; } this.zonesList.forEach(zone => { if (!zone.persistent && fault && (zone.state === 'open_circuit' || zone.state === 'short_circuit') && !this.isZoneByPassed(zone)) { this.togglePyPassZone(zone); } if (!zone.persistent && zone.group === group && !this.isZoneByPassed(zone)) { this.togglePyPassZone(zone); } }); } isZoneByPassed(zone) { const bypassedIndex = this.bypassZones.indexOf(zone.id); return bypassedIndex > -1 ? true : false; } renderZoneSelector() { const selectors = []; if (this.troubleList.length > 0) { selectors.push(index.h("lar-button", { onClick: () => this.bypassAutoSelect('', true), color: "danger", size: "small", class: "zone-group", expand: "block", outline: true }, index.h("lar-translate", { t: "area.faultedOrTampered" }))); } const filteredZones = this.zonesList.filter(z => !z.persistent && z.group !== ''); const allGroups = map.map(filteredZones, 'group'); const groups = uniq(allGroups); groups.forEach(group => { if (group === null || group === undefined) { return; } selectors.push(index.h("lar-button", { color: this.color, onClick: () => this.bypassAutoSelect(group), size: "small", expand: "block", class: "zone-group", outline: true }, index.h("lar-translate", { t: (group || '<no name>') }))); }); selectors.push(index.h("lar-button", { color: "warning", onClick: () => this.bypassAutoSelect(), size: "small", class: "zone-group", expand: "block", outline: true }, index.h("lar-translate", { t: "area.clearSelection" }))); return selectors; } partialarm() { if (this.modal) { this.modal.dismiss(); } this.output.emit({ command: 'arm', override_zones: this.bypassZones, override_troubles: this.troubleList.length > 0 }); } render() { const zones = []; this.zonesList = sortBy.sortBy(JSON.parse(this.zones), 'group'); this.troubleList = JSON.parse(this.troubles); const groupedZones = groupBy.groupBy(this.zonesList, 'group'); sortBy.forOwn(groupedZones, (groupedZonesOwn, group) => { zones.push(index.h("lar-list-header", null, index.h("lar-translate", { t: group }))); sortBy.sortBy(groupedZonesOwn, 'name').forEach(zone => { let color = 'success'; if (zone.state === 'open') { color = 'tertiary'; } if (zone.state === 'short_circuit') { color = 'warning'; } if (zone.state === 'open_circuit') { color = 'danger'; } zones.push(index.h("lar-list-item", { disabled: this.isZoneByPassed(zone), onClick: () => { this.togglePyPassZone(zone); }, style: { cursor: 'pointer' } }, index.h("div", { slot: "start", class: "circle" }, index.h("lar-icon", { icon: zone.type, color: color })), index.h("div", null, index.h("h4", null, index.h("lar-translate", { t: zone.name })), index.h("lar-badge", { color: color }, index.h("lar-translate", { t: 'area.zone_state.' + zone.state })), zone.overridden && index.h("span", null, "\u00A0", index.h("lar-badge", { color: "danger" }, index.h("lar-translate", { t: 'area.zone_state.bypassed' })))))); }); }); return [ index.h("h4", { key: 'a639c373104330dce549c827228b90fa7b637f36', class: "center" }, this.troubleList.length > 0 ? index.h("lar-translate", { t: "area.overrideTroblesZonesInfo", values: { troubles: this.troubleList.length > 0 ? this.troubleList.length : '0', zones: this.bypassZones.length > 0 ? this.bypassZones.length : '0' } }) : index.h("lar-translate", { t: "area.overrideZonesInfo", values: { zones: this.bypassZones.length > 0 ? this.bypassZones.length : '0' } })), index.h("div", { key: '175ee2779e2be92ceafcbf94b5bbdf3c579e0d8c', class: "spacer" }), index.h("lar-button", { key: '04ca711a74cf8c1ccdddf2b6e8b88363f478d226', onClick: () => this.partialarm(), color: this.color }, index.h("lar-icon", { key: 'e069488cc386283388c82d48339fcfe429d09e4c', icon: this.bypassZones.length > 0 ? 'halflock' : 'lock' }), "\u00A0", index.h("lar-translate", { key: 'a904c8a02dd66e01e2f28e3674b539980278ad09', t: this.troubleList.length > 0 ? this.bypassZones.length > 0 ? 'area.overridePartialArm' : 'area.overridearm' : this.bypassZones.length > 0 ? 'area.partialarm' : 'area.arm' })), index.h("div", { key: '6bd714fc9d6fba22efdc20a8cfafc918afb4b02a', class: "spacer" }), index.h("div", { key: '1ec33348a229db7c430f856f19230f94a1c06a23', class: "zone-selectors" }, this.renderZoneSelector()), index.h("div", { key: '2b9856f1a1c6f870f3523bb65c926f9d4ee5cf66', class: "zone-list" }, zones) ]; } get el() { return index.getElement(this); } }; AreaBypass.style = areaCss; exports.lar_area_bypass = AreaBypass; //# sourceMappingURL=lar-area-bypass.entry.cjs.js.map