* Code for task#77802.

This commit is contained in:
xieqiyu
2022-11-30 22:18:27 +08:00
parent 9952631059
commit 7c51a7f992
11 changed files with 139 additions and 42 deletions
+42
View File
@@ -977,4 +977,46 @@ class productplan extends control
if(isset($parentPlanPairs[$planID])) unset($parentPlanPairs[$planID]);
return print(html::select('parent', array(0 => '') + $parentPlanPairs, 0, 'class="form-control"'));
}
/**
* AJAX: Get diff branches tips.
*
* @param int $productID
* @param int $parentID
* @param string $branches
* @access public
* @return void
*/
public function ajaxGetDiffBranchesTip($productID = 0, $parentID = 0, $branches = '')
{
if(empty($parentID) or empty($productID)) return;
/* If it has children, return. */
$parentBranch = $this->productplan->getByID($parentID);
if($parentBranch->parent == '-1') return;
/* Find diff branches between parent plan and child plan. */
$diffBranches = array();
$diffBranchesTip = '';
$product = $this->loadModel('product')->getByID($productID);
$branchPairs = $this->loadModel('branch')->getPairs($productID);
foreach(explode(',', $parentBranch->branch) as $parentBranchID)
{
if(empty($parentBranchID)) continue;
if(strpos(",$branches,", ",$parentBranchID,") === false)
{
$diffBranches[$parentBranchID] = $parentBranchID;
$diffBranchesTip .= "{$branchPairs[$parentBranchID]},";
}
}
if(empty($diffBranchesTip)) return;
/* Find stories and bugs in diff branches. */
$unlinkStories = $this->dao->select('*')->from(TABLE_STORY)->where('branch')->in($diffBranches)->andWhere("CONCAT(',', plan, ',')")->like("%,{$parentID},%")->fetchAll('id');
$unlinkBugs = $this->dao->select('*')->from(TABLE_BUG)->where('branch')->in($diffBranches)->andWhere('plan')->eq($parentID)->fetchAll('id');
if(empty($unlinkStories) and empty($unlinkBugs)) return;
$this->lang->productplan->diffBranchesTip = str_replace('@branch@', $this->lang->product->branchName[$product->type], $this->lang->productplan->diffBranchesTip);
printf($this->lang->productplan->diffBranchesTip, trim($diffBranchesTip, ','));
}
}
+17
View File
@@ -65,6 +65,8 @@ $('#future').on('change', function()
$('#branch').change(function()
{
if(parentPlanID) return;
var branchIdList = $(this).val();
if(!branchIdList) return;
@@ -86,3 +88,18 @@ $('#branch').change(function()
$('#parent').chosen();
})
});
$('#submit').click(function()
{
var parentPlan = $('#parent').val();
var branches = $('#branch').val();
if(parentPlan != 0 && branches)
{
link = createLink('productplan', 'ajaxGetDiffBranchesTip', "produtID=" + productID + "&parentID=" + parentPlan + "&branches=" + branches.toString());
$.post(link, function(diffBranchesTip)
{
if((diffBranchesTip != '' && confirm(diffBranchesTip)) || !diffBranchesTip) $('form#dataform').submit();
});
return false;
}
});
+15 -1
View File
@@ -86,5 +86,19 @@ $('#future').on('change', function()
}
});
$('#future').change();
$('#submit').click(function()
{
var parentPlan = $('#parent').val();
var branches = $('#branch').val();
if(parentPlan != 0 && branches)
{
link = createLink('productplan', 'ajaxGetDiffBranchesTip', "produtID=" + productID + "&parentID=" + parentPlan + "&branches=" + branches.toString());
$.post(link, function(diffBranchesTip)
{
if((diffBranchesTip != '' && confirm(diffBranchesTip)) || !diffBranchesTip) $('form#dataform').submit();
});
return false;
}
});
+1
View File
@@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s
$lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s.";
$lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s.";
$lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s.";
$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?";
$lang->productplan->featureBar['browse']['all'] = 'Alle';
$lang->productplan->featureBar['browse']['undone'] = 'Undone';
+1
View File
@@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s
$lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s.";
$lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s.";
$lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s.";
$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?";
$lang->productplan->featureBar['browse']['all'] = 'All';
$lang->productplan->featureBar['browse']['undone'] = 'Undone';
+1
View File
@@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s
$lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s.";
$lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s.";
$lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s.";
$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?";
$lang->productplan->featureBar['browse']['all'] = 'Tous';
$lang->productplan->featureBar['browse']['undone'] = 'Undone';
+1
View File
@@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "父计划[%s]的开始日期:%s
$lang->productplan->endLetterChildTip = "父计划[%s]的完成日期:%s,不能小于子计划的完成日期: %s";
$lang->productplan->beginLetterParentTip = "子计划[%s]的开始日期:%s,不能小于父计划的开始日期: %s";
$lang->productplan->endGreaterParentTip = "子计划[%s]的完成日期:%s,不能大于父计划的完成日期: %s";
$lang->productplan->diffBranchesTip = "父计划的@branch@ %s 未被子计划关联,对应@branch@的需求和bug将自动从计划中移除,是否保存?";
$lang->productplan->featureBar['browse']['all'] = '全部';
$lang->productplan->featureBar['browse']['undone'] = '未完成';
+48 -37
View File
@@ -554,24 +554,10 @@ class productplanModel extends model
$planID = $this->dao->lastInsertID();
$this->file->updateObjectID($this->post->uid, $planID, 'plan');
$this->loadModel('score')->create('productplan', 'create', $planID);
if(!empty($plan->parent))
if(!empty($plan->parent) and $parentPlan->parent == '0')
{
if($parentPlan->parent == '0')
{
$this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec();
/* Transfer stories and bugs linked with the parent plan to the child plan. */
$this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec();
$this->dao->update(TABLE_BUG)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec();
$stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id');
foreach($stories as $storyID => $story)
{
$storyPlan = str_replace(",{$plan->parent},", ",$planID,", ",$story->plan,");
$storyPlan = trim($storyPlan, ',');
$this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec();
}
}
$plan->id = $planID;
$this->transferStoriesAndBugs($plan);
}
return $planID;
}
@@ -597,7 +583,7 @@ class productplanModel extends model
->get();
$product = $this->loadModel('product')->getByID($oldPlan->product);
if($product->type != 'normal' and !isset($_POST['branch']))
if($product->type != 'normal' and $oldPlan->parent != -1 and !isset($_POST['branch']))
{
$this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]);
dao::$errors['branch'] = sprintf($this->lang->error->notempty, $this->lang->product->branch);
@@ -649,25 +635,7 @@ class productplanModel extends model
if(!dao::isError())
{
$this->file->updateObjectID($this->post->uid, $planID, 'plan');
if(!empty($plan->parent))
{
if($parentPlan->parent == '0')
{
$this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec();
/* Transfer stories and bugs linked with the parent plan to the child plan. */
$this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec();
$this->dao->update(TABLE_BUG)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec();
$stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id');
foreach($stories as $storyID => $story)
{
$storyPlan = str_replace(",{$plan->parent},", ",$planID,", ",$story->plan,");
$storyPlan = trim($storyPlan, ',');
$this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec();
}
}
}
if(!empty($plan->parent) and $parentPlan->parent == '0') $this->transferStoriesAndBugs($plan);
return common::createChanges($oldPlan, $plan);
}
}
@@ -1304,4 +1272,47 @@ class productplanModel extends model
if($product->type == 'normal') unset($this->config->productplan->search['fields']['branch']);
$this->loadModel('search')->setSearchParams($this->config->productplan->search);
}
/**
* Transfer stories and bugs to new plan.
*
* @param object $plan
* @access public
* @return void
*/
public function transferStoriesAndBugs($plan)
{
$this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec();
/* Transfer stories linked with the parent plan to the child plan. */
$stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id');
$unlinkStories = array();
foreach($stories as $storyID => $story)
{
if(!empty($story->branch) and strpos(",$plan->branch,", ",$story->branch,") === false)
{
$unlinkStories[$storyID] = $storyID;
$storyPlan = str_replace(",{$plan->parent},", ',', ",$story->plan,");
}
else
{
$storyPlan = str_replace(",{$plan->parent},", ",$plan->id,", ",$story->plan,");
}
$storyPlan = trim($storyPlan, ',');
$this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec();
}
if(!empty($unlinkStories)) $this->dao->delete()->from(TABLE_PLANSTORY)->where('plan')->eq($plan->parent)->andWhere('story')->in($unlinkStories)->exec();
$this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($plan->id)->where('plan')->eq($plan->parent)->exec();
/* Transfer bugs linked with the parent plan to the child plan. */
$bugs = $this->dao->select('*')->from(TABLE_BUG)->where('plan')->eq($plan->parent)->fetchAll('id');
$unlinkBugs = array();
foreach($bugs as $bugID => $bug)
{
if(!empty($bug->branch) and strpos(",$plan->branch,", ",$bug->branch,") === false) $unlinkBugs[$bugID] = $bugID;
}
if(!empty($unlinkBugs)) $this->dao->update(TABLE_BUG)->set('plan')->eq(0)->where('plan')->eq($plan->parent)->andWhere('id')->in($unlinkBugs)->exec();
$this->dao->update(TABLE_BUG)->set('plan')->eq($plan->id)->where('plan')->eq($plan->parent)->exec();
}
}
+1 -1
View File
@@ -44,7 +44,7 @@
<?php if($product->type != 'normal'):?>
<td class='text-left'>
<?php $disabled = $plan->parent == -1 ? "disabled='disabled'" : '';?>
<?php echo html::select("branch[$plan->id][]", $plan->parent == '-1' ? '' : $branchTagOption, $plan->branch, "onchange='getConflictStories($plan->id); 'class='form-control chosen' multiple $disabled");?>
<?php echo html::select("branch[$plan->id][]", $branchTagOption, $plan->branch, "onchange='getConflictStories($plan->id); 'class='form-control chosen' multiple $disabled");?>
</td>
<?php endif;?>
<td title='<?php echo $plan->title?>'><?php echo html::input("title[$plan->id]", $plan->title, "class='form-control'")?></td>
@@ -163,7 +163,7 @@
<?php if($this->session->currentProductType != 'normal'):?>
<?php $planBranches = '';?>
<?php foreach(explode(',', $plan->branch) as $branchID) $planBranches .= $branchOption[$branchID] . ',';?>
<td class='c-branch' title='<?php echo trim($planBranches, ',');?>'><?php if($plan->parent != '-1') echo trim($planBranches, ',');?></td>
<td class='c-branch' title='<?php echo trim($planBranches, ',');?>'><?php echo trim($planBranches, ',');?></td>
<?php endif;?>
<td><?php echo $plan->begin == $config->productplan->future ? $lang->productplan->future : $plan->begin;?></td>
<td><?php echo $plan->end == $config->productplan->future ? $lang->productplan->future : $plan->end;?></td>
+11 -2
View File
@@ -15,6 +15,7 @@
<?php js::set('weekend', $config->execution->weekend);?>
<?php js::set('productID', $productID);?>
<?php js::set('lastLang', $lang->productplan->last);?>
<?php js::set('parentPlanID', $parent);?>
<?php js::import($jsRoot . 'misc/date.js');?>
<div id='mainContent'class='main-content'>
<div class='center-block'>
@@ -35,13 +36,22 @@
<th><?php echo $lang->productplan->product;?></th>
<td class='muted'><?php echo $product->name;?></td><td></td><td></td>
</tr>
<?php endif;?>
<?php if($product->type != 'normal'):?>
<tr>
<th><?php echo $lang->product->branch;?></th>
<?php
if($parent)
{
foreach($branches as $branchID => $branchName)
{
if(strpos(",$parentPlan->branch,", ",$branchID,") === false) unset($branches[$branchID]);
}
}
?>
<td><?php echo html::select('branch[]', $branches, '', "class='form-control chosen' multiple required");?></td><td></td><td></td>
</tr>
<?php endif;?>
<?php endif;?>
<tr>
<th><?php echo $lang->productplan->title;?></th>
<td><?php echo html::input('title', '', "class='form-control' required");?></td>
@@ -79,7 +89,6 @@
<?php echo html::backButton();?>
<?php echo html::hidden('product', $product->id);?>
<?php if($parent):?>
<?php echo html::hidden('branch', $parentPlan->branch);?>
<?php echo html::hidden('parent', $parent);?>
<?php endif;?>
</td>