UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

374 lines (354 loc) 14.7 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ import { p as proxyCustomElement, H, c as createEvent, f as forceUpdate, h } from './p-AOwgnAK2.js'; import { m as map } from './p-jfT03zNm.js'; import { s as sortBy, f as forOwn } from './p-C45Zg0QW.js'; import { s as setToArray, S as SetCache, c as cacheHas } from './p-C7LWA9xi.js'; import { S as Set } from './p-Cvhpe3ZV.js'; import { g as groupBy } from './p-Pkz17Qo1.js'; import { d as defineCustomElement$7 } from './p-DzVmQ9SH.js'; import { d as defineCustomElement$6 } from './p-BiG3U7GV.js'; import { d as defineCustomElement$5 } from './p-C9VBtzS4.js'; import { d as defineCustomElement$4 } from './p-BcSt9bUd.js'; import { d as defineCustomElement$3 } from './p-DwjVtK9p.js'; import { d as defineCustomElement$2 } from './p-B-fmI6sr.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 = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { return new 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 setToArray(set); } isCommon = false; includes = cacheHas; seen = new 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 = /*@__PURE__*/ proxyCustomElement(class AreaBypass extends H { constructor(registerHost) { super(); if (registerHost !== false) { this.__registerHost(); } this.__attachShadow(); this.output = 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); } 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(h("lar-button", { onClick: () => this.bypassAutoSelect('', true), color: "danger", size: "small", class: "zone-group", expand: "block", outline: true }, h("lar-translate", { t: "area.faultedOrTampered" }))); } const filteredZones = this.zonesList.filter(z => !z.persistent && z.group !== ''); const allGroups = map(filteredZones, 'group'); const groups = uniq(allGroups); groups.forEach(group => { if (group === null || group === undefined) { return; } selectors.push(h("lar-button", { color: this.color, onClick: () => this.bypassAutoSelect(group), size: "small", expand: "block", class: "zone-group", outline: true }, h("lar-translate", { t: (group || '<no name>') }))); }); selectors.push(h("lar-button", { color: "warning", onClick: () => this.bypassAutoSelect(), size: "small", class: "zone-group", expand: "block", outline: true }, 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(JSON.parse(this.zones), 'group'); this.troubleList = JSON.parse(this.troubles); const groupedZones = groupBy(this.zonesList, 'group'); forOwn(groupedZones, (groupedZonesOwn, group) => { zones.push(h("lar-list-header", null, h("lar-translate", { t: group }))); 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(h("lar-list-item", { disabled: this.isZoneByPassed(zone), onClick: () => { this.togglePyPassZone(zone); }, style: { cursor: 'pointer' } }, h("div", { slot: "start", class: "circle" }, h("lar-icon", { icon: zone.type, color: color })), h("div", null, h("h4", null, h("lar-translate", { t: zone.name })), h("lar-badge", { color: color }, h("lar-translate", { t: 'area.zone_state.' + zone.state })), zone.overridden && h("span", null, "\u00A0", h("lar-badge", { color: "danger" }, h("lar-translate", { t: 'area.zone_state.bypassed' })))))); }); }); return [ h("h4", { key: 'a639c373104330dce549c827228b90fa7b637f36', class: "center" }, this.troubleList.length > 0 ? 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' } }) : h("lar-translate", { t: "area.overrideZonesInfo", values: { zones: this.bypassZones.length > 0 ? this.bypassZones.length : '0' } })), h("div", { key: '175ee2779e2be92ceafcbf94b5bbdf3c579e0d8c', class: "spacer" }), h("lar-button", { key: '04ca711a74cf8c1ccdddf2b6e8b88363f478d226', onClick: () => this.partialarm(), color: this.color }, h("lar-icon", { key: 'e069488cc386283388c82d48339fcfe429d09e4c', icon: this.bypassZones.length > 0 ? 'halflock' : 'lock' }), "\u00A0", 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' })), h("div", { key: '6bd714fc9d6fba22efdc20a8cfafc918afb4b02a', class: "spacer" }), h("div", { key: '1ec33348a229db7c430f856f19230f94a1c06a23', class: "zone-selectors" }, this.renderZoneSelector()), h("div", { key: '2b9856f1a1c6f870f3523bb65c926f9d4ee5cf66', class: "zone-list" }, zones) ]; } get el() { return this; } static get style() { return areaCss; } }, [257, "lar-area-bypass", { "color": [1], "zones": [1], "troubles": [1], "modal": [8], "bypassZones": [32] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["lar-area-bypass", "lar-badge", "lar-button", "lar-icon", "lar-list-header", "lar-list-item", "lar-translate"]; components.forEach(tagName => { switch (tagName) { case "lar-area-bypass": if (!customElements.get(tagName)) { customElements.define(tagName, AreaBypass); } break; case "lar-badge": if (!customElements.get(tagName)) { defineCustomElement$7(); } break; case "lar-button": if (!customElements.get(tagName)) { defineCustomElement$6(); } break; case "lar-icon": if (!customElements.get(tagName)) { defineCustomElement$5(); } break; case "lar-list-header": if (!customElements.get(tagName)) { defineCustomElement$4(); } break; case "lar-list-item": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "lar-translate": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } defineCustomElement$1(); const LarAreaBypass = AreaBypass; const defineCustomElement = defineCustomElement$1; export { LarAreaBypass, defineCustomElement }; //# sourceMappingURL=lar-area-bypass.js.map //# sourceMappingURL=lar-area-bypass.js.map