From 205912feccc86a0e5f5cff20c24529e1779b61df Mon Sep 17 00:00:00 2001 From: mokaddem Date: Wed, 13 Feb 2019 14:59:49 +0100 Subject: [PATCH] chg: [eventFiltering] IU/UX Improvements --- app/Controller/EventsController.php | 47 ++++--- .../View/eventFilteringQueryBuilder.ctp | 117 +++++++----------- app/View/Elements/eventattribute.ctp | 2 +- 3 files changed, 75 insertions(+), 91 deletions(-) diff --git a/app/Controller/EventsController.php b/app/Controller/EventsController.php index 2afe9218e..68cd80f80 100644 --- a/app/Controller/EventsController.php +++ b/app/Controller/EventsController.php @@ -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); diff --git a/app/View/Elements/Events/View/eventFilteringQueryBuilder.ctp b/app/View/Elements/Events/View/eventFilteringQueryBuilder.ctp index ce97fbff6..7572d3595 100644 --- a/app/View/Elements/Events/View/eventFilteringQueryBuilder.ctp +++ b/app/View/Elements/Events/View/eventFilteringQueryBuilder.ctp @@ -1,9 +1,10 @@ function triggerEventFilteringTool(clicked) { + var 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": }, - // { - // "input": "select", - // "type": "string", - // "operators": [ - // "equal", - // ], - // "unique": false, - // "id": "objectType", - // "label": "Object Types", - // $object) { - // if ($object['objectType'] == 'object') { - // $object_types[$object['name']] = $object['name']; - // } - // } - // ksort($object_types); - // ?> - // "values": - // }, - // { - // "input": "select", - // "type": "string", - // "operators": [ - // "equal", - // ], - // "unique": false, - // "id": "attributeType", - // "label": "Attribute Types", - // $attribute) { - // if ($attribute['objectType'] == 'attribute') { - // $attribute_types[$attribute['type']] = $attribute['type']; - // } - // } - // ksort($attribute_types); - // ?> - // "values": - // }, { "input": "text", "type": "string", @@ -255,11 +216,14 @@ function triggerEventFilteringTool(clicked) { condition: 'AND', not: false, rules: [ + { field: 'searchFor', id: 'searchFor', value: $('
').html("").text() }, + + { field: 'attributeFilter', id: 'attributeFilter', @@ -269,87 +233,78 @@ function triggerEventFilteringTool(clicked) { value: "" }, + + { field: 'proposal', id: 'proposal', value: }, + + { field: 'correlation', id: 'correlation', value: }, + + { field: 'warning', id: 'warning', value: }, + + { field: 'deleted', id: 'deleted', value: }, + + { field: 'includeRelatedTags', id: 'includeRelatedTags', value: }, + + { field: 'feed', id: 'feed', value: }, + + { field: 'server', id: 'server', value: }, + + { field: 'distribution', id: 'distribution', operator: 'in', value: }, - + + { field: 'taggedAttributes', id: 'taggedAttributes', - value: + value: '' }, - + { field: 'galaxyAttachedAttributes', id: 'galaxyAttachedAttributes', - value: + value: '' }, - // { - // condition: 'OR', - // not: false, - // flags: { - // no_add_group: true, - // condition_readonly: true, - // }, - // rules: [{ - // field: 'objectType', - // id: 'objectType', - // value: '', - // }] - // }, - // { - // condition: 'OR', - // not: false, - // flags: { - // no_add_group: true, - // condition_readonly: true, - // }, - // rules: [{ - // field: 'attributeType', - // id: 'attributeType', - // value: '', - // }] - // } ], 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; } diff --git a/app/View/Elements/eventattribute.ctp b/app/View/Elements/eventattribute.ctp index 9eaef5b3d..79374f785 100644 --- a/app/View/Elements/eventattribute.ctp +++ b/app/View/Elements/eventattribute.ctp @@ -158,7 +158,7 @@ - +