Improved event widget, added custom filters
This commit is contained in:
parent
0be3e0ab90
commit
20dc58a140
|
@ -1002,3 +1002,11 @@ function check_massive_response_event(
|
|||
counter++;
|
||||
});
|
||||
}
|
||||
|
||||
function event_widget_options() {
|
||||
if ($("#customFilter").val() != "-1") {
|
||||
$(".event-widget-input").disable();
|
||||
} else {
|
||||
$(".event-widget-input").enable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1362,6 +1362,7 @@ class Manager
|
|||
|
||||
$instance = $this->instanceWidget();
|
||||
$htmlInputs = $instance->getFormInputs([]);
|
||||
$js = $instance->getFormJS();
|
||||
|
||||
View::render(
|
||||
'dashboard/configurationWidgets',
|
||||
|
@ -1369,6 +1370,7 @@ class Manager
|
|||
'dashboardId' => $this->dashboardId,
|
||||
'cellId' => $this->cellId,
|
||||
'htmlInputs' => $htmlInputs,
|
||||
'js' => $js,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
|
@ -622,4 +622,15 @@ class Widget
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return aux javascript code for forms.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormJS()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -246,6 +246,10 @@ class EventsListWidget extends Widget
|
|||
$values['groupRecursion'] = $decoder['groupRecursion'];
|
||||
}
|
||||
|
||||
if (isset($decoder['customFilter']) === true) {
|
||||
$values['customFilter'] = $decoder['customFilter'];
|
||||
}
|
||||
|
||||
if (isset($decoder['groupId']) === true) {
|
||||
$values['groupId'] = $decoder['groupId'];
|
||||
}
|
||||
|
@ -258,6 +262,17 @@ class EventsListWidget extends Widget
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Aux javascript to be run after form load.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormJS(): string
|
||||
{
|
||||
return '$( document ).ready(function() {event_widget_options();});';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates inputs for form (specific).
|
||||
*
|
||||
|
@ -274,6 +289,21 @@ class EventsListWidget extends Widget
|
|||
// Retrieve global - common inputs.
|
||||
$inputs = parent::getFormInputs();
|
||||
|
||||
// Select pre built filter.
|
||||
$inputs[] = [
|
||||
'label' => \__('Custom filters'),
|
||||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'id' => 'select-custom-filter',
|
||||
'fields' => \events_get_event_filter_select(false),
|
||||
'name' => 'customFilter',
|
||||
'script' => 'event_widget_options();',
|
||||
'nothing' => \__('None'),
|
||||
'nothing_value' => -1,
|
||||
'selected' => $this->values['customFilter'],
|
||||
],
|
||||
];
|
||||
|
||||
$fields = \get_event_types();
|
||||
$fields['not_normal'] = \__('Not normal');
|
||||
|
||||
|
@ -292,6 +322,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'class' => 'event-widget-input',
|
||||
'name' => 'eventType',
|
||||
'selected' => $values['eventType'],
|
||||
'return' => true,
|
||||
|
@ -306,6 +337,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'name' => 'maxHours',
|
||||
'type' => 'number',
|
||||
'class' => 'event-widget-input',
|
||||
'value' => $values['maxHours'],
|
||||
'return' => true,
|
||||
'min' => 0,
|
||||
|
@ -328,6 +360,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'class' => 'event-widget-input',
|
||||
'name' => 'limit',
|
||||
'selected' => $values['limit'],
|
||||
'return' => true,
|
||||
|
@ -346,6 +379,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'class' => 'event-widget-input',
|
||||
'name' => 'eventStatus',
|
||||
'selected' => $values['eventStatus'],
|
||||
'return' => true,
|
||||
|
@ -360,6 +394,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'class' => 'event-widget-input',
|
||||
'name' => 'severity',
|
||||
'selected' => $values['severity'],
|
||||
'return' => true,
|
||||
|
@ -386,6 +421,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select_groups',
|
||||
'name' => 'groupId[]',
|
||||
'class' => 'event-widget-input',
|
||||
'returnAllGroup' => true,
|
||||
'privilege' => 'AR',
|
||||
'selected' => $selected_groups_array,
|
||||
|
@ -401,6 +437,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'switch',
|
||||
'name' => 'groupRecursion',
|
||||
'class' => 'event-widget-input',
|
||||
'value' => $values['groupRecursion'],
|
||||
'return' => true,
|
||||
],
|
||||
|
@ -414,6 +451,7 @@ class EventsListWidget extends Widget
|
|||
'arguments' => [
|
||||
'type' => 'select',
|
||||
'fields' => $fields,
|
||||
'class' => 'event-widget-input',
|
||||
'name' => 'tagsId[]',
|
||||
'selected' => explode(',', $values['tagsId'][0]),
|
||||
'return' => true,
|
||||
|
@ -445,6 +483,7 @@ class EventsListWidget extends Widget
|
|||
$values['groupId'] = \get_parameter_switch('groupId', []);
|
||||
$values['tagsId'] = \get_parameter_switch('tagsId', []);
|
||||
$values['groupRecursion'] = \get_parameter_switch('groupRecursion', 0);
|
||||
$values['customFilter'] = \get_parameter('customFilter', -1);
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
@ -461,14 +500,6 @@ class EventsListWidget extends Widget
|
|||
|
||||
$output = '';
|
||||
|
||||
$return_all_group = false;
|
||||
|
||||
if ((bool) \users_can_manage_group_all('RM') === true) {
|
||||
$return_all_group = true;
|
||||
}
|
||||
|
||||
$user_groups = \users_get_groups(false, 'AR', $return_all_group);
|
||||
|
||||
\ui_require_css_file('events', 'include/styles/', true);
|
||||
\ui_require_css_file('tables', 'include/styles/', true);
|
||||
|
||||
|
@ -494,39 +525,51 @@ class EventsListWidget extends Widget
|
|||
$filter = [];
|
||||
$order = [];
|
||||
|
||||
// Filtering.
|
||||
$filter['event_view_hr'] = $hours;
|
||||
|
||||
// Group.
|
||||
$filter['id_group_filter'] = $this->values['groupId'];
|
||||
if (empty($filter['id_group_filter']) === true
|
||||
|| $filter['id_group_filter'][0] === ''
|
||||
|| $filter['id_group_filter'][0] === '0'
|
||||
) {
|
||||
// No filter specified. Don't filter at all...
|
||||
$filter['id_group_filter'] = null;
|
||||
}
|
||||
|
||||
// Tags.
|
||||
if (empty($this->values['tagsId']) === false) {
|
||||
$customFilter = \events_get_event_filter($this->values['customFilter']);
|
||||
if ($customFilter !== false) {
|
||||
$filter = $customFilter;
|
||||
$filter['tag_with'] = base64_encode(
|
||||
json_encode($this->values['tagsId'])
|
||||
json_encode($filter['tag_with'])
|
||||
);
|
||||
}
|
||||
|
||||
// Severity.
|
||||
if (isset($this->values['severity']) === true) {
|
||||
$filter['severity'] = $this->values['severity'];
|
||||
}
|
||||
$filter['tag_without'] = base64_encode(
|
||||
json_encode($filter['tag_without'])
|
||||
);
|
||||
} else {
|
||||
// Filtering.
|
||||
$filter['event_view_hr'] = $hours;
|
||||
|
||||
// Event types.
|
||||
if (empty($this->values['eventType']) === false) {
|
||||
$filter['event_type'] = $this->values['eventType'];
|
||||
}
|
||||
// Group.
|
||||
$filter['id_group_filter'] = $this->values['groupId'];
|
||||
if (empty($filter['id_group_filter']) === true
|
||||
|| $filter['id_group_filter'][0] === ''
|
||||
|| $filter['id_group_filter'][0] === '0'
|
||||
) {
|
||||
// No filter specified. Don't filter at all...
|
||||
$filter['id_group_filter'] = null;
|
||||
}
|
||||
|
||||
// Event status.
|
||||
if ((int) $this->values['eventStatus'] !== -1) {
|
||||
$filter['status'] = $this->values['eventStatus'];
|
||||
// Tags.
|
||||
if (empty($this->values['tagsId']) === false) {
|
||||
$filter['tag_with'] = base64_encode(
|
||||
json_encode($this->values['tagsId'])
|
||||
);
|
||||
}
|
||||
|
||||
// Severity.
|
||||
if (isset($this->values['severity']) === true) {
|
||||
$filter['severity'] = $this->values['severity'];
|
||||
}
|
||||
|
||||
// Event types.
|
||||
if (empty($this->values['eventType']) === false) {
|
||||
$filter['event_type'] = $this->values['eventType'];
|
||||
}
|
||||
|
||||
// Event status.
|
||||
if ((int) $this->values['eventStatus'] !== -1) {
|
||||
$filter['status'] = $this->values['eventStatus'];
|
||||
}
|
||||
}
|
||||
|
||||
// Order.
|
||||
|
@ -638,6 +681,12 @@ class EventsListWidget extends Widget
|
|||
$data[1] = ' ';
|
||||
}
|
||||
|
||||
if (isset($event['event_rep']) === true
|
||||
&& $event['event_rep'] > 1
|
||||
) {
|
||||
$data[1] .= ' ('.$event['event_rep'].')';
|
||||
}
|
||||
|
||||
// Group.
|
||||
$data[2] = $event['group_name'];
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ HTML::printForm(
|
|||
[
|
||||
'form' => $form,
|
||||
'inputs' => $htmlInputs,
|
||||
'js' => $js,
|
||||
]
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue