Visual Console Refactor: fixed some image urls to load them from the public view
Former-commit-id: 833a5529304b343ac22a0d054ced47d48667c306
This commit is contained in:
parent
3cda4523b4
commit
75d0e11dac
|
@ -144,13 +144,16 @@ final class Group extends Item
|
|||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_groups.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
|
||||
// Get the status img src.
|
||||
$groupId = static::extractGroupId($data);
|
||||
$status = \groups_get_status($groupId);
|
||||
$data['statusImageSrc'] = \visual_map_get_image_status_element(
|
||||
$data,
|
||||
$status
|
||||
$data['statusImageSrc'] = \ui_get_full_url(
|
||||
\visual_map_get_image_status_element(
|
||||
$data,
|
||||
$status
|
||||
)
|
||||
);
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -33,11 +33,38 @@ final class Icon extends Item
|
|||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = ICON;
|
||||
$return['imageSrc'] = $this->extractImageSrc($data);
|
||||
$return['image'] = static::extractImage($data);
|
||||
$return['imageSrc'] = static::extractImageSrc($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid image can't be found.
|
||||
*/
|
||||
private static function extractImage(array $data)
|
||||
{
|
||||
$image = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['image']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($image === null) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the image property is required and should be a non empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image src value.
|
||||
*
|
||||
|
@ -47,20 +74,49 @@ final class Icon extends Item
|
|||
*
|
||||
* @throws \InvalidArgumentException When a valid image src can't be found.
|
||||
*/
|
||||
private function extractImageSrc(array $data)
|
||||
private static function extractImageSrc(array $data)
|
||||
{
|
||||
$imageSrc = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc', 'image']),
|
||||
return static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc']),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if ($imageSrc === null || \strlen($imageSrc) === 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the image src property is required and should be a non empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return 'images/console/icons/'.$imageSrc.'.png';
|
||||
// 'images/console/icons/'.$imageSrc.'.png'
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a vc item data structure from the database using a filter.
|
||||
*
|
||||
* @param array $filter Filter of the Visual Console Item.
|
||||
*
|
||||
* @return array The Visual Console Item data structure stored into the DB.
|
||||
* @throws \InvalidArgumentException When an agent Id cannot be found.
|
||||
*
|
||||
* @override Item::fetchDataFromDB.
|
||||
*/
|
||||
protected static function fetchDataFromDB(array $filter): array
|
||||
{
|
||||
// Due to this DB call, this function cannot be unit tested without
|
||||
// a proper mock.
|
||||
$data = parent::fetchDataFromDB($filter);
|
||||
|
||||
/*
|
||||
* Retrieve extra data.
|
||||
*/
|
||||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
// Get the img src.
|
||||
$data['imageSrc'] = \ui_get_full_url(
|
||||
\visual_map_get_image_status_element($data)
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -149,6 +149,7 @@ final class StaticGraph extends Item
|
|||
|
||||
// Load side libraries.
|
||||
global $config;
|
||||
include_once $config['homedir'].'/include/functions_ui.php';
|
||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||
|
||||
// Get the linked module Id.
|
||||
|
@ -176,17 +177,15 @@ final class StaticGraph extends Item
|
|||
}
|
||||
|
||||
// Get the img src.
|
||||
$data['statusImageSrc'] = \visual_map_get_image_status_element($data);
|
||||
$data['statusImageSrc'] = \ui_get_full_url(
|
||||
\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)
|
||||
)
|
||||
);
|
||||
$unit_text = \trim(\io_safe_output(\modules_get_unit($moduleId)));
|
||||
|
||||
$value = \modules_get_last_value($moduleId);
|
||||
|
||||
|
|
|
@ -77,36 +77,6 @@ try {
|
|||
$visualConsoleData = $visualConsole->toArray();
|
||||
$visualConsoleName = $visualConsoleData['name'];
|
||||
|
||||
// TODO: Extract to a function.
|
||||
$baseUrl = ui_get_full_url(false, false, false, false);
|
||||
$vcClientPath = 'include/visual-console-client';
|
||||
$dir = $config['homedir'].'/'.$vcClientPath;
|
||||
if (is_dir($dir)) {
|
||||
$dh = opendir($dir);
|
||||
if ($dh) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file === '.' || $file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
preg_match('/.*.js$/', $file, $match, PREG_OFFSET_CAPTURE);
|
||||
if (empty($match) === false) {
|
||||
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
|
||||
echo '<script type="text/javascript" src="'.$url.'"></script>';
|
||||
continue;
|
||||
}
|
||||
|
||||
preg_match('/.*.css$/', $file, $match, PREG_OFFSET_CAPTURE);
|
||||
if (empty($match) === false) {
|
||||
$url = $baseUrl.$vcClientPath.'/'.$match[0][0];
|
||||
echo '<link type="text/css" rel="stylesheet" href="'.$url.'" />';
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
echo '<div id="visual-console-container" style="margin:0px auto;position:relative;"></div>';
|
||||
|
||||
// Floating menu - Start.
|
||||
|
@ -141,6 +111,7 @@ echo '</div>';
|
|||
$visualConsoleItems = VisualConsole::getItemsFromDB($visualConsoleId);
|
||||
|
||||
ui_require_javascript_file('pandora_visual_console');
|
||||
visual_map_load_client_resources();
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
Loading…
Reference in New Issue