Skip to content

Commit

Permalink
amendme: Add concept of customizable queues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Hancock committed Oct 5, 2017
1 parent acac370 commit 64b4daf
Show file tree
Hide file tree
Showing 30 changed files with 4,808 additions and 203 deletions.
1 change: 1 addition & 0 deletions bootstrap.php
Expand Up @@ -133,6 +133,7 @@ static function defineTables($prefix) {
define('SEQUENCE_TABLE', $prefix.'sequence');
define('TRANSLATION_TABLE', $prefix.'translation');
define('QUEUE_TABLE', $prefix.'queue');
define('QUEUE_COLUMN_TABLE', $prefix.'queue_column');

define('API_KEY_TABLE',$prefix.'api_key');
define('TIMEZONE_TABLE',$prefix.'timezone');
Expand Down
158 changes: 120 additions & 38 deletions include/ajax.search.php
Expand Up @@ -19,6 +19,7 @@

include_once(INCLUDE_DIR.'class.ticket.php');
require_once(INCLUDE_DIR.'class.ajax.php');
require_once(INCLUDE_DIR.'class.queue.php');

class SearchAjaxAPI extends AjaxController {

Expand All @@ -30,7 +31,7 @@ function getAdvancedSearchDialog() {

$search = SavedSearch::create();
$form = $search->getFormFromSession('advsearch') ?: $search->getForm();
$matches = self::_getSupportedTicketMatches();
$matches = SavedSearch::getSupportedTicketMatches();

include STAFFINC_DIR . 'templates/advanced-search.tmpl.php';
}
Expand Down Expand Up @@ -96,7 +97,7 @@ function doSearch() {

$form = $search->getForm($_POST);
if (!$form->isValid()) {
$matches = self::_getSupportedTicketMatches();
$matches = SavedSearch::getSupportedTicketMatches();
include STAFFINC_DIR . 'templates/advanced-search.tmpl.php';
return;
}
Expand Down Expand Up @@ -148,41 +149,6 @@ function _saveSearch($search) {
)));
}

function _getSupportedTicketMatches() {
// User information
$matches = array(
__('Ticket Built-In') => SavedSearch::getExtendedTicketFields(),
__('Custom Forms') => array()
);
foreach (array('ticket'=>'TicketForm', 'user'=>'UserForm', 'organization'=>'OrganizationForm') as $k=>$F) {
$form = $F::objects()->one();
$fields = &$matches[$form->getLocal('title')];
foreach ($form->getFields() as $f) {
if (!$f->hasData() || $f->isPresentationOnly())
continue;
$fields[":$k!".$f->get('id')] = __(ucfirst($k)).' / '.$f->getLocal('label');
/* TODO: Support matches on list item properties
if (($fi = $f->getImpl()) && $fi->hasSubFields()) {
foreach ($fi->getSubFields() as $p) {
$fields[":$k.".$f->get('id').'.'.$p->get('id')]
= __(ucfirst($k)).' / '.$f->getLocal('label').' / '.$p->getLocal('label');
}
}
*/
}
}
$fields = &$matches[__('Custom Forms')];
foreach (DynamicForm::objects()->filter(array('type'=>'G')) as $form) {
foreach ($form->getFields() as $f) {
if (!$f->hasData() || $f->isPresentationOnly())
continue;
$key = sprintf(':field!%d', $f->get('id'), $f->get('id'));
$fields[$key] = $form->getLocal('title').' / '.$f->getLocal('label');
}
}
return $matches;
}

function createSearch() {
global $thisstaff;

Expand All @@ -208,7 +174,7 @@ function loadSearch($id) {
$form = $search->loadFromState($state);
$form->loadState($state);
}
$matches = self::_getSupportedTicketMatches();
$matches = SavedSearch::getSupportedTicketMatches();

include STAFFINC_DIR . 'templates/advanced-search.tmpl.php';
}
Expand All @@ -231,4 +197,120 @@ function deleteSearch($id) {
'success' => true,
)));
}


