From 2339fb2bc82b3091c1a51334969f74c986623648 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 18 Aug 2023 15:53:57 +0800 Subject: [PATCH] * testcase: users can change their order by dragging a row to an adjacent row below it. --- module/testcase/control.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index ff5c8b3683..f4296a0fda 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -2792,12 +2792,15 @@ class testcase extends control $targetID = $this->post->targetID; $dataList = $this->post->dataList; if(!$type || !$sourceID || !$targetID || !$dataList) return false; + if($sourceID == $targetID) return false; $idList = array_map(function($data){return $data['id'];}, $dataList); $orderList = array_map(function($data){return $data['order'];}, $dataList); $sourceIndex = array_search($sourceID, $idList); $targetIndex = array_search($targetID, $idList); + if($sourceIndex === false || $targetIndex === false) return false; + if($sourceIndex > $targetIndex) { $idList = array_slice($idList, $targetIndex, $sourceIndex - $targetIndex + 1); @@ -2808,7 +2811,14 @@ class testcase extends control { $idList = array_slice($idList, $sourceIndex, $targetIndex - $sourceIndex + 1); $orderList = array_slice($orderList, $sourceIndex, $targetIndex - $sourceIndex + 1); - array_splice($idList, -1, 0, array_shift($idList)); + if(count($idList) == 2) + { + $idList = array_reverse($idList); + } + else + { + array_splice($idList, -1, 0, array_shift($idList)); + } } $table = $type == 'case' ? TABLE_CASE : TABLE_SCENE;