Merge branch 'ent-7143-Autoajuste-de-la-consola-visual' into 'develop'

Ent 7143 autoajuste de la consola visual

See merge request artica/pandorafms!4218
This commit is contained in:
Daniel Rodriguez 2021-06-29 10:02:13 +00:00
commit 397eebd86c
26 changed files with 195 additions and 50 deletions

View File

@ -11,4 +11,6 @@ UPDATE `tuser_task_scheduled` SET
`args`= REPLACE(`args`, 's:15:"first_execution"', 'i:2;s:0:"";i:7;s:3:"PDF";s:15:"first_execution"')
WHERE `id_user_task` = 2;
ALTER TABLE `tlayout` ADD COLUMN `auto_adjust` INTEGER UNSIGNED NOT NULL default 0;
COMMIT;

View File

@ -1665,6 +1665,8 @@ UPDATE tlayout SET is_favourite = 1 WHERE name REGEXP '^(' OR name REGEXP '^
ALTER TABLE `tlayout` MODIFY COLUMN `is_favourite` int(10) unsigned NOT NULL DEFAULT '0';
ALTER TABLE `tlayout` ADD COLUMN `auto_adjust` INTEGER UNSIGNED NOT NULL default 0;
-- ---------------------------------------------------------------------
-- Table `tlayout_data`
-- ---------------------------------------------------------------------

View File

