Skip to content

Commit

Permalink
enhancement: introduced persistent filter support (LMS+ #620)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilek committed Sep 6, 2018
1 parent 159b2a0 commit 707575c
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 15 deletions.
1 change: 1 addition & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ version ?.??.?? (????-??-??):
- improvement: new quicksearch for networks [interduo]
- enhancement: allow to show/hide quick search fields on top [chilan]
- enhancement: allow to clear filter in helpdesk queue and event list view [chilan]
- enhancement: introduced persistent filter support [chilan]

version 1.11.23 (2018-03-21):

Expand Down
27 changes: 27 additions & 0 deletions img/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1947,3 +1947,30 @@ table.dataTable thead tr:last-child th {
.chosen-container-single .chosen-drop {
border-radius: unset;
}
div.lms-ui-persistent-filter {
display: flex;
align-items: center;
vertical-align: middle;
margin-bottom: 10px;
}
div.lms-ui-persistent-filter > * {
margin-left: 5px;
}
div.lms-ui-persistent-filter .lms-ui-filter-name {
display: none;
}
div.lms-ui-persistent-filter .lms-ui-button {
height: 25px;
padding-left: 20px;
background-repeat: no-repeat;
background-position: 3px 4px;
}
div.lms-ui-persistent-filter .lms-ui-button.lms-ui-filter-apply-button {
background-image: url(reload.gif);
}
div.lms-ui-persistent-filter .lms-ui-button.lms-ui-filter-modify-button {
background-image: url(add.gif);
}
div.lms-ui-persistent-filter .lms-ui-button.lms-ui-filter-delete-button {
background-image: url(delete.gif);
}
30 changes: 30 additions & 0 deletions img/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -1703,3 +1703,33 @@ table.dataTable {
border-radius: unset;
}
}

div.lms-ui-persistent-filter {
display: flex;
align-items: center;
vertical-align: middle;
margin-bottom: 10px;
& > * {
margin-left: 5px;
}
.lms-ui-filter-name {
display: none;
}
.lms-ui-button {
height: 25px;
padding-left: 20px;
background-repeat: no-repeat;
background-position: 3px 4px;
&.lms-ui-filter-apply-button {
background-image: url(reload.gif);

}
&.lms-ui-filter-modify-button {
background-image: url(add.gif);

}
&.lms-ui-filter-delete-button {
background-image: url(delete.gif);
}
}
}
48 changes: 41 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,6 @@
$qs_fields = array_flip(explode(',', $qs_fields));
}
$SMARTY->assign('qs_fields', $qs_fields);

if (isset($_GET['removefilter'])) {
$SESSION->removeFilter($layout['module']);
$backto = $SESSION->get('backto');
$backto = preg_replace('/&.+$/', '', $backto);
$SESSION->redirect('?' . $backto);
}
}

// Load plugin files and register hook callbacks
Expand Down Expand Up @@ -303,6 +296,47 @@

