diff options
author | Gregory Chalenko <gregory.chalenko@zabbix.com> | 2020-07-27 10:31:08 +0300 |
---|---|---|
committer | Gregory Chalenko <gregory.chalenko@zabbix.com> | 2020-07-27 10:31:08 +0300 |
commit | 74a590a11f5177538dc1de3efdf6e3a53c42f750 (patch) | |
tree | ce5d101b8df08d24b410b91c8f0ad2002de280a9 | |
parent | 383f5a41a3b0f888db6605c699490c2bc59a90c7 (diff) |
..F....... [ZBXNEXT-710] fixed js template value init; added getcount; moved constant to abstract class
-rw-r--r-- | ui/app/controllers/CControllerHost.php | 59 | ||||
-rw-r--r-- | ui/app/controllers/CControllerHostView.php | 6 | ||||
-rw-r--r-- | ui/app/controllers/CControllerHostViewRefresh.php | 29 | ||||
-rw-r--r-- | ui/app/controllers/CControllerProfileUpdate.php | 4 | ||||
-rw-r--r-- | ui/app/partials/monitoring.host.filter.php | 22 | ||||
-rw-r--r-- | ui/app/partials/monitoring.host.view.html.php | 4 |
6 files changed, 84 insertions, 40 deletions
diff --git a/ui/app/controllers/CControllerHost.php b/ui/app/controllers/CControllerHost.php index 8d0de19416b..c938383a518 100644 --- a/ui/app/controllers/CControllerHost.php +++ b/ui/app/controllers/CControllerHost.php @@ -25,6 +25,53 @@ */ abstract class CControllerHost extends CController { + const FILTER_IDX = 'web.monitoringhosts'; + /** + * Filter fields default values. + */ + const FILTER_FIELDS_DEFAULT = [ + 'name' => '', + 'groupids' => [], + 'ip' => '', + 'dns' => '', + 'port' => '', + 'status' => HOST_STATUS_MONITORED, + 'evaltype' => TAG_EVAL_TYPE_AND_OR, + 'tags' => [], + 'severities' => [], + 'show_suppressed' => ZBX_PROBLEM_SUPPRESSED_FALSE, + 'maintenance_status' => HOST_MAINTENANCE_STATUS_ON, + 'from' => 'now-1d', + 'to' => 'now', + 'page' => null, + 'sort' => 'name', + 'sortorder' => ZBX_SORT_UP + ]; + + /** + * Get host list results count for passed filter. + * + * @param array $filter Filter options. + * @param string $filter['name'] Filter hosts by name. + * @param array $filter['groupids'] Filter hosts by host groups. + * @param string $filter['ip'] Filter hosts by IP. + * @param string $filter['dns'] Filter hosts by DNS. + * @param string $filter['port'] Filter hosts by port. + * @param string $filter['status'] Filter hosts by status. + * @param string $filter['evaltype'] Filter hosts by tags. + * @param string $filter['tags'] Filter hosts by tag names and values. + * @param string $filter['severities'] Filter problems on hosts by severities. + * @param string $filter['show_suppressed'] Filter supressed problems. + * @param int $filter['maintenance_status'] Filter hosts by maintenance. + * @param int $filter['page'] Page number. + * + * @return int + */ + protected function getCount(array $filter) { + // TODO + return 1; + } + /** * Prepares the host list based on the given filter and sorting options. * @@ -41,12 +88,12 @@ abstract class CControllerHost extends CController { * @param string $filter['show_suppressed'] Filter supressed problems. * @param int $filter['maintenance_status'] Filter hosts by maintenance. * @param int $filter['page'] Page number. - * @param string $sort Sorting field. - * @param string $sortorder Sorting order. + * @param string $filter['sort'] Sorting field. + * @param string $filter['sortorder'] Sorting order. * * @return array */ - protected function prepareData(array $filter, string $sort, string $sortorder): array { + protected function getData(array $filter): array { $child_groups = []; // Multiselect host groups. @@ -117,12 +164,12 @@ abstract class CControllerHost extends CController { ]); // Sort for paging so we know which IDs go to which page. - CArrayHelper::sort($hosts, [['field' => $sort, 'order' => $sortorder]]); + CArrayHelper::sort($hosts, [['field' => $filter['sort'], 'order' => $filter['sortorder']]]); $view_curl = (new CUrl('zabbix.php'))->setArgument('action', 'host.view'); // Split result array and create paging. - $paging = CPagerHelper::paginate($filter['page'], $hosts, $sortorder, $view_curl); + $paging = CPagerHelper::paginate($filter['page'], $hosts, $filter['sortorder'], $view_curl); // Get additonal data to limited host amount. $hosts = API::Host()->get([ @@ -140,7 +187,7 @@ abstract class CControllerHost extends CController { 'preservekeys' => true ]); // Re-sort the results again. - CArrayHelper::sort($hosts, [['field' => $sort, 'order' => $sortorder]]); + CArrayHelper::sort($hosts, [['field' => $filter['sort'], 'order' => $filter['sortorder']]]); $maintenanceids = []; diff --git a/ui/app/controllers/CControllerHostView.php b/ui/app/controllers/CControllerHostView.php index b255de0fb95..25cb2741608 100644 --- a/ui/app/controllers/CControllerHostView.php +++ b/ui/app/controllers/CControllerHostView.php @@ -44,12 +44,10 @@ class CControllerHostView extends CControllerHostViewRefresh { ->setArgument('sortorder', $filter['sortorder']) ->setArgument('page', $filter['page']); - $prepared_data = $this->prepareData($filter, $filter['sort'], $filter['sortorder']); + $prepared_data = $this->getData($filter); $data = [ - 'filter' => $filter, - // 'sort' => $sort, - // 'sortorder' => $sortorder, + //'filter' => $filter, 'refresh_url' => $refresh_curl->getUrl(), 'refresh_interval' => CWebUser::getRefresh() * 1000, diff --git a/ui/app/controllers/CControllerHostViewRefresh.php b/ui/app/controllers/CControllerHostViewRefresh.php index 550af333c25..35ae6ac31b4 100644 --- a/ui/app/controllers/CControllerHostViewRefresh.php +++ b/ui/app/controllers/CControllerHostViewRefresh.php @@ -25,29 +25,6 @@ */ class CControllerHostViewRefresh extends CControllerHost { - const FILTER_IDX = 'web.monitoringhosts'; - /** - * Filter fields default values. - */ - const FILTER_FIELDS_DEFAULT = [ - 'name' => '', - 'groupids' => [], - 'ip' => '', - 'dns' => '', - 'port' => '', - 'status' => '', - 'evaltype' => TAG_EVAL_TYPE_AND_OR, - 'tags' => [], - 'severities' => [], - 'show_suppressed' => ZBX_PROBLEM_SUPPRESSED_FALSE, - 'maintenance_status' => HOST_MAINTENANCE_STATUS_ON, - 'from' => 'now-1d', - 'to' => 'now', - 'page' => null, - 'sort' => 'name', - 'sortorder' => ZBX_SORT_UP - ]; - protected function init(): void { $this->disableSIDValidation(); } @@ -118,14 +95,14 @@ class CControllerHostViewRefresh extends CControllerHost { $show_counters = []; foreach ($profile->getTabsWithDefaults() as $index => $filter) { - $show_counters[$index] = $this->prepareData($filter, $filter['sort'], $filter['sortorder']); + $show_counters[$index] = $filter['show_counter'] ? $this->getCount($filter) : 0; } - $data['show_counters'] = $show_counters; + $data['show_counter'] = $show_counters; } else { $this->getInputs($filter, array_keys($filter)); - $prepared_data = $this->prepareData($filter, $filter['sort'], $filter['sortorder']); + $prepared_data = $this->getData($filter); $data = [ 'filter' => $filter, diff --git a/ui/app/controllers/CControllerProfileUpdate.php b/ui/app/controllers/CControllerProfileUpdate.php index cae622fc0a3..5ee279fdc4e 100644 --- a/ui/app/controllers/CControllerProfileUpdate.php +++ b/ui/app/controllers/CControllerProfileUpdate.php @@ -175,7 +175,9 @@ class CControllerProfileUpdate extends CController { $idx2 = reset($idx2); $properties = []; parse_str($this->getInput('value_str'), $properties); - $properties['severities'] = array_values($properties['severities']); + $properties['severities'] = array_key_exists('severities', $properties) + ? array_values($properties['severities']) + : []; $filter = (new CTabFilterProfile(CControllerHostViewRefresh::FILTER_IDX))->read(); $filter->setFilterDefaults(CControllerHostViewRefresh::FILTER_FIELDS_DEFAULT); diff --git a/ui/app/partials/monitoring.host.filter.php b/ui/app/partials/monitoring.host.filter.php index eb4994f3ad1..ef4b0f6a42f 100644 --- a/ui/app/partials/monitoring.host.filter.php +++ b/ui/app/partials/monitoring.host.filter.php @@ -205,6 +205,7 @@ $(function($) { // Tags table var tag_row = new Template($('#filter-tag-row-tmpl').html()), i = 0; + $('#tags_' + data.uniqid + ' tr.form_row', container).remove(); data.filter.tags.forEach(tag => { var $row = $(tag_row.evaluate({rowNum: i++})); @@ -213,7 +214,7 @@ $(function($) { $row.find('[name$="[value]"]').val(tag.value); $row.find('[name$="[operator]"][value="'+tag.operator+'"]').attr('checked', 'checked'); - $('#tags_' + data.uniqid, container).append($row); + $row.insertBefore($('#tags_' + data.uniqid + ' tr', container).last()); }); $('#tags_' + data.uniqid, container).dynamicRows({template: '#filter-tag-row-tmpl'}); @@ -221,6 +222,25 @@ $(function($) { $('[name="maintenance_status"]', container).click(function () { $('[name="show_suppressed"]', container).prop('disabled', !this.checked); }); + + for (key in data.filter) { + var elm = $('[name="' + key + '"]'); + + if (!elm.length || typeof data.filter[key] === 'object') { + continue; + } + + if (elm.is(':radio,:checkbox')) { + elm.filter('[value="' + data.filter[key] + '"]').attr('checked', true); + } + else { + elm.val(data.filter[key]); + } + }; + + data.filter.severities.forEach((value) => { + $('[name="severities[' + value + ']"]', container).attr('checked', true); + }); } function expand(data, container) { diff --git a/ui/app/partials/monitoring.host.view.html.php b/ui/app/partials/monitoring.host.view.html.php index df237042b31..9e411e3b39c 100644 --- a/ui/app/partials/monitoring.host.view.html.php +++ b/ui/app/partials/monitoring.host.view.html.php @@ -30,12 +30,12 @@ $table = (new CTableInfo()); $view_url = $data['view_curl']->getUrl(); $table->setHeader([ - make_sorting_header(_('Name'), 'name', $data['sort'], $data['sortorder'], $view_url), + make_sorting_header(_('Name'), 'name', $data['filter']['sort'], $data['filter']['sortorder'], $view_url), (new CColHeader(_('Interface'))), (new CColHeader(_('Availability'))), (new CColHeader(_('Tags'))), (new CColHeader(_('Problems'))), - make_sorting_header(_('Status'), 'status', $data['sort'], $data['sortorder'], $view_url), + make_sorting_header(_('Status'), 'status', $data['filter']['sort'], $data['filter']['sortorder'], $view_url), (new CColHeader(_('Latest data'))), (new CColHeader(_('Problems'))), (new CColHeader(_('Graphs'))), |