From 2d60b14e2128bbd1920217e6634a5227edea5bef Mon Sep 17 00:00:00 2001 From: chenfeiCF Date: Fri, 13 Jan 2017 13:22:28 +0800 Subject: [PATCH] * finish task #2877. --- module/bug/model.php | 54 ++++++++++++++++++---- module/build/control.php | 2 +- module/project/control.php | 12 ++++- module/project/js/bug.js | 1 + module/project/model.php | 78 ++++++++++++++++++++++++++++++++ module/project/view/bug.html.php | 1 + 6 files changed, 136 insertions(+), 12 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index a56d157b44..ae760f5a85 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -1111,19 +1111,55 @@ class bugModel extends model /** * Get bugs of a project. * - * @param int $projectID - * @param string $orderBy - * @param object $pager + * @param int $projectID + * @param int $build + * @param string $type + * @param int $param + * @param string $orderBy + * @param object $pager * @access public * @return array */ - public function getProjectBugs($projectID, $orderBy = 'id_desc', $pager = null, $build = 0) + public function getProjectBugs($projectID, $build = 0, $type = '', $param = 0, $orderBy = 'id_desc', $pager = null) { - $bugs = $this->dao->select('*')->from(TABLE_BUG) - ->where('deleted')->eq(0) - ->beginIF(empty($build))->andWhere('project')->eq($projectID)->fi() - ->beginIF($build)->andWhere("CONCAT(',', openedBuild, ',') like '%,$build,%'")->fi() - ->orderBy($orderBy)->page($pager)->fetchAll(); + if($type == 'bySearch') + { + $queryID = (int)$param; + $products = $this->loadModel('project')->getProducts($projectID); + + if($this->session->projectBugQuery == false) $this->session->set('projectBugQuery', ' 1 = 1'); + if($queryID) + { + $query = $this->loadModel('search')->getQuery($queryID); + if($query) + { + $this->session->set('projectBugQuery', $query->sql); + $this->session->set('projectBugForm', $query->form); + } + } + + $allProduct = "`product` = 'all'"; + $bugQuery = $this->session->projectBugQuery; + if(strpos($this->session->projectBugQuery, $allProduct) !== false) + { + $bugQuery = str_replace($allProduct, '1', $this->session->projectBugQuery); + } + + $bugs = $this->dao->select('*')->from(TABLE_BUG) + ->where($bugQuery) + ->andWhere('project')->eq((int)$projectID) + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } + else + { + $bugs = $this->dao->select('*')->from(TABLE_BUG) + ->where('deleted')->eq(0) + ->beginIF(empty($build))->andWhere('project')->eq($projectID)->fi() + ->beginIF($build)->andWhere("CONCAT(',', openedBuild, ',') like '%,$build,%'")->fi() + ->orderBy($orderBy)->page($pager)->fetchAll(); + } $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'bug'); diff --git a/module/build/control.php b/module/build/control.php index 331f09ac93..d12bd46d4a 100644 --- a/module/build/control.php +++ b/module/build/control.php @@ -148,7 +148,7 @@ class build extends control $this->view->title = "BUILD #$build->id $build->name - " . $projects[$build->project]; $this->view->position[] = html::a($this->createLink('project', 'task', "projectID=$build->project"), $projects[$build->project]); $this->view->position[] = $this->lang->build->view; - $this->view->generatedBugs = $this->bug->getProjectBugs($build->project, 'status_desc,id_desc', null, $build->id); + $this->view->generatedBugs = $this->bug->getProjectBugs($build->project, $build->id, '', 0, 'status_desc,id_desc', null); $this->view->users = $this->loadModel('user')->getPairs('noletter'); $this->view->build = $build; $this->view->stories = $stories; diff --git a/module/project/control.php b/module/project/control.php index eadb4ae70f..afa1df8da9 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -608,13 +608,16 @@ class project extends control * * @param int $projectID * @param string $orderBy + * @param int $build + * @param string $type + * @param int $param * @param int $recTotal * @param int $recPerPage * @param int $pageID * @access public * @return void */ - public function bug($projectID = 0, $orderBy = 'status,id_desc', $build = 0, $recTotal = 0, $recPerPage = 20, $pageID = 1) + public function bug($projectID = 0, $orderBy = 'status,id_desc', $build = 0, $type = '', $param = 0, $recTotal = 0, $recPerPage = 20, $pageID = 1) { /* Load these two models. */ $this->loadModel('bug'); @@ -623,6 +626,7 @@ class project extends control /* Save session. */ $this->session->set('bugList', $this->app->getURI(true)); + $queryID = ($type == 'bySearch') ? (int)$param : 0; $project = $this->commonAction($projectID); $projectID = $project->id; $products = $this->project->getProducts($project->id); @@ -638,7 +642,7 @@ class project extends control $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); $sort = $this->loadModel('common')->appendOrder($orderBy); - $bugs = $this->bug->getProjectBugs($projectID, $sort, $pager, $build); + $bugs = $this->bug->getProjectBugs($projectID, $build, $type, $param, $sort, $pager); $users = $this->user->getPairs('noletter'); /* team member pairs. */ @@ -649,6 +653,10 @@ class project extends control $memberPairs[$key] = $member->realname; } + /* Build the search form. */ + $actionURL = $this->createLink('project', 'bug', "projectID=$projectID&orderBy=$orderBy&build=$build&type=bySearch&queryID=myQueryID"); + $this->project->buildBugSearchForm($products, $queryID, $actionURL); + /* Assign. */ $this->view->title = $title; $this->view->position = $position; diff --git a/module/project/js/bug.js b/module/project/js/bug.js index f14a95bf75..e6076cc651 100644 --- a/module/project/js/bug.js +++ b/module/project/js/bug.js @@ -14,6 +14,7 @@ $(document).ready(function() $option.toggleClass('hide', $option.text().toString().toLowerCase().indexOf(val) < 0 && $option.data('key').toString().toLowerCase().indexOf(val) < 0); }); }); + ajaxGetSearchForm(); fixedTfootAction('#projectBugForm'); fixedTheadOfList('#bugList'); }); diff --git a/module/project/model.php b/module/project/model.php index 07f7c819ce..8b33688f60 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -1952,6 +1952,84 @@ class projectModel extends model return $productBranchPairs; } + /** + * Build bug search form. + * + * @param int $products + * @param int $queryID + * @param int $actionURL + * @access public + * @return void + */ + public function buildBugSearchForm($products, $queryID, $actionURL) + { + $modules = array(); + $builds = array('' => '', 'trunk' => 'Trunk'); + foreach($products as $product) + { + $productModules = $this->loadModel('tree')->getOptionMenu($product->id); + $productBuilds = $this->loadModel('build')->getProductBuildPairs($product->id, 0, $params = 'noempty|notrunk'); + foreach($productModules as $moduleID => $moduleName) + { + $modules[$moduleID] = ((count($products) >= 2 and $moduleID) ? $product->name : '') . $moduleName; + } + foreach($productBuilds as $buildID => $buildName) + { + $builds[$buildID] = ((count($products) >= 2 and $buildID) ? $product->name . '/' : '') . $buildName; + } + } + + $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noempty'); + $branchPairs = array(); + $productType = 'normal'; + $productNum = count($products); + $productPairs = array(0 => ''); + foreach($products as $product) + { + $productPairs[$product->id] = $product->name; + if($product->type != 'normal') + { + $productType = $product->type; + if($product->branch) + { + $branchPairs[$product->branch] = (count($products) > 1 ? $product->name . '/' : '') . $branchGroups[$product->id][$product->branch]; + } + else + { + $productBranches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(0); + if(count($products) > 1) + { + foreach($productBranches as $branchID => $branchName) $productBranches[$branchID] = $product->name . '/' . $branchName; + } + $branchPairs += $productBranches; + } + } + } + + $this->config->bug->search['module'] = 'projectBug'; + $this->config->bug->search['actionURL'] = $actionURL; + $this->config->bug->search['queryID'] = $queryID; + unset($this->config->bug->search['fields']['project']); + $this->config->bug->search['params']['product']['values'] = $productPairs + array('all' => $this->lang->product->allProductsOfProject); + $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getForProducts($products); + $this->config->bug->search['params']['module']['values'] = $modules; + $this->config->bug->search['params']['openedBuild']['values'] = $builds; + $this->config->bug->search['params']['resolvedBuild']['values'] = $this->config->bug->search['params']['openedBuild']['values']; + if($productType == 'normal') + { + unset($this->config->bug->search['fields']['branch']); + unset($this->config->bug->search['params']['branch']); + } + else + { + $this->config->bug->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$productType]); + $this->config->bug->search['params']['branch']['values'] = array('' => '') + $branchPairs; + } + $this->config->bug->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->bug->statusList); + + $this->loadModel('search')->setSearchParams($this->config->bug->search); + } + /** * Build task search form. * diff --git a/module/project/view/bug.html.php b/module/project/view/bug.html.php index b171dc6336..621123ea58 100644 --- a/module/project/view/bug.html.php +++ b/module/project/view/bug.html.php @@ -20,6 +20,7 @@ id");?> +