From 9c783532118cc5cbc78b2ba010be0ca346ff3e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=87=91=E5=8B=87?= Date: Fri, 2 Jun 2023 02:22:53 +0000 Subject: [PATCH] + Add config of databable actions. --- framework/helper.class.php | 64 +++++++++++++++++++++++++++++++ module/execution/ui/task.html.php | 37 ++---------------- module/task/config/dtable.php | 39 ++++++++++++------- module/task/model.php | 19 ++++----- 4 files changed, 102 insertions(+), 57 deletions(-) diff --git a/framework/helper.class.php b/framework/helper.class.php index f6b7216618..ae3c54b03d 100644 --- a/framework/helper.class.php +++ b/framework/helper.class.php @@ -428,6 +428,70 @@ function formatTime(string|null $time, string $format = ''): string return trim($time); } +/** + * Init table data of zin. + * + * @param array $items + * @param array $actionConfig + * @param object $checkModel + * @access public + * @return void + */ +function initTableData($items, $actionConfig, $checkModel) +{ + global $app; + + /* Order actions. */ + $orderActions = array(); + foreach($actionConfig['actionsMap'] as $actionKey => $action) + { + $order = zget($action, 'order', 0); + if(!isset($orderActions[$order])) $orderActions[$order] = array(); + $orderActions[$order][$actionKey] = $action; + } + ksort($orderActions); + + /* Append actions field. */ + $itemList = array(); + foreach($items as $item) + { + $actions = array(); + foreach($orderActions as $order => $configs) + { + foreach($configs as $actionName => $config) + { + $show = zget($config, 'show', 'default'); + if($checkModel->isClickable($item, $actionName)) + { + $actions[$order] = array('name' => $actionName); + } + elseif($show == 'always') + { + $actions[$order] = array('name' => $actionName, 'disabled' => true); + } + elseif($show == 'default' && !isset($actions[$order])) + { + $actions[$order] = array('name' => $actionName, 'disabled' => true); + } + } + } + $item->actions = array_values($actions); + + /* Set parent attribute. */ + $item->isParent = false; + if($item->parent == -1) + { + /* When the parent is -1, the hierarchical structure is displayed incorrectly. */ + $item->parent = 0; + $item->isParent = true; + } + + $itemList[] = $item; + } + + return $itemList; +} + /** * Fix for session error. * diff --git a/module/execution/ui/task.html.php b/module/execution/ui/task.html.php index ec89eb1983..3479685e1d 100644 --- a/module/execution/ui/task.html.php +++ b/module/execution/ui/task.html.php @@ -48,6 +48,8 @@ if(common::canModify('execution', $execution)) } } +$tableData = initTableData($tasks, $config->task->dtable->fieldList['actions'], $this->task); + toolbar ( hasPriv('task', 'report') ? item(set(array @@ -97,39 +99,6 @@ sidebar ))) ); -/* zin: Define the dtable in main content. */ -foreach($tasks as &$task) -{ - /* Set parent task attribute. */ - $task->isParent = false; - if($task->parent == -1) - { - /* When the parent task is -1, the hierarchical structure is displayed incorrectly. */ - $task->parent = 0; - $task->isParent = true; - } - - $actions = array(); - if(!in_array($task->status, array('cancel', 'closed')) && !empty($task->storyStatus) && $task->storyStatus == 'active' && $task->latestStoryVersion > $task->storyVersion) $actions[] = 'confirmStoryChange'; - - if($task->status != 'pause' && common::hasPriv('task', 'start')) $actions[] = 'start'; - if($task->status == 'pause' && common::hasPriv('task', 'restart')) $actions[] = 'restart'; - - if(common::hasPriv('task', 'finish')) $actions[] = 'finish'; - if(common::hasPriv('task', 'close')) $actions[] = 'close'; - - if(common::hasPriv('task', 'recordWorkhour')) $actions[] = 'recordWorkhour'; - if(common::hasPriv('task', 'edit')) $actions[] = 'edit'; - - if($this->config->vision == 'rnd' && common::hasPriv('task', 'batchCreate')) $actions[] = 'batchCreate'; - - foreach($actions as &$action) - { - if(!$this->task->isClickable($task, $action)) $action = array('name' => $action, 'disabled' => true); - } - $task->actions = $actions; -} - $firstTask = reset($tasks); $canBatchEdit = common::hasPriv('firstTask', 'batchEdit', !empty($firstTask) ? $firstTask : null); $canBatchClose = common::hasPriv('firstTask', 'batchClose', !empty($firstTask) ? $firstTask : null) && strtolower($browseType) != 'closed'; @@ -214,7 +183,7 @@ dtable ( set::userMap($memberPairs), set::cols(array_values($config->task->dtable->fieldList)), - set::data(array_values($tasks)), + set::data($tableData), set::checkable($canBatchAction), set::sortLink(helper::createLink('execution', 'task', "executionID={$execution->id}&status={$status}¶m={$param}&orderBy={name}_{sortType}&recTotal={$recTotal}&recPerPage={$recPerPage}")), set::footToolbar($footToolbar), diff --git a/module/task/config/dtable.php b/module/task/config/dtable.php index 7aaf412796..b72fd36f2d 100644 --- a/module/task/config/dtable.php +++ b/module/task/config/dtable.php @@ -151,45 +151,56 @@ $config->task->dtable->fieldList['mailto']['name'] = 'mailto'; $config->task->dtable->fieldList['mailto']['type'] = 'user'; $config->task->dtable->fieldList['mailto']['sortType'] = true; -$config->task->dtable->fieldList['actions']['title'] = $lang->actions; -$config->task->dtable->fieldList['actions']['name'] = 'actions'; -$config->task->dtable->fieldList['actions']['fixed'] = 'right'; -$config->task->dtable->fieldList['actions']['width'] = '180'; -$config->task->dtable->fieldList['actions']['type'] = 'actions'; +$config->task->dtable->fieldList['actions']['title'] = $lang->actions; +$config->task->dtable->fieldList['actions']['name'] = 'actions'; +$config->task->dtable->fieldList['actions']['fixed'] = 'right'; +$config->task->dtable->fieldList['actions']['width'] = '180'; +$config->task->dtable->fieldList['actions']['type'] = 'actions'; -$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['icon'] = 'search'; -$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['hint'] = $lang->task->activate; -$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['url'] = helper::createLink('task', 'confirmStoryChange', 'taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['icon'] = 'search'; +$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['hint'] = $lang->task->activate; +$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['url'] = helper::createLink('task', 'confirmStoryChange', 'taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['order'] = 5; +$config->task->dtable->fieldList['actions']['actionsMap']['confirmStoryChange']['show'] = 'clickable'; $config->task->dtable->fieldList['actions']['actionsMap']['start']['icon'] = 'play'; $config->task->dtable->fieldList['actions']['actionsMap']['start']['hint'] = $lang->task->start; $config->task->dtable->fieldList['actions']['actionsMap']['start']['url'] = helper::createLink('task', 'start', 'taskID={id}', '', true); $config->task->dtable->fieldList['actions']['actionsMap']['start']['data-toggle'] = 'modal'; +$config->task->dtable->fieldList['actions']['actionsMap']['start']['order'] = 10; +$config->task->dtable->fieldList['actions']['actionsMap']['start']['show'] = 'default'; $config->task->dtable->fieldList['actions']['actionsMap']['restart']['icon'] = 'icon-restart'; $config->task->dtable->fieldList['actions']['actionsMap']['restart']['hint'] = $lang->task->restart; $config->task->dtable->fieldList['actions']['actionsMap']['restart']['url'] = helper::createLink('task', 'restart', 'taskID={id}', '', true); $config->task->dtable->fieldList['actions']['actionsMap']['restart']['data-toggle'] = 'modal'; +$config->task->dtable->fieldList['actions']['actionsMap']['restart']['order'] = 10; +$config->task->dtable->fieldList['actions']['actionsMap']['restart']['show'] = 'clickable'; $config->task->dtable->fieldList['actions']['actionsMap']['finish']['icon'] = 'checked'; $config->task->dtable->fieldList['actions']['actionsMap']['finish']['hint'] = $lang->task->finish; $config->task->dtable->fieldList['actions']['actionsMap']['finish']['url'] = helper::createLink('task', 'finish', 'taskID={id}', '', true); $config->task->dtable->fieldList['actions']['actionsMap']['finish']['data-toggle'] = 'modal'; +$config->task->dtable->fieldList['actions']['actionsMap']['finish']['order'] = 15; $config->task->dtable->fieldList['actions']['actionsMap']['close']['icon'] = 'off'; $config->task->dtable->fieldList['actions']['actionsMap']['close']['hint'] = $lang->task->close; $config->task->dtable->fieldList['actions']['actionsMap']['close']['url'] = helper::createLink('task', 'close', 'taskID={id}', '', true); $config->task->dtable->fieldList['actions']['actionsMap']['close']['data-toggle'] = 'modal'; +$config->task->dtable->fieldList['actions']['actionsMap']['close']['order'] = 20; $config->task->dtable->fieldList['actions']['actionsMap']['recordWorkhour']['icon'] = 'time'; $config->task->dtable->fieldList['actions']['actionsMap']['recordWorkhour']['hint'] = $lang->task->record; $config->task->dtable->fieldList['actions']['actionsMap']['recordWorkhour']['url'] = helper::createLink('task', 'recordWorkhour', 'taskID={id}', '', true); $config->task->dtable->fieldList['actions']['actionsMap']['recordWorkhour']['data-toggle'] = 'modal'; +$config->task->dtable->fieldList['actions']['actionsMap']['recordWorkhour']['order'] = 25; -$config->task->dtable->fieldList['actions']['actionsMap']['edit']['icon'] = 'edit'; -$config->task->dtable->fieldList['actions']['actionsMap']['edit']['hint'] = $lang->task->edit; -$config->task->dtable->fieldList['actions']['actionsMap']['edit']['url'] = helper::createLink('task', 'edit', 'taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['edit']['icon'] = 'edit'; +$config->task->dtable->fieldList['actions']['actionsMap']['edit']['hint'] = $lang->task->edit; +$config->task->dtable->fieldList['actions']['actionsMap']['edit']['url'] = helper::createLink('task', 'edit', 'taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['edit']['order'] = 30; -$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['icon'] = 'split'; -$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['hint'] = $lang->task->batchCreate; -$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['url'] = helper::createLink('task', 'batchCreate', 'execution={execution}&storyID={story}&moduleID={module}&taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['icon'] = 'split'; +$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['hint'] = $lang->task->batchCreate; +$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['url'] = helper::createLink('task', 'batchCreate', 'execution={execution}&storyID={story}&moduleID={module}&taskID={id}'); +$config->task->dtable->fieldList['actions']['actionsMap']['batchCreate']['order'] = 35; diff --git a/module/task/model.php b/module/task/model.php index 398ca222f6..2230bbd801 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -2497,15 +2497,13 @@ class taskModel extends model { $action = strtolower($action); - if($action == 'start' and $task->parent < 0) return false; - if($action == 'finish' and $task->parent < 0) return false; - if($action == 'pause' and $task->parent < 0) return false; - if($action == 'assignto' and $task->parent < 0) return false; - if($action == 'close' and $task->parent < 0) return false; - if($action == 'batchcreate' and !empty($task->team)) return false; - if($action == 'batchcreate' and $task->parent > 0) return false; - if($action == 'recordworkhour' and $task->parent == -1) return false; - if($action == 'delete' and $task->parent < 0) return false; + if(!common::hasPriv('task', $action)) return false; + + /* 父任务只能编辑和创建子任务。 Parent task only can edit task and create children. */ + if($task->parent < 0 && !in_array($action, array('edit', 'batchcreate'))) return false; + + /* 子任务和多人任务不能创建子任务。Multi task and child task cannot create children. */ + if($action == 'batchcreate' && (!empty($task->team) || $task->parent > 0)) return false; if(!empty($task->team)) { @@ -2531,6 +2529,7 @@ class taskModel extends model } } + /* 根据状态判断是否可以点击。 Check clickable by status. */ if($action == 'start') return $task->status == 'wait'; if($action == 'restart') return $task->status == 'pause'; if($action == 'pause') return $task->status == 'doing'; @@ -2540,6 +2539,8 @@ class taskModel extends model if($action == 'finish') return $task->status != 'done' and $task->status != 'closed' and $task->status != 'cancel'; if($action == 'cancel') return $task->status != 'done' and $task->status != 'closed' and $task->status != 'cancel'; + if($action == 'confirmstorychange') return !in_array($task->status, array('cancel', 'closed')) && !empty($task->storyStatus) && $task->storyStatus == 'active' && $task->latestStoryVersion > $task->storyVersion; + return true; }