diff --git a/module/tree/control.php b/module/tree/control.php index ec506ad59e..e85a9de756 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -11,7 +11,7 @@ */ class tree extends control { - const NEW_CHILD_COUNT = 10; + const NEW_CHILD_COUNT = 5; /** * Module browse. @@ -22,12 +22,13 @@ class tree extends control * @access public * @return void */ - public function browse($rootID, $viewType, $currentModuleID = 0) + public function browse($rootID, $viewType, $currentModuleID = 0, $branch = 0) { /* According to the type, set the module root and modules. */ if(strpos('story|bug|case', $viewType) !== false) { $product = $this->loadModel('product')->getById($rootID); + if($product->type != 'normal') $this->view->branches = $this->loadModel('branch')->getPairs($product->id); $this->view->root = $product; $this->view->productModules = $this->tree->getOptionMenu($rootID, 'story'); } @@ -64,7 +65,6 @@ class tree extends control $this->view->allProduct = $products; $this->view->currentProduct = $currentProduct; - $this->view->productModules = $this->tree->getOptionMenu($currentProduct, 'story'); $title = $product->name . $this->lang->colon . $this->lang->tree->manageProduct; $position[] = html::a($this->createLink('product', 'browse', "product=$rootID"), $product->name); @@ -110,9 +110,10 @@ class tree extends control $this->view->rootID = $rootID; $this->view->viewType = $viewType; $this->view->modules = $this->tree->getTreeMenu($rootID, $viewType, $rooteModuleID = 0, array('treeModel', 'createManageLink')); - $this->view->sons = $this->tree->getSons($rootID, $currentModuleID, $viewType); + $this->view->sons = $this->tree->getSons($rootID, $currentModuleID, $viewType, $branch); $this->view->currentModuleID = $currentModuleID; $this->view->parentModules = $parentModules; + $this->view->branch = $branch; $this->display(); } @@ -170,7 +171,7 @@ class tree extends control * @access public * @return void */ - public function edit($moduleID, $type) + public function edit($moduleID, $type, $branch = 0) { if(!empty($_POST)) { @@ -192,11 +193,12 @@ class tree extends control } else { - $this->view->optionMenu = $this->tree->getOptionMenu($module->root, $module->type); + $this->view->optionMenu = $this->tree->getOptionMenu($module->root, $module->type, 0, $branch); } $this->view->module = $module; $this->view->type = $type; + $this->view->branch = $branch; $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted', $module->owner); $showProduct = strpos('story|bug|case', $type) !== false ? true : false; @@ -291,7 +293,7 @@ class tree extends control * @access public * @return string the html select string. */ - public function ajaxGetOptionMenu($rootID, $viewType = 'story', $rootModuleID = 0, $returnType = 'html', $needManage = false) + public function ajaxGetOptionMenu($rootID, $viewType = 'story', $branch = 0, $rootModuleID = 0, $returnType = 'html', $needManage = false) { if($viewType == 'task') { @@ -299,7 +301,7 @@ class tree extends control } else { - $optionMenu = $this->tree->getOptionMenu($rootID, $viewType, $rootModuleID); + $optionMenu = $this->tree->getOptionMenu($rootID, $viewType, $rootModuleID, $branch); } if($returnType == 'html') { @@ -309,7 +311,7 @@ class tree extends control if(count($optionMenu) == 1 and $needManage) { $output .= ""; - $output .= html::a($this->createLink('tree', 'browse', "rootID=$rootID&view=$viewType"), $this->lang->tree->manage, '_blank'); + $output .= html::a($this->createLink('tree', 'browse', "rootID=$rootID&view=$viewType¤tModuleID=0&branch=$branch"), $this->lang->tree->manage, '_blank'); $output .= '  '; $output .= html::a("javascript:loadProductModules($rootID)", $this->lang->refresh); $output .= ''; diff --git a/module/tree/css/common.css b/module/tree/css/common.css index 5d2f25501d..d919ec95de 100644 --- a/module/tree/css/common.css +++ b/module/tree/css/common.css @@ -3,7 +3,7 @@ .outer .row .col-md-8 .table-form {max-width: 600px} -#sonModule {max-width: 240px} +#sonModule {max-width: 330px} #moduleBox span > .form-control {margin-bottom: 5px;} .w-260px {width: 260px!important} diff --git a/module/tree/js/browse.js b/module/tree/js/browse.js index 5870f3a8b2..9a9e395070 100644 --- a/module/tree/js/browse.js +++ b/module/tree/js/browse.js @@ -7,8 +7,9 @@ function syncModule(rootID, type) $.getJSON(link, function(modules) { $('.helplink').addClass('hidden'); + var $inputgroup = $('
').append($('.input-group .icon-remove:first').closest('.input-group').clone()).html(); $.each(modules, function(key, value) - { + { moduleName = value; $('.form-control').each(function() { @@ -18,8 +19,12 @@ function syncModule(rootID, type) }); $.each(modules, function(key, value) - { - if(value) $('#sonModule').append(""); + { + if(value) + { + $('#sonModule .input-group:last').after($inputgroup); + $('#sonModule .input-group:last input').val(value); + } }) }) } @@ -28,7 +33,7 @@ function syncProductOrProject(obj, type) { if(type == 'product') viewType = 'story'; if(type == 'project') viewType = 'task'; - link = createLink('tree', 'ajaxGetOptionMenu', 'rootID=' + obj.value + "&viewType=" + viewType + "&rootModuleID=0&returnType=json"); + link = createLink('tree', 'ajaxGetOptionMenu', 'rootID=' + obj.value + "&viewType=" + viewType + "&branch=0&rootModuleID=0&returnType=json"); $.getJSON(link, function(modules) { $('.helplink').addClass('hidden'); @@ -50,6 +55,18 @@ function toggleCopy() $copy.toggle(); } +function addItem(obj) +{ + var $inputgroup = $(obj).closest('.input-group'); + $inputgroup.after($inputgroup.clone()).next('.input-group').find('input').val(''); +} + +function deleteItem(obj) +{ + if($(obj).closest('.input-group').parent().find('i.icon-remove').size() <= 1) return; + $(obj).closest('.input-group').remove(); +} + $(document).ready(function() { toggleCopy(); diff --git a/module/tree/model.php b/module/tree/model.php index f69d14549a..0b5a78907c 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -34,7 +34,7 @@ class treeModel extends model * @access public * @return void */ - public function buildMenuQuery($rootID, $type, $startModule) + public function buildMenuQuery($rootID, $type, $startModule, $branch = 0) { /* Set the start module. */ $startModulePath = ''; @@ -57,6 +57,8 @@ class treeModel extends model ->where('root')->eq((int)$rootID) ->andWhere('type')->in("story,$type") ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() + ->beginIF($branch === 'null')->andWhere('branch')->eq(0)->fi() + ->beginIF((!empty($branch) and $branch != 'null'))->andWhere("branch")->eq($branch)->fi() ->orderBy('grade desc, type desc, `order`') ->get(); } @@ -67,6 +69,8 @@ class treeModel extends model ->where('root')->eq((int)$rootID) ->andWhere('type')->eq($type) ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() + ->beginIF($branch === 'null')->andWhere('branch')->eq(0)->fi() + ->beginIF((!empty($branch) and $branch != 'null'))->andWhere("branch")->eq($branch)->fi() ->orderBy('grade desc, `order`') ->get(); } @@ -80,51 +84,27 @@ class treeModel extends model * @access public * @return string */ - public function getOptionMenu($rootID, $type = 'story', $startModule = 0) + public function getOptionMenu($rootID, $type = 'story', $startModule = 0, $branch = 0) { - $treeMenu = array(); - $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule)); - $modules = array(); - while($module = $stmt->fetch()) $modules[$module->id] = $module; - - foreach($modules as $module) + $branches = array($branch => ''); + if(strpos('story|bug|case', $type) !== false and empty($branch)) { - $parentModules = explode(',', $module->path); - $moduleName = '/'; - foreach($parentModules as $parentModuleID) - { - if(empty($parentModuleID)) continue; - $moduleName .= $modules[$parentModuleID]->name . '/'; - } - $moduleName = rtrim($moduleName, '/'); - $moduleName .= "|$module->id\n"; - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(isset($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= $moduleName; - } - else - { - $treeMenu[$module->parent] = $moduleName;; - } - $treeMenu[$module->parent] .= $treeMenu[$module->id]; - } - else - { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= $moduleName; - } - else - { - $treeMenu[$module->parent] = $moduleName; - } - } + $product = $this->loadModel('product')->getById($rootID); + if($product->type != 'normal') $branches = array('null' => '') + $this->loadModel('branch')->getPairs($rootID, 'noempty'); } - $topMenu = @array_pop($treeMenu); + $treeMenu = array(); + foreach($branches as $branchID => $branch) + { + $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule, $branchID)); + $modules = array(); + while($module = $stmt->fetch()) $modules[$module->id] = $module; + + foreach($modules as $module) $this->buildTreeArray($treeMenu, $modules, $module, (empty($branch) or $branch == 'null') ? '/' : "/$branch/"); + } + + ksort($treeMenu); + $topMenu = @array_shift($treeMenu); $topMenu = explode("\n", trim($topMenu)); $lastMenu[] = '/'; foreach($topMenu as $menu) @@ -133,6 +113,7 @@ class treeModel extends model list($label, $moduleID) = explode('|', $menu); $lastMenu[$moduleID] = $label; } + return $lastMenu; } @@ -171,22 +152,21 @@ class treeModel extends model $noProductModules = $this->dao->select('*')->from(TABLE_MODULE)->where("root = $rootID and type = 'task' and parent = 0")->fetchPairs('id', 'name'); /* Fix for not in product modules. */ + $productNum = count($products); foreach(array('product' => $products, 'noProduct' => $noProductModules) as $type => $rootModules) { foreach($rootModules as $id => $rootModule) { if($type == 'product') { - $modules = $this->dao->select('*')->from(TABLE_MODULE) - ->where("((root = $rootID and type = 'task') OR (root = $id and type = 'story'))") + $modules = $this->dao->select('*')->from(TABLE_MODULE)->where("((root = $rootID and type = 'task') OR (root = $id and type = 'story'))") ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() ->orderBy('grade desc, type, `order`') ->fetchAll('id'); } else { - $modules = $this->dao->select('*')->from(TABLE_MODULE) - ->where("root = $rootID and type = 'task' and path like '%,$id,%'") + $modules = $this->dao->select('*')->from(TABLE_MODULE)->where("root = $rootID and type = 'task' and path like '%,$id,%'") ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() ->orderBy('grade desc, type, `order`') ->fetchAll('id'); @@ -196,41 +176,11 @@ class treeModel extends model { $parentModules = explode(',', trim($module->path, ',')); if($type == 'product' and isset($noProductModules[$parentModules[0]])) continue; - - $moduleName = $type == 'product' ? '/' . $rootModule : ''; - foreach($parentModules as $parentModuleID) - { - if(empty($parentModuleID) or !isset($modules[$parentModuleID])) continue; - $moduleName .= '/' . $modules[$parentModuleID]->name; - } - $moduleName = rtrim($moduleName, '/'); - $moduleName .= "|$module->id\n"; - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(isset($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= $moduleName; - } - else - { - $treeMenu[$module->parent] = $moduleName;; - } - $treeMenu[$module->parent] .= $treeMenu[$module->id]; - } - else - { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= $moduleName; - } - else - { - $treeMenu[$module->parent] = $moduleName; - } - } + $this->buildTreeArray($treeMenu, $modules, $module, $productNum > 1 ? "/$rootModule/" : '/'); } - $topMenu = @array_pop($treeMenu); + + ksort($treeMenu); + $topMenu = @array_shift($treeMenu); $topMenu = explode("\n", trim($topMenu)); foreach($topMenu as $menu) { @@ -247,6 +197,52 @@ class treeModel extends model return $lastMenu; } + /** + * Build tree array. + * + * @param $&treeMenu + * @param array $modules + * @param object $module + * @param string $moduleName + * @access public + * @return void + */ + public function buildTreeArray(& $treeMenu, $modules, $module, $moduleName = '/') + { + $parentModules = explode(',', $module->path); + foreach($parentModules as $parentModuleID) + { + if(empty($parentModuleID)) continue; + $moduleName .= $modules[$parentModuleID]->name . '/'; + } + $moduleName = rtrim($moduleName, '/'); + $moduleName .= "|$module->id\n"; + + if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) + { + if(isset($treeMenu[$module->parent])) + { + $treeMenu[$module->parent] .= $moduleName; + } + else + { + $treeMenu[$module->parent] = $moduleName;; + } + $treeMenu[$module->parent] .= $treeMenu[$module->id]; + } + else + { + if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) + { + $treeMenu[$module->parent] .= $moduleName; + } + else + { + $treeMenu[$module->parent] = $moduleName; + } + } + } + /** * Get the tree menu in html. * @@ -258,46 +254,37 @@ class treeModel extends model * @access public * @return string */ - public function getTreeMenu($rootID, $type = 'root', $startModule = 0, $userFunc, $extra = '') + public function getTreeMenu($rootID, $type = 'root', $startModule = 0, $userFunc, $extra = '', $branch = 0) { - $treeMenu = array(); - $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule)); + $branches = array($branch => ''); + $manage = $userFunc[1] == 'createManageLink' ? true : false; + if(strpos('story|bug|case', $type) !== false and empty($branch)) + { + $product = $this->loadModel('product')->getById($rootID); + if($product->type != 'normal') $branches = array('null' => '') + $this->loadModel('branch')->getPairs($rootID, 'noempty'); + } /* Add for task #1945. check the module has case or no. */ if($type == 'case' and !empty($extra)) $this->loadModel('testtask'); - while($module = $stmt->fetch()) + $lastMenu = ''; + foreach($branches as $branchID => $branch) { - /* Add for task #1945. check the module has case or no. */ - if($type == 'case' and !empty($extra)) + $treeMenu = array(); + $stmt = $this->dbh->query($this->buildMenuQuery($rootID, $type, $startModule, $branchID)); + while($module = $stmt->fetch()) $this->buildTree($treeMenu, $module, $type, $userFunc, $extra, $branchID); + ksort($treeMenu); + if(!empty($branchID) and $branchID != 'null') { - $modules = $this->getAllChildID($module->id); - $runs = $this->testtask->getRuns($extra, $modules, 'id'); - if(empty($runs)) continue; - } - - $linkHtml = call_user_func($userFunc, $type, $module, $extra); - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = ''; - $treeMenu[$module->parent] .= "
  • $linkHtml"; - $treeMenu[$module->parent] .= "
      " . $treeMenu[$module->id] . "
    \n"; + $linkHtml = $manage ? html::a(inlink('browse', "root=$rootID&viewType=$type¤tModuleID=0&branch=$branchID"), $branch) : $this->createBranchLink($type, $rootID, $branchID, $branch); + $lastMenu .= "
  • $linkHtml
      " . @array_shift($treeMenu) . "
  • \n"; } else { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= "
  • $linkHtml\n"; - } - else - { - $treeMenu[$module->parent] = "
  • $linkHtml\n"; - } + $lastMenu .= array_shift($treeMenu); } - $treeMenu[$module->parent] .= "
  • \n"; } - $lastMenu = "\n"; + $lastMenu = "\n"; return $lastMenu; } @@ -360,8 +347,7 @@ class treeModel extends model /* tree menu. */ $treeMenu = array(); - $query = $this->dao->select('*')->from(TABLE_MODULE) - ->where("((root = $rootID and type = 'task' and parent != 0) OR (root = $id and type = 'story'))") + $query = $this->dao->select('*')->from(TABLE_MODULE)->where("((root = $rootID and type = 'task' and parent != 0) OR (root = $id and type = 'story'))") ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() ->orderBy('grade desc, type, `order`') ->get(); @@ -370,27 +356,7 @@ class treeModel extends model { /* if not manage, ignore unused modules. */ if(!$manage and !isset($projectModules[$module->id])) continue; - - $linkHtml = call_user_func($userFunc, 'task', $module, $extra); - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = ''; - $treeMenu[$module->parent] .= "
  • $linkHtml"; - $treeMenu[$module->parent] .= "
      " . $treeMenu[$module->id] . "
    \n"; - } - else - { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= "
  • $linkHtml\n"; - } - else - { - $treeMenu[$module->parent] = "
  • $linkHtml\n"; - } - } - $treeMenu[$module->parent] .= "
  • \n"; + $this->buildTree($treeMenu, $module, 'task', $userFunc, $extra); } $tree = isset($treeMenu[0]) ? $treeMenu[0] : ''; @@ -403,36 +369,13 @@ class treeModel extends model { /* tree menu. */ $treeMenu = array(); - $query = $this->dao->select('*')->from(TABLE_MODULE) - ->where("root = $rootID and type = 'task'") - ->orderBy('grade desc, type, `order`') - ->get(); - $stmt = $this->dbh->query($query); + $query = $this->dao->select('*')->from(TABLE_MODULE)->where("root = $rootID and type = 'task'")->orderBy('grade desc, type, `order`')->get(); + $stmt = $this->dbh->query($query); while($module = $stmt->fetch()) { /* if not manage, ignore unused modules. */ if(!$manage and !isset($projectModules[$module->id])) continue; - - $linkHtml = call_user_func($userFunc, 'task', $module, $extra); - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = ''; - $treeMenu[$module->parent] .= "
  • $linkHtml"; - $treeMenu[$module->parent] .= "
      " . $treeMenu[$module->id] . "
    \n"; - } - else - { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= "
  • $linkHtml\n"; - } - else - { - $treeMenu[$module->parent] = "
  • $linkHtml\n"; - } - } - $treeMenu[$module->parent] .= "
  • \n"; + $this->buildTree($treeMenu, $module, 'task', $userFunc, $extra); } $tree = isset($treeMenu[0]) ? $treeMenu[0] : ''; @@ -475,8 +418,7 @@ class treeModel extends model /* tree menu. */ $treeMenu = array(); - $query = $this->dao->select('*')->from(TABLE_MODULE) - ->where("(root = $id and type = 'story')") + $query = $this->dao->select('*')->from(TABLE_MODULE)->where("(root = $id and type = 'story')") ->beginIF($startModulePath)->andWhere('path')->like($startModulePath)->fi() ->orderBy('grade desc, type, `order`') ->get(); @@ -485,27 +427,7 @@ class treeModel extends model { /* if not manage, ignore unused modules. */ if(!isset($projectModules[$module->id])) continue; - - $linkHtml = call_user_func($userFunc, 'task', $module, $extra); - - if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) - { - if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = ''; - $treeMenu[$module->parent] .= "
  • $linkHtml"; - $treeMenu[$module->parent] .= "
      " . $treeMenu[$module->id] . "
    \n"; - } - else - { - if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) - { - $treeMenu[$module->parent] .= "
  • $linkHtml\n"; - } - else - { - $treeMenu[$module->parent] = "
  • $linkHtml\n"; - } - } - $treeMenu[$module->parent] .= "
  • \n"; + $this->buildTree($treeMenu, $module, 'task', $userFunc, $extra); } $tree = isset($treeMenu[0]) ? $treeMenu[0] : ''; @@ -517,6 +439,51 @@ class treeModel extends model return $menu; } + /** + * Build tree. + * + * @param & $&treeMenu + * @param object $module + * @param string $type + * @param array $userFunc + * @param array $extra + * @param int $branch + * @access public + * @return void + */ + public function buildTree(& $treeMenu, $module, $type, $userFunc, $extra, $branch = 0) + { + /* Add for task #1945. check the module has case or no. */ + if($type == 'case' and !empty($extra)) + { + $modules = $this->getAllChildID($module->id); + $runs = $this->testtask->getRuns($extra, $modules, 'id'); + if(empty($runs)) continue; + } + + $extra['branchID'] = $branch; + $linkHtml = call_user_func($userFunc, $type, $module, $extra); + + if(isset($treeMenu[$module->id]) and !empty($treeMenu[$module->id])) + { + if(!isset($treeMenu[$module->parent])) $treeMenu[$module->parent] = ''; + $treeMenu[$module->parent] .= "
  • $linkHtml"; + $treeMenu[$module->parent] .= "
      " . $treeMenu[$module->id] . "
    \n"; + } + else + { + if(isset($treeMenu[$module->parent]) and !empty($treeMenu[$module->parent])) + { + $treeMenu[$module->parent] .= "
  • $linkHtml\n"; + } + else + { + $treeMenu[$module->parent] = "
  • $linkHtml\n"; + } + } + $treeMenu[$module->parent] .= "
  • \n"; + } + /** * Get project modules. * @@ -568,10 +535,7 @@ class treeModel extends model foreach($paths as $path) { $modules = explode(',', $path); - foreach($modules as $module) - { - $projectModules[$module] = $module; - } + foreach($modules as $module) $projectModules[$module] = $module; } return $projectModules; } @@ -680,7 +644,7 @@ class treeModel extends model */ public function createStoryLink($type, $module) { - $linkHtml = html::a(helper::createLink('product', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); + $linkHtml = html::a(helper::createLink('product', 'browse', "root={$module->root}&branch=&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); return $linkHtml; } @@ -749,8 +713,9 @@ class treeModel extends model * @access public * @return string */ - public function createManageLink($type, $module) + public function createManageLink($type, $module, $extra) { + $branchID = $extra['branchID']; $tip = strpos('bug,case', $type) === false ? '' : ' [' . strtoupper(substr($type, 0, 1)) . ']'; static $users; if(empty($users)) $users = $this->loadModel('user')->getPairs('noletter'); @@ -759,13 +724,13 @@ class treeModel extends model if($type == 'bug' and $module->owner) $linkHtml .= '[' . $users[$module->owner] . ']'; if($type != 'story' and $module->type == 'story') { - if(common::hasPriv('tree', 'edit') and $type == 'bug') $linkHtml .= ' ' . html::a(helper::createLink('tree', 'edit', "module={$module->id}&type=$type"), $this->lang->tree->edit, '', 'data-toggle="modal" data-type="ajax"'); - if(common::hasPriv('tree', 'browse')) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'browse', "root={$module->root}&type=$type&module={$module->id}"), $this->lang->tree->child); + if(common::hasPriv('tree', 'edit') and $type == 'bug') $linkHtml .= ' ' . html::a(helper::createLink('tree', 'edit', "module={$module->id}&type=$type&branch=$branchID"), $this->lang->tree->edit, '', 'data-toggle="modal" data-type="ajax"'); + if(common::hasPriv('tree', 'browse')) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'browse', "root={$module->root}&type=$type&module={$module->id}&branch=$branchID"), $this->lang->tree->child); } else { - if(common::hasPriv('tree', 'edit')) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'edit', "module={$module->id}&type=$type"), $this->lang->tree->edit, '', 'data-toggle="modal" data-type="ajax" data-width="500"'); - if(common::hasPriv('tree', 'browse') and strpos($this->config->tree->noBrowse, ",$module->type,") === false) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'browse', "root={$module->root}&type=$type&module={$module->id}"), $this->lang->tree->child); + if(common::hasPriv('tree', 'edit')) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'edit', "module={$module->id}&type=$type&branch=$branchID"), $this->lang->tree->edit, '', 'data-toggle="modal" data-type="ajax" data-width="500"'); + if(common::hasPriv('tree', 'browse') and strpos($this->config->tree->noBrowse, ",$module->type,") === false) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'browse', "root={$module->root}&type=$type&module={$module->id}&branch=$branchID"), $this->lang->tree->child); if(common::hasPriv('tree', 'delete')) $linkHtml .= ' ' . html::a(helper::createLink('tree', 'delete', "root={$module->root}&module={$module->id}"), $this->lang->delete, 'hiddenwin'); if(common::hasPriv('tree', 'updateorder')) $linkHtml .= ' ' . html::input("orders[$module->id]", $module->order, 'class="text-center w-30px form-control inline input-sm"'); } @@ -810,7 +775,7 @@ class treeModel extends model */ public function createBugLink($type, $module) { - $linkHtml = html::a(helper::createLink('bug', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); + $linkHtml = html::a(helper::createLink('bug', 'browse', "root={$module->root}&branch=&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); return $linkHtml; } @@ -823,7 +788,7 @@ class treeModel extends model */ public function createCaseLink($type, $module) { - $linkHtml = html::a(helper::createLink('testcase', 'browse', "root={$module->root}&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); + $linkHtml = html::a(helper::createLink('testcase', 'browse', "root={$module->root}&branch=&type=byModule¶m={$module->id}"), $module->name, '_self', "id='module{$module->id}'"); return $linkHtml; } @@ -840,6 +805,13 @@ class treeModel extends model return $linkHtml; } + public function createBranchLink($type, $rootID, $branchID, $branch) + { + if($type == 'story') return html::a(helper::createLink('product', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); + if($type == 'bug') return html::a(helper::createLink('bug', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); + if($type == 'case') return html::a(helper::createLink('testcase', 'browse', "productID={$rootID}&branch=$branchID"), $branch, '_self', "id='branch{$branchID}'"); + } + /** * Get sons of a module. * @@ -849,7 +821,7 @@ class treeModel extends model * @access public * @return array */ - public function getSons($rootID, $moduleID, $type = 'root') + public function getSons($rootID, $moduleID, $type = 'root', $branch = 0) { $createdVersion = $this->dao->select('createdVersion')->from(TABLE_PRODUCT) ->where('id')->eq($rootID) @@ -862,6 +834,8 @@ class treeModel extends model ->where('root')->eq((int)$rootID) ->andWhere('parent')->eq((int)$moduleID) ->andWhere('type')->eq($type) + ->beginIF(empty($branch))->andWhere("branch")->eq(0)->fi() + ->beginIF(!empty($branch))->andWhere("branch")->eq($branch)->fi() ->orderBy('`order`') ->fetchAll(); } @@ -872,6 +846,8 @@ class treeModel extends model ->where('root')->eq((int)$rootID) ->andWhere('parent')->eq((int)$moduleID) ->andWhere('type')->in($type) + ->beginIF(empty($branch))->andWhere("branch")->eq(0)->fi() + ->beginIF(!empty($branch))->andWhere("branch")->eq($branch)->fi() ->orderBy('type desc,`order`') ->fetchAll(); } @@ -1014,23 +990,24 @@ class treeModel extends model public function updateOrder($orders) { asort($orders); - $orderInfo = $this->dao->select('id,grade, parent')->from(TABLE_MODULE)->where('id')->in(array_keys($orders))->fetchAll('id'); + $orderInfo = $this->dao->select('id,grade, parent, branch')->from(TABLE_MODULE)->where('id')->in(array_keys($orders))->fetchAll('id'); $newOrders = array(); foreach($orders as $moduleID => $order) { $parent = $orderInfo[$moduleID]->parent; $grade = $orderInfo[$moduleID]->grade; + $branch = $orderInfo[$moduleID]->branch; - if(!isset($newOrders[$parent][$grade])) + if(!isset($newOrders[$parent][$grade][$branch])) { - $newOrders[$parent][$grade] = 1; + $newOrders[$parent][$grade][$branch] = 1; } else { - $newOrders[$parent][$grade] ++; + $newOrders[$parent][$grade][$branch] ++; } - $newOrder = $newOrders[$parent][$grade] * 10; + $newOrder = $newOrders[$parent][$grade][$branch] * 10; $this->dao->update(TABLE_MODULE)->set('`order`')->eq($newOrder)->where('id')->eq((int)$moduleID)->limit(1)->exec(); } } @@ -1048,6 +1025,7 @@ class treeModel extends model public function manageChild($rootID, $type, $parentModuleID, $childs) { $parentModule = $this->getByID($parentModuleID); + $branches = $this->post->branch; if($parentModule) { $grade = $parentModule->grade + 1; @@ -1070,6 +1048,7 @@ class treeModel extends model $module->root = $rootID; $module->name = strip_tags($moduleName); $module->parent = $parentModuleID; + $module->branch = $branches[$moduleID]; $module->grade = $grade; $module->type = $type; $module->order = $this->post->maxOrder + $i * 10; @@ -1213,7 +1192,7 @@ class treeModel extends model { /* Get all modules grouped by parent. */ if($type == 'bug' or $type == 'case') $type = 'story,' . $type; - $groupModules = $this->dao->select('id, parent')->from(TABLE_MODULE)->where('root')->eq($root)->andWhere('type')->in($type)->fetchGroup('parent', 'id'); + $groupModules = $this->dao->select('id, parent, branch')->from(TABLE_MODULE)->where('root')->eq($root)->andWhere('type')->in($type)->fetchGroup('parent', 'id'); $modules = array(); /* Cycle the groupModules until it has no item any more. */ @@ -1238,8 +1217,9 @@ class treeModel extends model /* Compute it's child modules. */ foreach($childModules as $childModuleID => $childModule) { - $childModule->grade = $parentModule->grade + 1; - $childModule->path = $parentModule->path . $childModule->id . ','; + $childModule->grade = $parentModule->grade + 1; + $childModule->path = $parentModule->path . $childModule->id . ','; + if(isset($parentModule->branch))$childModule->branch = $parentModule->branch; $modules[$childModuleID] = $childModule; // Save child module to modules, thus the child of child can compute it's grade and path. } unset($groupModules[$parentModuleID]); // Remove it from the groupModules. diff --git a/module/tree/view/browse.html.php b/module/tree/view/browse.html.php index e4535386f6..8689014f17 100644 --- a/module/tree/view/browse.html.php +++ b/module/tree/view/browse.html.php @@ -12,6 +12,7 @@ ?> +type != 'normal') ? true : false;?>
    tree->common;?>
    @@ -74,9 +75,20 @@ { if($sonModule->order > $maxOrder) $maxOrder = $sonModule->order; $disabled = $sonModule->type == $viewType ? '' : 'disabled="true"'; - echo '' . html::input("modules[id$sonModule->id]", $sonModule->name, 'class=form-control style="margin-bottom:5px" ' . $disabled) . ''; + echo $hasBranch ? "
    " : "
    "; + echo html::input("modules[id$sonModule->id]", $sonModule->name, 'class="form-control"' . $disabled); + if($hasBranch) echo '' . html::select("branch[id$sonModule->id]", $branches, $sonModule->branch, 'class="form-control" disabled'); + echo '
    '; + } + for($i = 0; $i < TREE::NEW_CHILD_COUNT ; $i ++) + { + echo "
    "; + echo html::input("modules[]", '', 'class="form-control"'); + if($hasBranch) echo '' . html::select("branch[]", $branches, $branch, 'class="form-control"'); + echo ""; + echo ""; + echo '
    '; } - for($i = 0; $i < TREE::NEW_CHILD_COUNT ; $i ++) echo '' . html::input("modules[]", '', 'class=form-control style="margin-bottom:5px"') . ''; ?>