From c031603a4fcc017eb1ac759fe1aa1efedf3afdbf Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 16 Aug 2024 14:17:26 +0800 Subject: [PATCH] * [refac bug #54038] Adjust setmenu by app. --- module/testcase/control.php | 16 +++++++--------- module/testcase/js/importfromlib.ui.js | 2 +- module/testcase/ui/header.html.php | 12 +----------- module/testcase/zen.php | 10 +++++++--- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/module/testcase/control.php b/module/testcase/control.php index 7d4c5a8cd0..671330a0d4 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -140,8 +140,7 @@ class testcase extends control /* 设置菜单。 */ /* Set menu. */ - if($this->app->tab == 'project') $this->loadModel('project')->setMenu((int)$this->session->project); - if($this->app->tab == 'qa') $this->testcase->setMenu($productID, $branch); + $this->testcaseZen->setMenu((int)$this->session->project, 0, $productID, $branch); /* 展示变量. */ /* Show the variables. */ @@ -181,9 +180,9 @@ class testcase extends control /* Set session, cookie and set menu. */ $this->session->set('storyList', $this->app->getURI(true) . '#app=' . $this->app->tab, 'product'); $this->session->set('caseList', $this->app->getURI(true), $this->app->tab); + $this->testcaseZen->setMenu((int)$this->session->project, 0, $productID, $branchID); if($this->app->tab == 'project') { - $this->loadModel('project')->setMenu($this->session->project); $products = $this->product->getProducts($this->session->project, 'all', '', false); $productID = $this->product->checkAccess($productID, $products); $this->config->hasSwitcherMethods[] = 'testcase-zerocase'; @@ -199,7 +198,6 @@ class testcase extends control $this->loadModel('qa'); $this->app->rawModule = 'testcase'; foreach($this->config->qa->menuList as $module) $this->lang->navGroup->$module = 'qa'; - $this->qa->setMenu($productID, $branchID); } /* 设置 分页。*/ @@ -334,7 +332,7 @@ class testcase extends control /* 设置菜单。 */ /* Set menu. */ - $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($productID, $branch); + $this->testcaseZen->setMenu((int)$this->session->project, 0, $productID, $branch); /* 指派产品、分支、需求、自定义字段等变量. */ /* Assign the variables about product, branches, story and custom fields. */ @@ -440,6 +438,7 @@ class testcase extends control { $libraries = $this->loadModel('caselib')->getLibraries(); $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->caselib->setLibMenu($libraries, $case->lib); + if($this->app->tab == 'project') $this->view->projectID = (int)$this->session->project; $this->view->libID = $case->lib; $this->view->title = "CASE #$case->id $case->title - " . $libraries[$case->lib]; @@ -1191,7 +1190,7 @@ class testcase extends control /* 设置菜单。 */ /* Set menu. */ - $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($productID, $branch); + $this->testcaseZen->setMenu((int)$this->session->project, 0, $productID, $branch); $browseType = strtolower($browseType); @@ -1245,7 +1244,7 @@ class testcase extends control return $this->testcaseZen->responseAfterShowImport($productID, $branch, $maxImport, $tmpFile); } - $this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($productID, $branch); + $this->testcaseZen->setMenu((int)$this->session->project, 0, $productID, $branch); /* Get imported data. */ if(!empty($maxImport) && file_exists($tmpFile)) @@ -1808,8 +1807,7 @@ class testcase extends control if(!commonModel::hasPriv('testcase', 'importXmind')) $this->loadModel('common')->deny('testcase', 'importXmind'); /* Set menu. */ - if($this->app->tab == 'project') $this->loadModel('project')->setMenu(null); - if($this->app->tab == 'qa') $this->testcase->setMenu($productID, $branch); + $this->testcaseZen->setMenu(0, 0, $productID, $branch); $product = $this->product->getByID($productID); $branches = (isset($product->type) && $product->type != 'normal') ? $this->loadModel('branch')->getPairs($productID, 'active') : array(); diff --git a/module/testcase/js/importfromlib.ui.js b/module/testcase/js/importfromlib.ui.js index 2124557fad..003a71e200 100644 --- a/module/testcase/js/importfromlib.ui.js +++ b/module/testcase/js/importfromlib.ui.js @@ -27,7 +27,7 @@ window.toggleLib = function(event) { const libID = $(event.target).val(); const link = $.createLink('testcase','importFromLib','productID=' + productID + '&branch=' + branch + '&libID=' + libID); - openUrl(link); + loadPage(link); } $(document).off('click', '.import-btn').on('click', '.import-btn', function() diff --git a/module/testcase/ui/header.html.php b/module/testcase/ui/header.html.php index 338fea732e..f5f463dd6c 100644 --- a/module/testcase/ui/header.html.php +++ b/module/testcase/ui/header.html.php @@ -45,17 +45,7 @@ $canCreateCase = hasPriv('testcase', 'create'); $canBatchCreateCase = $productID && hasPriv('testcase', 'batchCreate'); $canCreateScene = $productID && hasPriv('testcase', 'createScene'); $canImportUnitResult = hasPriv('testtask', 'importUnitResult'); - -if($this->app->tab != 'qa') -{ - $canBatchCreateCase = false; - $canCreateScene = false; - $canImport = false; - $canImportFromLib = false; - $canImportXmind = false; -} - -$canCreate = $canCreateCase || $canBatchCreateCase || $canCreateScene; +$canCreate = $canCreateCase || $canBatchCreateCase || $canCreateScene; $lang->testcase->typeList[''] = $lang->testcase->allType; if(!isset($param)) $param = 0; diff --git a/module/testcase/zen.php b/module/testcase/zen.php index 578feb41ef..ef7d8d4d92 100755 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -111,12 +111,15 @@ class testcaseZen extends testcase * @access protected * @return array */ - protected function setBrowseMenu(int $productID, string|bool $branch, int $projectID): array + protected function setBrowseMenu(int $productID, string|bool $branch, int $projectID = 0): array { /* 在不同的应用中,设置不同的导航。 */ /* Set menu, save session. */ if($this->app->tab == 'project') { + if(empty($projectID)) $projectID = (int)$this->session->project; + if(empty($projectID)) return array($productID, $branch); + $linkedProducts = $this->product->getProducts($projectID, 'all', '', false); $this->products = count($linkedProducts) > 1 ? array('0' => $this->lang->product->all) + $linkedProducts : $linkedProducts; $productID = count($linkedProducts) > 1 ? $productID : key($linkedProducts); @@ -128,11 +131,12 @@ class testcaseZen extends testcase $this->loadModel('project')->setMenu($projectID); $this->view->products = $this->products; + $this->view->projectID = $projectID; $this->view->hasProduct = $hasProduct; } else { - $this->qa->setMenu($productID, $branch); + $this->loadModel('qa')->setMenu($productID, $branch); } return array($productID, $branch); @@ -149,7 +153,7 @@ class testcaseZen extends testcase * @access protected * @return void */ - protected function setMenu(int $projectID, int $executionID, int $productID, string|int $branch) + protected function setMenu(int $projectID = 0, int $executionID = 0, int $productID = 0, string|int $branch = '') { if($this->app->tab == 'project') $this->loadModel('project')->setMenu($projectID); if($this->app->tab == 'execution') $this->loadModel('execution')->setMenu($executionID);