+ bugModel: add methods to generate columns and rows displayed in datatable.
This commit is contained in:
+229
-2
@@ -3570,10 +3570,11 @@ class bugModel extends model
|
||||
*
|
||||
* @param object $bug
|
||||
* @param array $users
|
||||
* @param bool $output
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function printAssignedHtml($bug, $users)
|
||||
public function printAssignedHtml($bug, $users, $output = true)
|
||||
{
|
||||
$btnTextClass = '';
|
||||
$btnClass = '';
|
||||
@@ -3588,7 +3589,10 @@ class bugModel extends model
|
||||
$assignToLink = helper::createLink('bug', 'assignTo', "bugID=$bug->id", '', true);
|
||||
$assignToHtml = html::a($assignToLink, "<i class='icon icon-hand-right'></i> <span title='" . zget($users, $bug->assignedTo) . "'>{$assignedToText}</span>", '', "class='$btnClass'");
|
||||
|
||||
echo !common::hasPriv('bug', 'assignTo', $bug) ? "<span style='padding-left: 21px' class='{$btnTextClass}'>{$assignedToText}</span>" : $assignToHtml;
|
||||
$html = !common::hasPriv('bug', 'assignTo', $bug) ? "<span style='padding-left: 21px' class='{$btnTextClass}'>{$assignedToText}</span>" : $assignToHtml;
|
||||
if(!$output) return $html;
|
||||
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3807,4 +3811,227 @@ class bugModel extends model
|
||||
return (object) array('value' => $key, 'text' => $value);
|
||||
}, array_keys($data), array_values($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate columns used in datatable.
|
||||
*
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function generateCol($orderBy)
|
||||
{
|
||||
$setting = $this->loadModel('datatable')->getSetting('bug');
|
||||
$fieldList = $this->config->bug->datatable->fieldList;
|
||||
|
||||
if(empty($setting))
|
||||
{
|
||||
$setting = $this->config->bug->datatable->defaultField;
|
||||
$order = 1;
|
||||
foreach($setting as $key => $value)
|
||||
{
|
||||
if(isset($fieldList[$value]['display']) && $fieldList[$value]['display'] === false)
|
||||
{
|
||||
unset($setting[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = $value;
|
||||
$set = new stdclass();;
|
||||
$set->order = $order++;
|
||||
$set->show = true;
|
||||
$set->name = $value;
|
||||
$set->title = $fieldList[$id]['title'];
|
||||
|
||||
$sortType = '';
|
||||
if(strpos($orderBy, $id) !== false)
|
||||
{
|
||||
$sort = str_replace("{$id}_", '', $orderBy);
|
||||
$sortType = $sort == 'asc' ? 'up' : 'down';
|
||||
}
|
||||
|
||||
if(isset($fieldList[$id]['checkbox'])) $set->checkbox = $fieldList[$id]['checkbox'];
|
||||
if(isset($fieldList[$id]['fixed'])) $set->fixed = $fieldList[$id]['fixed'];
|
||||
if(isset($fieldList[$id]['width'])) $set->width = $fieldList[$id]['width'];
|
||||
if(isset($fieldList[$id]['type'])) $set->type = $fieldList[$id]['type'];
|
||||
if(isset($fieldList[$id]['sortType'])) $set->sortType = $fieldList[$id]['sortType'];
|
||||
if(isset($fieldList[$id]['flex'])) $set->flex = $fieldList[$id]['flex'];
|
||||
if(isset($fieldList[$id]['minWidth'])) $set->minWidth = $fieldList[$id]['minWidth'];
|
||||
if(isset($fieldList[$id]['maxWidth'])) $set->maxWidth = $fieldList[$id]['maxWidth'];
|
||||
if(isset($fieldList[$id]['pri'])) $set->pri = $fieldList[$id]['pri'];
|
||||
|
||||
if($sortType) $set->sortType = $sortType;
|
||||
|
||||
$setting[$key] = $set;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($setting as $key => $set)
|
||||
{
|
||||
if(empty($set->show))
|
||||
{
|
||||
unset($setting[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($fieldList[$set->id]['display']) && $fieldList[$set->id]['display'] === false)
|
||||
{
|
||||
unset($setting[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$sortType = '';
|
||||
if(strpos($orderBy, $set->id) !== false)
|
||||
{
|
||||
$sort = str_replace("{$set->id}_", '', $orderBy);
|
||||
$sortType = $sort == 'asc' ? 'up' : 'down';
|
||||
}
|
||||
|
||||
$set->name = $set->id;
|
||||
$set->title = $fieldList[$set->id]['title'];
|
||||
|
||||
if(isset($fieldList[$set->id]['checkbox'])) $set->checkbox = $fieldList[$set->id]['checkbox'];
|
||||
if(isset($fieldList[$set->id]['fixed'])) $set->fixed = $fieldList[$set->id]['fixed'];
|
||||
if(isset($fieldList[$set->id]['type'])) $set->type = $fieldList[$set->id]['type'];
|
||||
if(isset($fieldList[$set->id]['sortType'])) $set->sortType = $fieldList[$set->id]['sortType'];
|
||||
if(isset($fieldList[$set->id]['flex'])) $set->flex = $fieldList[$set->id]['flex'];
|
||||
if(isset($fieldList[$set->id]['minWidth'])) $set->minWidth = $fieldList[$set->id]['minWidth'];
|
||||
if(isset($fieldList[$set->id]['maxWidth'])) $set->maxWidth = $fieldList[$set->id]['maxWidth'];
|
||||
if(isset($fieldList[$set->id]['pri'])) $set->pri = $fieldList[$set->id]['pri'];
|
||||
|
||||
if($sortType) $set->sortType = $sortType;
|
||||
|
||||
if(isset($set->width)) $set->width = str_replace('px', '', $set->width);
|
||||
|
||||
unset($set->id);
|
||||
}
|
||||
}
|
||||
|
||||
usort($setting, array('datatableModel', 'sortCols'));
|
||||
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate rows displayed in datatable.
|
||||
*
|
||||
* @param array $bugs
|
||||
* @param array $branches
|
||||
* @param array $modulePairs
|
||||
* @param array $projectPairs
|
||||
* @param array $plans
|
||||
* @param array $executions
|
||||
* @param array $stories
|
||||
* @param array $tasks
|
||||
* @param array $users
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function generateRow($bugs, $branches, $modulePairs, $projectPairs, $plans, $executions, $stories, $tasks, $users)
|
||||
{
|
||||
$rows = array();
|
||||
$userFields = array('openedBy', 'assignedTo', 'resolvedBy', 'closedBy', 'lastEditedBy');
|
||||
$dateFields = array('activatedDate', 'openedDate', 'assignedDate', 'deadline', 'resolvedDate', 'closedDate', 'lastEditedDate');
|
||||
$canViewBug = common::hasPriv('bug', 'view');
|
||||
$canViewCase = common::hasPriv('case', 'view');
|
||||
$canViewTask = common::hasPriv('task', 'view');
|
||||
$canViewStory = common::hasPriv('story', 'view');
|
||||
|
||||
foreach($bugs as $bug)
|
||||
{
|
||||
$severityValue = zget($this->lang->bug->severityList, $bug->severity);
|
||||
$severityClass = !is_numeric($severityValue) ? 'label-severity-custom' : 'label-severity';
|
||||
$bugSeverity = !is_numeric($severityValue) ? $severityValue : '';
|
||||
$bug->severity = "<span class='{$severityClass}' data-severity='{$bug->severity}' title='{$severityValue}'>{$bugSeverity}</span>";
|
||||
|
||||
$bugPri = zget($this->lang->bug->priList, $bug->pri);
|
||||
$bug->pri = $bug->pri ? "<span class='label-pri label-pri-{$bug->pri}' title='{$bugPri}'>{$bugPri}</span>" : '';
|
||||
|
||||
$bugConfirmed = zget($this->lang->bug->confirmedList, $bug->confirmed);
|
||||
$bug->confirmed = "<span class='confirm{$bug->confirmed}' title='{$bugConfirmed}'>{$bugConfirmed}</span>";
|
||||
|
||||
$bugTitle = '';
|
||||
$showBranch = isset($this->config->bug->browse->showBranch) ? $this->config->bug->browse->showBranch : 1;
|
||||
if($showBranch && !empty($branches[$bug->branch])) $bugTitle .= "<span class='label label-outline label-badge' title={$branches[$bug->branch]}>{$branches[$bug->branch]}</span> ";
|
||||
if($bug->module && !empty($modulePairs[$bug->module])) $bugTitle .= "<span class='label label-gray label-badge'>{$modulePairs[$bug->module]}</span> ";
|
||||
$bugTitle .= $canViewBug ? html::a(helper::createLink('bug', 'view', "bugID={$bug->id}"), $bug->title, null, "style='color: {$bug->color}' data-app={$this->app->tab}") : "<span style='color: {$bug->color}'>{$bug->title}</span>";
|
||||
if($bug->case)
|
||||
{
|
||||
$bugCase = "[{$this->lang->testcase->common}#{$bug->case}]";
|
||||
$bugTitle .= $canViewCase ? html::a(helper::createLink('testcase', 'view', "caseID={$bug->case}&version={$bug->caseVersion}"), $bugCase, '', "class='bug' title='{$bug->case}'") : $bugCase;
|
||||
}
|
||||
$bug->title = $bugTitle;
|
||||
|
||||
$bug->branch = zget($branches, $bug->branch, '');
|
||||
$bug->project = zget($projectPairs, $bug->project, '');
|
||||
$bug->plan = zget($plans, $bug->plan, '');
|
||||
$bug->execution = zget($executions, $bug->execution, '');
|
||||
|
||||
if($bug->story && !empty($stories[$bug->story]))
|
||||
{
|
||||
$story = $stories[$bug->story];
|
||||
$bug->story = $canViewStory ? html::a(helper::createLink('story', 'view', "storyID={$story->id}", 'html', true), $story->title, '', "class='iframe'") : $story->title;
|
||||
}
|
||||
|
||||
if($bug->task && !empty($tasks[$bug->task]))
|
||||
{
|
||||
$task = $tasks[$bug->task];
|
||||
$bug->task = $canViewTask ? html::a(helper::createLink('task', 'view', "taskID={$task->id}", 'html', true), $task->name, '', "class='iframe'") : $task->name;
|
||||
}
|
||||
|
||||
if($bug->toTask && !empty($tasks[$bug->toTask]))
|
||||
{
|
||||
$task = $tasks[$bug->toTask];
|
||||
$bug->toTask = $canViewTask ? html::a(helper::createLink('task', 'view', "taskID={$task->id}", 'html', true), $task->name, '', "class='iframe'") : $task->name;
|
||||
}
|
||||
|
||||
$bug->type = zget($this->lang->bug->typeList, $bug->type, '');
|
||||
|
||||
$bugStatus = $this->processStatus('bug', $bug);
|
||||
$bug->status = "<span class='status-bug status-{$bug->status}' title='{$bugStatus}'> {$bugStatus}</span>";
|
||||
|
||||
$bugOS = array();
|
||||
if($bug->os)
|
||||
{
|
||||
foreach(explode(',', $bug->os) as $os)
|
||||
{
|
||||
$os = trim($os);
|
||||
if($os) $bugOS[] = zget($this->lang->bug->osList, $os, '');
|
||||
}
|
||||
}
|
||||
$bug->os = implode(',', $bugOS);
|
||||
|
||||
$bugBrowser = array();
|
||||
if($bug->browser)
|
||||
{
|
||||
foreach(explode(',', $bug->browser) as $browser)
|
||||
{
|
||||
$browser = trim($browser);
|
||||
if($browser) $bugBrowser[] = zget($this->lang->bug->browserList, $browser, '');
|
||||
}
|
||||
}
|
||||
$bug->browser = implode(',', $bugBrowser);
|
||||
|
||||
$bugMailto = array();
|
||||
if($bug->mailto)
|
||||
{
|
||||
foreach(explode(',', $bug->mailto) as $account)
|
||||
{
|
||||
$account = trim($account);
|
||||
if($account) $bugMailto[] = zget($users, $account);
|
||||
}
|
||||
}
|
||||
$bug->mailto = implode(' ', $bugMailto);
|
||||
|
||||
$bug->assignedTo = $this->printAssignedHtml($bug, $users, false);
|
||||
$bug->actions = '<div class="c-actions">' . $this->buildOperateMenu($bug, 'browse') . '</div>';
|
||||
|
||||
foreach($userFields as $field) $bug->$field = zget($users, $bug->$field);
|
||||
foreach($dateFields as $field) $bug->$field = empty($bug->$field) || helper::isZeroDate($bug->$field) ? '' : $bug->$field;
|
||||
|
||||
$rows[] = $bug;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user