function editColumn($queue_id, $column) {
global $thisstaff;

if (!$thisstaff) {
Http::response(403, 'Agent login is required');
}
elseif (!($queue = CustomQueue::lookup($queue_id))) {
Http::response(404, 'No such queue');
}

$data_form = new QueueDataConfigForm($_POST);
include STAFFINC_DIR . 'templates/queue-column.tmpl.php';
}

function previewQueue($id=false) {
global $thisstaff;

if (!$thisstaff) {
Http::response(403, 'Agent login is required');
}
if ($id && (!($queue = CustomQueue::lookup($id)))) {
Http::response(404, 'No such queue');
}

if (!$queue) {
$queue = CustomQueue::create();
}

$form = $queue->getForm($_POST);

// TODO: Update queue columns (but without save)
foreach ($_POST['columns'] as $colid) {
$col = QueueColumn::create(array("id" => $colid));
$col->update($_POST);
$queue->addColumn($col);
}

$tickets = $queue->getQuery($form);
$count = 10; // count($queue->getBasicQuery($form));

include STAFFINC_DIR . 'templates/queue-tickets.tmpl.php';
}

function addCondition() {
global $thisstaff;

if (!$thisstaff) {
Http::response(403, 'Agent login is required');
}
elseif (!isset($_GET['field'])) {
Http::response(400, '`field` parameter is required');
}
$fields = SavedSearch::getSearchableFields('Ticket');
if (!isset($fields[$_GET['field']])) {
Http::response(400, sprintf('%s: No such searchable field'),
Format::htmlchars($_GET['field']));
}

$field = $fields[$_GET['field']];
$condition = new QueueColumnCondition();
include STAFFINC_DIR . 'templates/queue-column-condition.tmpl.php';
}

function addConditionProperty() {
global $thisstaff;

if (!$thisstaff) {
Http::response(403, 'Agent login is required');
}
elseif (!isset($_GET['prop'])) {
Http::response(400, '`prop` parameter is required');
}

$prop = $_GET['prop'];
include STAFFINC_DIR . 'templates/queue-column-condition-prop.tmpl.php';
}

function addColumn() {
global $thisstaff;

if (!$thisstaff) {
Http::response(403, 'Agent login is required');
}
elseif (!isset($_GET['field'])) {
Http::response(400, '`field` parameter is required');
}

$field = $_GET['field'];
// XXX: This method should receive a queue ID or queue root so that
// $field can be properly checked
$fields = SavedSearch::getSearchableFields('Ticket');
if (!isset($fields[$field])) {
Http::response(400, 'Not a supported field for this queue');
}

// Get the tabbed column configuration
$F = $fields[$field];
$column = QueueColumn::create(array(
"id" => (int) $_GET['id'],
"heading" => _S($F->getLabel()),
"primary" => $field,
"width" => 100,
));
ob_start();
include STAFFINC_DIR . 'templates/queue-column.tmpl.php';
$config = ob_get_clean();

// Send back the goodies
Http::response(200, $this->encode(array(
'config' => $config,
'heading' => _S($F->getLabel()),
'width' => $column->getWidth(),
)), 'application/json');
}
}
14 changes: 13 additions & 1 deletion include/class.dept.php
Expand Up @@ -13,9 +13,10 @@ class.dept.php
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
require_once INCLUDE_DIR . 'class.search.php';

class Dept extends VerySimpleModel
implements TemplateVariable {
implements TemplateVariable, Searchable {

static $meta = array(
'table' => DEPT_TABLE,
Expand Down Expand Up @@ -98,6 +99,17 @@ function getVar($tag) {
}
}

static function getSearchableFields() {
return array(
'name' => new TextboxField(array(
'label' => __('Name'),
)),
'manager' => new AgentSelectionField(array(
'label' => __('Manager'),
)),
);
}

function getId() {
return $this->id;
}
Expand Down

0 comments on commit 64b4daf

Please sign in to comment.