* Finish task #54191.

This commit is contained in:
mayue
2022-05-17 07:06:36 +00:00
parent 3d3000f06f
commit be47bb739c
6 changed files with 119 additions and 25 deletions
+24 -4
View File
@@ -91,6 +91,10 @@ class productplan extends control
if($parent) $this->view->parentPlan = $this->productplan->getById($parent);
$branchPairs = $product->type == 'normal' ? array() : $this->loadModel('branch')->getPairs($productID, 'active');
/* Get parent plan pairs. */
$parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branchID);
$this->view->parentPlanPairs = $parentPlanPairs;
/*Get default branch.*/
$branchList = $this->loadModel('branch')->getList($productID);
foreach($branchList as $branch)
@@ -140,10 +144,12 @@ class productplan extends control
$oldBranch = array($planID => $plan->branch);
$this->commonAction($plan->product, $plan->branch);
$this->view->title = $this->view->product->name . $this->lang->colon . $this->lang->productplan->edit;
$this->view->position[] = $this->lang->productplan->edit;
$this->view->oldBranch = $oldBranch;
$this->view->plan = $plan;
$this->view->title = $this->view->product->name . $this->lang->colon . $this->lang->productplan->edit;
$this->view->position[] = $this->lang->productplan->edit;
$this->view->productID = $plan->product;
$this->view->oldBranch = $oldBranch;
$this->view->plan = $plan;
$this->view->parentPlanPairs = $this->productplan->getTopPlanPairs($plan->product, $plan->branch, $planID);
$this->display();
}
@@ -942,4 +948,18 @@ class productplan extends control
$lastPlan = $this->productplan->getLast($productID, $branch, $parent);
echo json_encode($lastPlan);
}
/**
* AJAX: Get top plan.
*
* @param int $productID
* @param int $branch
* @access public
* @return object
*/
public function ajaxGetTopPlan($productID, $branch = 0)
{
$parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branch);
return print(html::select('parent', array('0' => '') + $parentPlanPairs, '', 'class="form-control"'));
}
}
+11 -3
View File
@@ -66,12 +66,20 @@ $('#future').on('change', function()
$('#branch').change(function()
{
var branchID = $(this).val();
var link = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchID);
var getLastLink = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchID);
var getTopPlanLink = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branchID);
$.post(link, function(data)
$.post(getLastLink, function(data)
{
data = JSON.parse(data);
var planTitle = data ? '(' + lastLang + ': ' + data.title + ')' : '';
$('#title').parent().next('td').html(planTitle);
})
})
$.post(getTopPlanLink, function(data)
{
$('#parent').replaceWith(data);
$('#parent_chosen').remove();
$('#parent').chosen();
})
});
+13 -2
View File
@@ -25,11 +25,23 @@ function getConflictStories(planID, branch)
{
$.get(createLink('productplan', 'ajaxGetConflictStory', 'planID=' + planID + '&newBranch=' + branch), function(conflictStories)
{
if(conflictStories != '' && !confirm(conflictStories))
var result = confirm(conflictStories) ? true : false;
if(conflictStories != '' && !result)
{
$('#branch').val(oldBranch[planID]);
$('#branch').trigger("chosen:updated");
}
if(result)
{
var link = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branch);
$.post(link, function(data)
{
$('#parent').replaceWith(data);
$('#parent_chosen').remove();
$('#parent').chosen();
})
}
});
}
@@ -73,4 +85,3 @@ $('#future').on('change', function()
}
});
$('#future').change();
+55 -13
View File
@@ -177,6 +177,29 @@ class productplanModel extends model
return $plans;
}
/**
* Get top plan pairs.
*
* @param int $productID
* @param int $branch
* @param int $exclude
* @access public
* @return array
*/
public function getTopPlanPairs($productID, $branch = '', $exclude = '')
{
$planPairs = $this->dao->select("id,title")->from(TABLE_PRODUCTPLAN)
->where('product')->eq($productID)
->beginIF($branch !== '')->andWhere('branch')->eq($branch)->fi()
->andWhere('parent')->le(0)
->andWhere('deleted')->eq(0)
->fetchPairs();
if($exclude) unset($planPairs[$exclude]);
return $planPairs;
}
/**
* Get plan pairs.
*
@@ -404,19 +427,17 @@ class productplanModel extends model
if($plan->parent > 0)
{
if($plan->parentBegin != $this->config->productplan->future)
$parentPlan = $this->getByID($plan->parent);
if($parentPlan->begin != $this->config->productplan->future)
{
if($plan->begin < $plan->parentBegin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $plan->parentBegin);
if($plan->begin < $parentPlan->begin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $parentPlan->begin);
}
if($plan->parentEnd != $this->config->productplan->future)
if($parentPlan->end != $this->config->productplan->future)
{
if($plan->end !== $this->config->productplan->future and $plan->end > $plan->parentEnd) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $plan->parentEnd);
if($plan->end !== $this->config->productplan->future and $plan->end > $parentPlan->end) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $parentPlan->end);
}
}
unset($plan->parentBegin);
unset($plan->parentEnd);
if(!$this->post->future and strpos($this->config->productplan->create->requiredFields, 'begin') !== false and empty($_POST['begin']))
{
dao::$errors['begin'] = sprintf($this->lang->error->notempty, $this->lang->productplan->begin);
@@ -442,7 +463,6 @@ class productplanModel extends model
$this->loadModel('score')->create('productplan', 'create', $planID);
if(!empty($plan->parent))
{
$parentPlan = $this->getByID($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();
@@ -473,7 +493,7 @@ class productplanModel extends model
*/
public function update($planID)
{
$oldPlan = $this->dao->findByID((int)$planID)->from(TABLE_PRODUCTPLAN)->fetch();
$oldPlan = $this->getByID($planID);
$plan = fixer::input('post')->stripTags($this->config->productplan->editor->edit['id'], $this->config->allowedTags)
->setIF($this->post->future or empty($_POST['begin']), 'begin', $this->config->productplan->future)
->setIF($this->post->future or empty($_POST['end']), 'end', $this->config->productplan->future)
@@ -481,9 +501,11 @@ class productplanModel extends model
->remove('delta,uid,future')
->get();
if($oldPlan->parent > 0)
$parentPlan = $this->getByID($plan->parent);
if($plan->parent > 0)
{
$parentPlan = $this->getByID($oldPlan->parent);
if($parentPlan->begin !== $this->config->productplan->future)
{
if($plan->begin < $parentPlan->begin) dao::$errors['begin'] = sprintf($this->lang->productplan->beginLetterParent, $parentPlan->begin);
@@ -493,9 +515,9 @@ class productplanModel extends model
if($plan->end !== $this->config->productplan->future and $plan->end > $parentPlan->end) dao::$errors['end'] = sprintf($this->lang->productplan->endGreaterParent, $parentPlan->end);
}
}
elseif($oldPlan->parent == -1 and $plan->begin != $this->config->productplan->future)
elseif($parentPlan and $plan->begin != $this->config->productplan->future)
{
$childPlans = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($planID)->andWhere('deleted')->eq(0)->fetchAll('id');
$childPlans = $this->getChildren($parentPlan->id);
$minBegin = $plan->begin;
$maxEnd = $plan->end;
foreach($childPlans as $childID => $childPlan)
@@ -520,11 +542,31 @@ class productplanModel extends model
->exec();
if(dao::isError()) return false;
if($plan->parent > 0) $this->updateParentStatus($plan->parent);
if($oldPlan->parent > 0) $this->updateParentStatus($oldPlan->parent);
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();
}
}
}
return common::createChanges($oldPlan, $plan);
}
}
+9 -3
View File
@@ -28,8 +28,6 @@
<tr>
<th><?php echo $lang->productplan->parent;?></th>
<td class='muted'><?php echo $parentPlan->title;?>
<?php echo html::hidden('parentBegin', $parentPlan->begin);?>
<?php echo html::hidden('parentEnd', $parentPlan->end);?>
</td><td></td><td></td>
</tr>
<?php else:?>
@@ -49,6 +47,12 @@
<td><?php echo html::input('title', '', "class='form-control' required");?></td>
<td colspan='2' class='muted'><?php if($lastPlan) echo '(' . $lang->productplan->last . ': ' . $lastPlan->title . ')';?></td>
</tr>
<?php if(!$parent):?>
<tr>
<th><?php echo $lang->productplan->parent;?></th>
<td><?php echo html::select('parent', array('0' => '') + $parentPlanPairs, '', "class='form-control chosen'");?>
</tr>
<?php endif;?>
<tr>
<th><?php echo $lang->productplan->begin;?></th>
<td><?php echo html::input('begin', formatTime($begin), "class='form-control form-date'");?></td>
@@ -74,8 +78,10 @@
<?php echo html::submitButton();?>
<?php echo html::backButton();?>
<?php echo html::hidden('product', $product->id);?>
<?php if($parent) echo html::hidden('branch', $parentPlan->branch);?>
<?php if($parent):?>
<?php echo html::hidden('branch', $parentPlan->branch);?>
<?php echo html::hidden('parent', $parent);?>
<?php endif;?>
</td>
</tr>
</tbody>
+7
View File
@@ -15,6 +15,7 @@
<?php js::set('weekend', $config->execution->weekend);?>
<?php js::import($jsRoot . 'misc/date.js');?>
<?php js::set('today', helper::today());?>
<?php js::set('productID', $productID);?>
<?php js::set('oldBranch', $oldBranch);?>
<div id='mainContent' class='main-content'>
<div class='center-block'>
@@ -38,6 +39,12 @@
<th><?php echo $lang->productplan->title;?></th>
<td><?php echo html::input('title', $plan->title, "class='form-control' required");?></td><td></td><td></td>
</tr>
<?php if($plan->parent >= 0):?>
<tr <?php echo $plan->parent == '-1' ? "class='hidden'" : ''?>>
<th><?php echo $lang->productplan->parent;?></th>
<td><?php echo html::select('parent', array('0' => '') + $parentPlanPairs, $plan->parent, "class='form-control chosen'");?>
</tr>
<?php endif;?>
<tr>
<th><?php echo $lang->productplan->status;?></th>
<?php $disabled = $plan->parent == -1 ? "disabled='disabled'" : '' ;?>