From fd6f9f5ac9fc6be7fa37e540feb6fa1fa33a3a07 Mon Sep 17 00:00:00 2001 From: holan20180123 <56391770@qq.com> Date: Mon, 28 Sep 2020 10:46:14 +0800 Subject: [PATCH] * Finish task #7951. --- module/common/model.php | 27 +++++++-- module/product/control.php | 1 + module/productplan/control.php | 49 ++++++++------- module/productplan/js/view.js | 2 +- module/productplan/view/view.html.php | 3 + module/project/control.php | 1 + module/story/model.php | 86 +++++++++++++++++++++++++++ 7 files changed, 142 insertions(+), 27 deletions(-) diff --git a/module/common/model.php b/module/common/model.php index 920e38de2d..60fb288711 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1425,11 +1425,27 @@ EOD; */ public function getPreAndNextObject($type, $objectID) { - $preAndNextObject = new stdClass(); + $preAndNextObject = new stdClass(); + $preAndNextObject->pre = ''; + $preAndNextObject->next = ''; - /* Use existObject when the preAndNextObject of this objectID has exist in session. */ - $existObject = $type . 'PreAndNext'; - if(isset($_SESSION[$existObject]) and $_SESSION[$existObject]['objectID'] == $objectID) return $_SESSION[$existObject]['preAndNextObject']; + if($type == 'story' and !empty($_SESSION['planStoryOrder'])) + { + $objects = explode(',', $_SESSION['planStoryOrder']); + $key = array_search($objectID, $objects); + + if($key > 0) + { + $preObjectID = $objects[$key - 1]; + $preAndNextObject->pre = $this->loadModel('story')->getByID($preObjectID); + } + if($key < (count($objects) - 1)) + { + $nextObjectID = $objects[$key + 1]; + $preAndNextObject->next = $this->loadModel('story')->getByID($nextObjectID); + } + return $preAndNextObject; + } /* Get objectIDList. */ $table = $this->config->objectTables[$type]; @@ -1451,8 +1467,6 @@ EOD; } $preObj = false; - $preAndNextObject->pre = ''; - $preAndNextObject->next = ''; while($object = $queryObjects->fetch()) { $key = (!$this->session->$typeOnlyCondition and $type == 'testcase' and isset($object->case)) ? 'case' : 'id'; @@ -1474,6 +1488,7 @@ EOD; if($preObj !== true) $preObj = $object; } + $existObject = $type . 'PreAndNext'; $this->session->set($existObject, array('objectID' => $objectID, 'preAndNextObject' => $preAndNextObject)); return $preAndNextObject; } diff --git a/module/product/control.php b/module/product/control.php index d335963e7d..4e71b4e927 100644 --- a/module/product/control.php +++ b/module/product/control.php @@ -116,6 +116,7 @@ class product extends control /* Save session. */ $this->session->set('storyList', $this->app->getURI(true)); $this->session->set('productList', $this->app->getURI(true)); + $this->session->set('planStoryOrder', ''); /* Set product, module and query. */ $productID = $this->product->saveState($productID, $this->products); diff --git a/module/productplan/control.php b/module/productplan/control.php index fc938de088..e9a1e95d83 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -262,6 +262,10 @@ class productplan extends control $orderBy = str_replace('order', 'id', $orderBy); $reSort = true; } + else + { + $this->session->set('planStoryOrder', ''); + } /* Append id for secend sort. */ $sort = $this->loadModel('common')->appendOrder($orderBy); @@ -269,26 +273,26 @@ class productplan extends control $this->commonAction($plan->product, $plan->branch); $products = $this->product->getPairs('', $this->session->PRJ); - $bugPager = new pager(0, $recPerPage, $type == 'bug' ? $pageID : 1); - $storyPager = new pager(0, $recPerPage, $type == 'story' ? $pageID : 1); - $planStories = $this->loadModel('story')->getPlanStories($planID, 'all', $type == 'story' ? $sort : 'id_desc', $storyPager); + $bugPager = new pager(0, $recPerPage, $type == 'bug' ? $pageID : 1); + $storyPager = new pager(0, $recPerPage, $type == 'story' ? $pageID : 1); + + $this->loadModel('story'); + if(!$reSort or empty($plan->order)) $planStories = $this->story->getPlanStories($planID, 'all', $type == 'story' ? $sort : 'id_desc', $storyPager); + if($reSort) { if(!empty($plan->order)) { - $stories = array(); - $order = explode(',', $plan->order); - if(strpos($orderBy, 'desc') !== false) $order = array_reverse($order, true); - foreach($order as $id) - { - if(empty($id)) continue; - if(!isset($planStories[$id])) continue; - $stories[$id] = $planStories[$id]; - unset($planStories[$id]); - } - if($planStories) $stories += $planStories; - $planStories = $stories; - unset($stories); + $planStories = $this->story->getPlanStories($planID, 'all', $sort); + $planStories = $this->story->sortPlanStory($planStories, $plan->order, $orderBy); + + $storyIDList = implode(',', array_keys($planStories)); + $this->session->set('planStoryOrder', $storyIDList); + + $storyPager->recTotal = count($planStories); + + $frontCount = $storyPager->recPerPage * ($storyPager->pageID - 1); + $planStories = array_slice($planStories, $frontCount, $storyPager->recPerPage); } $orderBy = str_replace('id', 'order', $orderBy); } @@ -333,9 +337,9 @@ class productplan extends control { $plans = $this->productplan->getPairs($productID, $branch); - $planName = $number === '' ? 'plan' : "plan[$number]"; - $plans = empty($plans) ? array('' => '') : $plans; - die(html::select($planName, $plans, '', "class='form-control'")); + $planName = $number === '' ? 'plan' : "plan[$number]"; + $plans = empty($plans) ? array('' => '') : $plans; + die(html::select($planName, $plans, '', "class='form-control'")); } /** @@ -349,7 +353,12 @@ class productplan extends control public function ajaxStorySort($planID = 0) { if(empty($planID)) return true; - $this->dao->update(TABLE_PRODUCTPLAN)->set('`order`')->eq($this->post->storys)->where('id')->eq((int)$planID)->exec(); + + $plan = $this->productplan->getByID($planID, true); + $order = $this->loadModel('story')->getAllStorySort($planID, $plan->order); + + $this->dao->update(TABLE_PRODUCTPLAN)->set('`order`')->eq($order)->where('id')->eq((int)$planID)->exec(); + $this->session->set('planStoryOrder', $order); } /** diff --git a/module/productplan/js/view.js b/module/productplan/js/view.js index 623342a598..0e0d2e64f7 100644 --- a/module/productplan/js/view.js +++ b/module/productplan/js/view.js @@ -71,7 +71,7 @@ $(function() { var list = ''; for(i = 0; i < data.list.length; i++) list += $(data.list[i].item).attr('data-id') + ','; - $.post(createLink('productplan', 'ajaxStorySort', 'planID=' + planID), {'storys' : list, 'orderBy' : orderBy}, function() + $.post(createLink('productplan', 'ajaxStorySort', 'planID=' + planID), {'stories' : list, 'orderBy' : orderBy, 'pageID' : storyPageID, 'recPerPage' : storyRecPerPage, 'recTotal' : storyRecTotal}, function() { var $target = $(data.element[0]); $target.hide(); diff --git a/module/productplan/view/view.html.php b/module/productplan/view/view.html.php index 13585279a6..264df106ab 100644 --- a/module/productplan/view/view.html.php +++ b/module/productplan/view/view.html.php @@ -16,6 +16,9 @@ productplan->confirmUnlinkStory)?> productplan->confirmUnlinkBug)?> id);?> +pageID);?> +recPerPage);?> +recTotal);?>