Update visual console
This commit is contained in:
parent
dffe03aaa8
commit
aafba795ee
pandora_console
godmode/reporting
include
javascript
rest-api
operation/visual_console
visual_console_client/src
|
@ -761,7 +761,7 @@ $buttons['consoles_list'] = [
|
|||
];
|
||||
$buttons['public_link'] = [
|
||||
'active' => false,
|
||||
'text' => '<a href="'.ui_get_full_url('operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$idVisualConsole.'&id_user='.$config['id_user']).'">'.html_print_image('images/camera_mc.png', true, ['title' => __('Show link to public Visual Console')]).'</a>',
|
||||
'text' => '<a href="'.ui_get_full_url('operation/visual_console/public_console.php?hash='.$hash.'&refr='.$refr.'&id_layout='.$idVisualConsole.'&id_user='.$config['id_user']).'">'.html_print_image('images/camera_mc.png', true, ['title' => __('Show link to public Visual Console')]).'</a>',
|
||||
];
|
||||
$buttons['data'] = [
|
||||
'active' => false,
|
||||
|
|
|
@ -202,7 +202,6 @@ function createVisualConsole(
|
|||
id,
|
||||
data,
|
||||
function(error, data) {
|
||||
// if (!error && !data) return;
|
||||
if (error || !data) {
|
||||
console.log(
|
||||
"[ERROR]",
|
||||
|
@ -215,6 +214,39 @@ function createVisualConsole(
|
|||
e.item.resize(e.prevSize.width, e.prevSize.height);
|
||||
}
|
||||
|
||||
var taskItem = "update-item-resize-" + id;
|
||||
asyncTaskManager
|
||||
.add(taskItem, function(done) {
|
||||
var abortable = getVisualConsoleItem(baseUrl, id, function(
|
||||
error,
|
||||
data
|
||||
) {
|
||||
if (error || !data) {
|
||||
console.log(
|
||||
"[ERROR]",
|
||||
"[VISUAL-CONSOLE-CLIENT]",
|
||||
"[API]",
|
||||
error ? error.message : "Invalid response"
|
||||
);
|
||||
}
|
||||
|
||||
if (typeof data === "string") {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
|
||||
visualConsole.updateElement(data);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
return {
|
||||
cancel: function() {
|
||||
abortable.abort();
|
||||
}
|
||||
};
|
||||
})
|
||||
.init();
|
||||
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
@ -423,6 +455,71 @@ function updateVisualConsoleItem(baseUrl, vcId, vcItemId, data, callback) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a Visual Console's structure and its items.
|
||||
* @param {string} baseUrl Base URL to build the API path.
|
||||
* @param {number} vcItemId Identifier of the Visual Console's item.
|
||||
* @param {function} callback Function to be executed on request success or fail.
|
||||
* @return {Object} Cancellable. Object which include and .abort([statusText]) function.
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function getVisualConsoleItem(baseUrl, vcItemId, callback) {
|
||||
// var apiPath = baseUrl + "/include/rest-api";
|
||||
var apiPath = baseUrl + "/ajax.php";
|
||||
var jqXHR = null;
|
||||
|
||||
// Cancel the ajax requests.
|
||||
var abort = function(textStatus) {
|
||||
if (textStatus == null) textStatus = "abort";
|
||||
|
||||
// -- XMLHttpRequest.readyState --
|
||||
// Value State Description
|
||||
// 0 UNSENT Client has been created. open() not called yet.
|
||||
// 4 DONE The operation is complete.
|
||||
|
||||
if (jqXHR.readyState !== 0 && jqXHR.readyState !== 4)
|
||||
jqXHR.abort(textStatus);
|
||||
};
|
||||
|
||||
// Failed request handler.
|
||||
var handleFail = function(jqXHR, textStatus, errorThrown) {
|
||||
abort();
|
||||
// Manually aborted or not.
|
||||
if (textStatus === "abort") {
|
||||
callback();
|
||||
} else {
|
||||
var error = new Error(errorThrown);
|
||||
error.request = jqXHR;
|
||||
callback(error);
|
||||
}
|
||||
};
|
||||
|
||||
// Function which handle success case.
|
||||
var handleSuccess = function(data) {
|
||||
callback(null, data);
|
||||
};
|
||||
|
||||
// Visual Console container request.
|
||||
jqXHR = jQuery
|
||||
// .get(apiPath + "/visual-consoles/" + vcId, null, "json")
|
||||
.get(
|
||||
apiPath,
|
||||
{
|
||||
page: "include/rest-api/index",
|
||||
getVisualConsoleItem: 1,
|
||||
itemId: vcItemId
|
||||
},
|
||||
"json"
|
||||
)
|
||||
.done(handleSuccess)
|
||||
.fail(handleFail);
|
||||
|
||||
// Abortable.
|
||||
return {
|
||||
abort: abort
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: Delete the functions below when you can.
|
||||
/**************************************
|
||||
These functions require jQuery library
|
||||
|
|
|
@ -14,6 +14,7 @@ $visualConsoleId = (int) get_parameter('visualConsoleId');
|
|||
$getVisualConsole = (bool) get_parameter('getVisualConsole');
|
||||
$getVisualConsoleItems = (bool) get_parameter('getVisualConsoleItems');
|
||||
$updateVisualConsoleItem = (bool) get_parameter('updateVisualConsoleItem');
|
||||
$getVisualConsoleItem = (bool) get_parameter('getVisualConsoleItem');
|
||||
|
||||
// Check groups can access user.
|
||||
$aclUserGroups = [];
|
||||
|
@ -51,15 +52,22 @@ if ($getVisualConsole === true) {
|
|||
$data = get_parameter('data');
|
||||
|
||||
$class = VisualConsole::getItemClass($data['type']);
|
||||
unset($data['type']);
|
||||
|
||||
$item_data = [];
|
||||
$item_data['id'] = $visualConsoleItemId;
|
||||
$item_data['id_layout'] = $visualConsoleId;
|
||||
|
||||
$item = $class::fromDB($item_data);
|
||||
$result = $item->save($data);
|
||||
$updateItem = $class::fromDB($item_data);
|
||||
$result = $updateItem->save($data);
|
||||
|
||||
echo json_encode($result);
|
||||
} else if ($getVisualConsoleItem === true) {
|
||||
$itemId = (integer) get_parameter('itemId');
|
||||
|
||||
$item = VisualConsole::getItemFromDB($itemId);
|
||||
|
||||
echo $item;
|
||||
}
|
||||
|
||||
exit;
|
||||
|
|
|
@ -406,4 +406,67 @@ final class Container extends Model
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain an items which belong to the Visual Console.
|
||||
*
|
||||
* @param integer $itemId Identifier of the Item.
|
||||
* @param array $groupsFilter Groups can access user.
|
||||
*
|
||||
* @return array A list of items.
|
||||
* @throws \Exception When the data cannot be retrieved from the DB.
|
||||
*/
|
||||
public static function getItemFromDB(
|
||||
int $itemId,
|
||||
array $groupsFilter=[]
|
||||
): Object {
|
||||
// Default filter.
|
||||
$filter = ['id' => $itemId];
|
||||
$fields = [
|
||||
'DISTINCT(id) AS id',
|
||||
'type',
|
||||
'cache_expiration',
|
||||
'id_layout',
|
||||
];
|
||||
|
||||
// Override the filter if the groups filter is not empty.
|
||||
if (count($groupsFilter) > 0) {
|
||||
// Filter group for elements groups.
|
||||
$filter = [];
|
||||
$filter[] = \db_format_array_where_clause_sql(
|
||||
[
|
||||
'id' => $itemId,
|
||||
'element_group' => $groupsFilter,
|
||||
]
|
||||
);
|
||||
|
||||
// Filter groups for type groups.
|
||||
// Only true condition if type is GROUP_ITEM.
|
||||
$filter[] = '('.\db_format_array_where_clause_sql(
|
||||
[
|
||||
'id' => $itemId,
|
||||
'type' => GROUP_ITEM,
|
||||
'id_group' => $groupsFilter,
|
||||
]
|
||||
).')';
|
||||
}
|
||||
|
||||
$row = \db_get_row_filter(
|
||||
'tlayout_data',
|
||||
$filter,
|
||||
$fields,
|
||||
'OR'
|
||||
);
|
||||
|
||||
$class = static::getItemClass((int) $row['type']);
|
||||
|
||||
try {
|
||||
$item = $class::fromDB($row);
|
||||
} catch (\Throwable $e) {
|
||||
// TODO: Log this?
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ final class Percentile extends Item
|
|||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = PERCENTILE_BAR;
|
||||
$return['type'] = (int) $data['type'];
|
||||
$return['percentileType'] = static::extractPercentileType($data);
|
||||
$return['valueType'] = static::extractValueType($data);
|
||||
// TODO: Add min value to the database.
|
||||
|
|
|
@ -28,6 +28,8 @@ if (file_exists(ENTERPRISE_DIR.'/include/functions_login.php')) {
|
|||
|
||||
require_once $config['homedir'].'/vendor/autoload.php';
|
||||
|
||||
ui_require_css_file('visual_maps');
|
||||
|
||||
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
|
||||
echo '<head>';
|
||||
|
@ -215,6 +217,9 @@ $visualConsoleItems = VisualConsole::getItemsFromDB(
|
|||
handleUpdate
|
||||
);
|
||||
|
||||
var controls = document.getElementById('vc-controls');
|
||||
autoHideElement(controls, 1000);
|
||||
|
||||
// Update the data fetch interval.
|
||||
$('select#vc-refr').change(function(event) {
|
||||
var refr = Number.parseInt(event.target.value);
|
||||
|
|
|
@ -87,7 +87,7 @@ if ($aclWrite || $aclManage) {
|
|||
$hash = md5($config['dbpass'].$visualConsoleId.$config['id_user']);
|
||||
|
||||
$options['public_link']['text'] = '<a href="'.ui_get_full_url(
|
||||
'operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$visualConsoleId.'&id_user='.$config['id_user']
|
||||
'operation/visual_console/public_console.php?hash='.$hash.'&id_layout='.$visualConsoleId.'&refr='.$refr.'&id_user='.$config['id_user']
|
||||
).'" target="_blank">'.html_print_image(
|
||||
'images/camera_mc.png',
|
||||
true,
|
||||
|
|
|
@ -386,6 +386,22 @@ export default class VisualConsole {
|
|||
this.buildRelations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter of the `element` property.
|
||||
* @param item.
|
||||
*/
|
||||
public updateElement(item: AnyObject): void {
|
||||
// Update item.
|
||||
try {
|
||||
this.elementsById[item.id].props = decodeProps(item);
|
||||
} catch (error) {
|
||||
console.log("Error updating element:", error.message);
|
||||
}
|
||||
|
||||
// Re-build relations.
|
||||
this.buildRelations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Public accessor of the `props` property.
|
||||
* @return Properties.
|
||||
|
|
Loading…
Reference in New Issue