Merge branch 'ent-6583-Bug-estado-de-elementos-consola-visual' into 'develop'

Mode ghost for disabled modules and agents

See merge request artica/pandorafms!3889
This commit is contained in:
Daniel Rodriguez 2021-03-22 14:10:14 +00:00
commit 6294910e29
16 changed files with 157 additions and 58 deletions

View File

@ -3272,12 +3272,6 @@ function visual_map_get_status_element($layoutData)
} }
} }
$module_value = db_get_sql(
'SELECT datos
FROM tagente_estado
WHERE id_agente_modulo = '.$layoutData['id_agente_modulo']
);
// Linked to other layout ?? - Only if not module defined // Linked to other layout ?? - Only if not module defined
if (!empty($layoutData['id_layout_linked'])) { if (!empty($layoutData['id_layout_linked'])) {
if (!empty($layoutData['linked_layout_node_id'])) { if (!empty($layoutData['linked_layout_node_id'])) {
@ -3379,6 +3373,11 @@ function visual_map_get_status_element($layoutData)
case PERCENTILE_BUBBLE: case PERCENTILE_BUBBLE:
case CIRCULAR_PROGRESS_BAR: case CIRCULAR_PROGRESS_BAR:
case CIRCULAR_INTERIOR_PROGRESS_BAR: case CIRCULAR_INTERIOR_PROGRESS_BAR:
$module_value = db_get_sql(
'SELECT datos
FROM tagente_estado
WHERE id_agente_modulo = '.$layoutData['id_agente_modulo']
);
if (empty($module_value) || $module_value == '') { if (empty($module_value) || $module_value == '') {
return VISUAL_MAP_STATUS_UNKNOWN; return VISUAL_MAP_STATUS_UNKNOWN;
@ -3907,9 +3906,19 @@ function visual_map_get_layout_status($layout_id, $status_data=[], $depth=0)
return VISUAL_MAP_STATUS_UNKNOWN; return VISUAL_MAP_STATUS_UNKNOWN;
} }
$layout_items = db_get_all_rows_filter( $layout_items = db_get_all_rows_sql(
'tlayout_data', sprintf(
['id_layout' => $layout_id] 'SELECT tld.*
FROM tlayout_data tld
LEFT JOIN tagente ta
ON ta.id_agente=tld.id_agent
LEFT JOIN tagente_modulo tam
ON tam.id_agente_modulo = tld.id_agente_modulo
WHERE tld.id_layout = %d
AND (ta.disabled = 0 OR ta.disabled is null)
AND (tam.disabled = 0 OR tam.disabled is null)',
$layout_id
)
); );
if ($layout_items === false) { if ($layout_items === false) {

View File

@ -455,7 +455,6 @@ function createVisualConsole(
}, },
createItem: function(typeString) { createItem: function(typeString) {
var type; var type;
console.log(typeString);
switch (typeString) { switch (typeString) {
case "STATIC_GRAPH": case "STATIC_GRAPH":
type = 0; type = 0;

View File

@ -242,6 +242,13 @@ class Item extends CachedModel
); );
} }
$decodedData['agentDisabled'] = static::parseBool(
$data['agentDisabled']
);
$decodedData['moduleDisabled'] = static::parseBool(
$data['moduleDisabled']
);
return $decodedData; return $decodedData;
} }
@ -939,7 +946,7 @@ class Item extends CachedModel
if (\is_metaconsole()) { if (\is_metaconsole()) {
$sql = sprintf( $sql = sprintf(
'SELECT nombre, alias, direccion, comentarios 'SELECT nombre, alias, direccion, comentarios, `disabled`
FROM tmetaconsole_agent FROM tmetaconsole_agent
WHERE id_tagente = %s and id_tmetaconsole_setup = %s', WHERE id_tagente = %s and id_tmetaconsole_setup = %s',
$agentId, $agentId,
@ -947,7 +954,7 @@ class Item extends CachedModel
); );
} else { } else {
$sql = sprintf( $sql = sprintf(
'SELECT nombre, alias, direccion, comentarios 'SELECT nombre, alias, direccion, comentarios, `disabled`
FROM tagente FROM tagente
WHERE id_agente = %s', WHERE id_agente = %s',
$agentId $agentId
@ -966,6 +973,7 @@ class Item extends CachedModel
$agentData['agentAlias'] = $agent['alias']; $agentData['agentAlias'] = $agent['alias'];
$agentData['agentDescription'] = $agent['comentarios']; $agentData['agentDescription'] = $agent['comentarios'];
$agentData['agentAddress'] = $agent['direccion']; $agentData['agentAddress'] = $agent['direccion'];
$agentData['agentDisabled'] = $agent['disabled'];
return \io_safe_output($agentData); return \io_safe_output($agentData);
} }
@ -1026,7 +1034,7 @@ class Item extends CachedModel
} }
$sql = sprintf( $sql = sprintf(
'SELECT nombre, descripcion 'SELECT nombre, descripcion, `disabled`
FROM tagente_modulo FROM tagente_modulo
WHERE id_agente_modulo = %s', WHERE id_agente_modulo = %s',
$moduleId $moduleId
@ -1046,6 +1054,7 @@ class Item extends CachedModel
$moduleData['moduleName'] = $moduleName['nombre']; $moduleData['moduleName'] = $moduleName['nombre'];
$moduleData['moduleDescription'] = $moduleName['descripcion']; $moduleData['moduleDescription'] = $moduleName['descripcion'];
$moduleData['moduleDisabled'] = $moduleName['disabled'];
return \io_safe_output($moduleData); return \io_safe_output($moduleData);
} }
@ -1076,6 +1085,12 @@ class Item extends CachedModel
$baseUrl = \ui_get_full_url('index.php'); $baseUrl = \ui_get_full_url('index.php');
if ((bool) $data['agentDisabled'] === true
|| (bool) $data['moduleDisabled'] === true
) {
return null;
}
// TODO: There's a feature to get the link from the label. // TODO: There's a feature to get the link from the label.
if (static::$useLinkedVisualConsole === true if (static::$useLinkedVisualConsole === true
&& $linkedVisualConsole['linkedLayoutId'] !== null && $linkedVisualConsole['linkedLayoutId'] !== null

View File

@ -133,7 +133,8 @@ final class StaticGraph extends Item
/** /**
* Fetch a vc item data structure from the database using a filter. * Fetch a vc item data structure from the database using a filter.
* *
* @param array $filter Filter of the Visual Console Item. * @param array $filter Filter of the Visual Console Item.
* @param float|null $ratio Ratio.
* *
* @return array The Visual Console Item data structure stored into the DB. * @return array The Visual Console Item data structure stored into the DB.
* @throws \InvalidArgumentException When an agent Id cannot be found. * @throws \InvalidArgumentException When an agent Id cannot be found.
@ -171,44 +172,57 @@ final class StaticGraph extends Item
throw new \InvalidArgumentException('missing module Id'); throw new \InvalidArgumentException('missing module Id');
} }
// Get the img src. if ((bool) $data['agentDisabled'] === false
// There's no need to connect to the metaconsole before searching for && (bool) $data['moduleDisabled'] === false
// the image status cause the function itself does that for us. ) {
$imagePath = \visual_map_get_image_status_element($data); // Get the img src.
$data['statusImageSrc'] = \ui_get_full_url( // There's no need to connect to the metaconsole before searching
$imagePath, // for the image status cause the function itself does that for us.
false, $imagePath = \visual_map_get_image_status_element($data);
false, $data['statusImageSrc'] = \ui_get_full_url(
false $imagePath,
); false,
false,
false
);
$status = \visual_map_get_status_element($data); $status = \visual_map_get_status_element($data);
// Magic numbers from the hell. // Magic numbers from the hell.
switch ($status) { switch ($status) {
case 1: case 1:
case 4: case 4:
// Critical or critical alert (BAD). // Critical or critical alert (BAD).
$data['colorStatus'] = COL_CRITICAL; $data['colorStatus'] = COL_CRITICAL;
break; break;
case 0: case 0:
// Normal (OK). // Normal (OK).
$data['colorStatus'] = COL_NORMAL; $data['colorStatus'] = COL_NORMAL;
break; break;
case 2: case 2:
case 10: case 10:
// Warning or warning alert. // Warning or warning alert.
$data['colorStatus'] = COL_WARNING; $data['colorStatus'] = COL_WARNING;
break; break;
case 3: case 3:
// Unknown. // Unknown.
default: default:
// Default is Grey (Other). // Default is Grey (Other).
$data['colorStatus'] = COL_UNKNOWN; $data['colorStatus'] = COL_UNKNOWN;
break; break;
}
} else {
$data['colorStatus'] = COL_UNKNOWN;
$imagePath = 'images/console/icons/'.$data['image'].'.png';
$data['statusImageSrc'] = \ui_get_full_url(
$imagePath,
false,
false,
false
);
} }
// If the width or the height are equal to 0 we will extract them // If the width or the height are equal to 0 we will extract them
@ -359,7 +373,6 @@ final class StaticGraph extends Item
'label' => __('Module'), 'label' => __('Module'),
'arguments' => [ 'arguments' => [
'type' => 'autocomplete_module', 'type' => 'autocomplete_module',
'fields' => $fields,
'name' => 'moduleId', 'name' => 'moduleId',
'selected' => $values['moduleId'], 'selected' => $values['moduleId'],
'return' => true, 'return' => true,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -75,9 +75,14 @@ export default class BarsGraph extends Item<BarsGraphProps> {
element.className = "bars-graph"; element.className = "bars-graph";
element.style.backgroundImage = `url(${this.props.html})`; element.style.backgroundImage = `url(${this.props.html})`;
element.style.backgroundRepeat = "no-repeat"; element.style.backgroundRepeat = "no-repeat";
element.style.backgroundSize = `${this.props.width}px ${ element.style.backgroundSize = `${this.props.width}px ${this.props.height}px`;
this.props.height
}px`; if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
return element; return element;
} }
@ -85,8 +90,13 @@ export default class BarsGraph extends Item<BarsGraphProps> {
protected updateDomElement(element: HTMLElement): void { protected updateDomElement(element: HTMLElement): void {
element.style.backgroundImage = `url(${this.props.html})`; element.style.backgroundImage = `url(${this.props.html})`;
element.style.backgroundRepeat = "no-repeat"; element.style.backgroundRepeat = "no-repeat";
element.style.backgroundSize = `${this.props.width}px ${ element.style.backgroundSize = `${this.props.width}px ${this.props.height}px`;
this.props.height
}px`; if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
} }
} }

View File

@ -410,6 +410,13 @@ export default class ColorCloud extends Item<ColorCloudProps> {
defs.append(radialGradient); defs.append(radialGradient);
svg.append(defs, circle); svg.append(defs, circle);
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
svg.setAttribute("opacity", "0.2");
}
return svg; return svg;
} }

View File

@ -56,6 +56,13 @@ export default class DonutGraph extends Item<DonutGraphProps> {
element.className = "donut-graph"; element.className = "donut-graph";
element.innerHTML = this.props.html; element.innerHTML = this.props.html;
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
// Hack to execute the JS after the HTML is added to the DOM. // Hack to execute the JS after the HTML is added to the DOM.
const scripts = element.getElementsByTagName("script"); const scripts = element.getElementsByTagName("script");
for (let i = 0; i < scripts.length; i++) { for (let i = 0; i < scripts.length; i++) {

View File

@ -48,6 +48,13 @@ export default class EventsHistory extends Item<EventsHistoryProps> {
element.className = "events-history"; element.className = "events-history";
element.innerHTML = this.props.html; element.innerHTML = this.props.html;
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
// Hack to execute the JS after the HTML is added to the DOM. // Hack to execute the JS after the HTML is added to the DOM.
const scripts = element.getElementsByTagName("script"); const scripts = element.getElementsByTagName("script");
for (let i = 0; i < scripts.length; i++) { for (let i = 0; i < scripts.length; i++) {

View File

@ -97,6 +97,12 @@ export default class ModuleGraph extends Item<ModuleGraphProps> {
element.innerHTML = this.props.html; element.innerHTML = this.props.html;
element.className = "module-graph"; element.className = "module-graph";
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
// Remove the overview graph. // Remove the overview graph.
const legendP = element.getElementsByTagName("p"); const legendP = element.getElementsByTagName("p");

View File

@ -261,6 +261,13 @@ export default class Percentile extends Item<PercentileProps> {
break; break;
} }
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
svg.setAttribute("opacity", "0.2");
}
if (svg !== null) element.append(svg); if (svg !== null) element.append(svg);
return element; return element;

View File

@ -22,7 +22,8 @@ export type SimpleValueProps = {
| { | {
processValue: "avg" | "max" | "min"; processValue: "avg" | "max" | "min";
period: number; period: number;
}) & }
) &
ItemProps & ItemProps &
WithModuleProps & WithModuleProps &
LinkedVisualConsoleProps; LinkedVisualConsoleProps;
@ -95,6 +96,13 @@ export default class SimpleValue extends Item<SimpleValueProps> {
const element = document.createElement("div"); const element = document.createElement("div");
element.className = "simple-value"; element.className = "simple-value";
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
if (this.props.valueType === "image") { if (this.props.valueType === "image") {
const img = document.createElement("img"); const img = document.createElement("img");
img.src = this.props.value; img.src = this.props.value;

View File

@ -78,6 +78,13 @@ export default class StaticGraph extends Item<StaticGraphProps> {
element.style.backgroundSize = "contain"; element.style.backgroundSize = "contain";
element.style.backgroundPosition = "center"; element.style.backgroundPosition = "center";
if (
this.props.agentDisabled === true ||
this.props.moduleDisabled === true
) {
element.style.opacity = "0.2";
}
// Show last value in a tooltip. // Show last value in a tooltip.
if ( if (
this.props.lastValue !== null && this.props.lastValue !== null &&

View File

@ -177,7 +177,8 @@ export function agentPropsDecoder(data: AnyObject): WithAgentProps {
agentName: notEmptyStringOr(data.agentName, null), agentName: notEmptyStringOr(data.agentName, null),
agentAlias: notEmptyStringOr(data.agentAlias, null), agentAlias: notEmptyStringOr(data.agentAlias, null),
agentDescription: notEmptyStringOr(data.agentDescription, null), agentDescription: notEmptyStringOr(data.agentDescription, null),
agentAddress: notEmptyStringOr(data.agentAddress, null) agentAddress: notEmptyStringOr(data.agentAddress, null),
agentDisabled: parseBoolean(data.agentDisabled)
}; };
return data.metaconsoleId != null return data.metaconsoleId != null
@ -198,6 +199,7 @@ export function modulePropsDecoder(data: AnyObject): WithModuleProps {
moduleId: parseIntOr(data.moduleId, null), moduleId: parseIntOr(data.moduleId, null),
moduleName: notEmptyStringOr(data.moduleName, null), moduleName: notEmptyStringOr(data.moduleName, null),
moduleDescription: notEmptyStringOr(data.moduleDescription, null), moduleDescription: notEmptyStringOr(data.moduleDescription, null),
moduleDisabled: parseBoolean(data.moduleDisabled),
...agentPropsDecoder(data) // Object spread: http://es6-features.org/#SpreadOperator ...agentPropsDecoder(data) // Object spread: http://es6-features.org/#SpreadOperator
}; };
} }

View File

@ -23,12 +23,14 @@ export interface WithAgentProps {
agentAlias: string | null; agentAlias: string | null;
agentDescription: string | null; agentDescription: string | null;
agentAddress: string | null; agentAddress: string | null;
agentDisabled: boolean;
} }
export interface WithModuleProps extends WithAgentProps { export interface WithModuleProps extends WithAgentProps {
moduleId: number | null; moduleId: number | null;
moduleName: string | null; moduleName: string | null;
moduleDescription: string | null; moduleDescription: string | null;
moduleDisabled: boolean;
} }
export type LinkedVisualConsolePropsStatus = export type LinkedVisualConsolePropsStatus =