* 1.change deleteLinkedStory method name to unlinkStory.

* 2.adjust the code for story module.
This commit is contained in:
chenfeiCF
2016-03-13 04:26:13 +08:00
parent eff03084c3
commit a3c5e42a7c
8 changed files with 143 additions and 102 deletions
+35 -35
View File
@@ -908,69 +908,65 @@ class story extends control
*
* @param int $storyID
* @param string $type
* @param string $stories
* @param string $browseType
* @param int $param
* @access public
* @return void
*/
public function linkStory($storyID, $type = '', $stories = '', $browseType = '', $param = 0)
public function linkStory($storyID, $type = 'linkStories', $browseType = '', $param = 0)
{
$this->commonAction($storyID);
/* Link stories. */
if(!empty($_POST))
{
$stories = $this->story->linkStories($storyID, $type, $stories);
if(isonlybody()) die(js::closeModal('parent.parent', '', "function(){parent.parent.loadLinkedStories('$storyID', '$type', '$stories')}"));
die(js::locate($this->createLink('story', 'edit', "storyID=$storyID"), 'parent'));
}
/* Get story, product, products, and queryID. */
$story = $this->story->getById($storyID);
$products = $this->product->getPairs();
$queryID = ($browseType == 'bySearch') ? (int)$param : 0;
/* Link stories. */
if(!empty($_POST))
{
$this->story->linkStories($storyID, $type);
if(isonlybody()) die(js::closeModal('parent.parent', '', "function(){parent.parent.loadLinkedStories('$storyID', '$type')}"));
die(js::locate($this->createLink('story', 'edit', "storyID=$storyID"), 'parent'));
}
/* Build search form. */
$actionURL = $this->createLink('story', 'linkStory', "storyID=$storyID&type=$type&stories=$stories&browseType=bySearch&queryID=myQueryID", '', true);
$actionURL = $this->createLink('story', 'linkStory', "storyID=$storyID&type=$type&browseType=bySearch&queryID=myQueryID", '', true);
$this->loadModel('product')->buildSearchForm($story->product, $products, $queryID, $actionURL);
$this->loadModel('search')->setSearchParams($this->config->product->search);
/* Get stories to link. */
$allStories = array();
if($browseType == 'bySearch') $allStories = $this->story->getBySearch($story->product, $queryID, 'id', null);
$stories2Link = $this->story->getStories2Link($storyID, $type, $browseType, $queryID);
/* Assign. */
$this->view->title = $this->lang->story->linkStory . "STORY" . $this->lang->colon .$this->lang->story->linkStory;
$this->view->position[] = $this->lang->story->linkStory;
$this->view->type = $type;
$this->view->allStories = $allStories;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->view->actionURL = $this->config->product->search;
$this->view->title = $this->lang->story->linkStory . "STORY" . $this->lang->colon .$this->lang->story->linkStory;
$this->view->position[] = $this->lang->story->linkStory;
$this->view->type = $type;
$this->view->stories2Link = $stories2Link;
$this->view->users = $this->loadModel('user')->getPairs('noletter');
$this->display();
}
/**
* AJAX: If type is linkStories, get related stories else get child stories.
* AJAX: if type is linkStories, get related stories else get child stories.
*
* @param int $storyID
* @param string $type
* @param string $linkedStories
* @access public
* @return string
*/
public function ajaxGetLinkedStories($storyID, $type = '', $linkedStories = '')
public function ajaxGetLinkedStories($storyID, $type = '')
{
$stories = $this->story->getLinkedStories($linkedStories);
$story = $this->story->getById($storyID);
/* Get linked stories. */
$stories = $this->story->getLinkedStories($storyID, $type);
/* Build linked stories list. */
$output = '';
foreach($stories as $storyId => $storyTitle)
{
$output .= '<li>';
$output .= html::a(inlink('view', "storyID=$storyId"), "#$storyId " . $storyTitle);
$output .= html::a("javascript:deleteLinkedStory($storyID, \"$type\", $storyId)", '<i class="icon-remove"></i>', '', "title='{$this->lang->unlink}' style='float:right'");
$output .= html::a(inlink('view', "storyID=$storyId"), "#$storyId " . $storyTitle, '_blank');
$output .= html::a("javascript:unlinkStory($storyID, \"$type\", $storyId)", '<i class="icon-remove"></i>', '', "title='{$this->lang->unlink}' style='float:right'");
$output .= '</li>';
}
@@ -978,25 +974,29 @@ class story extends control
}
/**
* AJAX: Delete linked story.
* AJAX: unlink story.
*
* @param int $storyID
* @param string $type
* @param int $deleteStory
* @param int $story2Unlink
* @access public
* @return string
*/
public function ajaxDeleteLinkedStory($storyID, $type = '', $deleteStory = 0)
public function ajaxUnlinkStory($storyID, $type = '', $story2Unlink = 0)
{
$stories = $this->story->deleteLinkedStory($storyID, $type, $deleteStory);
$story = $this->story->getById($storyID);
/* Unlink related story if type is linkStories else unlink child story. */
$this->story->unlinkStory($storyID, $type, $story2Unlink);
$output = "";
/* Get linkStories if type is linkStories else get childStories. */
$stories = $this->story->getLinkedStories($storyID, $type);
/* Build linked stories list from. */
$output = '';
foreach($stories as $storyId => $storyTitle)
{
$output .= '<li>';
$output .= html::a(inlink('view', "storyID=$storyId"), "#$storyId " . $storyTitle);
$output .= html::a("javascript:deleteLinkedStory($storyID, \"$type\", $storyId)", '<i class="icon-remove"></i>', '', "title='{$this->lang->unlink}' style='float:right'");
$output .= html::a(inlink('view', "storyID=$storyId"), "#$storyId " . $storyTitle, '_blank');
$output .= html::a("javascript:unlinkStory($storyID, \"$type\", $storyId)", '<i class="icon-remove"></i>', '', "title='{$this->lang->unlink}' style='float:right'");
$output .= '</li>';
}
+1 -1
View File
@@ -1 +1 @@
#linkStoryForm {min-height: 200px}
#linkStoryForm {min-height: 300px}
+9 -10
View File
@@ -1,17 +1,17 @@
/**
* Delete linked story.
* Unlink story.
*
* @param int $storyID
* @param string $linkType
* @param int deleteStory
* @param int story2Unlink
* @access public
* @return void
*/
function deleteLinkedStory(storyID, linkType, deleteStory)
function unlinkStory(storyID, linkType, story2Unlink)
{
deleteLink = createLink('story', 'ajaxDeleteLinkedStory', 'storyID=' + storyID + '&type=' + linkType + '&deleteStory=' + deleteStory);
if(linkType == 'linkStories') $('#linkStoriesBox').load(deleteLink);
if(linkType == 'childStories') $('#childStoriesBox').load(deleteLink);
link = createLink('story', 'ajaxUnlinkStory', 'storyID=' + storyID + '&type=' + linkType + '&story2Unlink=' + story2Unlink);
if(linkType == 'linkStories') $('#linkStoriesBox').load(link);
if(linkType == 'childStories') $('#childStoriesBox').load(link);
}
/**
@@ -19,13 +19,12 @@ function deleteLinkedStory(storyID, linkType, deleteStory)
*
* @param int $storyID
* @param string $linkType
* @param string $linkedStories
* @access public
* @return void
*/
function loadLinkedStories(storyID, linkType, linkedStories)
function loadLinkedStories(storyID, linkType)
{
storyLink = createLink('story', 'ajaxGetLinkedStories', 'storyID=' + storyID + '&type=' + linkType + '&linkedStories=' + linkedStories);
if(linkType == 'linkStories') $('#linkStoriesBox').load(storyLink);
storyLink = createLink('story', 'ajaxGetLinkedStories', 'storyID=' + storyID + '&type=' + linkType);
if(linkType == 'linkStories') $('#linkStoriesBox').load(storyLink);
if(linkType == 'childStories') $('#childStoriesBox').load(storyLink);
}
+5 -4
View File
@@ -177,6 +177,7 @@ $lang->story->confirmDelete = "Are you sure to delete this story?";
$lang->story->confirmBatchClose = "Are you sure to close those stories?";
$lang->story->errorFormat = 'Error format';
$lang->story->errorEmptyTitle = "Title can't be empty";
$lang->story->errorEmptyChildStory = '『Child story』can not be empty.';
$lang->story->mustChooseResult = 'Must choose s result';
$lang->story->mustChoosePreVersion = 'Must select an version to revert';
$lang->story->ajaxGetProjectStories = "API:{$lang->projectCommon} stories";
@@ -196,10 +197,10 @@ $lang->story->action->linked2plan = array('main' => '$date, linked to pl
$lang->story->action->unlinkedfromplan = array('main' => '$date, removed from <stong>$extra></strong> by <strong>$actor</strong>');
$lang->story->action->linked2project = array('main' => '$date, linked to ' . $lang->projectCommon . ' <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->unlinkedfromproject = array('main' => '$date, removed from ' . $lang->projectCommon . ' <strontg>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->linkstories = array('main' => '$date, linked stories <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->childstories = array('main' => '$date, subdivied to <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->mvchildstories = array('main' => '$date, removed child stories <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->mvlinkstories = array('main' => '$date, removed link stories <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->linkrelatedstory = array('main' => '$date, link related story <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->subdividestory = array('main' => '$date, subdivide to <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->unlinkrelatedstory = array('main' => '$date, unlink related story <strong>$extra</strong> by <strong>$actor</strong>.');
$lang->story->action->unlinkchildstory = array('main' => '$date, unlink child story <strong>$extra</strong> by <strong>$actor</strong>.');
/* Report*/
$lang->story->report = new stdclass();
+5 -4
View File
@@ -177,6 +177,7 @@ $lang->story->confirmDelete = "您确认删除该需求吗?";
$lang->story->confirmBatchClose = "您确认关闭这些需求吗?";
$lang->story->errorFormat = '需求数据有误';
$lang->story->errorEmptyTitle = '标题不能为空';
$lang->story->errorEmptyChildStory = '『细分需求』不能为空。';
$lang->story->mustChooseResult = '必须选择评审结果';
$lang->story->mustChoosePreVersion = '必须选择回溯的版本';
$lang->story->ajaxGetProjectStories = "接口:获取{$lang->projectCommon}需求列表";
@@ -196,10 +197,10 @@ $lang->story->action->linked2plan = array('main' => '$date, 由 <strong>
$lang->story->action->unlinkedfromplan = array('main' => '$date, 由 <strong>$actor</strong> 从计划 <strong>$extra</strong> 移除。');
$lang->story->action->linked2project = array('main' => '$date, 由 <strong>$actor</strong> 关联到' . $lang->projectCommon . ' <strong>$extra</strong>。');
$lang->story->action->unlinkedfromproject = array('main' => '$date, 由 <strong>$actor</strong> 从' . $lang->projectCommon . ' <strong>$extra</strong> 移除。');
$lang->story->action->linkstories = array('main' => '$date, 由 <strong>$actor</strong> 关联相关需求 <strong>$extra</strong>。');
$lang->story->action->childstories = array('main' => '$date, 由 <strong>$actor</strong> 细分为需求 <strong>$extra</strong>。');
$lang->story->action->mvchildstories = array('main' => '$date, 由 <strong>$actor</strong> 移除细分需求 <strong>$extra</strong>。');
$lang->story->action->mvlinkstories = array('main' => '$date, 由 <strong>$actor</strong> 移除相关需求 <strong>$extra</strong>。');
$lang->story->action->linkrelatedstory = array('main' => '$date, 由 <strong>$actor</strong> 关联相关需求 <strong>$extra</strong>。');
$lang->story->action->subdividestory = array('main' => '$date, 由 <strong>$actor</strong> 细分为需求 <strong>$extra</strong>。');
$lang->story->action->unlinkrelatedstory = array('main' => '$date, 由 <strong>$actor</strong> 移除相关需求 <strong>$extra</strong>。');
$lang->story->action->unlinkchildstory = array('main' => '$date, 由 <strong>$actor</strong> 移除细分需求 <strong>$extra</strong>。');
/* 统计报表。*/
$lang->story->report = new stdclass();
+61 -26
View File
@@ -426,9 +426,14 @@ class storyModel extends model
->setIF($this->post->closedReason != false and $this->post->closedBy == false, 'closedBy', $this->app->user->account)
->join('reviewedBy', ',')
->join('mailto', ',')
->remove('files,labels,comment')
->remove('linkStories,childStories,files,labels,comment')
->get();
if(is_array($story->plan)) $story->plan = trim(join(',', $story->plan), ',');
if($story->closedReason == 'subdivided' and $oldStory->childStories == '')
{
dao::$errors[] = $this->lang->story->errorEmptyChildStory;
return false;
}
$this->dao->update(TABLE_STORY)
->data($story)
@@ -1040,60 +1045,90 @@ class storyModel extends model
*
* @param int $storyID
* @param string $type
* @param string $stories
* @access public
* @return string
* @return void
*/
public function linkStories($storyID, $type = 'linkStories', $stories = '')
public function linkStories($storyID, $type = 'linkStories')
{
if($this->post->stories == false) return $stories;
if($this->post->stories == false) return;
$stories = implode(',', $this->post->stories) . ',' . trim($stories, ',');
$this->dao->update(TABLE_STORY)->set($type)->eq(trim($stories,','))->where('id')->eq($storyID)->exec();
$story = $this->getById($storyID);
$stories2Link = $this->post->stories;
$stories = implode(',', $stories2Link) . ',' . trim($story->$type, ',');
$this->dao->update(TABLE_STORY)->set($type)->eq(trim($stories, ','))->where('id')->eq($storyID)->exec();
if(dao::isError()) die(js::error(dao::getError()));
$this->loadModel('action')->create('story', $storyID, $type, '', implode(',', $this->post->stories));
return $stories;
$action = ($type == 'linkStories') ? 'linkRelatedStory' : 'subdivideStory';
$this->loadModel('action')->create('story', $storyID, $action, '', implode(',', $stories2Link));
}
/**
* Delete linked story.
* Get stories to link.
*
* @param int $storyID
* @param string $type
* @param int $deleteStory
* @param string $browseType
* @param int $queryID
* @access public
* @return array
*/
public function deleteLinkedStory($storyID, $type, $deleteStory)
public function getStories2Link($storyID, $type = 'linkStories', $browseType = 'bySearch', $queryID = 0)
{
$story = $this->getById($storyID);
$stories = explode(',', trim($story->$type, ','));
foreach($stories as $key => $storyId)
if($browseType == 'bySearch')
{
if($storyId == $deleteStory) unset($stories[$key]);
$story = $this->getById($storyID);
$stories2Link = $this->getBySearch($story->product, $queryID, 'id', null);
foreach($stories2Link as $key => $story2Link)
{
if($story2Link->id == $storyID) unset($stories2Link[$key]);
if(in_array($story2Link->id, explode(',', $story->$type))) unset($stories2Link[$key]);
}
return $stories2Link;
}
$stories = implode(',', $stories);
else
{
return array();
}
}
/**
* Unlink story.
*
* @param int $storyID
* @param string $type
* @param int $story2Unlink
* @access public
* @return void
*/
public function unlinkStory($storyID, $type = 'linkStories', $story2Unlink = 0)
{
$story = $this->getById($storyID);
$oldLinkedStories = explode(',', trim($story->$type, ','));
foreach($oldLinkedStories as $key => $storyId)
{
if($storyId == $story2Unlink) unset($oldLinkedStories[$key]);
}
$stories = implode(',', $oldLinkedStories);
$this->dao->update(TABLE_STORY)->set($type)->eq($stories)->where('id')->eq($storyID)->exec();
if(dao::isError()) die(js::error(dao::getError()));
$action = ($type == 'linkStories') ? 'mvLinkStories' : 'mvChildStories';
$this->loadModel('action')->create('story', $storyID, $action, '', $deleteStory);
return $this->getLinkedStories($stories);
$action = ($type == 'linkStories') ? 'unlinkRelatedStory' : 'unlinkChildStory';
$this->loadModel('action')->create('story', $storyID, $action, '', $story2Unlink);
}
/**
* Get linked stories.
*
* @param string $stories
* @param string $storyID
* @param string $type
* @access public
* @return array
*/
public function getLinkedStories($stories)
public function getLinkedStories($storyID, $type = 'linkStories')
{
return $this->dao->select('id, title')->from(TABLE_STORY)->where('id')->in($stories)->fetchPairs();
$story = $this->getById($storyID);
return $this->dao->select('id, title')->from(TABLE_STORY)->where('id')->in($story->$type)->fetchPairs();
}
/**
+13 -9
View File
@@ -156,7 +156,7 @@
</tr>
<tr>
<th><?php echo $lang->story->closedReason;?></th>
<td><?php echo html::select('closedReason', $lang->story->reasonList, $story->closedReason, 'class="form-control"');?></td>
<td><?php echo html::select('closedReason', $lang->story->reasonList, $story->closedReason, "class='form-control' onchange='setStory(this.value)'");?></td>
</tr>
<?php endif;?>
</table>
@@ -165,14 +165,16 @@
<fieldset>
<legend><?php echo $lang->story->legendMisc;?></legend>
<table class='table table-form'>
<tr>
<?php if($story->status == 'closed'):?>
<tr id='duplicateStoryBox'>
<th class='w-70px'><?php echo $lang->story->duplicateStory;?></th>
<td><?php echo html::input('duplicateStory', $story->duplicateStory, "class='form-control'");?></td>
</tr>
<?php endif;?>
<tr class='text-top'>
<th><?php echo $lang->story->linkStories;?></th>
<th class='w-70px'><?php echo $lang->story->linkStories;?></th>
<td>
<?php echo html::a($this->createLink('story', 'linkStory', "storyID=$story->id&type=linkStories&stories=$story->linkStories", '', true), $lang->story->linkStory, '', "data-toggle='modal' data-type='iframe' data-width='85%'");?>
<?php echo html::a($this->createLink('story', 'linkStory', "storyID=$story->id&type=linkStories", '', true), $lang->story->linkStory, '', "data-toggle='modal' data-type='iframe' data-width='95%'");?>
<ul class='list-unstyled' id='linkStoriesBox'>
<?php
$linkStories = explode(',', $story->linkStories);
@@ -181,8 +183,8 @@
if(isset($story->extraStories[$linkStoryID]))
{
echo '<li>';
echo html::a(inlink('view', "storyID=$linkStoryID"), "#$linkStoryID " . $story->extraStories[$linkStoryID]);
echo html::a("javascript:deleteLinkedStory($story->id, \"linkStories\", $linkStoryID)", '<i class="icon-remove"></i>', '', "title='{$lang->unlink}' style='float:right'");
echo html::a(inlink('view', "storyID=$linkStoryID"), "#$linkStoryID " . $story->extraStories[$linkStoryID], '_blank');
echo html::a("javascript:unlinkStory($story->id, \"linkStories\", $linkStoryID)", '<i class="icon-remove"></i>', '', "title='{$lang->unlink}' style='float:right'");
echo '</li>';
}
}
@@ -190,10 +192,11 @@
</ul>
</td>
</tr>
<?php if($story->status == 'closed'):?>
<tr class='text-top'>
<th><?php echo $lang->story->childStories;?></th>
<td>
<?php echo html::a($this->createLink('story', 'linkStory', "storyID=$story->id&type=childStories&stories=$story->childStories", '', true), $lang->story->linkStory, '', "data-toggle='modal' data-type='iframe' data-width='85%'");?>
<?php echo html::a($this->createLink('story', 'linkStory', "storyID=$story->id&type=childStories", '', true), $lang->story->linkStory, '', "data-toggle='modal' data-type='iframe' data-width='95%'");?>
<ul class='list-unstyled' id='childStoriesBox'>
<?php
$childStories = explode(',', $story->childStories);
@@ -202,8 +205,8 @@
if(isset($story->extraStories[$childStoryID]))
{
echo '<li>';
echo html::a(inlink('view', "storyID=$childStoryID"), "#$childStoryID" . $story->extraStories[$childStoryID]);
echo html::a("javascript:deleteLinkedStory($story->id, \"childStories\", $childStoryID)", '<i class="icon-remove"></i>', '', "title='{$lang->unlink}' style='float:right'");
echo html::a(inlink('view', "storyID=$childStoryID"), "#$childStoryID" . $story->extraStories[$childStoryID], '_blank');
echo html::a("javascript:unlinkStory($story->id, \"childStories\", $childStoryID)", '<i class="icon-remove"></i>', '', "title='{$lang->unlink}' style='float:right'");
echo '</li>';
}
}
@@ -211,6 +214,7 @@
</ul>
</td>
</tr>
<?php endif;?>
</table>
</fieldset>
</div>
+14 -13
View File
@@ -22,7 +22,7 @@
</div>
<form method='post' class='form-condensed' target='hiddenwin' id='linkStoryForm'>
<table class='table table-condensed table-hover table-striped tablesorter table-fixed' id='storyList'>
<?php if($allStories):?>
<?php if($stories2Link):?>
<thead>
<tr>
<th class='w-id'><?php echo $lang->idAB;?></th>
@@ -36,21 +36,19 @@
</thead>
<tbody>
<?php $storyCount = 0;?>
<?php foreach($allStories as $storyDetail):?>
<?php if(in_array($storyDetail->id, explode(',', $story->$type))) continue;?>
<?php if($storyDetail->id == $story->id) continue;?>
<?php $storyLink = $this->createLink('story', 'view', "storyID=$storyDetail->id");?>
<?php foreach($stories2Link as $story2Link):?>
<?php $storyLink = $this->createLink('story', 'view', "storyID=$story2Link->id");?>
<tr class='text-center'>
<td class='text-left'>
<input type='checkbox' name='stories[]' value='<?php echo $storyDetail->id;?>'/>
<?php echo html::a($storyLink, sprintf('%03d', $storyDetail->id));?>
<input type='checkbox' name='stories[]' value='<?php echo $story2Link->id;?>'/>
<?php echo html::a($storyLink, sprintf('%03d', $story2Link->id));?>
</td>
<td><span class='<?php echo 'pri' . zget($lang->story->priList, $storyDetail->pri, $storyDetail->pri)?>'><?php echo zget($lang->story->priList, $storyDetail->pri, $storyDetail->pri);?></span></td>
<td><?php echo html::a($this->createLink('product', 'browse', "productID=$storyDetail->product&branch=$storyDetail->branch"), $products[$storyDetail->product], '_blank');?></td>
<td class='text-left nobr' title="<?php echo $storyDetail->title?>"><?php echo html::a($storyLink, $storyDetail->title, '_blank');?></td>
<td><?php echo $storyDetail->planTitle;?></td>
<td><?php echo $users[$storyDetail->openedBy];?></td>
<td><?php echo $storyDetail->estimate;?></td>
<td><span class='<?php echo 'pri' . zget($lang->story->priList, $story2Link->pri, $story2Link->pri)?>'><?php echo zget($lang->story->priList, $story2Link->pri, $story2Link->pri);?></span></td>
<td><?php echo html::a($this->createLink('product', 'browse', "productID=$story2Link->product&branch=$story2Link->branch"), $products[$story2Link->product], '_blank');?></td>
<td class='text-left nobr' title="<?php echo $story2Link->title?>"><?php echo html::a($storyLink, $story2Link->title, '_blank');?></td>
<td><?php echo $story2Link->planTitle;?></td>
<td><?php echo $users[$story2Link->openedBy];?></td>
<td><?php echo $story2Link->estimate;?></td>
</tr>
<?php $storyCount ++;?>
<?php endforeach;?>
@@ -63,6 +61,9 @@
</div>
</td>
</tr>
<tr>
<td class='hidden'><?php echo html::input('story', $story->id);?></td>
</tr>
</tfoot>
<?php endif;?>
</table>