chg: [eventFiltering] IU/UX Improvements

pull/4076/head
mokaddem 2019-02-13 14:59:49 +01:00
parent 5516b4f603
commit 205912fecc
3 changed files with 75 additions and 91 deletions

View File

@ -29,6 +29,21 @@ class EventsController extends AppController
'searchFor', 'attributeFilter', 'proposal', 'correlation', 'warning', 'deleted', 'includeRelatedTags', 'distribution', 'taggedAttributes', 'galaxyAttachedAttributes', 'objectType', 'attributeType', 'focus', 'extended', 'overrideLimit', 'filterColumnsOverwrite', 'feed', 'server',
);
public $defaultFilteringRules = array(
'searchFor' => '',
'attributeFilter' => 'all',
'proposal' => 0,
'correlation' => 0,
'warning' => 0,
'deleted' => 2,
'includeRelatedTags' => 0,
'feed' => 0,
'server' => 0,
'distribution' => array(0, 1, 2, 3, 4, 5),
'taggedAttributes' => '',
'galaxyAttachedAttributes' => ''
);
public $helpers = array('Js' => array('Jquery'));
public $paginationFunctions = array('index', 'proposalEventIndex');
@ -1068,6 +1083,12 @@ class EventsController extends AppController
}
$this->set('passedArgsArray', array('all' => $filters['searchFor']));
}
if (isset($filters['taggedAttributes']) && $filters['taggedAttributes'] !== '') {
$this->__applyQueryString($event, $filters['taggedAttributes'], 'Tag.name');
}
if (isset($filters['galaxyAttachedAttributes']) && $filters['galaxyAttachedAttributes'] !== '') {
$this->__applyQueryString($event, $filters['galaxyAttachedAttributes'], 'Tag.name');
}
$emptyEvent = (empty($event['Object']) && empty($event['Attribute']));
$this->set('emptyEvent', $emptyEvent);
@ -1155,6 +1176,7 @@ class EventsController extends AppController
$advancedFiltering = $this->__checkIfAdvancedFiltering($filters);
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTags = $this->Event->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $event['Event']['id']);
$attributeTags = array_column($attributeTags, 'name');
$this->set('attributeTags', $attributeTags);
@ -1423,6 +1445,7 @@ class EventsController extends AppController
$advancedFiltering = $this->__checkIfAdvancedFiltering($filters);
$this->set('advancedFilteringActive', $advancedFiltering['active'] ? 1 : 0);
$this->set('advancedFilteringActiveRules', $advancedFiltering['activeRules']);
$this->set('defaultFilteringRules', $this->defaultFilteringRules);
$attributeTags = $this->Event->Attribute->AttributeTag->getAttributesTags($this->Auth->user(), $event['Event']['id']);
$attributeTags = array_column($attributeTags, 'name');
$this->set('attributeTags', $attributeTags);
@ -1505,6 +1528,12 @@ class EventsController extends AppController
if (isset($this->params['named']['searchFor']) && $this->params['named']['searchFor'] !== '') {
$this->__applyQueryString($event, $this->params['named']['searchFor']);
}
if (isset($this->params['named']['taggedAttributes']) && $this->params['named']['taggedAttributes'] !== '') {
$this->__applyQueryString($event, $this->params['named']['taggedAttributes'], 'Tag.name');
}
if (isset($this->params['named']['galaxyAttachedAttributes']) && $this->params['named']['galaxyAttachedAttributes'] !== '') {
$this->__applyQueryString($event, $this->params['named']['galaxyAttachedAttributes'], 'Tag.name');
}
if ($this->_isRest()) {
$this->set('event', $event);
@ -1670,22 +1699,10 @@ class EventsController extends AppController
unset($filters['sort']);
unset($filters['direction']);
$defaultRules = array(
'searchFor' => '',
'attributeFilter' => 'all',
'proposal' => '0',
'correlation' => '0',
'warning' => '0',
'deleted' => '2',
'includeRelatedTags' => '0',
'feed' => '0',
'server' => '0',
'distribution' => array('0', '1', '2', '3', '4', '5'),
);
$activeRules = 0;
$activeRules = array();
foreach ($filters as $k => $v) {
if (isset($defaultRules[$k]) && $defaultRules[$k] != $v) {
$activeRules++;
if (isset($this->defaultFilteringRules[$k]) && $this->defaultFilteringRules[$k] != $v) {
$activeRules[$k] = 1;
}
}
return array('active' => $activeRules > 0 ? $res : false, 'activeRules' => $activeRules);

View File

@ -1,9 +1,10 @@
<div id="eventFilteringQBWrapper" style="padding: 5px; display: none; border: 1px solid #dddddd; border-bottom: 0px;">
<div id="eventFilteringQB"></div>
<div style="display: flex; justify-content: flex-end">
<input id="eventFilteringQBLinkInput" class="form-control" style="width: 500px;"></input>
<button id="eventFilteringQBLinkCopy" type="button" class="btn btn-inverse" style="margin-right: 5px; margin-left: 5px;" onclick="clickMessage(this);"> <i class="fa fa-clipboard"></i> Copy to clipboard </button>
<button id="eventFilteringQBSubmit" type="button" class="btn btn-inverse" style=""> <i class="fa fa-filter"></i> Filter </button>
<input id="eventFilteringQBLinkInput" class="form-control" style="width: 66%;"></input>
<button id="eventFilteringQBLinkCopy" type="button" class="btn btn-inverse" style="margin-right: 5px; margin-left: 5px;" onclick="clickMessage(this);"> <i class="fa fa-clipboard"></i> <?php echo h('Copy to clipboard'); ?> </button>
<button id="eventFilteringQBSubmit" type="button" class="btn btn-inverse" style="margin-right: 5px;"> <i class="fa fa-filter"></i> <?php echo h('Filter'); ?> </button>
<button id="eventFilteringQBClear" type="button" class="btn btn-xs btn-danger" style="" title="<?php echo h('Clear filtering rules'); ?>"> <i class="fa fa-times"></i> <?php echo h('Clear'); ?> </button>
</div>
</div>
<?php
@ -11,6 +12,7 @@
<script>
function triggerEventFilteringTool(clicked) {
var defaultFilteringRules = <?php echo json_encode($defaultFilteringRules); ?>;
var qbOptions = {
plugins: {
'filter-description' : {
@ -20,7 +22,6 @@ function triggerEventFilteringTool(clicked) {
'bt-tooltip-errors': null,
},
allow_empty: true,
display_empty_filter: false,
lang: {
operators: {
equal: 'show',
@ -192,46 +193,6 @@ function triggerEventFilteringTool(clicked) {
"values": <?php echo json_encode($attributeClusters); ?>
},
<?php endif; ?>
// {
// "input": "select",
// "type": "string",
// "operators": [
// "equal",
// ],
// "unique": false,
// "id": "objectType",
// "label": "Object Types",
// <?php
// $object_types = array();
// foreach ($event['objects'] as $k => $object) {
// if ($object['objectType'] == 'object') {
// $object_types[$object['name']] = $object['name'];
// }
// }
// ksort($object_types);
// ?>
// "values": <?php //echo json_encode($object_types); ?>
// },
// {
// "input": "select",
// "type": "string",
// "operators": [
// "equal",
// ],
// "unique": false,
// "id": "attributeType",
// "label": "Attribute Types",
// <?php
// $attribute_types = array();
// foreach ($event['objects'] as $k => $attribute) {
// if ($attribute['objectType'] == 'attribute') {
// $attribute_types[$attribute['type']] = $attribute['type'];
// }
// }
// ksort($attribute_types);
// ?>
// "values": <?php //echo json_encode($attribute_types); ?>
// },
{
"input": "text",
"type": "string",
@ -255,11 +216,14 @@ function triggerEventFilteringTool(clicked) {
condition: 'AND',
not: false,
rules: [
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['searchFor'])): ?>
{
field: 'searchFor',
id: 'searchFor',
value: $('<div />').html("<?php echo isset($filters['searchFor']) ? h($filters['searchFor']) : ''; ?>").text()
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['attributeFilter'])): ?>
{
field: 'attributeFilter',
id: 'attributeFilter',
@ -269,87 +233,78 @@ function triggerEventFilteringTool(clicked) {
value: "<?php echo 'all'; ?>"
<?php endif; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['proposal'])): ?>
{
field: 'proposal',
id: 'proposal',
value: <?php echo isset($filters['proposal']) ? h($filters['proposal']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['correlation'])): ?>
{
field: 'correlation',
id: 'correlation',
value: <?php echo isset($filters['correlation']) ? h($filters['correlation']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['warning'])): ?>
{
field: 'warning',
id: 'warning',
value: <?php echo isset($filters['warning']) ? h($filters['warning']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['deleted'])): ?>
{
field: 'deleted',
id: 'deleted',
value: <?php echo isset($filters['deleted']) ? h($filters['deleted']) : 2; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['includeRelatedTags'])): ?>
{
field: 'includeRelatedTags',
id: 'includeRelatedTags',
value: <?php echo isset($filters['includeRelatedTags']) ? h($filters['includeRelatedTags']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['feed'])): ?>
{
field: 'feed',
id: 'feed',
value: <?php echo isset($filters['feed']) ? h($filters['feed']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['server'])): ?>
{
field: 'server',
id: 'server',
value: <?php echo isset($filters['server']) ? h($filters['server']) : 0; ?>
},
<?php endif; ?>
<?php if (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['distribution'])): ?>
{
field: 'distribution',
id: 'distribution',
operator: 'in',
value: <?php echo isset($filters['distribution']) ? json_encode($filters['distribution']) : json_encode(array(0, 1, 2, 3, 4, 5)); ?>
},
<?php if (!empty($attributeTags)): ?>
<?php endif; ?>
<?php if (!empty($attributeTags) && (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['taggedAttributes']))): ?>
{
field: 'taggedAttributes',
id: 'taggedAttributes',
value: <?php echo isset($filters['taggedAttributes']) ? h($filters['taggedAttributes']) : 0; ?>
value: '<?php echo isset($filters['taggedAttributes']) ? h($filters['taggedAttributes']) : $attributeTags[0]; ?>'
},
<?php endif; ?>
<?php if (!empty($attributeClusters)): ?>
<?php if (!empty($attributeClusters) && (count($advancedFilteringActiveRules) == 0 || isset($advancedFilteringActiveRules['galaxyAttachedAttributes']))): ?>
{
field: 'galaxyAttachedAttributes',
id: 'galaxyAttachedAttributes',
value: <?php echo isset($filters['galaxyAttachedAttributes']) ? h($filters['galaxyAttachedAttributes']) : 0; ?>
value: '<?php echo isset($filters['galaxyAttachedAttributes']) ? h($filters['galaxyAttachedAttributes']) : $attributeClusters[0]; ?>'
},
<?php endif; ?>
// {
// condition: 'OR',
// not: false,
// flags: {
// no_add_group: true,
// condition_readonly: true,
// },
// rules: [{
// field: 'objectType',
// id: 'objectType',
// value: '<?php //reset($object_types); echo key($object_types); ?>',
// }]
// },
// {
// condition: 'OR',
// not: false,
// flags: {
// no_add_group: true,
// condition_readonly: true,
// },
// rules: [{
// field: 'attributeType',
// id: 'attributeType',
// value: '<?php //reset($attribute_types); echo key($attribute_types); ?>',
// }]
// }
],
flags: {
no_add_group: true,
@ -386,6 +341,12 @@ function triggerEventFilteringTool(clicked) {
copyToClipboard($('#eventFilteringQBLinkInput'));
});
$('#eventFilteringQBClear').off('click').on('click', function() {
// querybuilderTool.setRules({condition: "AND", rules: []});
querybuilderTool.reset();
$('#eventFilteringQB').queryBuilder('reset');
});
$ev.off('keyup').on('keyup', function(e){
if(e.keyCode == 13) {
$('#eventFilteringQBSubmit').trigger("click");
@ -409,7 +370,13 @@ function triggerEventFilteringTool(clicked) {
// v = JSON.stringify(v);
v = v.join('||');
}
url += "/" + k + ":" + v;
if (!Array.isArray(defaultFilteringRules[k]) && defaultFilteringRules[k] != v) {
url += "/" + k + ":" + v;
} else {
if (Array.isArray(defaultFilteringRules[k]) && defaultFilteringRules[k].join('||') != v) {
url += "/" + k + ":" + v;
}
}
});
return url;
}

View File

@ -158,7 +158,7 @@
<it class="fa fa-filter"></it>
<?php echo __('Filtering tool'); ?>
<?php if($advancedFilteringActive): ?>
<span class="badge badge-warning" title="<?php echo h($advancedFilteringActiveRules) . __(' active rule(s)')?>"><?php echo h($advancedFilteringActiveRules) ?></span>
<span class="badge badge-warning" title="<?php echo h(count($advancedFilteringActiveRules)) . __(' active rule(s)')?>"><?php echo h(count($advancedFilteringActiveRules)) ?></span>
<?php endif; ?>
</div>