@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
321 lines (302 loc) • 12.9 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { r as registerInstance, c as createEvent, f as forceUpdate, h, g as getElement } from './index-C4h1muVj.js';
import { m as map } from './map-C29-xOJP.js';
import { s as sortBy, f as forOwn } from './sortBy-CwYoYzqo.js';
import { s as setToArray, S as SetCache, c as cacheHas } from './_baseMap-kP2T3hT_.js';
import { S as Set } from './_getTag-CFse-dEC.js';
import { g as groupBy } from './groupBy-_4PRCRNk.js';
import './_hasPath-BgJxJEDp.js';
import './isArray-C_HhfJYh.js';
import './isObjectLike-CIR68wtF.js';
import './global-C56buD75.js';
import './_isIndex-DgTx77bC.js';
import './isLength-BBM_tGdM.js';
import './isObject-C7eoH3L1.js';
import './_setToString-CpaW37bP.js';
import './_getAllKeys-C08dM1uK.js';
import './_defineProperty-CWEcucM9.js';
import './_baseAssignValue-DAaC80vH.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 = class {
constructor(hostRef) {
registerInstance(this, hostRef);
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 getElement(this); }
};
AreaBypass.style = areaCss;
export { AreaBypass as lar_area_bypass };
//# sourceMappingURL=lar-area-bypass.entry.js.map