v1.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'idlabel' . DS . 'v1.php';
  4. require_once dirname(__DIR__) . DS . 'statuslabel' . DS . 'v1.php';
  5. class executionTaskList extends wg
  6. {
  7. /**
  8. * @var mixed[]
  9. */
  10. protected static $defineProps = array
  11. (
  12. 'tasks' => 'array', // 任务列表。
  13. 'executions' => 'array', // 执行列表。
  14. 'onRenderItem' => '?callable' // 渲染需求对象的回调函数。
  15. );
  16. protected function getItems()
  17. {
  18. global $lang, $config;
  19. $tasks = $this->prop('tasks', array());
  20. $executions = $this->prop('executions', array());
  21. $onRenderItem = $this->prop('onRenderItem', array());
  22. $items = array();
  23. $isInModal = isInModal();
  24. $canViewTask = hasPriv('task', 'view');
  25. foreach($tasks as $task)
  26. {
  27. if(!isset($task->execution) || !isset($executions[$task->execution])) continue;
  28. $execution = $executions[$task->execution];
  29. $executionID = $execution->id;
  30. if(!isset($items[$executionID]))
  31. {
  32. $executionLink = (isset($execution->type) && $execution->type == 'kanban' && $isInModal) ? null : (empty($execution->multiple) ? createLink('project', 'view', "projectID=$task->project") : createLink('execution', 'view', "executionID=$executionID"));
  33. $items[$executionID] = array
  34. (
  35. 'icon' => 'run',
  36. 'title' => $execution->name,
  37. 'hint' => $execution->name,
  38. 'url' => !in_array($config->vision, array('lite', 'or')) ? $executionLink : null,
  39. 'items' => array()
  40. );
  41. }
  42. $item = array
  43. (
  44. 'title' => $task->name,
  45. 'hint' => $task->name,
  46. 'leading' => array('html' => wg(idLabel::create($task->id))->render()),
  47. 'content' => array('html' => wg(statusLabel::create($task->status, $lang->task->statusList[$task->status]))->render(), 'className' => 'flex-none'),
  48. 'url' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? createLink('task', 'view', "taskID=$task->id") : null,
  49. 'data-toggle' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? 'modal' : null,
  50. 'data-size' => !in_array($config->vision, array('lite', 'or')) && $canViewTask ? 'lg' : null,
  51. );
  52. if(is_callable($onRenderItem)) $item = $onRenderItem($item, $task);
  53. $items[$executionID]['items'][] = $item;
  54. $items[$executionID]['content'] = array('html' => '<span class="label gray-pale rounded-full size-sm">' . count($items[$executionID]['items']) . '</span>');
  55. }
  56. foreach($executions as $executionID => $execution)
  57. {
  58. if(isset($items[$executionID])) continue;
  59. $executionLink = (isset($execution->type) && $execution->type == 'kanban' && $isInModal) ? null : createLink('execution', 'view', "executionID=$executionID");
  60. if(!$execution->multiple) $executionLink = createLink('project', 'view', "projectID=$execution->project");
  61. $items[$executionID] = array
  62. (
  63. 'icon' => 'run',
  64. 'title' => $execution->name,
  65. 'hint' => $execution->name,
  66. 'url' => !in_array($config->vision, array('lite', 'or')) ? $executionLink : null,
  67. 'content' => array('html' => '<span class="label gray-pale rounded-full size-sm">0</span>'),
  68. 'items' => array()
  69. );
  70. }
  71. return array_values($items);
  72. }
  73. protected function build()
  74. {
  75. return zui::nestedList
  76. (
  77. set::className('execution-task-list'),
  78. set::defaultNestedShow(),
  79. set::itemProps(array('titleClass' => 'text-clip')),
  80. set::items($this->getItems())
  81. );
  82. }
  83. }