if ($global_allow || $allow) {
$layout['module'] = $module;

$SESSION->save('module', $module);

if (!$api) {
// remove current filter
if (isset($_GET['removefilter'])) {
$SESSION->removeFilter($layout['module']);
$backto = $SESSION->get('backto');
$backto = preg_replace('/&.+$/', '', $backto);
$SESSION->redirect('?' . $backto);
}

// get all persistent filters
$SMARTY->assign('persistent_filters', $SESSION->getAllPersistentFilters());

// persister filter apply
if (isset($_GET['persistent-filter']) && isset($_POST['name']) && $_POST['action'] == 'apply') {
$filter = $SESSION->getPersistentFilter($_POST['name']);
$SESSION->saveFilter($filter);
}
} else {
// persistent filter ajax management
if (isset($_GET['persistent-filter']) && isset($_POST['name']))
switch ($_POST['action']) {
case 'modify':
$SESSION->savePersistentFilter($_POST['name'], $SESSION->getFilter());
$persistent_filters = $SESSION->getAllPersistentFilters();
$SESSION->close();
header('Content-type: application/json');
die(json_encode(array_keys($persistent_filters)));
break;
case 'delete':
$SESSION->removePersistentFilter($_POST['name']);
$persistent_filters = $SESSION->getAllPersistentFilters();
$SESSION->close();
header('Content-type: application/json');
die(json_encode(array_keys($persistent_filters)));
break;
}
}

$LMS->InitUI();
$LMS->executeHook($module.'_on_load');

Expand Down
59 changes: 53 additions & 6 deletions lib/Session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,19 @@ public function save_persistent_setting($variable, $content) {

public function saveFilter($filter, $module = null) {
if (empty($module))
$module = $this->_content['lastmodule'];
$module = $this->_content['module'];

$this->_content['filters'][$module] = $filter;

if ($this->autoupdate)
$this->_saveSession();
else
$this->_updated = TRUE;
$this->_updated = true;
}

public function restoreFilter($module = null) {
public function getFilter($module = null) {
if (empty($module))
$module = $this->_content['lastmodule'];
$module = $this->_content['module'];

if (!isset($this->_content['filters'][$module]))
return array();
Expand All @@ -247,11 +247,58 @@ public function restoreFilter($module = null) {

public function removeFilter($module = null) {
if (empty($module))
$module = $this->_content['lastmodule'];
$module = $this->_content['module'];

if (isset($this->_content['filters'][$module])) {
unset($this->_content['filters'][$module]);
if( $this->autoupdate)
if ($this->autoupdate)
$this->_saveSession();
else
$this->_updated = true;
return true;
} else
return false;
}

public function savePersistentFilter($name, $filter, $module = null) {
if (empty($module))
$module = $this->_content['module'];

$this->_persistent_settings['filters'][$module][$name] = $filter;

if ($this->autoupdate)
$this->_saveSession();
else
$this->_updated = true;
}

public function getPersistentFilter($name, $module = null) {
if (empty($module))
$module = $this->_content['module'];

if (!isset($this->_persistent_settings['filters'][$module][$name]))
return array();

return $this->_persistent_settings['filters'][$module][$name];
}

public function getAllPersistentFilters($module = null) {
if (empty($module))
$module = $this->_content['module'];

if (!isset($this->_persistent_settings['filters'][$module]))
return array();

return $this->_persistent_settings['filters'][$module];
}

public function removePersistentFilter($name, $module = null) {
if (empty($module))
$module = $this->_content['module'];

if (isset($this->_persistent_settings['filters'][$module][$name])) {
unset($this->_persistent_settings['filters'][$module][$name]);
if ($this->autoupdate)
$this->_saveSession();
else
$this->_updated = TRUE;
Expand Down
7 changes: 7 additions & 0 deletions lib/locale/pl/strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4044,4 +4044,11 @@

$_LANG['Clear filter'] = 'Wyczyść filtr';

$_LANG['Persistent filter:'] = 'Filtr trwały:';
$_LANG['<!filter>Apply'] = 'Zastosuj';
$_LANG['<!filter>Update'] = 'Aktualizuj';
$_LANG['<!filter>Delete'] = 'Usuń';
$_LANG['<!filter>- none -'] = '- żaden - ';
$_LANG['<!filter>- new -'] = '- nowy -';

?>
2 changes: 1 addition & 1 deletion modules/eventlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* $Id$
*/

$filter = $SESSION->restoreFilter();
$filter = $SESSION->getFilter();

if (isset($filter['edate']) && !empty($filter['edate']))
list ($filter['year'], $filter['month'], $filter['day']) = explode('/', $filter['edate']);
Expand Down
2 changes: 1 addition & 1 deletion modules/rtqueueview.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

$LMS->CleanupTicketLastView();

$filter = $SESSION->restoreFilter();
$filter = $SESSION->getFilter();

// queue id's
if (isset($_GET['id']) && $_GET['id'] != 'all') {
Expand Down
3 changes: 3 additions & 0 deletions templates/default/event/eventlist.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ <H1>{trans("Overdue events")}</H1>
{/if}

<H1>{$layout.pagetitle}</H1>

{persistent_filter}

<TABLE class="lmsbox">
<COLGROUP>
<COL style="width: 1%;">
Expand Down
1 change: 1 addition & 0 deletions templates/default/jquery.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<script type="text/javascript" src="img/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="img/clipboard.min.js"></script>
<script type="text/javascript" src="img/jquery-chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="img/lms-ui-persistent-filter.js"></script>
<script type="text/javascript">
<!--
var lmsSettings = {
Expand Down
3 changes: 3 additions & 0 deletions templates/default/rt/rtqueueview.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{block name=module_content}
<!-- $Id$ -->
<H1>{$layout.pagetitle}</H1>

{persistent_filter}

<TABLE class="lmsbox lms-ui-background-cycle">
<COLGROUP>
<COL style="width: 1%;">
Expand Down

0 comments on commit 707575c

Please sign in to comment.