diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php
index cc2e560141..07cf94cc0a 100644
--- a/pandora_console/include/lib/Dashboard/Widget.php
+++ b/pandora_console/include/lib/Dashboard/Widget.php
@@ -687,6 +687,8 @@ class Widget
switch ($this->className) {
case 'EventsListWidget':
case 'ReportsWidget':
+ case 'MapsMadeByUser':
+ case 'AlertsFiredWidget':
$this->showSelectNodeMeta = true;
break;
diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php
index 5c5a12e16f..e60915f0cc 100644
--- a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php
+++ b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php
@@ -213,6 +213,81 @@ class MapsMadeByUser extends Widget
}
+ /**
+ * Dumps consoles list in json to fullfill select for consoles.
+ *
+ * @return void
+ */
+ public function getVisualConsolesList(): void
+ {
+ $node_id = \get_parameter('nodeId', $this->nodeId);
+ if (\is_metaconsole() === true && $node_id > 0) {
+ if (\metaconsole_connect(null, $node_id) !== NOERR) {
+ echo json_encode(
+ ['error' => __('Failed to connect to node %d', $node_id) ]
+ );
+ }
+ }
+
+ echo json_encode(
+ $this->getVisualConsoles(),
+ 1
+ );
+
+ if (\is_metaconsole() === true && $node_id > 0) {
+ \metaconsole_restore_db();
+ }
+ }
+
+
+ /**
+ * Retrieve visual consoles.
+ *
+ * @return array
+ */
+ private function getVisualConsoles()
+ {
+ global $config;
+
+ $return_all_group = false;
+
+ if (users_can_manage_group_all('RM')) {
+ $return_all_group = true;
+ }
+
+ $fields = \visual_map_get_user_layouts(
+ $config['id_user'],
+ true,
+ ['can_manage_group_all' => $return_all_group],
+ $return_all_group
+ );
+
+ foreach ($fields as $k => $v) {
+ $fields[$k] = \io_safe_output($v);
+ }
+
+ // If currently selected graph is not included in fields array
+ // (it belongs to a group over which user has no permissions), then add
+ // it to fields array.
+ // This is aimed to avoid overriding this value when a user with
+ // narrower permissions edits widget configuration.
+ if ($this->values['vcId'] !== null
+ && array_key_exists($this->values['vcId'], $fields) === false
+ ) {
+ $selected_vc = db_get_value(
+ 'name',
+ 'tlayout',
+ 'id',
+ $this->values['vcId']
+ );
+
+ $fields[$this->values['vcId']] = $selected_vc;
+ }
+
+ return $fields;
+ }
+
+
/**
* Generates inputs for form (specific).
*
@@ -229,31 +304,13 @@ class MapsMadeByUser extends Widget
// Retrieve global - common inputs.
$inputs = parent::getFormInputs();
- $return_all_group = false;
-
- if (users_can_manage_group_all('RM')) {
- $return_all_group = true;
- }
-
- $fields = \visual_map_get_user_layouts(
- $config['id_user'],
- true,
- ['can_manage_group_all' => $return_all_group],
- $return_all_group
- );
-
- // If currently selected graph is not included in fields array (it belongs to a group over which user has no permissions), then add it to fields array.
- // This is aimed to avoid overriding this value when a user with narrower permissions edits widget configuration.
- if ($values['vcId'] !== null && !array_key_exists($values['vcId'], $fields)) {
- $selected_vc = db_get_value('name', 'tlayout', 'id', $values['vcId']);
-
- $fields[$values['vcId']] = $selected_vc;
- }
+ $fields = $this->getVisualConsoles();
// Visual console.
$inputs[] = [
'label' => __('Visual console'),
'arguments' => [
+ 'id' => 'vcId',
'type' => 'select',
'fields' => $fields,
'name' => 'vcId',
@@ -454,4 +511,51 @@ class MapsMadeByUser extends Widget
}
+ /**
+ * Return aux javascript code for forms.
+ *
+ * @return string
+ */
+ public function getFormJS()
+ {
+ ob_start();
+ ?>
+ $('#node').on('change', function() {
+ $.ajax({
+ method: "POST",
+ url: '',
+ data: {
+ page: 'operation/dashboard/dashboard',
+ dashboardId: 'dashboardId; ?>',
+ widgetId: 'widgetId; ?>',
+ cellId: 'cellId; ?>',
+ class: '',
+ method: 'getVisualConsolesList',
+ nodeId: $('#node').val()
+ },
+ dataType: 'JSON',
+ success: function(data) {
+ console.log(data);
+ $('#vcId').empty();
+ Object.entries(data).forEach(e => {
+ key = e[0];
+ value = e[1];
+ $('#vcId').append($('