diff -Nadur a/actions/WidgetView.php b/actions/WidgetView.php --- a/actions/WidgetView.php 2025-01-27 15:12:30.000000000 +0100 +++ b/actions/WidgetView.php 2025-02-18 11:34:20.764251547 +0100 @@ -176,8 +176,8 @@ 'label_units_show' => $this->fields_values['secondary_label_units_show'] ]) : ''; - - $cells[] = [ + + $cell = [ 'hostid' => $item['hostid'], 'itemid' => $item['itemid'], 'primary_label' => $primary_label, @@ -188,6 +188,22 @@ 'key_' => $item['key_'] ]; + if ($this->fields_values['onclick_show_custom_url'] == 1) { + if (trim($this->fields_values['onclick_custom_url']) !== '') { + $cell['onclick_url'] = trim($this->fields_values['onclick_custom_url']); + + if (!$this->isTemplateDashboard() || $this->fields_values['hostids']) { + $resolved_url = CMacrosResolverHelper::resolveItemBasedWidgetMacros( + [$item['itemid'] => $item + ['url' => $cell['onclick_url']]], + ['url' => 'url'] + ); + $cell['onclick_url'] = trim($resolved_url[$item['itemid']]['url']); + } + } + } + + $cells[] = $cell; + if (count($cells) == $limit) { break; } @@ -315,6 +331,15 @@ } unset($threshold); + if ($this->fields_values['onclick_show_custom_url'] == 1) { + if (trim($this->fields_values['onclick_custom_url']) !== '') { + $config['onclick'] = [ + 'enabled' => true, + 'new_window' => ($this->fields_values['onclick_new_window'] == 1), + ]; + } + } + return $config; } } diff -Nadur a/assets/js/class.svghoneycomb.js b/assets/js/class.svghoneycomb.js --- a/assets/js/class.svghoneycomb.js 2025-01-27 15:12:30.000000000 +0100 +++ b/assets/js/class.svghoneycomb.js 2025-02-18 11:34:00.020554665 +0100 @@ -456,9 +456,18 @@ } #drawCell(cell) { - cell - .call(cell => this.#drawLabel(cell)) - .on('click', (e, d) => { + cell.call(cell => this.#drawLabel(cell)); + + if (this.#config.onclick.enabled) { + cell.on('click', (e, d) => { + if (this.#config.onclick.new_window) { + window.open(d.onclick_url, '_blank'); + } else { + window.open(d.onclick_url, '_self'); + } + }); + } else { + cell.on('click', (e, d) => { if (this.selectCell(d.itemid)) { this.#svg.dispatch(CSVGHoneycomb.EVENT_CELL_CLICK, { detail: { @@ -467,52 +476,55 @@ } }); } - }) - .on('mouseenter', (e, d) => { - if (d.enter_timeout === undefined && d.scale_timeout === undefined && !d.scaled) { - d.enter_timeout = setTimeout(() => { - delete d.enter_timeout; - cell.raise(); - this.#leaveAll(); - - d.scale_timeout = setTimeout(() => { - delete d.scale_timeout; - d.scaled = true; - this.#cellEnter(cell, d); - }, 50); - }, 150); - } + }); + } - this.#svg.dispatch(CSVGHoneycomb.EVENT_CELL_ENTER, { - detail: { - hostid: d.hostid, - itemid: d.itemid - } - }); - }) - .on('mouseleave', (e, d) => { - if (d.enter_timeout !== undefined) { - clearTimeout(d.enter_timeout); + cell.on('mouseenter', (e, d) => { + if (d.enter_timeout === undefined && d.scale_timeout === undefined && !d.scaled) { + d.enter_timeout = setTimeout(() => { delete d.enter_timeout; - } + cell.raise(); + this.#leaveAll(); - if (d.scale_timeout !== undefined) { - clearTimeout(d.scale_timeout); - delete d.scale_timeout; - } + d.scale_timeout = setTimeout(() => { + delete d.scale_timeout; + d.scaled = true; + this.#cellEnter(cell, d); + }, 50); + }, 150); + } - if (d.scaled) { - this.#cellLeave(cell, d); - d.scaled = false; + this.#svg.dispatch(CSVGHoneycomb.EVENT_CELL_ENTER, { + detail: { + hostid: d.hostid, + itemid: d.itemid } + }); + }); - this.#svg.dispatch(CSVGHoneycomb.EVENT_CELL_LEAVE, { - detail: { - hostid: d.hostid, - itemid: d.itemid - } - }); + cell.on('mouseleave', (e, d) => { + if (d.enter_timeout !== undefined) { + clearTimeout(d.enter_timeout); + delete d.enter_timeout; + } + + if (d.scale_timeout !== undefined) { + clearTimeout(d.scale_timeout); + delete d.scale_timeout; + } + + if (d.scaled) { + this.#cellLeave(cell, d); + d.scaled = false; + } + + this.#svg.dispatch(CSVGHoneycomb.EVENT_CELL_LEAVE, { + detail: { + hostid: d.hostid, + itemid: d.itemid + } }); + }); } #cellEnter(cell, d) { diff -Nadur a/includes/WidgetForm.php b/includes/WidgetForm.php --- a/includes/WidgetForm.php 2025-01-27 15:12:30.000000000 +0100 +++ b/includes/WidgetForm.php 2025-02-17 16:48:05.244505789 +0100 @@ -209,6 +209,15 @@ ) ->addField( new CWidgetFieldThresholds('thresholds', _('Thresholds')) + ) + ->addField( + (new CWidgetFieldCheckBox('onclick_show_custom_url'))->setDefault(0) + ) + ->addField( + (new CWidgetFieldTextBox('onclick_custom_url', _('URL'))) + ) + ->addField( + (new CWidgetFieldCheckBox('onclick_new_window'))->setDefault(0) ); } diff -Nadur a/views/widget.edit.php b/views/widget.edit.php --- a/views/widget.edit.php 2025-01-27 15:12:30.000000000 +0100 +++ b/views/widget.edit.php 2025-02-18 09:54:59.164636689 +0100 @@ -108,6 +108,9 @@ ->addFieldsGroup( getThresholdFieldsGroupView($form, $data['fields']) ) + ->addFieldsGroup( + getCustomOnclickURLView($form, $data['fields']) + ) ) ->includeJsFile('widget.edit.js.php') ->addJavaScript('widget_honeycomb_form.init('.json_encode([ @@ -199,3 +202,26 @@ (new CWidgetFieldThresholdsView($fields['thresholds']))->removeLabel() ); } + +function getCustomOnclickURLView(CWidgetFormView $form, array $fields) +{ + $onclick_show_field = $form->registerField(new CWidgetFieldCheckBoxView($fields['onclick_show_custom_url'])); + $onclick_url_field = $form->registerField((new CWidgetFieldTextBoxView($fields['onclick_custom_url']))->setAdaptiveWidth(ZBX_TEXTAREA_MEDIUM_WIDTH)); + $onclick_nw_field = $form->registerField(new CWidgetFieldCheckBoxView($fields['onclick_new_window'])); + + return (new CWidgetFieldsGroupView(_('Custom URL on click'))) + ->addItem([ + (new CDiv([ + $onclick_show_field->getView(), + $onclick_url_field->getLabel(), + ' ', + $onclick_url_field->getView(), + ])) + ]) + ->addItem([ + (new CDiv([ + $onclick_nw_field->getView(), + _('Show in a new window') + ])) + ]); +} \ No newline at end of file