@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
263 lines (258 loc) • 13.4 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
'use strict';
var index = require('./index-B0SElCD3.js');
var reportCodesHelper = require('./report-codes-helper-B2sq9R2v.js');
var has = require('./has-1ajHnNuK.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');
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 Area = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.output = index.createEvent(this, "output");
this.request = index.createEvent(this, "request");
/////// LarvaNode base properties
/**
* Component main icon
*/
this.icon = 'security';
/**
* The color to use from your application's color palette.
* Detrouble options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`.
*/
this.color = 'primary';
/**
* Allow node indication color automatic change based on feedback/node value. Defaults to false
*/
this.allowIndicationAutoColoring = false;
/**
* Allow node color automatic change based on feedback/node value. Defaults to true
*/
this.allowNodeAutoColoring = true;
/**
* Enable quick action for security node
*/
this.enableSecurityQuickActions = false;
/**
* Is logging for this component enabled (lar-log subcomponent loaded)
*/
this.log = false;
/**
* Node size
*/
this.nodeSize = 'default';
/////// LarvaNode base properties and events - end
this.troubles = [];
this.zones = [];
this.armed = false;
this.zoneopened = false;
this.exitDelayActive = false;
this.entryDelayActive = false;
this.transactionDelay = 0;
this.alarm = false;
this.loading = true;
}
/**
* Larva input message
*/
async input(data) {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (!this.validateData(data)) {
// this may be some success response ors.
return;
}
// 8.5 Indications - Table 8 – Indication - I&HAS set / I&HAS unset
this.armed = ((_a = data.state) === null || _a === void 0 ? void 0 : _a.armed) ? true : false;
// 8.5 Indications - Table 8 – Indication - Entry indication (see 8.3.8.2) & Completion of setting (see 8.3.7) & Setting (see 8.3.4)
this.exitDelayActive = ((_b = data.state) === null || _b === void 0 ? void 0 : _b.exit_delay_active) ? true : false;
this.entryDelayActive = ((_c = data.state) === null || _c === void 0 ? void 0 : _c.entry_delay_active) ? true : false;
if (this.exitDelayActive || this.entryDelayActive) {
this.transactionDelay = this.exitDelayActive ? (_d = data.state) === null || _d === void 0 ? void 0 : _d.exit_delay_expires_in_seconds : (_e = data.state) === null || _e === void 0 ? void 0 : _e.entry_delay_expires_in_seconds;
this.transactionDelay = this.transactionDelay || 0;
this.transactionDelay = Math.round(this.transactionDelay);
}
// 8.5 Indications - Table 8 – Indication - Hold-up alarm condition, Intruder alarm condition
this.alarm = ((_f = data.state) === null || _f === void 0 ? void 0 : _f.alarm) ? true : false;
// 8.5 Indications - Table 8 – Indication - Fault conditions (see Table 1), Tamper condition, Alert indication
this.troubles = Array.isArray((_g = data.state) === null || _g === void 0 ? void 0 : _g.troubles) ? (_h = data.state) === null || _h === void 0 ? void 0 : _h.troubles : [];
// show only unacked troubles
this.troubles = this.troubles.filter(e => e.acked === null || e.acked === undefined);
// 8.5 Indications - Table 8 – Indication - Individual intrusion detector indication
this.zones = Array.isArray(data.zones) ? data.zones : [];
this.zonesString = JSON.stringify(this.zones);
this.troublesString = JSON.stringify(this.troubles);
this.loading = false;
}
/**
* Larva error input
*/
async error(data) {
if (this.node) {
this.node.error(data);
}
this.loading = false;
}
componentDidLoad() {
const el = this.el.shadowRoot || this.el;
this.node = el.querySelector('lar-node');
this.output.emit();
}
validateData(data) {
if (has.has(data, 'id') && has.has(data, 'state') && has.has(data, 'state.armed')) {
return true;
}
if (!has.has(data, 'success')) {
console.error('Area Invalid input message', data);
}
return false;
}
arm() {
this.loading = true;
return this.output.emit({ command: 'arm' });
}
partialArm(data) {
this.loading = true;
this.output.emit({ command: 'arm', override_zones: data.bypassZones, override_troubles: data.overrideTroubles });
}
disarm() {
this.loading = true;
this.output.emit({ command: 'disarm' });
}
render() {
let value = this.loading ? ' ' : 'area.disarmed';
let iconSmall = 'unlock';
let valueTranslationValues;
let iconSmallColor = this.colorIconSmall;
if (this.transactionDelayTimeout !== undefined) {
clearTimeout(this.transactionDelayTimeout);
this.transactionDelayTimeout = undefined;
}
// if ARMED, detect how its armed
if (this.armed) {
const bypassedZone = this.zones.find(z => z.overridden === true) ? true : false;
const bypassedTrouble = this.troubles.find(t => t.overridden === true) ? true : false;
const newTroubles = this.troubles.find(t => !t.overridden) ? true : false;
if (bypassedZone && bypassedTrouble) {
value = 'area.partalArmedWithTrouble';
iconSmall = 'halflock_trouble';
}
else if (bypassedTrouble) {
value = 'area.armedWithTouble';
iconSmall = 'lock_trouble';
}
else if (bypassedZone) {
value = 'area.partalArmed';
iconSmall = 'halflock';
}
else {
value = 'area.armed';
iconSmall = 'lock';
}
if (newTroubles) {
iconSmall = 'warning';
}
}
// if unarmed and we have troubles, change icon to warning
if (this.troubles.length > 0 && !this.armed) {
iconSmall = 'warning';
}
// exit delay indiction
if ((this.exitDelayActive || this.entryDelayActive) && this.transactionDelay > 0) {
value = this.exitDelayActive ? 'area.exitdelay' : 'area.entrydelay';
valueTranslationValues = { seconds: String(this.transactionDelay) };
this.transactionDelayTimeout = window.setTimeout(() => {
if (this.transactionDelay === 0) {
clearTimeout(this.transactionDelayTimeout);
}
else {
this.transactionDelay--;
}
index.forceUpdate(this.el);
}, 1000);
}
// if we have alarm state
// detect what alarm we have
if (this.alarm) {
const alarms = [];
const unresolvedRroubles = this.troubles.filter(t => (t.resolved === '' || t.resolved === null || t.resolved === undefined));
const intruderAlarm = unresolvedRroubles.find(t => (t.type_id === 0)) ? true : false;
const zoneAlarms = unresolvedRroubles.filter(t => { var _a; return t.type_id === 3 && !!((_a = t.zone) === null || _a === void 0 ? void 0 : _a.reportcode); });
const fireAlarm = zoneAlarms.find(t => { var _a; return reportCodesHelper.ReportCodesHelpers.isFireAlarm((_a = t.zone) === null || _a === void 0 ? void 0 : _a.reportcode); }) ? true : false;
const medicalAlarm = zoneAlarms.find(t => { var _a; return reportCodesHelper.ReportCodesHelpers.isMedicalAlarm((_a = t.zone) === null || _a === void 0 ? void 0 : _a.reportcode); }) ? true : false;
const panicAlarm = zoneAlarms.find(t => { var _a; return reportCodesHelper.ReportCodesHelpers.isPanicAlarm((_a = t.zone) === null || _a === void 0 ? void 0 : _a.reportcode); }) ? true : false;
const otherAlarm = zoneAlarms.find(t => { var _a; return reportCodesHelper.ReportCodesHelpers.isOtherAreaAlarm((_a = t.zone) === null || _a === void 0 ? void 0 : _a.reportcode); }) ? true : false;
if (intruderAlarm) {
alarms.push('intruder');
}
if (fireAlarm) {
alarms.push('fire');
}
if (medicalAlarm) {
alarms.push('medical');
}
if (panicAlarm) {
alarms.push('panic');
}
if (otherAlarm) {
alarms.push('other');
}
if (alarms.length === 0) {
alarms.push('other');
}
value = alarms.length > 1 ? 'area.alarms.multiple' : 'area.alarms.' + alarms[0];
iconSmall = alarms.length > 1 ? 'alarm' : alarms[0] + '_alarm';
}
if (this.allowIndicationAutoColoring && this.alarm) {
iconSmallColor = this.allowNodeAutoColoring === true ? 'light' : 'danger'; // node is collored, do not color icon
}
else if (this.allowIndicationAutoColoring) {
switch (iconSmall) {
case 'halflock_trouble':
case 'lock_trouble':
case 'halflock':
case 'warning':
iconSmallColor = 'warning';
break;
case 'unlock':
iconSmallColor = 'danger';
break;
case 'lock':
iconSmallColor = 'success';
break;
}
}
const componentProps = {
color: this.colorInputs || this.color,
colorModal: this.colorModal || this.color,
zones: this.zonesString,
troubles: this.troublesString,
armed: this.armed,
alarm: this.alarm,
zoneopened: this.zones.find(z => (z.state === 'open')) ? true : false,
hastroubles: this.troubles.length > 0,
icon: this.icon,
loading: this.loading,
onArm: () => this.arm(),
onDisarm: () => this.disarm(),
onOutput: (evt) => {
this.loading = true;
this.output.emit(evt.detail);
},
};
return [
index.h("lar-node", { key: 'f4d76b79f0f754bd1c672f2c10e853ac11838452', value: value, hideTitles: this.hideTitles, valueTranslationValues: valueTranslationValues, iconSmall: iconSmall, icon: this.icon, colorIconSmall: iconSmallColor, color: this.alarm && this.allowNodeAutoColoring === true ? 'danger' : this.color, supTitle: this.supTitle, mainTitle: this.mainTitle, subTitle: this.subTitle, colorModal: this.alarm && this.allowNodeAutoColoring === true ? 'danger' : this.colorModal, colorInputs: this.colorInputs, log: this.log, loading: this.loading, nodeSize: this.nodeSize, component: "lar-area-content", componentProps: componentProps }, this.enableSecurityQuickActions === true &&
index.h("lar-button-push", { key: 'b2a6c303bb9c096c499229f2d3acd77e31f1bd2a', size: "small", slot: "titles", color: this.colorInputs || this.color, disabled: this.loading || (this.zoneopened && !this.armed) || this.troubles.length > 0, onClick: ev => this.armed ? this.disarm() : this.arm() }), index.h("slot", { key: '8283b482e42c33b91a44cc1882be1e648a9e1920' })),
];
}
get el() { return index.getElement(this); }
};
Area.style = areaCss;
exports.lar_area = Area;
//# sourceMappingURL=lar-area.entry.cjs.js.map