Merge branch 'sprint/211_liumengyi_59477' into 'master'

* Finish task #59477.

See merge request easycorp/zentaopms!4364
This commit is contained in:
王怡栋
2022-07-06 01:50:59 +00:00
9 changed files with 140 additions and 47 deletions
+25 -21
View File
@@ -1860,14 +1860,6 @@ class testcase extends control
$this->loadModel('branch');
if($product->type != 'normal') $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active', $projectID);
if($_POST)
{
$this->testcase->importFromLib($productID);
return print(js::reload('parent'));
}
$this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch);
$libraries = $this->loadModel('caselib')->getLibraries();
if(empty($libraries))
{
@@ -1876,6 +1868,14 @@ class testcase extends control
}
if(empty($libID) or !isset($libraries[$libID])) $libID = key($libraries);
if($_POST)
{
$this->testcase->importFromLib($productID, $libID, $branch);
return print(js::reload('parent'));
}
$this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch);
/* Build the search form. */
$actionURL = $this->createLink('testcase', 'importFromLib', "productID=$productID&branch=$branch&libID=$libID&orderBy=$orderBy&browseType=bySearch&queryID=myQueryID");
$this->config->testcase->search['module'] = 'testsuite';
@@ -1890,6 +1890,10 @@ class testcase extends control
unset($this->config->testcase->search['fields']['branch']);
$this->loadModel('search')->setSearchParams($this->config->testcase->search);
$this->loadModel('testsuite');
foreach($branches as $branchID => $branchName) $canImportModules[$branchID] = $this->testsuite->getCanImportModules($productID, $libID, $branchID);
if(empty($branches)) $canImportModules[0] = $this->testsuite->getCanImportModules($productID, $libID, 0);
/* Load pager. */
$this->app->loadClass('pager', $static = true);
$pager = pager::init(0, $recPerPage, $pageID);
@@ -1897,19 +1901,19 @@ class testcase extends control
$this->view->title = $this->lang->testcase->common . $this->lang->colon . $this->lang->testcase->importFromLib;
$this->view->position[] = $this->lang->testcase->importFromLib;
$this->view->libraries = $libraries;
$this->view->libID = $libID;
$this->view->product = $product;
$this->view->productID = $productID;
$this->view->branch = $branch;
$this->view->cases = $this->loadModel('testsuite')->getNotImportedCases($productID, $libID, $orderBy, $pager, $browseType, $queryID);
$this->view->modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch === 'all' ? 0 : (int)$branch);
$this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib');
$this->view->pager = $pager;
$this->view->orderBy = $orderBy;
$this->view->branches = $branches;
$this->view->browseType = $browseType;
$this->view->queryID = $queryID;
$this->view->libraries = $libraries;
$this->view->libID = $libID;
$this->view->product = $product;
$this->view->productID = $productID;
$this->view->branch = $branch;
$this->view->cases = $this->testsuite->getCanImportCases($productID, $libID, $branch, $orderBy, $pager, $browseType, $queryID);
$this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib');
$this->view->pager = $pager;
$this->view->orderBy = $orderBy;
$this->view->branches = $branches;
$this->view->browseType = $browseType;
$this->view->queryID = $queryID;
$this->view->canImportModules = $canImportModules;
$this->display();
}
+19 -5
View File
@@ -52,14 +52,14 @@ function updateModules(productID, branch, caseID)
var tr = $('#module' + caseID).closest('tr');
if(branch !== 'ditto')
{
loadModules(tr, caseID, moduleLink);
loadModules(tr, caseID, moduleLink, undefined, branch);
tr.nextAll().each(function()
{
var nextCaseID = $(this).attr('id');
var nextBranch = $('#branch' + nextCaseID + ' option:selected').val();
if(nextBranch !== 'ditto') return false;
var nextTr = $('#module' + nextCaseID).closest('tr');
loadModules(nextTr, nextCaseID, moduleLink, true);
loadModules(nextTr, nextCaseID, moduleLink, true, branch);
});
}
else
@@ -76,14 +76,14 @@ function updateModules(productID, branch, caseID)
}
});
link = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=case&branch=' + branchID + '&rootModuleID=0&returnType=html&fieldID=&needManage=true');
loadModules(tr, caseID, link, true);
loadModules(tr, caseID, link, true, branchID);
tr.nextAll().each(function()
{
var nextCaseID = $(this).attr('id');
var nextBranch = $('#branch' + nextCaseID + ' option:selected').val();
if(nextBranch !== 'ditto') return false;
var nextTr = $('#module' + nextCaseID).closest('tr');
loadModules(nextTr, nextCaseID, link, true);
loadModules(nextTr, nextCaseID, link, true, branchID);
});
}
}
@@ -95,17 +95,31 @@ function updateModules(productID, branch, caseID)
* @param int $caseID
* @param string $link
* @param boolean $isAddDitto
* @param int $branch
* @access public
* @return void
*/
function loadModules(tr, caseID, link, isAddDitto)
function loadModules(tr, caseID, link, isAddDitto, branch)
{
var isAddDitto = (typeof(isAddDitto) === 'undefined') ? false : true;
$('#module' + caseID).parent('td').load(link, function(data)
{
if(canImportModules[branch][caseID] != undefined && Object.keys(canImportModules[branch][caseID]).length > 0)
{
$('tr select#module').children().each(function()
{
moduleID = $(this).val();
if(canImportModules[branch][caseID][moduleID] == undefined)
{
$(this).remove();
}
})
}
tr.find('#module').chosen();
tr.find('#module').attr({"id": 'module' + caseID, "name": 'module[' + caseID + ']'});
tr.find('#module' + caseID).removeAttr('onchange');
if(isAddDitto == true) addDittoOption(caseID);
});
}
+1
View File
@@ -235,6 +235,7 @@ $lang->testcase->noLibrary = "Es existiert keine Bibliothek. Bitte erstel
$lang->testcase->mustChooseResult = 'Prüfungsergebnis wird benötigt.';
$lang->testcase->noModule = '<div>Es existieren keine Module</div><div>Jetzt verwalten</div>';
$lang->testcase->noCase = 'Keine Fälle. ';
$lang->testcase->importedCases = 'The case with ID%s has been imported in the same module and has been ignored.';
$lang->testcase->searchStories = 'Story suchen';
$lang->testcase->selectLib = 'Bibliothek wählen';
+1
View File
@@ -235,6 +235,7 @@ $lang->testcase->noLibrary = "No library exists. Please create one first.
$lang->testcase->mustChooseResult = 'Review result is required.';
$lang->testcase->noModule = '<div>You have no modules.</div><div>Manage it now.</div>';
$lang->testcase->noCase = 'No cases yet. ';
$lang->testcase->importedCases = 'The case with ID%s has been imported in the same module and has been ignored.';
$lang->testcase->searchStories = 'Enter to search for stories';
$lang->testcase->selectLib = 'Select Library';
+1
View File
@@ -235,6 +235,7 @@ $lang->testcase->noLibrary = "Aucune library n'existe. Créez-en une pour
$lang->testcase->mustChooseResult = 'La Validation du résultat est nécessaire.';
$lang->testcase->noModule = "<div>Vous n'avez aucun modules.</div><div>Gérer les modules maintenant.</div>";
$lang->testcase->noCase = "Aucun CasTest pour l'instant. ";
$lang->testcase->importedCases = 'Le cas d\'utilisation avec l\'ID %s est déjà importé dans le même module, il est donc ignoré.';
$lang->testcase->searchStories = 'Rechercher des stories';
$lang->testcase->selectLib = 'Sélectionner Library';
+1
View File
@@ -235,6 +235,7 @@ $lang->testcase->noLibrary = "现在还没有用例库,请先创建!"
$lang->testcase->mustChooseResult = '必须选择评审结果';
$lang->testcase->noModule = '<div>您现在还没有模块信息</div><div>请维护测试模块</div>';
$lang->testcase->noCase = '暂时没有用例。';
$lang->testcase->importedCases = 'ID为 %s 的用例在相同模块已经导入,已忽略。';
$lang->testcase->searchStories = "键入来搜索{$lang->SRCommon}";
$lang->testcase->selectLib = '请选择库';
+23 -1
View File
@@ -1576,10 +1576,12 @@ class testcaseModel extends model
* Import case from Lib.
*
* @param int $productID
* @param int $libID
* @param int $branch
* @access public
* @return void
*/
public function importFromLib($productID)
public function importFromLib($productID, $libID, $branch)
{
$data = fixer::input('post')->get();
@@ -1591,18 +1593,26 @@ class testcaseModel extends model
if($module == 'ditto') $data->module[$i] = $prevModule;
}
$caseModules = array();
$this->loadModel('testsuite');
if(isset($data->branch))
{
foreach($data->branch as $i => $branch)
{
if($branch != 'ditto') $prevBranch = $branch;
if($branch == 'ditto') $data->branch[$i] = $prevBranch;
if(!isset($caseModules[$data->branch[$i]])) $caseModules[$data->branch[$i]] = $this->testsuite->getCanImportModules($productID, $libID, $data->branch[$i]);
}
}
else
{
$caseModules[$branch] = $this->loadModel('testsuite')->getCanImportModules($productID, $libID, $branch);
}
$libCases = $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq(0)->andWhere('id')->in($data->caseIdList)->fetchAll('id');
$libSteps = $this->dao->select('*')->from(TABLE_CASESTEP)->where('`case`')->in($data->caseIdList)->orderBy('id')->fetchGroup('case');
$libFiles = $this->dao->select('*')->from(TABLE_FILE)->where('objectID')->in($data->caseIdList)->andWhere('objectType')->eq('testcase')->fetchGroup('objectID', 'id');
$imported = '';
foreach($libCases as $libCaseID => $case)
{
$case->fromCaseID = $case->id;
@@ -1612,6 +1622,13 @@ class testcaseModel extends model
if(isset($data->branch[$case->id])) $case->branch = $data->branch[$case->id];
unset($case->id);
$branch = isset($case->branch) ? $case->branch : 0;
if(empty($caseModules[$branch][$case->fromCaseID][$case->module]))
{
$imported .= "$case->fromCaseID,";
continue;
}
$this->dao->insert(TABLE_CASE)->data($case)->autoCheck()->exec();
if(!dao::isError())
@@ -1655,6 +1672,11 @@ class testcaseModel extends model
$this->loadModel('action')->create('case', $caseID, 'fromlib', '', $case->lib);
}
}
if(!empty($imported))
{
$imported = trim($imported, ',');
return print(js::error(sprintf($this->lang->testcase->importedCases, $imported)));
}
}
/**
+18 -5
View File
@@ -13,6 +13,7 @@
<?php include '../../common/view/header.html.php';?>
<?php js::set('flow', $config->global->flow);?>
<?php js::set('ditto', $lang->testcase->ditto);?>
<?php js::set('canImportModules', $canImportModules);?>
<div id='mainMenu' class='clearfix'>
<div class='btn-toolbar pull-left'>
<div class='input-group w-300px'>
@@ -46,7 +47,19 @@
</thead>
<tbody>
<?php $i = 0;?>
<?php foreach($cases as $case):?>
<?php foreach($cases as $id => $case):?>
<?php
$caseBranches = $branches;
$caseBranch = ($branch == 'all' or empty($branch)) ? 0 : $branch;
foreach($caseBranches as $branchID => $branchName)
{
if(empty($canImportModules[$branchID][$case->id]))
{
unset($caseBranches[$branchID]);
if($caseBranch == $branchID) $caseBranch = key($caseBranches);
}
}
?>
<tr id='<?php echo $case->id;?>'>
<td class='c-id'>
<div class="checkbox-primary">
@@ -56,16 +69,16 @@
<?php printf('%03d', $case->id);?>
</td>
<?php if($product->type != 'normal'):?>
<?php if($i > 0) $branches['ditto'] = $lang->testcase->ditto;?>
<td><?php echo html::select("branch[{$case->id}]", $branches, $i == 0 ? $branch : 'ditto', "class='form-control' onchange='updateModules($productID, this.value, $case->id)'")?></td>
<?php if($i > 0) $caseBranches['ditto'] = $lang->testcase->ditto;?>
<td><?php echo html::select("branch[{$case->id}]", $caseBranches, $i == 0 ? $caseBranch : 'ditto', "class='form-control' onchange='updateModules($productID, this.value, $case->id)'")?></td>
<?php endif;?>
<td><span class='label-pri <?php echo 'label-pri-' . $case->pri;?>' title='<?php echo zget($lang->testcase->priList, $case->pri, $case->pri);?>'><?php echo $case->pri == '0' ? '' : zget($lang->testcase->priList, $case->pri, $case->pri);?></span></td>
<td class='text-left nobr'><?php if(!common::printLink('testcase', 'view', "caseID=$case->id", $case->title)) echo $case->title;?></td>
<?php $libModule = zget($libModules, $case->module, '');?>
<td class='text-left' title='<?php echo $libModule?>'><?php echo $libModule;?></td>
<td class='text-left' data-module='<?php echo $case->module?>' style='overflow:visible'>
<?php if($i > 0) $modules['ditto'] = $lang->testcase->ditto;?>
<?php echo html::select("module[{$case->id}]", $modules, $i == 0 ? 0 : 'ditto', "class='form-control chosen'");?>
<?php if($i == 0) unset($canImportModules[$caseBranch][$case->id]['ditto']);?>
<?php echo html::select("module[{$case->id}]", $canImportModules[$caseBranch][$case->id], $i == 0 ? 0 : 'ditto', "class='form-control chosen'");?>
</td>
<td><?php echo zget($lang->testcase->typeList, $case->type);?></td>
</tr>
+51 -15
View File
@@ -314,24 +314,18 @@ class testsuiteModel extends model
}
/**
* Get not imported cases.
* Get can import cases.
*
* @param int $productID
* @param int $libID
* @param int $branch
* @param string $orderBy
* @param object $pager
* @access public
* @return array
*/
public function getNotImportedCases($productID, $libID, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0)
public function getCanImportCases($productID, $libID, $branch, $orderBy = 'id_desc', $pager = null, $browseType = '', $queryID = 0)
{
$importedCases = $this->dao->select('fromCaseID')->from(TABLE_CASE)
->where('product')->eq($productID)
->andWhere('lib')->eq($libID)
->andWhere('fromCaseID')->ne('')
->andWhere('deleted')->eq(0)
->fetchPairs('fromCaseID', 'fromCaseID');
$query = '';
if($browseType == 'bysearch')
{
@@ -357,22 +351,64 @@ class testsuiteModel extends model
if(!$withAllLib) $query .= " AND `lib` = '$libID'";
}
$this->loadModel('branch');
$product = $this->loadModel('product')->getById($productID);
$branches = $product->type != 'normal' ? array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active') : array(0);
$canImport = array();
foreach($branches as $branchID => $branchName) $canImport += $this->getCanImportModules($productID, $libID, $branchID);
return $this->dao->select('*')->from(TABLE_CASE)->where('deleted')->eq(0)
->beginIF($browseType != 'bysearch')->andWhere('lib')->eq($libID)->fi()
->beginIF($browseType == 'bysearch')->andWhere($query)->fi()
->andWhere('id')->in(array_keys($canImport))
->andWhere('product')->eq(0)
->andWhere('id')->notIN($importedCases)
->orderBy($orderBy)
->page($pager)
->fetchAll('id');
}
/**
* Build testsuite menu.
*
* @param object $suite
* @param string $type
* Get imported case modules.
*
* @param int $productID
* @param int $libID
* @param int $branch
* @access public
* @return array
*/
public function getCanImportModules($productID, $libID, $branch)
{
$importedModules = $this->dao->select('fromCaseID,module')->from(TABLE_CASE)
->where('product')->eq($productID)
->andWhere('lib')->eq($libID)
->andWhere('branch')->eq($branch)
->andWhere('fromCaseID')->ne('')
->andWhere('deleted')->eq(0)
->fetchGroup('fromCaseID', 'module');
foreach($importedModules as $fromCaseID => $modules) $importedModules[$fromCaseID] = array_combine(array_keys($modules), array_keys($modules));
$libCases = $this->loadModel('caselib')->getLibCases($libID, 'all');
$modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, $branch);
$canImportModules = array();
foreach($libCases as $caseID => $case)
{
$caseModules = !empty($importedModules[$caseID]) ? $importedModules[$caseID] : array();
$canImportModules[$caseID] = array_diff_key($modules, $caseModules);
if(!empty($canImportModules[$caseID])) $canImportModules[$caseID]['ditto'] = $this->lang->testcase->ditto;
if(empty($canImportModules[$caseID])) unset($canImportModules[$caseID]);
}
return $canImportModules;
}
/**
* Build testsuite menu.
*
* @param object $suite
* @param string $type
* @access public
* @return string
*/