From 0ab5b2956d100425d8703efb50770790b04c77a6 Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 4 Aug 2022 09:07:37 +0800 Subject: [PATCH 1/4] * Finish task #62892. --- db/update17.4.sql | 3 +- module/programplan/control.php | 18 +++---- module/programplan/model.php | 2 +- module/programplan/view/gantt.html.php | 28 +++++------ module/task/model.php | 70 ++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 26 deletions(-) diff --git a/db/update17.4.sql b/db/update17.4.sql index 658ea1b080..36b545f067 100644 --- a/db/update17.4.sql +++ b/db/update17.4.sql @@ -1 +1,2 @@ -ALTER TABLE `zt_task` add `order` mediumint(8) NOT NULL AFTER `activatedDate`; +ALTER TABLE `zt_task` ADD `order` mediumint(8) NOT NULL DEFAULT '0' AFTER `activatedDate`; +ALTER TABLE `zt_task` ADD INDEX `order` (`order`); diff --git a/module/programplan/control.php b/module/programplan/control.php index bb2530c811..f175bb02fd 100644 --- a/module/programplan/control.php +++ b/module/programplan/control.php @@ -266,21 +266,19 @@ class programplan extends control /** * Save task drag action. * + * @param int $productID + * + * @access public * @access public * @return void */ - public function ajaxSaveGanttMove() + public function ajaxSaveGanttMove($productID = 0) { - if($_POST) + if(!empty($_POST)) { - $data = fixer::input('post')->get(); - $IdList = explode('-', $data->id); - $executionID = $IdList[0]; - $taskID = $IdList[1]; - - return 1231231; + $this->loadModel('task')->saveTaskMove($productID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success')); } - - return $this->send(); } } diff --git a/module/programplan/model.php b/module/programplan/model.php index b01efa8209..d877c4bf9b 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -218,7 +218,7 @@ class programplanModel extends model if(empty($selectCustom)) $selectCustom = $this->loadModel('setting')->getItem("owner={$owner}&module={$module}§ion={$section}&key={$object}"); - $tasks = $this->dao->select('*')->from(TABLE_TASK)->where('deleted')->eq(0)->andWhere('execution')->in($planIdList)->fetchAll('id'); + $tasks = $this->dao->select('*')->from(TABLE_TASK)->where('deleted')->eq(0)->andWhere('execution')->in($planIdList)->orderBy('execution_asc, order_asc, id_desc')->fetchAll('id'); $taskTeams = $this->dao->select('root,account')->from(TABLE_TEAM)->where('type')->eq('task')->andWhere('root')->in(array_keys($tasks))->fetchGroup('root', 'account'); $users = $this->loadModel('user')->getPairs('noletter'); diff --git a/module/programplan/view/gantt.html.php b/module/programplan/view/gantt.html.php index 831a520152..bb5efa388d 100644 --- a/module/programplan/view/gantt.html.php +++ b/module/programplan/view/gantt.html.php @@ -459,10 +459,8 @@ $(function() gantt.config.readonly = false; gantt.config.details_on_dblclick = false; gantt.config.order_branch = 'marker'; - gantt.config.details_on_dblclick = false; - gantt.config.drag_progress = true; + gantt.config.drag_progress = false; gantt.config.drag_links = false; - gantt.config.drag_resize = false; gantt.config.smart_rendering = true; gantt.config.smart_scales = true; gantt.config.static_background = true; @@ -621,18 +619,20 @@ $(function() var link = createLink('programplan', 'ajaxSaveGanttMove'); //prevent moving to another position. - if(task.parent != parent || id.indexOf('-') == -1) return false; - - $.ajax({ + if(task.parent != parent || id.indexOf('-') == -1) + { + return false; + } + else + { + $.ajax({ url: link, - dataType: "json", - data: {id: id, type: task.type, order: tindex}, - type: "post", - success: function(result) - { - var target = result; - } - }); + dataType: "json", + data: {id: id, type: task.type, index: tindex}, + type: "post", + success: function(result){} + }); + } return true; }); diff --git a/module/task/model.php b/module/task/model.php index cdba5ab456..c44660fdf9 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -3977,4 +3977,74 @@ class taskModel extends model return true; } + + /** + * Save task order. + * + * @param int $productID + * @access public + * @return void + */ + public function saveTaskMove($productID = 0) + { + $data = fixer::input('post')->get(); + $targetTaskID = explode('-', $data->dropTarget)[1]; + $IdList = explode('-', $data->id); + $executionID = $IdList[0]; + $taskID = $IdList[1]; + $index = (int)$data->index; + + $oldTask = $this->loadModel('task')->getByID($taskID); + $targetTask = $this->loadModel('task')->getByID($targetTaskID); + $execution = $this->loadModel('execution')->getByID($executionID); + $tasks = $this->dao->select('id')->from(TABLE_TASK) + ->where('execution')->eq($executionID) + ->andWhere('deleted')->eq(0) + ->beginIF($oldTask->parent <= 0)->andWhere('parent')->le(0) + ->beginIF($oldTask->parent > 0)->andWhere('parent')->eq($oldTask->parent) + ->fetchPairs('id'); + $taskOrderSum = $this->dao->select('SUM(`order`) as sum')->from(TABLE_TASK) + ->where('deleted')->eq(0) + ->andWhere('execution')->eq($executionID) + ->beginIF($oldTask->parent <= 0)->andWhere('parent')->le(0) + ->beginIF($oldTask->parent > 0)->andWhere('parent')->eq($oldTask->parent) + ->fetch('sum'); + + if(!$taskOrderSum) + { + $order = 1; + foreach($tasks as $task) + { + $this->dao->update(TABLE_TASK)->set('`order`')->eq($order)->where('id')->eq($task)->exec(); + $order ++; + } + } + else + { + $order = ++ $index; + $oldOrder = (int)$oldTask->order; + if($order > $oldOrder) + { + $this->dao->update(TABLE_TASK)->set('`order`')->eq('`order`-1') + ->where('execution')->eq($executionID) + ->andWhere('`order`')->le($order) + ->andWhere('`order`')->gt($oldOrder) + ->beginIF($oldTask->parent <= 0)->andWhere('parent')->le(0) + ->beginIF($oldTask->parent > 0)->andWhere('parent')->eq($oldTask->parent) + ->exec(); + } + else if($order < $oldOrder) + { + $this->dao->update(TABLE_TASK)->set('`order`=`order`+1') + ->where('execution')->eq($executionID) + ->andWhere('`order`')->lt($oldOrder) + ->andWhere('`order`')->ge($order) + ->beginIF($oldTask->parent <= 0)->andWhere('parent')->le(0) + ->beginIF($oldTask->parent > 0)->andWhere('parent')->eq($oldTask->parent) + ->exec(); + } + + $this->dao->update(TABLE_TASK)->set('`order`')->eq($order)->where('id')->eq($taskID)->exec(); + } + } } From dfeafd9dbd38b5d6d9aea813ff19def27ddea589 Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 4 Aug 2022 09:21:05 +0800 Subject: [PATCH 2/4] * Add key for zt_task. --- db/zentao.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/zentao.sql b/db/zentao.sql index 5cd07c3b2c..eab2fde60b 100755 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -1537,6 +1537,7 @@ CREATE TABLE IF NOT EXISTS `zt_task` ( KEY `story` (`story`), KEY `parent` (`parent`), KEY `assignedTo` (`assignedTo`) + KEY `order` (`order`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- DROP TABLE IF EXISTS `zt_taskestimate`; CREATE TABLE IF NOT EXISTS `zt_taskestimate` ( From 397c6d55b429cb8c666224507b7cca6e79254773 Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 4 Aug 2022 09:38:01 +0800 Subject: [PATCH 3/4] * Optimize code. --- module/programplan/view/gantt.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/programplan/view/gantt.html.php b/module/programplan/view/gantt.html.php index a50396eb6f..d3089e6ff8 100644 --- a/module/programplan/view/gantt.html.php +++ b/module/programplan/view/gantt.html.php @@ -457,7 +457,7 @@ $(function() ?> gantt.serverList("userList", ); - gantt.config.readonly = canGanttEdit ? true : false; + gantt.config.readonly = canGanttEdit ? false : true; gantt.config.details_on_dblclick = false; gantt.config.order_branch = 'marker'; gantt.config.drag_progress = false; From 58567b28e7250865210a97cb3176d558a44a5677 Mon Sep 17 00:00:00 2001 From: mayue Date: Thu, 4 Aug 2022 11:09:48 +0800 Subject: [PATCH 4/4] * Finish task #62887. --- module/programplan/model.php | 6 +++--- module/task/model.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/programplan/model.php b/module/programplan/model.php index ae44e791a8..361dddfd0b 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -337,7 +337,7 @@ class programplanModel extends model public function getDataForGanttGroupByAssignedTo($executionID, $productID, $baselineID = 0, $selectCustom = '', $returnJson = true) { $plans = $this->getStage($executionID, $productID); - + $datas = array(); $planIdList = array(); $isMilestone = " "; @@ -414,7 +414,7 @@ class programplanModel extends model $groupKey = $groupID . $group; $datas['data'][$groupKey] = $dataGroup; - foreach($tasks as $taskID => $task) + foreach($tasks as $taskID => $task) { // if($task->parent > 0 and $task->assignedTo) // { @@ -423,7 +423,7 @@ class programplanModel extends model // a($task->parent);exit; // } $execution = zget($plans, $task->execution, array()); - + $priIcon = sprintf($taskPri, $task->pri, $task->pri, $task->pri); $estStart = helper::isZeroDate($task->estStarted) ? '' : $task->estStarted; diff --git a/module/task/model.php b/module/task/model.php index 296ac6ebaa..2c520ac2fa 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -3935,7 +3935,7 @@ class taskModel extends model } $updateStartArg = !empty($objectData->realStarted) ? 'realStarted' : 'estStarted'; - $updateEndArg = !empty($objectData->finishedDate) ? 'finishedDate' : 'deadline'; + $updateEndArg = strpos($objectData->status, 'closed, done') !== false ? 'finishedDate' : 'deadline'; $this->dao->update(TABLE_TASK) ->set($updateStartArg)->eq($post->start_date) ->set($updateEndArg)->eq($post->end_date)