@ -222,6 +222,9 @@ $table->data[5][1] .= '<span class="opt" style="visibility:hidden;">
$table->data[6][0] = __('Favourite visual console');
$table->data[6][1] = html_print_checkbox('is_favourite', 0, $is_favourite, true);
$table->data[7][0] = __('Auto adjust to screen in fullscreen');
$table->data[7][1] = html_print_checkbox('auto_adjust', 0, $auto_adjust, true);
if ($action == 'new') {
$textButtonSubmit = __('Save');
$classButtonSubmit = 'sub wand';
@ -427,6 +430,22 @@ $(document).ready (function () {
}
});
if($("#checkbox-auto_adjust").is(":checked")) {
$("#hidden-auto_adjust_sent").val(1);
}
else{
$("#hidden-auto_adjust_sent").val(0);
}
$("#checkbox-auto_adjust").change(function(){
if($(this).is(":checked")) {
$("#hidden-auto_adjust_sent").val(1);
}
else{
$("#hidden-auto_adjust_sent").val(0);
}
});
function metaconsole_url() {
metaconsole = $("input[name='metaconsole_activated']").val();
if( metaconsole == 0 || metaconsole === undefined){

View File

@ -151,6 +151,7 @@ switch ($activeTab) {
$height = '';
$visualConsoleName = '';
$is_favourite = 0;
$auto_adjust = 0;
break;
case 'update':
@ -162,6 +163,7 @@ switch ($activeTab) {
$height = (int) get_parameter('height');
$visualConsoleName = (string) get_parameter('name');
$is_favourite = (int) get_parameter('is_favourite_sent');
$auto_adjust = (int) get_parameter('auto_adjust_sent');
// ACL for the new visual console
// $vconsole_read_new = check_acl ($config['id_user'], $idGroup, "VR");
@ -186,6 +188,7 @@ switch ($activeTab) {
'width' => $width,
'height' => $height,
'is_favourite' => $is_favourite,
'auto_adjust' => $auto_adjust,
];
$error = $_FILES['background_image']['error'];
@ -353,6 +356,7 @@ switch ($activeTab) {
$width = $visualConsole['width'];
$height = $visualConsole['height'];
$is_favourite = $visualConsole['is_favourite'];
$auto_adjust = $visualConsole['auto_adjust'];
break;
}
break;

View File

@ -737,6 +737,13 @@ function loadVisualConsoleData(baseUrl, vcId, size, id_user, hash, callback) {
)
.done(handleSuccess("props"))
.fail(handleFail);
var queryString = new URLSearchParams(window.location.search);
var widthScreen = 0;
if (queryString.get("width")) {
widthScreen = document.body.offsetWidth;
}
// Visual Console items request.
itemsJqXHR = jQuery
// .get(apiPath + "/visual-consoles/" + vcId + "/items", null, "json")
@ -748,7 +755,8 @@ function loadVisualConsoleData(baseUrl, vcId, size, id_user, hash, callback) {
size: size,
visualConsoleId: vcId,
id_user: typeof id_user == undefined ? id_user : null,
auth_hash: typeof hash == undefined ? hash : null
auth_hash: typeof hash == undefined ? hash : null,
widthScreen: widthScreen
},
"json"
)

View File

@ -86,6 +86,8 @@ if ($getVisualConsole === true) {
$size = get_parameter('size', []);
$width = get_parameter('widthScreen', 0);
$ratio = 0;
if (isset($size) === true
&& is_array($size) === true
@ -107,10 +109,16 @@ if ($getVisualConsole === true) {
}
}
$widthRatio = 0;
if ($visualConsoleData['autoAdjust'] === true && $width > 0) {
$widthRatio = ($width / $visualConsoleData['width']);
}
$vcItems = VisualConsole::getItemsFromDB(
$visualConsoleId,
$aclUserGroups,
$ratio
$ratio,
$widthRatio
);
echo '['.implode(',', $vcItems).']';

View File

@ -72,17 +72,17 @@ abstract class CachedModel extends Model
*
* @overrides Model::fromDB.
*/
public static function fromDB(array $filter, ?float $ratio=0): Model
public static function fromDB(array $filter, ?float $ratio=0, ?float $widthRatio=0): Model
{
global $config;
$save_cache = false;
if ($ratio == 0 && $filter['cache_expiration'] > 0) {
if ($ratio == 0 && $filter['cache_expiration'] > 0 && $widthRatio == 0) {
$data = static::fetchCachedData($filter);
$save_cache = true;
}
if (isset($data) === false) {
$data = static::fetchDataFromDB($filter, $ratio);
$data = static::fetchDataFromDB($filter, $ratio, $widthRatio);
} else {
// Retrieved from cache.
$save_cache = false;

View File

@ -130,7 +130,8 @@ abstract class Model
*/
abstract protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
);
@ -141,10 +142,10 @@ abstract class Model
*
* @return self A modeled element's instance.
*/
public static function fromDB(array $filter, ?float $ratio=0): self
public static function fromDB(array $filter, ?float $ratio=0, ?float $widthRatio=0): self
{
// The reserved word static refers to the invoked class at runtime.
return static::fromArray(static::fetchDataFromDB($filter, $ratio));
return static::fromArray(static::fetchDataFromDB($filter, $ratio, $widthRatio));
}

View File

@ -84,6 +84,7 @@ final class Container extends Model
'backgroundImage' => static::extractBackgroundImage($data),
'backgroundColor' => static::extractBackgroundColor($data),
'isFavorite' => static::extractFavorite($data),
'autoAdjust' => static::extractAutoAdjust($data),
'width' => (int) $data['width'],
'height' => (int) $data['height'],
'backgroundURL' => static::extractBackgroundUrl($data),
@ -252,6 +253,21 @@ final class Container extends Model
}
/**
* Extract the "auto adjust" switch value.
*
* @param array $data Unknown input data structure.
*
* @return boolean If the item is favorite or not.
*/
private static function extractAutoAdjust(array $data): bool
{
return static::parseBool(
static::issetInArray($data, ['auto_adjust', 'autoAdjust'])
);
}
/**
* Obtain a container data structure from the database using a filter.
*
@ -264,7 +280,8 @@ final class Container extends Model
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
) {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
@ -387,7 +404,8 @@ final class Container extends Model
public static function getItemsFromDB(
int $layoutId,
array $groupsFilter=[],
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Default filter.
$filter = ['id_layout' => $layoutId];
@ -438,7 +456,7 @@ final class Container extends Model
$class = static::getItemClass((int) $data['type']);
try {
array_push($items, $class::fromDB($data, $ratio));
array_push($items, $class::fromDB($data, $ratio, $widthRatio));
} catch (\Throwable $e) {
error_log('VC[Container]: '.$e->getMessage());
}

View File

@ -765,7 +765,8 @@ class Item extends CachedModel
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Load side libraries.
global $config;
@ -805,6 +806,11 @@ class Item extends CachedModel
$row['pos_y'] = ($row['pos_y'] * $ratio);
}
if ($widthRatio != 0) {
$row['width'] = ($row['width'] * $widthRatio);
$row['pos_x'] = ($row['pos_x'] * $widthRatio);
}
return $row;
}

View File

@ -192,11 +192,12 @@ final class BarsGraph extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -419,11 +419,12 @@ final class Clock extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
// Default values.
if ((int) $data['width'] === 0) {

View File

@ -280,11 +280,12 @@ final class ColorCloud extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -89,11 +89,12 @@ final class DonutGraph extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -82,11 +82,12 @@ final class EventsHistory extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -204,11 +204,12 @@ final class Group extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -98,11 +98,12 @@ final class Icon extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -194,7 +194,8 @@ final class Line extends Model
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
@ -211,6 +212,11 @@ final class Line extends Model
$row['pos_y'] = ($row['pos_y'] * $ratio);
}
if ($widthRatio != 0) {
$row['width'] = ($row['width'] * $widthRatio);
$row['pos_x'] = ($row['pos_x'] * $widthRatio);
}
return $row;
}

View File

@ -266,11 +266,12 @@ final class ModuleGraph extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -359,7 +359,8 @@ final class NetworkLink extends Model
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
@ -376,6 +377,11 @@ final class NetworkLink extends Model
$row['pos_y'] = ($row['pos_y'] * $ratio);
}
if ($widthRatio != 0) {
$row['width'] = ($row['width'] * $widthRatio);
$row['pos_x'] = ($row['pos_x'] * $widthRatio);
}
$row['label'] = static::buildLabels($row);
return $row;

View File

@ -330,11 +330,12 @@ final class Percentile extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -230,11 +230,12 @@ final class SimpleValue extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -143,11 +143,12 @@ final class StaticGraph extends Item
*/
protected static function fetchDataFromDB(
array $filter,
?float $ratio=0
?float $ratio=0,
?float $widthRatio=0
): array {
// Due to this DB call, this function cannot be unit tested without
// a proper mock.
$data = parent::fetchDataFromDB($filter, $ratio);
$data = parent::fetchDataFromDB($filter, $ratio, $widthRatio);
/*
* Retrieve extra data.

View File

@ -77,6 +77,9 @@ $pure = (bool) get_parameter('pure', $config['pure']);
// Refresh interval in seconds.
$refr = (int) get_parameter('refr', $config['vc_refr']);
$width = (int) get_parameter('width', 0);
$height = (int) get_parameter('height', 0);
// Load Visual Console.
use Models\VisualConsole\Container as VisualConsole;
$visualConsole = null;
@ -200,7 +203,7 @@ $options['view']['active'] = true;
if (is_metaconsole() === false) {
if (!$config['pure']) {
$options['pure']['text'] = '<a href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$visualConsoleId.'&pure=1&refr='.$refr.'">'.html_print_image(
$options['pure']['text'] = '<a id ="full_screen" href="index.php?sec=network&sec2=operation/visual_console/render_view&id='.$visualConsoleId.'&pure=1&refr='.$refr.'">'.html_print_image(
'images/full_screen.png',
true,
[
@ -489,11 +492,47 @@ ui_require_javascript_file('pandora_visual_console');
include_javascript_d3();
visual_map_load_client_resources();
$widthRatio = 0;
if ($width > 0 && $pure == 1) {
$widthRatio = ($width / $visualConsoleData['width']);
if ($visualConsoleData['width'] > $height) {
?>
<style type="text/css">
div#main_pure {
width: 100%;
}
div#visual-console-container {
width: 100% !important;
}
</style>
<?php
} else {
?>
<style type="text/css">
div#main_pure {
width: 100%;
display: flex;
align-items: center;
}
div#visual-console-container {
width: 100% !important;
}
</style>
<?php
}
}
// Load Visual Console Items.
$visualConsoleItems = VisualConsole::getItemsFromDB(
$visualConsoleId,
$aclUserGroups
$aclUserGroups,
0,
$widthRatio
);
ui_require_css_file('modal');
ui_require_css_file('form');
?>
@ -506,6 +545,7 @@ ui_require_css_file('form');
var items = <?php echo '['.implode(',', $visualConsoleItems).']'; ?>;
var baseUrl = "<?php echo ui_get_full_url('/', false, false, false); ?>";
var controls = document.getElementById('vc-controls');
autoHideElement(controls, 1000);
var handleUpdate = function (prevProps, newProps) {
if (!newProps) return;
@ -683,6 +723,19 @@ if ($edit_capable === true) {
visualConsoleManager.createItem(type);
});
$('#full_screen').click(function (e) {
e.preventDefault();
if (props.autoAdjust === true) {
var hrefAux = $('#full_screen').attr('href');
hrefAux += '&width=' + document.body.offsetWidth+'&height=' + screen.height;
$('#full_screen').attr('href', hrefAux);
}
window.location.href = $('#full_screen').attr('href');
});
/**
* Process ajax responses and shows a dialog with results.
*/

View File

@ -1626,6 +1626,7 @@ CREATE TABLE IF NOT EXISTS `tlayout` (
`width` INTEGER UNSIGNED NOT NULL default 0,
`background_color` varchar(50) NOT NULL default '#FFF',
`is_favourite` INTEGER UNSIGNED NOT NULL default 0,
`auto_adjust` INTEGER UNSIGNED NOT NULL default 0,
PRIMARY KEY(`id`)
) ENGINE = InnoDB DEFAULT CHARSET=utf8;

View File

@ -1334,18 +1334,18 @@ UPDATE `tnotification_source` SET `enabled`=1 WHERE `description` = 'System&#x20
--
INSERT INTO `tlayout`
VALUES
(1, 'Demo&#x20;visual console', 0, 'fondo.jpg', 1080, 1920, 'white', 0),
(2,'Demo&#x20;visual console 2',0,'fondo-keep-alive.jpg',1080,1920,'#FFF',0),
(3,'Worldmap',0,'map_world.jpg',1080,1920,'white',0),
(4,'Europe',0,'map_europe_1.jpg',1080,1920,'white',0),
(5,'USA',0,'map_USA.jpg',1080,1920,'white',0),
(6,'Spain',0,'map_spain.jpg',1080,1920,'white',0),
(7,'Madrid',0,'map_madrid.jpg',1080,1920,'white',0),
(8,'Germany',0,'map_germany_1.jpg',1080,1920,'white',0),
(9,'France',0,'map_france.jpg',1080,1920,'white',0),
(10,'Catalonia',0,'map_catalonia.jpg',1080,1920,'white',0),
(11,'Basque&#x20;Country',0,'map_basque-country.jpg',1080,1920,'white',0),
(12,'Andalusia',0,'map_andalusia.jpg',1080,1920,'white',0)
(1, 'Demo&#x20;visual console', 0, 'fondo.jpg', 1080, 1920, 'white', 0, 0),
(2,'Demo&#x20;visual console 2',0,'fondo-keep-alive.jpg',1080,1920,'#FFF',0, 0),
(3,'Worldmap',0,'map_world.jpg',1080,1920,'white',0, 0),
(4,'Europe',0,'map_europe_1.jpg',1080,1920,'white',0, 0),
(5,'USA',0,'map_USA.jpg',1080,1920,'white',0, 0),
(6,'Spain',0,'map_spain.jpg',1080,1920,'white',0, 0),
(7,'Madrid',0,'map_madrid.jpg',1080,1920,'white',0, 0),
(8,'Germany',0,'map_germany_1.jpg',1080,1920,'white',0, 0),
(9,'France',0,'map_france.jpg',1080,1920,'white',0, 0),
(10,'Catalonia',0,'map_catalonia.jpg',1080,1920,'white',0, 0),
(11,'Basque&#x20;Country',0,'map_basque-country.jpg',1080,1920,'white',0, 0),
(12,'Andalusia',0,'map_andalusia.jpg',1080,1920,'white',0, 0)
;
--