* Modify the logic of loading stories when creating use cases in batches.

This commit is contained in:
tianshujie
2021-11-17 14:50:42 +08:00
parent fdade49b5d
commit 859327d7a3
6 changed files with 52 additions and 71 deletions
+8 -3
View File
@@ -1828,15 +1828,20 @@ class story extends control
* AJAX: get stories of a product in html select.
*
* @param int $productID
* @param int $branch
* @param int $moduleID
* @param int $storyID
* @param string $onlyOption
* @param string $status
* @param int $limit
* @param string $type
* @param bool $hasParent
* @param int $executionID
* @param int $number
* @access public
* @return void
*/
public function ajaxGetProductStories($productID, $branch = 0, $moduleID = 0, $storyID = 0, $onlyOption = 'false', $status = '', $limit = 0, $type = 'full', $hasParent = 1, $executionID = 0)
public function ajaxGetProductStories($productID, $branch = 0, $moduleID = 0, $storyID = 0, $onlyOption = 'false', $status = '', $limit = 0, $type = 'full', $hasParent = 1, $executionID = 0, $number = '')
{
if($moduleID)
{
@@ -1858,11 +1863,11 @@ class story extends control
}
else
{
$stories = $this->story->getProductStoryPairs($productID, $branch ? "0,$branch" : $branch, $moduleID, $storyStatus, 'id_desc', $limit, $type, 'story', $hasParent);
$stories = $this->story->getProductStoryPairs($productID, $branch, $moduleID, $storyStatus, 'id_desc', $limit, $type, 'story', $hasParent);
}
$storyID = isset($stories[$storyID]) ? $storyID : 0;
$select = html::select('story', empty($stories) ? array('' => '') : $stories, $storyID, "class='form-control'");
$select = html::select('story' . $number, empty($stories) ? array('' => '') : $stories, $storyID, "class='form-control'");
/* If only need options, remove select wrap. */
if($onlyOption == 'true') die(substr($select, strpos($select, '>') + 1, -10));
+2 -3
View File
@@ -2228,13 +2228,12 @@ class storyModel extends model
*/
public function getProductStoryPairs($productID = 0, $branch = 0, $moduleIdList = 0, $status = 'all', $order = 'id_desc', $limit = 0, $type = 'full', $storyType = 'story', $hasParent = true)
{
if($branch) $branch = "0,$branch";//Fix bug 1059.
$stories = $this->dao->select('t1.id, t1.title, t1.module, t1.pri, t1.estimate, t2.name AS product')
->from(TABLE_STORY)->alias('t1')->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')
->where('1=1')
->beginIF($productID)->andWhere('t1.product')->in($productID)->fi()
->beginIF($moduleIdList)->andWhere('t1.module')->in($moduleIdList)->fi()
->beginIF($branch)->andWhere('t1.branch')->in($branch)->fi()
->beginIF($branch !== 'all')->andWhere('t1.branch')->in($branch)->fi()
->beginIF(!$hasParent)->andWhere('t1.parent')->ge(0)->fi()
->beginIF($status and $status != 'all')->andWhere('t1.status')->in($status)->fi()
->andWhere('t1.deleted')->eq(0)
@@ -2673,7 +2672,7 @@ class storyModel extends model
->where('t1.project')->eq((int)$executionID)
->andWhere('t2.deleted')->eq(0)
->beginIF($productID)->andWhere('t2.product')->eq((int)$productID)->fi()
->beginIF($branch)->andWhere('t2.branch')->in("0,$branch")->fi()
->beginIF($branch != 'all')->andWhere('t2.branch')->eq($branch)->fi()
->beginIF($moduleIdList)->andWhere('t2.module')->in($moduleIdList)->fi()
->beginIF($status == 'unclosed')->andWhere('t2.status')->ne('closed')->fi()
->orderBy('t1.`order` desc')
+3 -2
View File
@@ -522,8 +522,9 @@ class testcase extends control
$this->app->tab == 'project' ? $this->loadModel('project')->setMenu($this->session->project) : $this->testcase->setMenu($this->products, $productID, $branch);
/* Set story list. */
$story = $storyID ? $this->story->getByID($storyID) : '';
$storyList = $storyID ? array($storyID => $story->id . ':' . $story->title) : array('');
$story = $storyID ? $this->story->getByID($storyID) : '';
$storyList = $this->loadModel('story')->getProductStoryPairs($productID, $branch);
$storyList += $storyID ? array($storyID => $story->id . ':' . $story->title) : array('');
/* Set module option menu. */
$moduleOptionMenu = $this->tree->getOptionMenu($productID, $viewType = 'case', $startModuleID = 0, $branch === 'all' ? 0 : $branch);
+14 -61
View File
@@ -3,66 +3,6 @@ $(document).ready(function()
removeDitto();//Remove 'ditto' in first row.
if($('#batchCreateForm table thead tr th.c-title').width() < 150) $('#batchCreateForm table thead tr th.c-title').width('150');
$(document).on('mouseup', '.chosen-with-drop', function()
{
var select = $(this).prev('select');
var id = $(select).attr('id');
if(id.indexOf('story') != -1)
{
var index = id.substring(5);
var moduleID = $('#module' + index).val();
var branch = $('#branch' + index).length > 0 ? $('#branch' + index).val() : 0;
if(moduleID == 'ditto')
{
for(var i = index - 1; i >=0; i--)
{
if($('#module' + i).val() != 'ditto')
{
moduleID = $('#module' + i).val();
break;
}
}
}
var link = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branch + '&moduleID=' + moduleID + '&storyID='+ ($(select).val() || '0') + '&onlyOption=true&status=noclosed&limit=0&type=null&hasParent=0');
var $story = $('#story' + index);
if($story.data('loadLink') !== link)
{
$story.load(link, function(){$story.data('loadLink', link).trigger("chosen:updated");});
}
}
if($(select).val() == 'ditto')
{
var index = $(select).closest('td').index();
var row = $(select).closest('tr').index();
var table = $(select).closest('tr').parent();
var value = '';
for(i = row - 1; i >= 0; i--)
{
value = $(table).find('tr').eq(i).find('td').eq(index).find('select').val();
if(value != 'ditto') break;
}
$(select).val(value);
$(select).trigger("chosen:updated");
}
});
$(document).on('mousedown', 'select', function()
{
if($(this).val() == 'ditto')
{
var index = $(this).closest('td').index();
var row = $(this).closest('tr').index();
var table = $(this).closest('tr').parent();
var value = '';
for(i = row - 1; i >= 0; i--)
{
value = $(table).find('tr').eq(i).find('td').eq(index).find('select').val();
if(value != 'ditto') break;
}
$(this).val(value);
}
});
$(document).keydown(function(event)
{
if(event.ctrlKey && event.keyCode == 38)
@@ -106,6 +46,19 @@ function setModules(branchID, productID, num)
$('#module' + num).replaceWith(modules);
$("#module" + num + "_chosen").remove();
$("#module" + num).next('.picker').remove();
$("#module" + num).chosen();
$("#module" + num).attr('onchange', "loadStories("+ productID + ", this.value, " + num + ")").chosen();
});
loadStories(productID, 0, num);
/* If the branch of the current row is inconsistent with the one below, clear the module and story of the nex row. */
var nextBranchID = $('#branch' + (num + 1)).val();
if(nextBranchID != branchID)
{
$('#module' + (num + 1)).find("option[value='ditto']").remove();
$('#module' + (num + 1)).trigger("chosen:updated");
$('#plan' + (num + 1)).find("option[value='ditto']").remove();
$('#plan' + (num + 1)).trigger("chosen:updated");
}
}
+23
View File
@@ -343,3 +343,26 @@ function updateStepID()
var i = 1;
$('.stepID').each(function(){$(this).html(i ++)});
}
/**
* Set stories.
*
* @param int productID
* @param int moduleID
* @param int num
* @access public
* @return void
*/
function loadStories(productID, moduleID, num)
{
var branchID = $('#branch' + num).val();
var storyLink = createLink('story', 'ajaxGetProductStories', 'productID=' + productID + '&branch=' + branchID + '&moduleID=' + moduleID + '&storyID=0&onlyOption=false&status=noclosed&limit=50&type=full&hasParent=1&executionID=0&number=' + num);
$.get(storyLink, function(stories)
{
if(!stories) modules = '<select id="story' + num + '" name="story[' + num + ']" class="form-control"></select>';
$('#story' + num).replaceWith(stories);
$("#story" + num + "_chosen").remove();
$("#story" + num).next('.picker').remove();
$("#story" + num).chosen();
});
}
+2 -2
View File
@@ -83,7 +83,7 @@
<tr>
<td class="text-center"><?php echo $i+1;?></td>
<td class='text-left<?php echo zget($visibleFields, $product->type, ' hidden')?>'><?php echo html::select("branch[$i]", $branches, $branch, "class='form-control' onchange='setModules(this.value, $productID, $i)'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'module', ' hidden')?>' style='overflow:visible'><?php echo html::select("module[$i]", $moduleOptionMenu, $currentModuleID, "class='form-control chosen'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'module', ' hidden')?>' style='overflow:visible'><?php echo html::select("module[$i]", $moduleOptionMenu, $currentModuleID, "class='form-control chosen' onchange='loadStories($productID, this.value, $i)'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'story', ' hidden'); echo $hiddenStory;?>' style='overflow:visible'> <?php echo html::select("story[$i]", $storyList, $story ? $story->id : '', 'class="form-control chosen"');?></td>
<td style='overflow:visible'>
<div class="input-control has-icon-right">
@@ -124,7 +124,7 @@
<tr>
<td class="text-center">%s</td>
<td class='text-left<?php echo zget($visibleFields, $product->type, ' hidden')?>'><?php echo html::select("branch[%s]", $branches, $branch, "class='form-control chosen' onchange='setModules(this.value, $productID, \"%s\")'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'module', ' hidden')?>' style='overflow:visible'><?php echo html::select("module[%s]", $moduleOptionMenu, $currentModuleID, "class='form-control chosen'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'module', ' hidden')?>' style='overflow:visible'><?php echo html::select("module[%s]", $moduleOptionMenu, $currentModuleID, "class='form-control chosen' onchange='loadStories($productID, this.value, \"%s\")'");?></td>
<td class='text-left<?php echo zget($visibleFields, 'story', ' hidden'); echo $hiddenStory;?>' style='overflow:visible'> <?php echo html::select("story[%s]", '', '', 'class="form-control chosen"');?></td>
<td style='overflow:visible'>
<div class="input-control has-icon-right">