diff options
author | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-11-04 19:34:01 +0300 |
---|---|---|
committer | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-11-04 19:34:01 +0300 |
commit | 757603a9c80e0491e100265f49b3078ef60d484d (patch) | |
tree | 5dfcfc6783b9e5019e6501417b56fb9c5311ba65 | |
parent | 8728520cd26b9f9bce8631e8006d8e2bb8321f47 (diff) |
..F....... [ZBXNEXT-7469] implemented dashboard configuration monitoring #2
-rw-r--r-- | ui/app/controllers/CControllerDashboardConfigurationHashGet.php | 47 | ||||
-rw-r--r-- | ui/app/controllers/CControllerHostDashboardView.php | 8 | ||||
-rw-r--r-- | ui/app/views/js/monitoring.dashboard.view.js.php | 3 | ||||
-rw-r--r-- | ui/app/views/js/monitoring.host.dashboard.view.js.php | 11 | ||||
-rw-r--r-- | ui/app/views/monitoring.host.dashboard.view.php | 1 | ||||
-rw-r--r-- | ui/js/class.dashboard.js | 1 |
6 files changed, 46 insertions, 25 deletions
diff --git a/ui/app/controllers/CControllerDashboardConfigurationHashGet.php b/ui/app/controllers/CControllerDashboardConfigurationHashGet.php index 93b24950ba3..b528e08a3d9 100644 --- a/ui/app/controllers/CControllerDashboardConfigurationHashGet.php +++ b/ui/app/controllers/CControllerDashboardConfigurationHashGet.php @@ -21,8 +21,6 @@ class CControllerDashboardConfigurationHashGet extends CController { - private ?array $db_dashboard = null; - protected function init(): void { $this->setPostContentType(self::POST_CONTENT_TYPE_JSON); } @@ -32,7 +30,8 @@ class CControllerDashboardConfigurationHashGet extends CController { */ protected function checkInput(): bool { $fields = [ - 'dashboardid' => 'required|db dashboard.dashboardid|not_empty' + 'dashboardid' => 'required|db dashboard.dashboardid|not_empty', + 'templateid' => 'db dashboard.dashboardid|not_empty' ]; $ret = $this->validateInput($fields); @@ -51,32 +50,38 @@ class CControllerDashboardConfigurationHashGet extends CController { } protected function checkPermissions(): bool { - if (!$this->checkAccess(CRoleHelper::UI_MONITORING_DASHBOARD)) { - return false; - } + return true; + } - $db_dashboards = API::Dashboard()->get([ - 'output' => ['name', 'display_period', 'auto_start'], - 'selectPages' => ['dashboard_pageid', 'name', 'display_period', 'widgets'], - 'dashboardids' => $this->getInput('dashboardid') - ]); + /** + * @throws APIException|JsonException + */ + protected function doAction(): void { + $configuration_hash = null; - if (!$db_dashboards) { - return false; - } + if ($this->checkAccess(CRoleHelper::UI_MONITORING_DASHBOARD)) { + $db_dashboards = API::Dashboard()->get([ + 'output' => ['name', 'display_period', 'auto_start'], + 'selectPages' => ['dashboard_pageid', 'name', 'display_period', 'widgets'], + 'dashboardids' => $this->getInput('dashboardid') + ]); - $this->db_dashboard = $db_dashboards[0]; + if ($db_dashboards) { + $db_dashboard = $db_dashboards[0]; - return true; - } + $db_dashboard['pages'] = CDashboardHelper::preparePagesForGrid($db_dashboard['pages'], + $this->hasInput('templateid') ? $this->getInput('templateid') : null, + true + ); - protected function doAction(): void { - $this->db_dashboard['pages'] = CDashboardHelper::preparePagesForGrid($this->db_dashboard['pages'], null, true); + $widget_defaults = APP::ModuleManager()->getWidgetsDefaults($this->hasInput('templateid')); - $widget_defaults = APP::ModuleManager()->getWidgetsDefaults(); + $configuration_hash = CDashboardHelper::getConfigurationHash($db_dashboard, $widget_defaults); + } + } $output = [ - 'configuration_hash' => CDashboardHelper::getConfigurationHash($this->db_dashboard, $widget_defaults) + 'configuration_hash' => $configuration_hash ]; $this->setResponse(new CControllerResponseData(['main_block' => json_encode($output, JSON_THROW_ON_ERROR)])); diff --git a/ui/app/controllers/CControllerHostDashboardView.php b/ui/app/controllers/CControllerHostDashboardView.php index c9cbdbbaf32..b2062fe2d2c 100644 --- a/ui/app/controllers/CControllerHostDashboardView.php +++ b/ui/app/controllers/CControllerHostDashboardView.php @@ -60,6 +60,9 @@ class CControllerHostDashboardView extends CController { return (bool) $this->host; } + /** + * @throws APIException|JsonException + */ protected function doAction() { $host_dashboards = $this->getSortedHostDashboards(); @@ -101,11 +104,14 @@ class CControllerHostDashboardView extends CController { updateTimeSelectorPeriod($time_selector_options); + $widget_defaults = APP::ModuleManager()->getWidgetsDefaults(true); + $data = [ 'host' => $this->host, 'host_dashboards' => $host_dashboards, 'dashboard' => $dashboard, - 'widget_defaults' => APP::ModuleManager()->getWidgetsDefaults(true), + 'widget_defaults' => $widget_defaults, + 'configuration_hash' => CDashboardHelper::getConfigurationHash($dashboard, $widget_defaults), 'has_time_selector' => CDashboardHelper::hasTimeSelector($dashboard['pages']), 'time_period' => getTimeSelectorPeriod($time_selector_options), 'active_tab' => CProfile::get('web.dashboard.filter.active', 1) diff --git a/ui/app/views/js/monitoring.dashboard.view.js.php b/ui/app/views/js/monitoring.dashboard.view.js.php index 9c918318c5e..c1a623d43f4 100644 --- a/ui/app/views/js/monitoring.dashboard.view.js.php +++ b/ui/app/views/js/monitoring.dashboard.view.js.php @@ -105,7 +105,6 @@ if (web_layout_mode != <?= ZBX_LAYOUT_KIOSKMODE ?>) { ZABBIX.Dashboard.on(DASHBOARD_EVENT_EDIT, () => this.edit()); ZABBIX.Dashboard.on(DASHBOARD_EVENT_APPLY_PROPERTIES, this.events.applyProperties); - ZABBIX.Dashboard.on(DASHBOARD_EVENT_CONFIGURATION_OUTDATED, this.events.configurationOutdated); if (dynamic.has_dynamic_widgets) { jQuery('#dynamic_hostid').on('change', this.events.dynamicHostChange); @@ -125,6 +124,8 @@ } } + ZABBIX.Dashboard.on(DASHBOARD_EVENT_CONFIGURATION_OUTDATED, this.events.configurationOutdated); + if (dynamic.has_dynamic_widgets) { // Perform dynamic host switch when browser back/previous buttons are pressed. window.addEventListener('popstate', this.events.popState); diff --git a/ui/app/views/js/monitoring.host.dashboard.view.js.php b/ui/app/views/js/monitoring.host.dashboard.view.js.php index 3c04343cb13..7b7adbbaf5d 100644 --- a/ui/app/views/js/monitoring.host.dashboard.view.js.php +++ b/ui/app/views/js/monitoring.host.dashboard.view.js.php @@ -26,7 +26,7 @@ <script> const view = { - init({host, dashboard, widget_defaults, time_period, web_layout_mode}) { + init({host, dashboard, widget_defaults, configuration_hash, time_period, web_layout_mode}) { timeControl.refreshPage = false; ZABBIX.Dashboard = new CDashboard(document.querySelector('.<?= ZBX_STYLE_DASHBOARD ?>'), { @@ -61,7 +61,8 @@ max_rows: <?= DASHBOARD_MAX_ROWS ?>, widget_min_rows: <?= DASHBOARD_WIDGET_MIN_ROWS ?>, widget_max_rows: <?= DASHBOARD_WIDGET_MAX_ROWS ?>, - widget_defaults: widget_defaults, + widget_defaults, + configuration_hash, is_editable: false, is_edit_mode: false, can_edit_dashboards: false, @@ -80,6 +81,8 @@ ZABBIX.Dashboard.activate(); + ZABBIX.Dashboard.on(DASHBOARD_EVENT_CONFIGURATION_OUTDATED, this.events.configurationOutdated); + if (web_layout_mode == <?= ZBX_LAYOUT_NORMAL ?>) { document.getElementById('dashboardid').addEventListener('change', this.events.dashboardChange); } @@ -88,6 +91,10 @@ }, events: { + configurationOutdated() { + location.href = location.href; + }, + dashboardChange(e) { e.target.closest('form').submit(); } diff --git a/ui/app/views/monitoring.host.dashboard.view.php b/ui/app/views/monitoring.host.dashboard.view.php index e285da29521..5b154ebbd4f 100644 --- a/ui/app/views/monitoring.host.dashboard.view.php +++ b/ui/app/views/monitoring.host.dashboard.view.php @@ -182,6 +182,7 @@ if (count($data['dashboard']['pages']) > 1 'host' => $data['host'], 'dashboard' => $data['dashboard'], 'widget_defaults' => $data['widget_defaults'], + 'configuration_hash' => $data['configuration_hash'], 'time_period' => $data['time_period'], 'web_layout_mode' => $web_layout_mode ]).'); diff --git a/ui/js/class.dashboard.js b/ui/js/class.dashboard.js index b48f3ddfc95..69189dfd80a 100644 --- a/ui/js/class.dashboard.js +++ b/ui/js/class.dashboard.js @@ -388,6 +388,7 @@ class CDashboard extends CBaseComponent { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ + templateid: this._data.templateid ?? undefined, dashboardid: this._data.dashboardid }) }) |