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/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` ( diff --git a/module/programplan/control.php b/module/programplan/control.php index 2828763e31..e4e238c6ac 100644 --- a/module/programplan/control.php +++ b/module/programplan/control.php @@ -273,21 +273,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 4e4293e41b..4a4e475a9c 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -219,7 +219,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 d3e5a20e13..0843e6157f 100644 --- a/module/programplan/view/gantt.html.php +++ b/module/programplan/view/gantt.html.php @@ -479,7 +479,6 @@ $(function() gantt.config.order_branch = ganttType == 'assignedTo' ? false : 'marker'; 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; @@ -643,18 +642,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 64652f828e..9450ad4d61 100644 --- a/module/task/model.php +++ b/module/task/model.php @@ -3988,4 +3988,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(); + } + } }