Added last value in StaticGraph

Former-commit-id: 1cdf967b8bb05eff14b22684e8960c60d5b1d397
This commit is contained in:
Daniel Maya 2019-04-12 12:34:25 +02:00
parent 73e5dcf7f2
commit 7ddc4a70f1
2 changed files with 45 additions and 1 deletions

View File

@ -47,6 +47,10 @@ final class StaticGraph extends Item
static::issetInArray($data, ['statusImageSrc']),
null
);
$return['lastValue'] = static::notEmptyStringOr(
static::issetInArray($data, ['lastValue']),
null
);
return $return;
}
@ -174,6 +178,35 @@ final class StaticGraph extends Item
// Get the img src.
$data['statusImageSrc'] = \visual_map_get_image_status_element($data);
// Get last value.
if (isset($data['show_last_value']) && $data['show_last_value'] !== 2) {
$img_style_title = '';
$unit_text = \trim(
\io_safe_output(
\modules_get_unit($moduleId)
)
);
$value = \modules_get_last_value($moduleId);
if ((!\modules_is_boolean($moduleId))
|| (\modules_is_boolean($moduleId) && $data['show_last_value'] != 0)
) {
if (\is_numeric($value)) {
$img_style_title .= __('Last value: ').remove_right_zeros($value);
} else {
$img_style_title .= __('Last value: ').$value;
}
}
if (empty($unit_text) === false && empty($img_style_title) === false) {
$img_style_title .= ' '.$unit_text;
}
$data['lastValue'] = $img_style_title;
}
// Restore connection.
if ($nodeConnected === true) {
\metaconsole_restore_db();

View File

@ -16,6 +16,7 @@ export type StaticGraphProps = {
imageSrc: string; // URL?
showLastValueTooltip: "default" | "enabled" | "disabled";
statusImageSrc: string | null; // URL?
lastValue: string | null;
} & ItemProps &
(WithModuleProps | LinkedVisualConsoleProps);
@ -58,6 +59,7 @@ export function staticGraphPropsDecoder(
imageSrc: data.imageSrc,
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
statusImageSrc: notEmptyStringOr(data.statusImageSrc, null),
lastValue: notEmptyStringOr(data.lastValue, null),
...modulePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
};
@ -69,7 +71,16 @@ export default class StaticGraph extends Item<StaticGraphProps> {
img.className = "static-graph";
img.src = this.props.statusImageSrc || this.props.imageSrc;
// TODO: Show last value in a tooltip.
// Show last value in a tooltip.
if (
this.props.lastValue !== null &&
this.props.showLastValueTooltip !== "disabled"
) {
img.className = "static-graph image forced_title";
img.setAttribute("data-use_title_for_force_title", "1");
img.setAttribute("data-title", this.props.lastValue);
img.alt = this.props.lastValue;
}
return img;
}