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

queue: Add flag to inherit columns

Queues can elect to use the columns from a parent. This is enforced by
default for saved searches and queues not defining any columns.

* Fix wrapping issue combining truncated fields with annotations
* Only support criteria inheritance for queues with a parent
parent 23c05049
No related branches found
No related tags found
No related merge requests found
...@@ -314,6 +314,26 @@ class SearchAjaxAPI extends AjaxController { ...@@ -314,6 +314,26 @@ class SearchAjaxAPI extends AjaxController {
$queues->filter(array('id__in' => $ids)); $queues->filter(array('id__in' => $ids));
$query = Ticket::objects(); $query = Ticket::objects();
// Visibility contraints ------------------
// TODO: Consider SavedSearch::ignoreVisibilityConstraints()
// -- Open and assigned to me
$assigned = Q::any(array(
'staff_id' => $thisstaff->getId(),
));
// -- Open and assigned to a team of mine
if ($teams = array_filter($thisstaff->getTeams()))
$assigned->add(array('team_id__in' => $teams));
$visibility = Q::any(new Q(array('status__state'=>'open', $assigned)));
// -- Routed to a department of mine
if (!$thisstaff->showAssignedOnly() && ($depts=$thisstaff->getDepts()))
$visibility->add(array('dept_id__in' => $depts));
$query->filter($visibility);
foreach ($queues as $queue) { foreach ($queues as $queue) {
$Q = $queue->getBasicQuery(); $Q = $queue->getBasicQuery();
$query->aggregate(array( $query->aggregate(array(
......
...@@ -37,6 +37,13 @@ class CustomQueue extends SavedSearch { ...@@ -37,6 +37,13 @@ class CustomQueue extends SavedSearch {
} }
function getColumns() { function getColumns() {
if ($this->parent_id
&& $this->hasFlag(self::FLAG_INHERIT_COLUMNS)
&& $this->parent
) {
return $this->parent->getColumns();
}
if (!count($this->columns)) { if (!count($this->columns)) {
foreach (parent::getColumns() as $c) foreach (parent::getColumns() as $c)
$this->addColumn($c); $this->addColumn($c);
...@@ -76,7 +83,12 @@ class CustomQueue extends SavedSearch { ...@@ -76,7 +83,12 @@ class CustomQueue extends SavedSearch {
)); ));
} }
function getBasicQuery($form=false) { /**
* Add critiera to a query based on the constraints configured for this
* queue. The criteria of the parent queue is also automatically added
* if the queue is configured to inherit the criteria.
*/
function getBasicQuery() {
if ($this->parent && $this->inheritCriteria()) { if ($this->parent && $this->inheritCriteria()) {
$query = $this->parent->getBasicQuery(); $query = $this->parent->getBasicQuery();
} }
...@@ -137,7 +149,8 @@ class CustomQueue extends SavedSearch { ...@@ -137,7 +149,8 @@ class CustomQueue extends SavedSearch {
// Set basic queue information // Set basic queue information
$this->filter = $vars['filter']; $this->filter = $vars['filter'];
$this->setFlag(self::FLAG_INHERIT_CRITERIA, isset($vars['inherit'])); $this->setFlag(self::FLAG_INHERIT_CRITERIA,
$this->parent_id > 0 && isset($vars['inherit']));
// Update queue columns (but without save) // Update queue columns (but without save)
if (isset($vars['columns'])) { if (isset($vars['columns'])) {
...@@ -172,6 +185,10 @@ class CustomQueue extends SavedSearch { ...@@ -172,6 +185,10 @@ class CustomQueue extends SavedSearch {
// Re-sort the in-memory columns array // Re-sort the in-memory columns array
$this->columns->sort(function($c) { return $c->sort; }); $this->columns->sort(function($c) { return $c->sort; });
} }
else {
// No columns -- imply column inheritance
$this->setFlag(self::FLAG_INHERIT_COLUMNS);
}
return 0 === count($errors); return 0 === count($errors);
} }
...@@ -245,8 +262,8 @@ abstract class QueueColumnAnnotation { ...@@ -245,8 +262,8 @@ abstract class QueueColumnAnnotation {
static $positions = array( static $positions = array(
'<' => '<span class="pull-left">%2$s</span>%1$s', '<' => '<span class="pull-left">%2$s</span>%1$s',
'>' => '<span class="pull-right">%2$s</span>%1$s', '>' => '<span class="pull-right">%2$s</span>%1$s',
'a' => '%1$s %2$s', 'a' => '%1$s%2$s',
'b' => '%2$s %1$s', 'b' => '%2$s%1$s',
); );
$pos = $this->getPosition(); $pos = $this->getPosition();
......
...@@ -680,6 +680,7 @@ class SavedSearch extends VerySimpleModel { ...@@ -680,6 +680,7 @@ class SavedSearch extends VerySimpleModel {
const FLAG_QUEUE = 0x0002; // Shows up in queue navigation const FLAG_QUEUE = 0x0002; // Shows up in queue navigation
const FLAG_CONTAINER = 0x0004; // Container for other queues ('Open') const FLAG_CONTAINER = 0x0004; // Container for other queues ('Open')
const FLAG_INHERIT_CRITERIA = 0x0008; // Include criteria from parent const FLAG_INHERIT_CRITERIA = 0x0008; // Include criteria from parent
const FLAG_INHERIT_COLUMNS = 0x0010; // Inherit column layout from parent
var $criteria; var $criteria;
private $columns; private $columns;
...@@ -1062,6 +1063,12 @@ class SavedSearch extends VerySimpleModel { ...@@ -1062,6 +1063,12 @@ class SavedSearch extends VerySimpleModel {
// Use columns from cited queue // Use columns from cited queue
return $q->getColumns(); return $q->getColumns();
} }
elseif ($this->parent_id
&& $this->hasFlag(self::FLAG_INHERIT_COLUMNS)
&& $this->parent
) {
return $this->parent->getColumns();
}
if (isset($this->columns)) if (isset($this->columns))
return $this->columns; return $this->columns;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment