implemented alert warning in visual consoles

This commit is contained in:
alejandro.campos@artica.es 2022-12-13 12:03:13 +01:00
parent e3c46ab7d6
commit 79e9597dd5
9 changed files with 93 additions and 5 deletions

View File

@ -553,6 +553,4 @@ final class Container extends Model
return $item;
}
}

View File

@ -209,6 +209,7 @@ class Item extends CachedModel
'x' => static::extractX($data),
'y' => static::extractY($data),
'cacheExpiration' => static::extractCacheExpiration($data),
'alertOutline' => static::checkLayoutAlertsRecursive($data),
];
if (static::$useLinkedModule === true) {
@ -2614,4 +2615,74 @@ class Item extends CachedModel
}
/**
* Recursively check for alerts in a Visual Console item and its linked layout.
*
* @param array $item The Visual Console item to check for alerts.
* @param array $visitedLayouts A list of layouts that have already been visited to avoid circular references.
*
* @return boolean True if an alert has been found, false otherwise.
*/
public static function checkLayoutAlertsRecursive(array $item, array $visitedLayouts=[])
{
$agentID = (int) $item['id_agent'];
$agentModuleID = (int) $item['id_agente_modulo'];
$linkedLayoutID = (int) $item['id_layout_linked'];
$visitedLayouts[] = $item['id_layout'];
if ($agentModuleID !== 0 && $agentID !== 0) {
$alerts_sql = sprintf(
'SELECT talert_template_modules.id
FROM talert_template_modules
INNER JOIN tagente_modulo t2
ON talert_template_modules.id_agent_module = t2.id_agente_modulo
INNER JOIN tagente t3
ON t2.id_agente = t3.id_agente AND t3.id_agente = %d
INNER JOIN talert_templates t4
ON talert_template_modules.id_alert_template = t4.id
WHERE `id_agent_module` = %d AND talert_template_modules.times_fired > 0',
$agentID,
$agentModuleID
);
$firedAlert = db_get_sql($alerts_sql);
// Item has a triggered alert.
if ($firedAlert !== false) {
return true;
}
}
if ($linkedLayoutID === 0 || in_array($linkedLayoutID, $visitedLayouts) === true) {
// Item has no linked layout or it has already been visited (avoid infinite loop caused by circular references).
return false;
}
$filter = ['id_layout' => $linkedLayoutID];
$linkedLayoutItems = \db_get_all_rows_filter(
'tlayout_data',
$filter,
[
'id_layout',
'id_agent',
'id_agente_modulo',
'id_layout_linked',
]
);
if ($linkedLayoutItems === false) {
// There are no items in the linked visual console. Nothing to check.
return false;
}
foreach ($linkedLayoutItems as $linkedLayoutItem) {
if (self::checkLayoutAlertsRecursive($linkedLayoutItem, $visitedLayouts)) {
return true;
}
}
return false;
}
}

View File

@ -186,6 +186,11 @@ final class EventsHistory extends Item
*/
protected static function buildLink(array $data)
{
$link = parent::buildLink($data);
if ($link !== null) {
return $link;
}
// Get the linked agent and module Ids.
$linkedModule = static::extractLinkedModule($data);
$agentId = static::parseIntOr($linkedModule['agentId'], null);

View File

@ -74,6 +74,10 @@
}
}
.visual-console-item.is-alert-triggered {
border: 2px solid #f36201;
}
.visual-console-spinner {
background-color: transparent;
margin: 0px auto;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -66,6 +66,7 @@ export interface ItemProps extends Position, Size {
cacheExpiration: number | null;
colorStatus: string;
cellId: number | null;
alertOutline: boolean;
}
export interface ItemClickEvent {
@ -143,6 +144,7 @@ export function itemBasePropsDecoder(data: AnyObject): ItemProps | never {
cacheExpiration: parseIntOr(data.cacheExpiration, null),
colorStatus: notEmptyStringOr(data.colorStatus, "#CCC"),
cellId: parseIntOr(data.cellId, null),
alertOutline: parseBoolean(data.alertOutline),
...sizePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
...positionPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
};
@ -534,6 +536,10 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
box.style.left = `${this.props.x}px`;
box.style.top = `${this.props.y}px`;
if (this.props.alertOutline) {
box.classList.add("is-alert-triggered");
}
// Init the click listeners.
box.addEventListener("dblclick", e => {
if (!this.meta.isBeingMoved && !this.meta.isBeingResized) {

View File

@ -74,6 +74,10 @@
}
}
.visual-console-item.is-alert-triggered {
border: 2px solid #f36201;
}
.visual-console-spinner {
background-color: transparent;
margin: 0px auto;