mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-27 07:44:35 +02:00
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;
|
global $config;
|
||||||
include_once $config['homedir'].'/include/functions_groups.php';
|
include_once $config['homedir'].'/include/functions_groups.php';
|
||||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||||
|
include_once $config['homedir'].'/include/functions_ui.php';
|
||||||
|
|
||||||
// Get the status img src.
|
// Get the status img src.
|
||||||
$groupId = static::extractGroupId($data);
|
$groupId = static::extractGroupId($data);
|
||||||
$status = \groups_get_status($groupId);
|
$status = \groups_get_status($groupId);
|
||||||
$data['statusImageSrc'] = \visual_map_get_image_status_element(
|
$data['statusImageSrc'] = \ui_get_full_url(
|
||||||
|
\visual_map_get_image_status_element(
|
||||||
$data,
|
$data,
|
||||||
$status
|
$status
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -33,11 +33,38 @@ final class Icon extends Item
|
|||||||
{
|
{
|
||||||
$return = parent::decode($data);
|
$return = parent::decode($data);
|
||||||
$return['type'] = ICON;
|
$return['type'] = ICON;
|
||||||
$return['imageSrc'] = $this->extractImageSrc($data);
|
$return['image'] = static::extractImage($data);
|
||||||
|
$return['imageSrc'] = static::extractImageSrc($data);
|
||||||
return $return;
|
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.
|
* 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.
|
* @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(
|
return static::notEmptyStringOr(
|
||||||
static::issetInArray($data, ['imageSrc', 'image']),
|
static::issetInArray($data, ['imageSrc']),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($imageSrc === null || \strlen($imageSrc) === 0) {
|
|
||||||
throw new \InvalidArgumentException(
|
// 'images/console/icons/'.$imageSrc.'.png'
|
||||||
'the image src property is required and should be a non empty string'
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 'images/console/icons/'.$imageSrc.'.png';
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ final class StaticGraph extends Item
|
|||||||
|
|
||||||
// Load side libraries.
|
// Load side libraries.
|
||||||
global $config;
|
global $config;
|
||||||
|
include_once $config['homedir'].'/include/functions_ui.php';
|
||||||
include_once $config['homedir'].'/include/functions_visual_map.php';
|
include_once $config['homedir'].'/include/functions_visual_map.php';
|
||||||
|
|
||||||
// Get the linked module Id.
|
// Get the linked module Id.
|
||||||
@ -176,17 +177,15 @@ final class StaticGraph extends Item
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the img src.
|
// 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.
|
// Get last value.
|
||||||
if (isset($data['show_last_value']) && $data['show_last_value'] !== 2) {
|
if (isset($data['show_last_value']) && $data['show_last_value'] !== 2) {
|
||||||
$img_style_title = '';
|
$img_style_title = '';
|
||||||
|
|
||||||
$unit_text = \trim(
|
$unit_text = \trim(\io_safe_output(\modules_get_unit($moduleId)));
|
||||||
\io_safe_output(
|
|
||||||
\modules_get_unit($moduleId)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$value = \modules_get_last_value($moduleId);
|
$value = \modules_get_last_value($moduleId);
|
||||||
|
|
||||||
|
@ -77,36 +77,6 @@ try {
|
|||||||
$visualConsoleData = $visualConsole->toArray();
|
$visualConsoleData = $visualConsole->toArray();
|
||||||
$visualConsoleName = $visualConsoleData['name'];
|
$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>';
|
echo '<div id="visual-console-container" style="margin:0px auto;position:relative;"></div>';
|
||||||
|
|
||||||
// Floating menu - Start.
|
// Floating menu - Start.
|
||||||
@ -141,6 +111,7 @@ echo '</div>';
|
|||||||
$visualConsoleItems = VisualConsole::getItemsFromDB($visualConsoleId);
|
$visualConsoleItems = VisualConsole::getItemsFromDB($visualConsoleId);
|
||||||
|
|
||||||
ui_require_javascript_file('pandora_visual_console');
|
ui_require_javascript_file('pandora_visual_console');
|
||||||
|
visual_map_load_client_resources();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user