From 2675b16080242bd945ccb85bb6ddbcbabd180881 Mon Sep 17 00:00:00 2001 From: zhaixiaojian Date: Mon, 12 Aug 2024 16:05:52 +0800 Subject: [PATCH] * [task#125051,done,4h,3h] change the design of the submitted list to related. --- module/bug/model.php | 58 ++++++++++++++++++++++++++++++++++ module/design/model.php | 21 +++++++++++++ module/repo/config/dtable.php | 5 +++ module/repo/control.php | 41 ++++++++++++++++++++++++ module/repo/lang/de.php | 2 ++ module/repo/lang/en.php | 2 ++ module/repo/lang/fr.php | 2 ++ module/repo/lang/zh-cn.php | 4 ++- module/repo/model.php | 27 +++++++++++++++- module/repo/ui/log.html.php | 24 ++++++++++++++ module/story/model.php | 59 +++++++++++++++++++++++++++++++++++ module/task/model.php | 57 +++++++++++++++++++++++++++++++++ 12 files changed, 300 insertions(+), 2 deletions(-) diff --git a/module/bug/model.php b/module/bug/model.php index 0a0cceb2f1..0cd2e8f5cb 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -2085,4 +2085,62 @@ class bugModel extends model foreach($branches as $branchID => $branchName) $modules += $this->tree->getOptionMenu($productID, 'bug', 0, (string)$branchID); return $modules; } + + /** + * 更新Bug关联的代码提交记录。 + * Update the commit logs linked with the bugs. + * + * @param int $bugID + * @param int $repoID + * @param array $revisions + * @access protected + * @return bool + */ + public function updateLinkedCommits(int $bugID, int $repoID, array $revisions): bool + { + if(!$bugID || !$repoID || empty($revisions)) return true; + $bug = $this->dao->select('product')->from(TABLE_BUG)->where('id')->eq($bugID)->fetch(); + if(!$bug) return true; + foreach($revisions as $revision) + { + $data = new stdclass(); + $data->project = $bug->project; + $data->product = $bug->product; + $data->AType = 'bug'; + $data->AID = $bugID; + $data->BType = 'commit'; + $data->BID = $revision; + $data->relation = 'completedin'; + $data->extra = $repoID; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + + $data->AType = 'commit'; + $data->AID = $revision; + $data->BType = 'bug'; + $data->BID = $bugID; + $data->relation = 'completedfrom'; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + } + return !dao::isError(); + } + + /** + * 获取Bug关联的提交数据。 + * Get the commit data for the associated bugs + * @param int $repoID + * @param array $revisions + * @access protected + * @return bool + */ + public function getLinkedCommits(int $repoID, array $revisions): array + { + return $this->dao->select('h.revision,b.id AS id,b.title AS title') + ->from(TABLE_REPOHISTORY)->alias('h') + ->leftJoin(TABLE_RELATION)->alias('r')->on('r.relation="completedin" and r.BType="commit" and r.BID=h.id') + ->leftJoin(TABLE_BUG)->alias('b')->on('r.AType="bug" and r.AID=b.id') + ->where('h.revision')->in($revisions) + ->andWhere('h.repo')->eq($repoID) + ->andWhere('b.id')->ne('') + ->fetchGroup('revision', 'id'); + } } diff --git a/module/design/model.php b/module/design/model.php index 5c8a095572..08a203b9db 100755 --- a/module/design/model.php +++ b/module/design/model.php @@ -413,4 +413,25 @@ class designModel extends model { return $this->dao->select('*')->from(TABLE_REPOHISTORY)->where('id')->eq($revisionID)->fetch(); } + + /** + * 获取设计关联的提交数据。 + * Get the commit data for the associated designs + * @param int $repoID + * @param array $revisions + * @access public + * @return bool + */ + public function getLinkedCommits(int $repoID, array $revisions): array + { + return $this->dao->select('h.revision,d.id AS id,d.name AS title') + ->from(TABLE_REPOHISTORY)->alias('h') + ->leftJoin(TABLE_RELATION)->alias('r')->on('r.relation="completedin" and r.BType="commit" and r.BID=h.id') + ->leftJoin(TABLE_DESIGN)->alias('d')->on('r.AType="design" and r.AID=d.id') + ->where('h.revision')->in($revisions) + ->andWhere('h.repo')->eq($repoID) + ->andWhere('d.id')->ne('') + ->orderBy('id') + ->fetchGroup('revision', 'id'); + } } diff --git a/module/repo/config/dtable.php b/module/repo/config/dtable.php index 60806a0bcf..e2d4ff69f4 100644 --- a/module/repo/config/dtable.php +++ b/module/repo/config/dtable.php @@ -156,6 +156,11 @@ $config->repo->logDtable->fieldList['date']['width'] = '160'; $config->repo->logDtable->fieldList['committer']['name'] = 'committer'; $config->repo->logDtable->fieldList['committer']['width'] = '160'; +$config->repo->logDtable->fieldList['design']['name'] = 'designName'; +$config->repo->logDtable->fieldList['design']['type'] = 'html'; +$config->repo->logDtable->fieldList['design']['width'] = '450'; +$config->repo->logDtable->fieldList['design']['title'] = $lang->repo->design; + $config->repo->logDtable->fieldList['comment']['type'] = 'html'; $config->repo->logDtable->fieldList['comment']['width'] = '400'; diff --git a/module/repo/control.php b/module/repo/control.php index 587ad8a5d3..eaa148b534 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -583,6 +583,47 @@ class repo extends control $query = $browseType == 'bysearch' ? $this->repoZen->getSearchForm($queryID, !in_array($repo->SCM, $this->config->repo->notSyncSCM)) : null; $logs = $this->repo->getCommits($repo, $entry, $branchID, 'dir', $pager, '', '', $query); + $revisionIds = array_column($logs, 'revision'); + + $stories = $this->loadModel('story')->getLinkedCommits($repoID, $revisionIds); + $designs = $this->loadModel('design')->getLinkedCommits($repoID, $revisionIds); + $tasks = $this->loadModel('task')->getLinkedCommits($repoID, $revisionIds); + $bugs = $this->loadModel('bug')->getLinkedCommits($repoID, $revisionIds); + foreach($logs as $logItem) + { + if(!empty($designs[$logItem->revision])) + { + foreach($designs[$logItem->revision] as $item) $item->url = !empty($item->id) ? + $this->createLink('design', 'view','designID=' . $item->id) : + ''; + $logItem->relations['designs'] = $designs[$logItem->revision]; + } + + if(!empty($stories[$logItem->revision])) + { + foreach($stories[$logItem->revision] as $item) $item->url = !empty($item->id) ? + $this->createLink('story', 'view','storyID=' . $item->id) : + ''; + $logItem->relations['stroies'] = $stories[$logItem->revision]; + } + + if(!empty($tasks[$logItem->revision])) + { + foreach($tasks[$logItem->revision] as $item) $item->url = !empty($item->id) ? + $this->createLink('task', 'view','taskID=' . $item->id) : + ''; + $logItem->relations['tasks'] = $tasks[$logItem->revision]; + } + + if(!empty($bugs[$logItem->revision])) + { + foreach($bugs[$logItem->revision] as $item) $item->url = !empty($item->id) ? + $this->createLink('bug', 'view','bugID=' . $item->id) : + ''; + $logItem->relations['bugs'] = $bugs[$logItem->revision]; + } + } + $this->view->repo = $repo; $this->view->title = $this->lang->repo->common; $this->view->logs = $logs; diff --git a/module/repo/lang/de.php b/module/repo/lang/de.php index c3795271c1..a44e1e40d1 100644 --- a/module/repo/lang/de.php +++ b/module/repo/lang/de.php @@ -147,6 +147,8 @@ $lang->repo->lastCommitter = 'committer'; $lang->repo->lastUpdateTime = 'Last update time'; $lang->repo->createdBy = 'Created by'; $lang->repo->sourceCommit = 'Source Commit'; +$lang->repo->design = 'Design'; +$lang->repo->story = 'Story'; $lang->repo->title = 'Title'; $lang->repo->status = 'Status'; diff --git a/module/repo/lang/en.php b/module/repo/lang/en.php index d1759a3988..11b08585b4 100644 --- a/module/repo/lang/en.php +++ b/module/repo/lang/en.php @@ -147,6 +147,8 @@ $lang->repo->lastCommitter = 'committer'; $lang->repo->lastUpdateTime = 'Last update time'; $lang->repo->createdBy = 'Created by'; $lang->repo->sourceCommit = 'Source Commit'; +$lang->repo->design = 'Design'; +$lang->repo->story = 'story'; $lang->repo->title = 'Title'; $lang->repo->status = 'Status'; diff --git a/module/repo/lang/fr.php b/module/repo/lang/fr.php index e1663b7d59..6fdf2b2edb 100644 --- a/module/repo/lang/fr.php +++ b/module/repo/lang/fr.php @@ -147,6 +147,8 @@ $lang->repo->lastCommitter = 'committer'; $lang->repo->lastUpdateTime = 'Last update time'; $lang->repo->createdBy = 'Created by'; $lang->repo->sourceCommit = 'Source Commit'; +$lang->repo->design = 'Design'; +$lang->repo->story = 'Story'; $lang->repo->title = 'Titre'; $lang->repo->status = 'Statut'; diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php index 49f97ca6d6..746e556751 100644 --- a/module/repo/lang/zh-cn.php +++ b/module/repo/lang/zh-cn.php @@ -104,7 +104,7 @@ $lang->repo->password = '密码'; $lang->repo->encoding = '编码'; $lang->repo->client = '客户端'; $lang->repo->size = '大小'; -$lang->repo->revision = '查看提交'; +$lang->repo->revision = '提交'; $lang->repo->revisionA = '提交'; $lang->repo->revisions = '提交'; $lang->repo->time = '提交时间'; @@ -147,6 +147,8 @@ $lang->repo->lastCommitter = '提交人'; $lang->repo->lastUpdateTime = '最后修改时间'; $lang->repo->createdBy = '创建人'; $lang->repo->sourceCommit = '来源提交'; +$lang->repo->design = '相关设计'; +$lang->repo->story = '需求'; $lang->repo->title = '标题'; $lang->repo->status = '状态'; diff --git a/module/repo/model.php b/module/repo/model.php index eea791d39e..05ccdc72cf 100644 --- a/module/repo/model.php +++ b/module/repo/model.php @@ -1882,8 +1882,33 @@ class repoModel extends model } } } - } + if(!empty($objects['stories']) || !empty($objects['tasks']) || !empty($objects['bugs'])) + { + $historyLog = new stdclass(); + $historyLog->committer = $log->author; + $historyLog->revision = $log->revision; + $historyLog->comment = $commit->message; + $historyLog->time = date("Y-m-d H:i:s", strtotime($time)); + $this->saveCommit($repo->id, array('commits' => [$historyLog]), 0); + $revisions = $this->dao->select('id')->from(TABLE_REPOHISTORY) + ->where('revision')->in([$log->revision]) + ->andWhere('repo')->eq($repo->id) + ->fetchPairs('id'); + if(!empty($objects['stories'])) + { + foreach($objects['stories'] as $storyID) $this->loadModel('story')->updateLinkedCommits((int)$storyID, $repo->id, $revisions); + } + if(!empty($objects['tasks'])) + { + foreach($objects['tasks'] as $taskID) $this->loadModel('task')->updateLinkedCommits((int)$taskID, $repo->id, $revisions); + } + if(!empty($objects['bugs'])) + { + foreach($objects['bugs'] as $bugID) $this->loadModel('bug')->updateLinkedCommits((int)$bugID, $repo->id, $revisions); + } + } + } return !dao::isError(); } diff --git a/module/repo/ui/log.html.php b/module/repo/ui/log.html.php index b521a007d4..0d065252af 100644 --- a/module/repo/ui/log.html.php +++ b/module/repo/ui/log.html.php @@ -53,6 +53,30 @@ if($fileName) $breadcrumbItems[] = h::span($fileName); foreach($logs as $log) { $log->revision = substr($log->revision, 0, 10); + $log->designName = ''; + if(!empty($log->relations['stroies'])) + { + $log->designName .= html::commonButton($lang->repo->story , '', 'btn size-sm mx-2'); + foreach($log->relations['stroies'] as $item) $log->designName .= html::a($item->url, '#'.$item->id, '_blank'); + } + + if(!empty($log->relations['designs'])) + { + $log->designName .= html::commonButton($lang->design->common , '', 'btn size-sm mx-2'); + foreach($log->relations['designs'] as $item) $log->designName .= html::a($item->url, '#'.$item->id,'_blank'); + } + + if(!empty($log->relations['tasks'])) + { + $log->designName .= html::commonButton($lang->task->common , '', 'btn size-sm mx-2'); + foreach($log->relations['tasks'] as $item) $log->designName .= html::a($item->url, '#'.$item->id,'_blank'); + } + + if(!empty($log->relations['bugs'])) + { + $log->designName .= html::commonButton($lang->bug->common , '', 'btn size-sm mx-2'); + foreach($log->relations['bugs'] as $item) $log->designName .= html::a($item->url, '#'.$item->id,'_blank'); + } } /* Disbale check all checkbox of table header */ diff --git a/module/story/model.php b/module/story/model.php index 6096eec5d9..5c5c65995e 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -5363,4 +5363,63 @@ class storyModel extends model } } } + + /** + * 更新需求关联的代码提交记录。 + * Update the commit logs linked with the stories. + * + * @param int $storyID + * @param int $repoID + * @param array $revisions + * @access protected + * @return bool + */ + public function updateLinkedCommits(int $storyID, int $repoID, array $revisions): bool + { + if(!$storyID || !$repoID || empty($revisions)) return true; + $story = $this->dao->select('product')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch(); + if(!$story) return true; + foreach($revisions as $revision) + { + $data = new stdclass(); + $data->product = $story->product; + $data->AType = 'story'; + $data->AID = $storyID; + $data->BType = 'commit'; + $data->BID = $revision; + $data->relation = 'completedin'; + $data->extra = $repoID; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + + $data->AType = 'commit'; + $data->AID = $revision; + $data->BType = 'story'; + $data->BID = $storyID; + $data->relation = 'completedfrom'; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + } + + return !dao::isError(); + } + + /** + * 获取需求关联的提交数据。 + * Get the commit data for the associated stories + * @param int $storyID + * @param int $repoID + * @param array $revisions + * @access protected + * @return bool + */ + public function getLinkedCommits(int $repoID, array $revisions): array + { + return $this->dao->select('h.revision,s.id AS id,s.title AS title') + ->from(TABLE_REPOHISTORY)->alias('h') + ->leftJoin(TABLE_RELATION)->alias('r')->on('r.relation="completedin" and r.BType="commit" and r.BID=h.id') + ->leftJoin(TABLE_STORY)->alias('s')->on('r.AType="story" and r.AID=s.id') + ->where('h.revision')->in($revisions) + ->andWhere('h.repo')->eq($repoID) + ->andWhere('s.id')->ne('') + ->fetchGroup('revision', 'id'); + } } diff --git a/module/task/model.php b/module/task/model.php index 7104ce1f12..b2ba35718f 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -3279,4 +3279,61 @@ class taskModel extends model { return $this->dao->select('*')->from(TABLE_TASKTEAM)->where('task')->eq($taskID)->orderBy($orderBy)->fetchAll('id'); } + + /** + * 更新任务关联的代码提交记录。 + * Update the commit logs linked with the tasks. + * + * @param int $taskID + * @param int $repoID + * @param array $revisions + * @access public + * @return bool + */ + public function updateLinkedCommits(int $taskID, int $repoID, array $revisions): bool + { + if(!$taskID || !$repoID || empty($revisions)) return true; + $task = $this->dao->select('project')->from(TABLE_TASK)->where('id')->eq($taskID)->fetch(); + if(!$task) return true; + foreach($revisions as $revision) + { + $data = new stdclass(); + $data->project = $task->project; + $data->AType = 'task'; + $data->AID = $taskID; + $data->BType = 'commit'; + $data->BID = $revision; + $data->relation = 'completedin'; + $data->extra = $repoID; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + + $data->AType = 'commit'; + $data->AID = $revision; + $data->BType = 'task'; + $data->BID = $taskID; + $data->relation = 'completedfrom'; + $this->dao->replace(TABLE_RELATION)->data($data)->autoCheck()->exec(); + } + return !dao::isError(); + } + + /** + * 获取Task关联的提交数据。 + * Get the commit data for the associated bugs + * @param int $repoID + * @param array $revisions + * @access public + * @return bool + */ + public function getLinkedCommits(int $repoID, array $revisions): array + { + return $this->dao->select('h.revision,t.id AS id,t.name AS name') + ->from(TABLE_REPOHISTORY)->alias('h') + ->leftJoin(TABLE_RELATION)->alias('r')->on('r.relation="completedin" and r.BType="commit" and r.BID=h.id') + ->leftJoin(TABLE_TASK)->alias('t')->on('r.AType="task" and r.AID=t.id') + ->where('h.revision')->in($revisions) + ->andWhere('h.repo')->eq($repoID) + ->andWhere('t.id')->ne('') + ->fetchGroup('revision', 'id'); + } }