Skip to content
Snippets Groups Projects
Commit 674c0461 authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

queue: Add recent search history to search dropdown

parent 6f8e57f6
Branches
Tags
No related merge requests found
...@@ -22,7 +22,7 @@ require_once(INCLUDE_DIR.'class.ajax.php'); ...@@ -22,7 +22,7 @@ require_once(INCLUDE_DIR.'class.ajax.php');
class SearchAjaxAPI extends AjaxController { class SearchAjaxAPI extends AjaxController {
function getAdvancedSearchDialog() { function getAdvancedSearchDialog($key=false, $context='advsearch') {
global $thisstaff; global $thisstaff;
if (!$thisstaff) if (!$thisstaff)
...@@ -31,7 +31,14 @@ class SearchAjaxAPI extends AjaxController { ...@@ -31,7 +31,14 @@ class SearchAjaxAPI extends AjaxController {
$search = SavedSearch::create(array( $search = SavedSearch::create(array(
'root' => 'T', 'root' => 'T',
)); ));
$search->config = $_SESSION['advsearch']; if (isset($_SESSION[$context])) {
// Use the most recent search
if (!$key) {
reset($_SESSION[$context]);
$key = key($_SESSION[$context]);
}
$search->config = $_SESSION[$context][$key];
}
$this->_tryAgain($search, $search->getForm()); $this->_tryAgain($search, $search->getForm());
} }
...@@ -98,7 +105,39 @@ class SearchAjaxAPI extends AjaxController { ...@@ -98,7 +105,39 @@ class SearchAjaxAPI extends AjaxController {
if ($this->_hasErrors($search, $form)) if ($this->_hasErrors($search, $form))
return false; return false;
$_SESSION[$key] = $search->isolateCriteria($form->getClean()); if ($key) {
$keep = array();
// Add in new search to the list of recent searches
$criteria = $search->isolateCriteria($form->getClean());
$token = $this->_hashCriteria($criteria);
$keep[$token] = $criteria;
// Keep the last 5 recent searches looking from the beginning of
// the recent search list
if (isset($_SESSION[$key])) {
reset($_SESSION[$key]);
while (count($keep) < 5) {
list($k, $v) = each($_SESSION[$key]);
if (!$k)
break;
$keep[$k] = $v;
}
}
$_SESSION[$key] = $keep;
}
}
function _hashCriteria($criteria, $size=10) {
$parts = array();
foreach ($criteria as $C) {
list($name, $method, $value) = $C;
if (is_array($value))
$value = implode('+', $value);
$parts[] = "{$name} {$method} {$value}";
}
$hash = sha1(implode(' ', $parts), true);
return substr(
str_replace(array('+','/','='), '', base64_encode($hash)),
-$size);
} }
function _tryAgain($search, $form, $errors=array()) { function _tryAgain($search, $form, $errors=array()) {
......
...@@ -729,6 +729,20 @@ class SavedSearch extends VerySimpleModel { ...@@ -729,6 +729,20 @@ class SavedSearch extends VerySimpleModel {
return $this->criteria ?: array(); return $this->criteria ?: array();
} }
function describeCriteria($criteria=false){
$all = $this->getSupportedMatches($this->getRoot());
$items = array();
$criteria = $criteria ?: $this->getCriteria();
foreach ($criteria as $C) {
list($path, $method, $value) = $C;
if (!isset($all[$path]))
continue;
list($label, $field) = $all[$path];
$items[] = $field->describeSearch($method, $value, $label);
}
return implode(', ', $items);
}
/** /**
* Fetch an AdvancedSearchForm instance for use in displaying or * Fetch an AdvancedSearchForm instance for use in displaying or
* configuring this search in the user interface. * configuring this search in the user interface.
......
...@@ -61,7 +61,8 @@ $emitLevel = function($queues, $level=0) use ($all_queues, &$emitLevel) { ...@@ -61,7 +61,8 @@ $emitLevel = function($queues, $level=0) use ($all_queues, &$emitLevel) {
</td> </td>
<td width="63%" colspan="<?php echo max(1, 5-$level); ?>"><a <td width="63%" colspan="<?php echo max(1, 5-$level); ?>"><a
href="queues.php?id=<?php echo $q->getId(); ?>"><?php href="queues.php?id=<?php echo $q->getId(); ?>"><?php
echo Format::htmlchars($q->getFullName()); ?></a></td> echo Format::htmlchars($q->getFullName()); ?></a>
<i class="faded-more pull-right icon-sort"></i></td>
<td><?php echo Format::htmlchars($q->staff ? $q->staff->getName() : <td><?php echo Format::htmlchars($q->staff ? $q->staff->getName() :
__('SYSTEM')); ?></td> __('SYSTEM')); ?></td>
<td><?php echo Format::htmlchars($q->getStatus()); ?></td> <td><?php echo Format::htmlchars($q->getStatus()); ?></td>
......
...@@ -11,16 +11,6 @@ ...@@ -11,16 +11,6 @@
<div class="customQ-dropdown"> <div class="customQ-dropdown">
<ul class="scroll-height"> <ul class="scroll-height">
<!-- Start Dropdown and child queues --> <!-- Start Dropdown and child queues -->
<?php foreach ($searches->findAll(array(
'parent_id' => 0,
'flags__hasbit' => SavedSearch::FLAG_PUBLIC,
)) as $q) {
include 'queue-subnavigation.tmpl.php';
} ?>
<!-- Dropdown Titles -->
<li>
<h4><?php echo __('Personal Queues'); ?></h4>
</li>
<?php foreach ($searches->findAll(array( <?php foreach ($searches->findAll(array(
'staff_id' => $thisstaff->getId(), 'staff_id' => $thisstaff->getId(),
'parent_id' => 0, 'parent_id' => 0,
...@@ -30,6 +20,17 @@ ...@@ -30,6 +20,17 @@
)) as $q) { )) as $q) {
include 'queue-subnavigation.tmpl.php'; include 'queue-subnavigation.tmpl.php';
} ?> } ?>
<li>
<h4><?php echo __('Recent Searches'); ?></h4>
<?php foreach ($_SESSION['advsearch'] as $token=>$criteria) {
$q = new SavedSearch(array('root' => 'T'));
$q->id = 'adhoc,'.$token;
$q->title = $q->describeCriteria($criteria);
include 'queue-subnavigation.tmpl.php';
} ?>
<!-- Dropdown Titles -->
</li>
</ul> </ul>
<!-- Add Queue button sticky at the bottom --> <!-- Add Queue button sticky at the bottom -->
<div class="add-queue"> <div class="add-queue">
......
...@@ -13,7 +13,7 @@ global $thisstaff; ...@@ -13,7 +13,7 @@ global $thisstaff;
if ($hasChildren) { ?> if ($hasChildren) { ?>
<i class="icon-caret-down"></i> <i class="icon-caret-down"></i>
<?php } <?php }
if ($thisstaff->isAdmin()) { ?> if ($thisstaff->isAdmin() || $q->isPrivate()) { ?>
<!-- Edit Queue --> <!-- Edit Queue -->
<div class="editQ pull-right"> <div class="editQ pull-right">
<i class="icon-cog"></i> <i class="icon-cog"></i>
...@@ -28,7 +28,8 @@ global $thisstaff; ...@@ -28,7 +28,8 @@ global $thisstaff;
<li> <li>
<a href="<?php <a href="<?php
echo $queue->isPrivate() echo $queue->isPrivate()
? sprintf('#" data-dialog="ajax.php/tickets/search/%d', $queue->getId()) ? sprintf('#" data-dialog="ajax.php/tickets/search/%s',
urlencode($queue->getId()))
: sprintf('queues.php?id=%d', $queue->getId()); ?>"> : sprintf('queues.php?id=%d', $queue->getId()); ?>">
<i class="icon-fixed-width icon-pencil"></i> <i class="icon-fixed-width icon-pencil"></i>
<?php echo __('Edit'); ?></a> <?php echo __('Edit'); ?></a>
...@@ -44,7 +45,8 @@ global $thisstaff; ...@@ -44,7 +45,8 @@ global $thisstaff;
<span class="pull-right">(?)</span> <span class="pull-right">(?)</span>
<!-- End Edit Queue --> <!-- End Edit Queue -->
<a class="truncate <?php if ($selected) echo ' active'; ?>" href="<?php echo $queue->getHref(); <a class="truncate <?php if ($selected) echo ' active'; ?>" href="<?php echo $queue->getHref();
?>"><?php echo $q->getName(); ?></a> ?>" title="<?php echo Format::htmlchars($q->getName()); ?>"><?php
echo Format::htmlchars($q->getName()); ?></a>
<?php if ($hasChildren) { <?php if ($hasChildren) {
echo '<ul>'; echo '<ul>';
foreach ($children as $q) { foreach ($children as $q) {
......
...@@ -170,6 +170,7 @@ $dispatcher = patterns('', ...@@ -170,6 +170,7 @@ $dispatcher = patterns('',
url_get('^$', 'getAdvancedSearchDialog'), url_get('^$', 'getAdvancedSearchDialog'),
url_post('^$', 'doSearch'), url_post('^$', 'doSearch'),
url_get('^/(?P<id>\d+)$', 'editSearch'), url_get('^/(?P<id>\d+)$', 'editSearch'),
url_get('^/adhoc,(?P<key>[\w=/+]+)$', 'getAdvancedSearchDialog'),
url_post('^/(?P<id>\d+)$', 'saveSearch'), url_post('^/(?P<id>\d+)$', 'saveSearch'),
url_delete('^/(?P<id>\d+)$', 'deleteSearch'), url_delete('^/(?P<id>\d+)$', 'deleteSearch'),
url_post('^/create$', 'createSearch'), url_post('^/create$', 'createSearch'),
......
...@@ -62,6 +62,25 @@ $queue_id = @$_REQUEST['queue'] ?: $cfg->getDefaultTicketQueueId(); ...@@ -62,6 +62,25 @@ $queue_id = @$_REQUEST['queue'] ?: $cfg->getDefaultTicketQueueId();
if ((int) $queue_id) { if ((int) $queue_id) {
$queue = CustomQueue::lookup($queue_id); $queue = CustomQueue::lookup($queue_id);
} }
elseif (isset($_SESSION['advsearch'])
&& strpos($queue_id, 'adhoc') === 0
) {
list(,$key) = explode(',', $queue_id, 2);
// XXX: De-duplicate and simplify this code
$queue = SavedSearch::create(array(
'title' => __("Advanced Search"),
'root' => 'T',
));
// For queue=queue, use the most recent search
if (!$key) {
reset($_SESSION['advsearch']);
$key = key($_SESSION['advsearch']);
}
$queue->config = $_SESSION['advsearch'][$key];
// Slight hack here to make the `adhoc` queue be selected
$_REQUEST['queue'] = 'adhoc,'.$key;
}
// Configure form for file uploads // Configure form for file uploads
$response_form = new SimpleForm(array( $response_form = new SimpleForm(array(
...@@ -391,17 +410,6 @@ as $q) { ...@@ -391,17 +410,6 @@ as $q) {
}); });
} }
if (isset($_SESSION['advsearch'])) {
// XXX: De-duplicate and simplify this code
$adhoc = SavedSearch::create(array(
'title' => __("Advanced Search"),
'root' => 'T',
));
$adhoc->config = $_SESSION['advsearch'];
if ($_REQUEST['queue'] == 'adhoc')
$queue = $adhoc;
}
// Add my advanced searches // Add my advanced searches
$nav->addSubMenu(function() use ($queue, $adhoc) { $nav->addSubMenu(function() use ($queue, $adhoc) {
global $thisstaff; global $thisstaff;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment