@larva.io/webcomponents
Version:
Fentrica SmartUnits WebComponents package
580 lines (546 loc) • 18.5 kB
JavaScript
/*!
* (C) Fentrica http://fentrica.com - Seee LICENSE.md
*/
import { r as registerInstance, c as createEvent, h } from './index-C4h1muVj.js';
import { R as ReportCodesHelpers, d as distExports } from './report-codes-helper-BN3DZ42s.js';
import { h as hooks } from './moment-DAuPur-P.js';
import { e as baseGet, h as hasIn } from './_baseMap-kP2T3hT_.js';
import { a as assignValue, g as getPrototype, c as copyObject, b as getAllKeysIn, d as baseClone } from './_baseClone-DRQcJxio.js';
import { c as castPath, t as toKey, a as arrayMap } from './_hasPath-BgJxJEDp.js';
import { i as isIndex } from './_isIndex-DgTx77bC.js';
import { i as isObject } from './isObject-C7eoH3L1.js';
import { a as baseFlatten, s as setToString, o as overRest, b as baseOrderBy } from './_setToString-CpaW37bP.js';
import { i as isObjectLike, b as baseGetTag } from './isObjectLike-CIR68wtF.js';
import { k as keys } from './_getAllKeys-C08dM1uK.js';
import { i as isArray } from './isArray-C_HhfJYh.js';
import { b as config } from './config-Bt4QT_oL.js';
import './_getTag-CFse-dEC.js';
import './isLength-BBM_tGdM.js';
import './_baseAssignValue-DAaC80vH.js';
import './_defineProperty-CWEcucM9.js';
import './global-C56buD75.js';
/**
* The base implementation of `_.set`.
*
* @private
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to set.
* @param {*} value The value to set.
* @param {Function} [customizer] The function to customize path creation.
* @returns {Object} Returns `object`.
*/
function baseSet(object, path, value, customizer) {
if (!isObject(object)) {
return object;
}
path = castPath(path, object);
var index = -1,
length = path.length,
lastIndex = length - 1,
nested = object;
while (nested != null && ++index < length) {
var key = toKey(path[index]),
newValue = value;
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
return object;
}
if (index != lastIndex) {
var objValue = nested[key];
newValue = undefined;
if (newValue === undefined) {
newValue = isObject(objValue)
? objValue
: (isIndex(path[index + 1]) ? [] : {});
}
}
assignValue(nested, key, newValue);
nested = nested[key];
}
return object;
}
/**
* The base implementation of `_.pickBy` without support for iteratee shorthands.
*
* @private
* @param {Object} object The source object.
* @param {string[]} paths The property paths to pick.
* @param {Function} predicate The function invoked per property.
* @returns {Object} Returns the new object.
*/
function basePickBy(object, paths, predicate) {
var index = -1,
length = paths.length,
result = {};
while (++index < length) {
var path = paths[index],
value = baseGet(object, path);
if (predicate(value, path)) {
baseSet(result, castPath(path, object), value);
}
}
return result;
}
/**
* The base implementation of `_.pick` without support for individual
* property identifiers.
*
* @private
* @param {Object} object The source object.
* @param {string[]} paths The property paths to pick.
* @returns {Object} Returns the new object.
*/
function basePick(object, paths) {
return basePickBy(object, paths, function(value, path) {
return hasIn(object, path);
});
}
/**
* Flattens `array` a single level deep.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to flatten.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flatten([1, [2, [3, [4]], 5]]);
* // => [1, 2, [3, [4]], 5]
*/
function flatten(array) {
var length = array == null ? 0 : array.length;
return length ? baseFlatten(array) : [];
}
/**
* A specialized version of `baseRest` which flattens the rest array.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @returns {Function} Returns the new function.
*/
function flatRest(func) {
return setToString(overRest(func, undefined, flatten), func + '');
}
/**
* Creates an object composed of the picked `object` properties.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {...(string|string[])} [paths] The property paths to pick.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.pick(object, ['a', 'c']);
* // => { 'a': 1, 'c': 3 }
*/
var pick = flatRest(function(object, paths) {
return object == null ? {} : basePick(object, paths);
});
/**
* Gets the last element of `array`.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to query.
* @returns {*} Returns the last element of `array`.
* @example
*
* _.last([1, 2, 3]);
* // => 3
*/
function last(array) {
var length = array == null ? 0 : array.length;
return length ? array[length - 1] : undefined;
}
/**
* The base implementation of `_.slice` without an iteratee call guard.
*
* @private
* @param {Array} array The array to slice.
* @param {number} [start=0] The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the slice of `array`.
*/
function baseSlice(array, start, end) {
var index = -1,
length = array.length;
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
end = end > length ? length : end;
if (end < 0) {
end += length;
}
length = start > end ? 0 : ((end - start) >>> 0);
start >>>= 0;
var result = Array(length);
while (++index < length) {
result[index] = array[index + start];
}
return result;
}
/**
* Gets the parent value at `path` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} path The path to get the parent value of.
* @returns {*} Returns the parent value.
*/
function parent(object, path) {
return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
}
/**
* The base implementation of `_.unset`.
*
* @private
* @param {Object} object The object to modify.
* @param {Array|string} path The property path to unset.
* @returns {boolean} Returns `true` if the property is deleted, else `false`.
*/
function baseUnset(object, path) {
path = castPath(path, object);
object = parent(object, path);
return object == null || delete object[toKey(last(path))];
}
/** `Object#toString` result references. */
var objectTag = '[object Object]';
/** Used for built-in method references. */
var funcProto = Function.prototype,
objectProto = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to infer the `Object` constructor. */
var objectCtorString = funcToString.call(Object);
/**
* Checks if `value` is a plain object, that is, an object created by the
* `Object` constructor or one with a `[[Prototype]]` of `null`.
*
* @static
* @memberOf _
* @since 0.8.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @example
*
* function Foo() {
* this.a = 1;
* }
*
* _.isPlainObject(new Foo);
* // => false
*
* _.isPlainObject([1, 2, 3]);
* // => false
*
* _.isPlainObject({ 'x': 0, 'y': 0 });
* // => true
*
* _.isPlainObject(Object.create(null));
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
return false;
}
var proto = getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor &&
funcToString.call(Ctor) == objectCtorString;
}
/**
* Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
* objects.
*
* @private
* @param {*} value The value to inspect.
* @param {string} key The key of the property to inspect.
* @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
*/
function customOmitClone(value) {
return isPlainObject(value) ? undefined : value;
}
/** Used to compose bitmasks for cloning. */
var CLONE_DEEP_FLAG = 1,
CLONE_FLAT_FLAG = 2,
CLONE_SYMBOLS_FLAG = 4;
/**
* The opposite of `_.pick`; this method creates an object composed of the
* own and inherited enumerable property paths of `object` that are not omitted.
*
* **Note:** This method is considerably slower than `_.pick`.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The source object.
* @param {...(string|string[])} [paths] The property paths to omit.
* @returns {Object} Returns the new object.
* @example
*
* var object = { 'a': 1, 'b': '2', 'c': 3 };
*
* _.omit(object, ['a', 'c']);
* // => { 'b': '2' }
*/
var omit = flatRest(function(object, paths) {
var result = {};
if (object == null) {
return result;
}
var isDeep = false;
paths = arrayMap(paths, function(path) {
path = castPath(path, object);
isDeep || (isDeep = path.length > 1);
return path;
});
copyObject(object, getAllKeysIn(object), result);
if (isDeep) {
result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
}
var length = paths.length;
while (length--) {
baseUnset(result, paths[length]);
}
return result;
});
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
return arrayMap(props, function(key) {
return object[key];
});
}
/**
* Creates an array of the own enumerable string keyed property values of `object`.
*
* **Note:** Non-object values are coerced to objects.
*
* @static
* @since 0.1.0
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property values.
* @example
*
* function Foo() {
* this.a = 1;
* this.b = 2;
* }
*
* Foo.prototype.c = 3;
*
* _.values(new Foo);
* // => [1, 2] (iteration order is not guaranteed)
*
* _.values('hi');
* // => ['h', 'i']
*/
function values(object) {
return object == null ? [] : baseValues(object, keys(object));
}
/**
* This method is like `_.sortBy` except that it allows specifying the sort
* orders of the iteratees to sort by. If `orders` is unspecified, all values
* are sorted in ascending order. Otherwise, specify an order of "desc" for
* descending or "asc" for ascending sort order of corresponding values.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
* The iteratees to sort by.
* @param {string[]} [orders] The sort orders of `iteratees`.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
* @returns {Array} Returns the new sorted array.
* @example
*
* var users = [
* { 'user': 'fred', 'age': 48 },
* { 'user': 'barney', 'age': 34 },
* { 'user': 'fred', 'age': 40 },
* { 'user': 'barney', 'age': 36 }
* ];
*
* // Sort by `user` in ascending order and by `age` in descending order.
* _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
* // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
*/
function orderBy(collection, iteratees, orders, guard) {
if (collection == null) {
return [];
}
if (!isArray(iteratees)) {
iteratees = iteratees == null ? [] : [iteratees];
}
orders = orders;
if (!isArray(orders)) {
orders = orders == null ? [] : [orders];
}
return baseOrderBy(collection, iteratees, orders);
}
const logModalCss = "slot-fb[hidden],slot[hidden]{display:initial !important}.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%}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}h4{padding:0;margin:0;white-space:break-spaces}.date,small{color:var(--lar-text-color-step-150, rgb(216.75, 216.75, 216.75)) !important}lar-badge{margin-top:0.2rem;margin-right:0.3rem;font-weight:normal}";
const LogModal = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.request = createEvent(this, "request");
this.config = config;
/**
* Larva sub-components request event
*/
this.logreceived = false;
/**
* Larva sub-components request event
*/
this.logdata = [];
this.logcount = 0;
}
/**
* Request response method
*/
async response(data) {
if (this.modal) {
this.modal.setAttribute('icon-small', '');
}
this.logreceived = true;
this.logdata = data.logs;
this.logcount = data.count;
}
componentDidLoad() {
this.request.emit(); // request logs
}
/**
* Display Larva Error
*/
async error(data, timeout = 5000) {
this.logreceived = true;
let msg = 'error_messages.';
if (typeof data === 'string') {
msg += data;
}
else if (data && data.message && typeof data.message === 'string') {
msg += data.message;
}
else {
msg += 'UNKNOWN_ERROR';
}
h("lar-translate", { t: msg });
// this.notify.create(translate, 'danger', timeout); // @TODO: error notify
}
// @ts-ignore
static parseData(data, eventCode) {
let ret = {};
if (data && ReportCodesHelpers.isSecurityEvent(eventCode)) { // alarm zone info
ret = pick(data, ['name', 'sn', 'io', 'state', 'zone']);
}
else {
ret = omit(data, ['user', 'flow']);
}
return values(ret).toString();
}
renderLogList() {
const logs = [];
const logdata = orderBy(this.logdata, 'createdAt', 'desc');
const formatDateTime = this.config.get('formatDateTime', 'DD.MM.YYYY HH:mm');
if (logdata.length === 0) {
logs.push(h("lar-list-header", null, h("lar-translate", { t: "log.nologs" })));
return logs;
}
let prevMonth;
let prevYear;
logdata.forEach(logitem => {
let color = 'tertiary';
let icon = 'info';
const date = hooks(new Date(logitem.createdAt));
const month = date.month() + 1;
const year = date.year();
const code = Number(logitem.code);
const logLevel = distExports.getLogLevel(code);
const message = distExports.getEventMessage(code);
const qualify = Number(logitem.qualify);
if (prevMonth !== month || prevYear !== year) {
logs.push(h("lar-list-header", null, h("lar-translate", { t: 'date.months.' + month }), " ", year));
prevMonth = month;
prevYear = year;
}
if (logLevel === distExports.LogLevel.ERROR) {
color = 'danger';
}
else if (logLevel === distExports.LogLevel.WARNING) {
color = 'warning';
}
// if issue is resolved issue, change color to green
if (qualify === distExports.Qualify.RESTORE) {
color = 'success';
}
if (ReportCodesHelpers.isUserEvent(code)) {
icon = 'user';
}
else if (ReportCodesHelpers.isSecurityEvent(code)) {
icon = 'warning';
if (ReportCodesHelpers.isFireAlarm(code)) {
icon = 'fire_alarm';
}
if (ReportCodesHelpers.isMedicalAlarm(code)) {
icon = 'medical_alarm';
}
if (ReportCodesHelpers.isPanicAlarm(code)) {
icon = 'panic_alarm';
}
if (ReportCodesHelpers.isOtherAreaAlarm(code)) {
icon = 'other_alarm';
}
}
else if (ReportCodesHelpers.isCloudEvent(code)) {
icon = 'cloud';
}
else if (ReportCodesHelpers.isSystemEvent(code)) {
icon = 'device';
}
logs.push(h("lar-list-item", null, h("div", { slot: "start", class: "circle" }, h("lar-icon", { icon: icon, color: color })), h("div", null, h("div", { class: "date" }, h("small", null, hooks(new Date(logitem.createdAt)).format(formatDateTime))), h("h4", null, h("lar-translate", { t: 'log_entries.' + code, fallback: message })), h("div", null, logitem.data && logitem.data.user &&
h("small", null, logitem.data.user.firstname, " ", logitem.data.user.lastname)), logitem.data &&
h("div", null, h("small", null, LogModal.parseData(logitem.data, code))), qualify === distExports.Qualify.RESTORE &&
h("div", null, h("small", null, h("lar-badge", { color: "success" }, code === distExports.ReportEvent.SECURITY_PARTIAL_ARMED_DISARMED || code === distExports.ReportEvent.SECURITY_ARMED_DISARMED
? // if arm arm/disarm event then NEW = disrarm, RESTORE = arm
h("lar-translate", { t: "log.armed" })
:
h("lar-translate", { t: "log.resolved" })))))));
});
return logs;
}
render() {
return [
h("div", { key: 'ff4fda3f33471cd7c103e7bea437448152fe69e5' }, this.logreceived &&
h("lar-list", { key: '28f2ec6bdce7fc267bbf2e09e3943c2ca233e087' }, this.renderLogList()))
];
}
};
LogModal.style = logModalCss;
export { LogModal as lar_log_modal };
//# sourceMappingURL=lar-log-modal.entry.js.map