Merge branch 'ent-9530-Carrefour-Volver-a-poner-el-cuadro-naranja-en-las-consolas-visuales-cuando-hay-una-alerta' into 'develop'
implemented alert warning in visual consoles See merge request artica/pandorafms!5329
This commit is contained in:
commit
851ee9f4d5
|
@ -553,6 +553,4 @@ final class Container extends Model
|
|||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -2619,4 +2620,108 @@ 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=[])
|
||||
{
|
||||
if (isset($item['type']) === true) {
|
||||
$excludedItemTypes = [
|
||||
22,
|
||||
17,
|
||||
18,
|
||||
1,
|
||||
23,
|
||||
15,
|
||||
14,
|
||||
10,
|
||||
4,
|
||||
];
|
||||
|
||||
if (in_array($item['type'], $excludedItemTypes) === true) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$agentID = (int) $item['id_agent'];
|
||||
$agentModuleID = (int) $item['id_agente_modulo'];
|
||||
$linkedLayoutID = (int) $item['id_layout_linked'];
|
||||
$metaconsoleID = (int) $item['id_metaconsole'];
|
||||
|
||||
$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
|
||||
);
|
||||
|
||||
// Connect to node.
|
||||
if (\is_metaconsole() === true
|
||||
&& \metaconsole_connect(null, $metaconsoleID) !== NOERR
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'error connecting to the node'
|
||||
);
|
||||
}
|
||||
|
||||
$firedAlert = db_get_sql($alerts_sql);
|
||||
|
||||
// Restore connection.
|
||||
if (\is_metaconsole() === true) {
|
||||
\metaconsole_restore_db();
|
||||
}
|
||||
|
||||
// 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',
|
||||
'id_metaconsole',
|
||||
]
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -74,6 +74,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.visual-console-item.is-alert-triggered {
|
||||
border: 3px 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
|
@ -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) {
|
||||
|
@ -887,8 +893,13 @@ abstract class VisualConsoleItem<Props extends ItemProps> {
|
|||
) {
|
||||
if (this.meta.editMode && this.meta.maintenanceMode === false) {
|
||||
this.elementRef.classList.add("is-editing");
|
||||
this.elementRef.classList.remove("is-alert-triggered");
|
||||
} else {
|
||||
this.elementRef.classList.remove("is-editing");
|
||||
|
||||
if (this.props.alertOutline) {
|
||||
this.elementRef.classList.add("is-alert-triggered");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.visual-console-item.is-alert-triggered {
|
||||
border: 3px solid #f36201;
|
||||
}
|
||||
|
||||
.visual-console-spinner {
|
||||
background-color: transparent;
|
||||
margin: 0px auto;
|
||||
|
|
Loading…
Reference in New Issue