* [perf story #69206] Show task ui by viewType.

This commit is contained in:
wangyidong
2024-12-06 11:29:23 +08:00
committed by 孙广明
parent 205d497dc3
commit bb96ef712b
5 changed files with 140 additions and 17 deletions
+3 -17
View File
@@ -3366,30 +3366,16 @@ class execution extends control
*/
public function flattenObjectArray(array $array = array())
{
$this->loadModel('task');
$result = array();
$sortTasks = function($parents, $parentID = 0) use(&$sortTasks)
{
$tasks = array();
if(!isset($parents[$parentID])) return $tasks;
foreach($parents[$parentID] as $childTask)
{
$tasks[$childTask->id] = $childTask;
if(isset($parents[$childTask->id])) $tasks += $sortTasks($parents, $childTask->id);
}
return $tasks;
};
foreach($array as $key => $object)
{
$result[$object->id] = $object;
$tasks = zget($object, 'tasks', array());
if(empty($tasks)) continue;
$parents = array();
foreach($tasks as $task) $parents[$task->parent][$task->id] = $task;
$object->tasks = $sortTasks($parents);
$object->tasks = $this->task->mergeChildIntoParent($tasks);
}
return $result;
+7
View File
@@ -115,3 +115,10 @@ function convertStringToDate(dateString)
return Date.parse(dateString);
}
$(document).off('click', '.switchButton').on('click', '.switchButton', function()
{
var taskViewType = $(this).attr('data-type');
$.cookie.set('taskViewType', taskViewType, {expires:config.cookieLife, path:config.webRoot});
loadCurrentPage();
});
+27
View File
@@ -26,6 +26,33 @@ featureBar
li(searchToggle(set::module($this->app->rawMethod . 'Task'), set::open($type == 'bySearch')))
);
$viewType = $this->cookie->taskViewType ? $this->cookie->taskViewType : 'tree';
toolbar
(
item(set(array
(
'type' => 'btnGroup',
'items' => array(array
(
'icon' => 'list',
'class' => 'btn-icon switchButton' . ($viewType == 'tiled' ? ' text-primary' : ''),
'data-type' => 'tiled',
'hint' => $lang->task->viewTypeList['tiled']
), array
(
'icon' => 'treeview',
'class' => 'switchButton btn-icon' . ($viewType == 'tree' ? ' text-primary' : ''),
'data-type' => 'tree',
'hint' => $lang->task->viewTypeList['tree']
))
)))
);
if($viewType == 'tiled')
{
$config->my->task->dtable->fieldList['name']['nestedToggle'] = false;
$tasks = $this->task->mergeChildIntoParent($tasks);
}
$canBatchEdit = common::hasPriv('task', 'batchEdit');
$canBatchClose = common::hasPriv('task', 'batchClose') && $type != 'closedBy';
$footToolbar = array('items' => array
+38
View File
@@ -1094,4 +1094,42 @@ class taskTao extends taskModel
$this->dao->insert(TABLE_RELATION)->data($data)->exec();
return;
}
/**
* 归并子任务到父任务下。
* Merge child into parent
*
* @param array $tasks
* @access public
* @return array
*/
public function mergeChildIntoParent(array $tasks): array
{
$mergeTasks = function($parents, $parentID = 0) use(&$mergeTasks)
{
$tasks = array();
if(!isset($parents[$parentID])) return $tasks;
foreach($parents[$parentID] as $childTask)
{
$tasks[$childTask->id] = $childTask;
if(isset($parents[$childTask->id])) $tasks += $mergeTasks($parents, $childTask->id);
}
return $tasks;
};
$parents = array();
foreach($tasks as $task) $parents[$task->parent][$task->id] = $task;
$mergedTasks = array();
foreach($tasks as $task)
{
if(isset($mergedTasks[$task->id])) continue;
if($task->parent && isset($tasks[$task->parent])) continue;
$mergedTasks[$task->id] = $task;
$mergedTasks += $mergeTasks($parents, $task->id);
}
return $mergedTasks;
}
}
@@ -0,0 +1,65 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/task.unittest.class.php';
/**
title=taskTao->mergeChildIntoParent();
cid=0
- 传入空数组。 @0
- 检查归并后的第一个任务 @2
- 检查归并后的第二个任务 @1
- 检查归并后的第三个任务 @3
- 检查归并后的第四个任务 @5
- 检查归并后的第五个任务 @4
- 检查归并后的最后一个任务 @7
*/
$tasks = array();
$tasks['1'] = new stdclass();
$tasks['1']->id = 1;
$tasks['1']->parent = 2;
$tasks['2'] = new stdclass();
$tasks['2']->id = 2;
$tasks['2']->parent = 0;
$tasks['3'] = new stdclass();
$tasks['3']->id = 3;
$tasks['3']->parent = 2;
$tasks['4'] = new stdclass();
$tasks['4']->id = 4;
$tasks['4']->parent = 10;
$tasks['5'] = new stdclass();
$tasks['5']->id = 5;
$tasks['5']->parent = 2;
$tasks['6'] = new stdclass();
$tasks['6']->id = 6;
$tasks['6']->parent = 0;
$tasks['7'] = new stdclass();
$tasks['7']->id = 7;
$tasks['7']->parent = 0;
global $tester;
$taskModel = $tester->loadModel('task');
r(count($taskModel->mergeChildIntoParent(array()))) && p() && e('0'); //传入空数组。
$mergedTasks = $taskModel->mergeChildIntoParent($tasks);
$firstTask = array_shift($mergedTasks);
r($firstTask->id) && p() && e('2'); //检查归并后的第一个任务
$secondTask = array_shift($mergedTasks);
r($secondTask->id) && p() && e('1'); //检查归并后的第二个任务
$thirdTask = array_shift($mergedTasks);
r($thirdTask->id) && p() && e('3'); //检查归并后的第三个任务
$fourthTask = array_shift($mergedTasks);
r($fourthTask->id) && p() && e('5'); //检查归并后的第四个任务
$fifthTask = array_shift($mergedTasks);
r($fifthTask->id) && p() && e('4'); //检查归并后的第五个任务
$lastTask = array_pop($mergedTasks);
r($lastTask->id) && p() && e('7'); //检查归并后的最后一个任务