Visual Console Refactor: fixed some items

Former-commit-id: dbe93abb76ffb1e6e82492b8f2be380bc422bb3d
This commit is contained in:
Alejandro Gallardo Escobar 2019-04-22 10:05:54 +02:00
parent a03245a277
commit 37c562f210
5 changed files with 42 additions and 36 deletions

View File

@ -326,8 +326,8 @@ final class Container extends Model
/**
* Obtain a list of items which belong to the Visual Console.
*
* @param integer $layoutId Identifier of the Visual Console.
* @param array $aclUserGroups Groups can access user.
* @param integer $layoutId Identifier of the Visual Console.
* @param array $groupsFilter Groups can access user.
*
* @return array A list of items.
* @throws \Exception When the data cannot be retrieved from the DB.

View File

@ -804,11 +804,8 @@ class Item extends Model
$moduleName = \db_get_value_filter(
'nombre',
'tmetaconsole_agent',
[
'id_agente' => $agentId,
'id_tmetaconsole_setup' => $metaconsoleId,
]
'tagente_modulo',
['id_agente_modulo' => $moduleId]
);
// Restore connection.

View File

@ -150,15 +150,15 @@ final class Group extends Item
$groupId = static::extractGroupId($data);
$status = \groups_get_status($groupId);
$data['statusImageSrc'] = \ui_get_full_url(
\visual_map_get_image_status_element(
$data,
$status
)
\visual_map_get_image_status_element($data, $status),
false,
false,
false
);
// If the width and height are equal to 0.
// We need to know the width and height of the image.
if ($data['width'] == 0 && $data['height'] == 0) {
// If the width or the height are equal to 0 we will extract them
// from the real image size.
if ((int) $data['width'] === 0 || (int) $data['height'] === 0) {
$sizeImage = getimagesize($data['statusImageSrc']);
$data['width'] = $sizeImage[0];
$data['height'] = $sizeImage[1];

View File

@ -113,12 +113,15 @@ final class Icon extends Item
// Get the img src.
$data['imageSrc'] = \ui_get_full_url(
\visual_map_get_image_status_element($data)
\visual_map_get_image_status_element($data),
false,
false,
false
);
// If the width and height are equal to 0.
// We need to know the width and height of the image.
if ($data['width'] == 0 && $data['height'] == 0) {
// If the width or the height are equal to 0 we will extract them
// from the real image size.
if ((int) $data['width'] === 0 || (int) $data['height'] === 0) {
$sizeImage = getimagesize($data['imageSrc']);
$data['width'] = $sizeImage[0];
$data['height'] = $sizeImage[1];

View File

@ -41,8 +41,10 @@ final class StaticGraph extends Item
{
$return = parent::decode($data);
$return['type'] = STATIC_GRAPH;
$return['imageSrc'] = $this->extractImageSrc($data);
$return['showLastValueTooltip'] = $this->extractShowLastValueTooltip($data);
$return['imageSrc'] = static::extractImageSrc($data);
$return['showLastValueTooltip'] = static::extractShowLastValueTooltip(
$data
);
$return['statusImageSrc'] = static::notEmptyStringOr(
static::issetInArray($data, ['statusImageSrc']),
null
@ -65,7 +67,7 @@ final class StaticGraph extends Item
*
* @throws \InvalidArgumentException When a valid image src can't be found.
*/
private function extractImageSrc(array $data): string
private static function extractImageSrc(array $data): string
{
$imageSrc = static::notEmptyStringOr(
static::issetInArray($data, ['imageSrc', 'image']),
@ -90,7 +92,7 @@ final class StaticGraph extends Item
*
* @return string
*/
private function extractShowLastValueTooltip(array $data): string
private static function extractShowLastValueTooltip(array $data): string
{
$showLastValueTooltip = static::notEmptyStringOr(
static::issetInArray($data, ['showLastValueTooltip']),
@ -178,40 +180,44 @@ final class StaticGraph extends Item
// Get the img src.
$data['statusImageSrc'] = \ui_get_full_url(
\visual_map_get_image_status_element($data)
\visual_map_get_image_status_element($data),
false,
false,
false
);
// If the width and height are equal to 0.
// We need to know the width and height of the image.
if ($data['width'] == 0 && $data['height'] == 0) {
// If the width or the height are equal to 0 we will extract them
// from the real image size.
if ((int) $data['width'] === 0 || (int) $data['height'] === 0) {
$sizeImage = getimagesize($data['statusImageSrc']);
$data['width'] = $sizeImage[0];
$data['height'] = $sizeImage[1];
}
// Get last value.
if (isset($data['show_last_value']) && $data['show_last_value'] !== 2 && $moduleId !== 0) {
$showLastValueTooltip = static::extractShowLastValueTooltip($data);
if ($showLastValueTooltip !== 'disabled' && $moduleId > 0) {
$imgTitle = '';
$unit_text = \trim(\io_safe_output(\modules_get_unit($moduleId)));
$unit = \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)
$isBooleanModule = \modules_is_boolean($moduleId);
if (!$isBooleanModule
|| ($isBooleanModule && $showLastValueTooltip !== 'default')
) {
if (\is_numeric($value)) {
$imgTitle .= __('Last value: ').remove_right_zeros($value);
} else {
$imgTitle .= __('Last value: ').$value;
}
}
if (empty($unit_text) === false && empty($imgTitle) === false) {
$imgTitle .= ' '.$unit_text;
}
if (empty($unit) === false && empty($imgTitle) === false) {
$imgTitle .= ' '.$unit;
}
$data['lastValue'] = $imgTitle;
$data['lastValue'] = $imgTitle;
}
}
// Restore connection.