'array', // 任务列表。
'executions' => 'array', // 执行列表。
'onRenderItem' => '?callable' // 渲染需求对象的回调函数。
);
protected function getItems()
{
global $lang, $config;
$tasks = $this->prop('tasks', array());
$executions = $this->prop('executions', array());
$onRenderItem = $this->prop('onRenderItem', array());
$items = array();
$isInModal = isInModal();
$canViewTask = hasPriv('task', 'view');
foreach($tasks as $task)
{
if(!isset($task->execution) || !isset($executions[$task->execution])) continue;
$execution = $executions[$task->execution];
$executionID = $execution->id;
if(!isset($items[$executionID]))
{
$executionLink = (isset($execution->type) && $execution->type == 'kanban' && $isInModal) ? null : (empty($execution->multiple) ? createLink('project', 'view', "projectID=$task->project") : createLink('execution', 'view', "executionID=$executionID"));
$items[$executionID] = array
(
'icon' => 'run',
'title' => $execution->name,
'hint' => $execution->name,
'url' => !in_array($config->vision, array('lite', 'or')) ? $executionLink : null,
'items' => array()
);
}
$item = array
(
'title' => $task->name,
'hint' => $task->name,
'leading' => array('html' => wg(idLabel::create($task->id))->render()),
'content' => array('html' => wg(statusLabel::create($task->status, $lang->task->statusList[$task->status]))->render(), 'className' => 'flex-none'),
'url' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? createLink('task', 'view', "taskID=$task->id") : null,
'data-toggle' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? 'modal' : null,
'data-size' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? 'lg' : null,
);
if(is_callable($onRenderItem)) $item = $onRenderItem($item, $task);
$items[$executionID]['items'][] = $item;
$items[$executionID]['content'] = array('html' => '' . count($items[$executionID]['items']) . '');
}
foreach($executions as $executionID => $execution)
{
if(isset($items[$executionID])) continue;
$executionLink = (isset($execution->type) && $execution->type == 'kanban' && $isInModal) ? null : createLink('execution', 'view', "executionID=$executionID");
if(!$execution->multiple) $executionLink = createLink('project', 'view', "projectID=$execution->project");
$items[$executionID] = array
(
'icon' => 'run',
'title' => $execution->name,
'hint' => $execution->name,
'url' => !in_array($config->vision, array('lite', 'or')) ? $executionLink : null,
'content' => array('html' => '0'),
'items' => array()
);
}
return array_values($items);
}
protected function build()
{
return zui::nestedList
(
set::className('execution-task-list'),
set::defaultNestedShow(),
set::itemProps(array('titleClass' => 'text-clip')),
set::items($this->getItems())
);
}
}