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. * Obtain a list of items which belong to the Visual Console.
* *
* @param integer $layoutId Identifier of the Visual Console. * @param integer $layoutId Identifier of the Visual Console.
* @param array $aclUserGroups Groups can access user. * @param array $groupsFilter Groups can access user.
* *
* @return array A list of items. * @return array A list of items.
* @throws \Exception When the data cannot be retrieved from the DB. * @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( $moduleName = \db_get_value_filter(
'nombre', 'nombre',
'tmetaconsole_agent', 'tagente_modulo',
[ ['id_agente_modulo' => $moduleId]
'id_agente' => $agentId,
'id_tmetaconsole_setup' => $metaconsoleId,
]
); );
// Restore connection. // Restore connection.

View File

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

View File

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

View File

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