header.review.html.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /**
  3. * The header view file of repo module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author Ke Zhao<zhaoke@easycorp.ltd>
  8. * @package repo
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. /* get last review info in this file. */
  13. $lastReview = $this->repo->getLastReviewInfo($file);
  14. $repoModule = isset($lastReview) && isset($lastReview->module) ? $lastReview->module : '';
  15. $infoRevision = isset($info->revision) ? (string)$info->revision : $revision;
  16. /* Get product pairs. */
  17. if($repo->product)
  18. {
  19. $products = array();
  20. $userProductIds = explode(',', $this->app->user->view->products);
  21. $repoProductIds = explode(',', $repo->product);
  22. if($userProductIds && $repoProductIds) $products = $this->dao->select('id,name')->from(TABLE_PRODUCT)->where('`id`')->in(array_intersect($userProductIds, $repoProductIds))->fetchPairs();
  23. }
  24. else
  25. {
  26. $products = $this->loadModel('product')->getPairs('', 0, '', 'all');
  27. }
  28. /* get product by cookie or last review in this file. */
  29. $repoProduct = isset($_COOKIE['repoPairs'][$repoID]) ? $_COOKIE['repoPairs'][$repoID] : '';
  30. $repoProduct = isset($lastReview) && isset($lastReview->product) ? $lastReview->product : $repoProduct;
  31. $repoProduct = isset($products[$repoProduct]) ? $repoProduct : key($products);
  32. $executions = $this->repo->getExecutionPairs($repoProduct);
  33. $modules = $this->loadModel('tree')->getOptionMenu($repoProduct, $viewType = 'bug', $startModuleID = 0);
  34. $users = $this->loadModel('user')->getPairs('devfirst|nodeleted|noclosed');
  35. $products = array('' => '') + $products;
  36. $executions = array('' => '') + $executions;
  37. $cwd = getcwd();
  38. $commiters = $this->user->getCommiters();
  39. $blamePairs = array();
  40. if($suffix and $suffix != 'binary' and strpos($this->config->repo->images, "|$suffix|") === false)
  41. {
  42. $blames = $this->scm->blame($entry, $infoRevision, false);
  43. foreach($blames as $line => $blame)
  44. {
  45. if(!isset($blame['committer']))
  46. {
  47. if(isset($blamePairs[$line - 1])) $blamePairs[$line] = $blamePairs[$line - 1];
  48. continue;
  49. }
  50. $blamePairs[$line] = zget($commiters, $blame['committer'], $blame['committer']);
  51. }
  52. }
  53. chdir($cwd);
  54. $v1 = isset($oldRevision) ? str_replace('-', '*', $oldRevision) : 0;
  55. $v2 = str_replace('-', '*', $infoRevision);
  56. $reviews = $this->repo->getReview($repoID, $file, empty($type) || $type == 'view' ? '' : $v2);
  57. $bugUrl = $this->repo->createLink('addBug', "repoID=$repoID");
  58. $commentUrl = $this->repo->createLink('addComment');
  59. $branches = $this->loadModel('branch')->getPairs($repoProduct);
  60. $bugs = array();
  61. foreach($reviews as $line => $lineReview)
  62. {
  63. $lineBugs = array();
  64. foreach ($lineReview['bugs'] as $bugID => $bug)
  65. {
  66. $lineBug = array();
  67. $lineBug['id'] = $bugID;
  68. $lineBug['line'] = $line;
  69. $lineBug['title'] = $bug->title;
  70. $lineBug['steps'] = $bug->steps;
  71. $lineBug['realname'] = $bug->realname;
  72. $lineBug['openedDate'] = substr($bug->openedDate, 5, 11);
  73. $lineBug['lines'] = $bug->lines;
  74. $lineBug['file'] = $bug->entry;
  75. $lineBug['revision'] = $bug->v2;
  76. if($bug->edit) $lineBug['edit'] = true;
  77. if(!empty($bug->delete)) $lineBug['delete'] = true;
  78. if(isset($lineReview['comments']))
  79. {
  80. if(isset($lineReview['comments'][$bugID]))
  81. {
  82. $comments = $lineReview['comments'][$bugID];
  83. $bugComments = array();
  84. foreach ($comments as $commentID => $comment)
  85. {
  86. $bugComment = array(
  87. 'id' => $comment->id,
  88. 'edit' => $comment->edit,
  89. 'realname' => $comment->realname,
  90. 'user' => $comment->user,
  91. 'date' => substr($comment->date, 5, 11),
  92. 'comment' => $comment->comment,
  93. );
  94. $bugComments[] = $bugComment;
  95. }
  96. $lineBug['comments'] = $bugComments;
  97. }
  98. }
  99. $lineBugs[] = $lineBug;
  100. }
  101. $bugs[$line] = $lineBugs;
  102. }
  103. $productPickerItems = array();
  104. $executionPickerItems = array();
  105. $modulePickerItems = array();
  106. $typePickerItems = array();
  107. $userPickerItems = array();
  108. $branchPickerItems = array();
  109. foreach($products as $id => $product) $productPickerItems[] = array('text' => $product, 'value' => $id);
  110. foreach($branches as $id => $branch) $branchPickerItems[] = array('text' => $branch, 'value' => $id);
  111. foreach($executions as $id => $execution) $executionPickerItems[] = array('text' => $execution, 'value' => $id);
  112. foreach($modules as $id => $module) $modulePickerItems[] = array('text' => $module, 'value' => $id);
  113. foreach($lang->repo->typeList as $id => $repoType) $typePickerItems[] = array('text' => $repoType, 'value' => $id);
  114. foreach($users as $id => $user) $userPickerItems[] = array('text' => $user, 'value' => $id);
  115. $browser = helper::getBrowser();
  116. jsVar('browser', $browser['name']);
  117. jsVar('bugs', $bugs);
  118. jsVar('products', $productPickerItems);
  119. jsVar('executions', $executionPickerItems);
  120. jsVar('modules', $modulePickerItems);
  121. jsVar('branches', $branchPickerItems);
  122. jsVar('users', $userPickerItems);
  123. jsVar('typeList', $typePickerItems);
  124. jsVar('userList', $userPickerItems);
  125. jsVar('repoProduct', $repoProduct);
  126. jsVar('repoModule', $repoModule);
  127. jsVar('bugRevision', $v2);
  128. jsVar('productError', $lang->repo->error->product);
  129. jsVar('contentError', $lang->repo->error->commentText);
  130. jsVar('titleError', $lang->repo->error->title);
  131. jsVar('commentError', $lang->repo->error->comment);
  132. jsVar('submit', $lang->repo->submit);
  133. jsVar('cancel', $lang->repo->cancel);
  134. jsVar('confirmDelete', $lang->repo->notice->deleteBug);
  135. jsVar('confirmDeleteComment', $lang->repo->notice->deleteComment);
  136. jsVar('blamePairs', $blamePairs);
  137. jsVar('isonlybody', isonlybody());
  138. formPanel
  139. (
  140. set::formID('bugForm'),
  141. setStyle('display', 'none'),
  142. set::url($bugUrl),
  143. set::actions
  144. (
  145. array(
  146. 'submit',
  147. array(
  148. 'text' => $lang->cancel,
  149. 'class' => 'cancel',
  150. 'onclick' => 'hiddenForm()'
  151. )
  152. )
  153. ),
  154. $this->app->tab == 'project' && $objectID ? input(set::type('hidden'), set::name('project'), set::value($objectID)) : null,
  155. formRow
  156. (
  157. formGroup
  158. (
  159. set::id('product'),
  160. set::label($lang->repo->product),
  161. set::control('picker'),
  162. set::name('product'),
  163. set::required(true),
  164. set::items($products),
  165. set::value($repoProduct),
  166. on::change('changeProduct')
  167. ),
  168. formGroup
  169. (
  170. setID('branch'),
  171. setClass('ml-1'),
  172. setStyle('display', 'none'),
  173. set::control('picker'),
  174. set::name('branch'),
  175. set::items($productPickerItems),
  176. on::change('loadBranch')
  177. )
  178. ),
  179. formRow
  180. (
  181. formGroup
  182. (
  183. set::id('execution'),
  184. set::width('1/2'),
  185. set::label($lang->repo->execution),
  186. set::control('picker'),
  187. set::name('execution'),
  188. set::items($executions),
  189. on::change('changeExecution')
  190. ),
  191. formGroup
  192. (
  193. set::id('module'),
  194. set::width('1/2'),
  195. set::label($lang->repo->module),
  196. set::control('picker'),
  197. set::name('module'),
  198. set::items($modules),
  199. set::value($repoModule),
  200. on::change('changeExecution')
  201. )
  202. ),
  203. formRow
  204. (
  205. formGroup
  206. (
  207. set::label($lang->repo->title),
  208. set::name('title'),
  209. set::required(true)
  210. )
  211. ),
  212. formRow
  213. (
  214. formGroup
  215. (
  216. set::id('repoType'),
  217. set::width('1/2'),
  218. set::label($lang->repo->type),
  219. set::control('picker'),
  220. set::name('repoType'),
  221. set::items($lang->repo->typeList)
  222. ),
  223. formGroup
  224. (
  225. set::id('assignedTo'),
  226. set::width('1/2'),
  227. set::label($lang->repo->assign),
  228. set::control('picker'),
  229. set::name('assignedTo'),
  230. set::items($users)
  231. )
  232. ),
  233. formGroup
  234. (
  235. set::label($lang->repo->lines),
  236. inputGroup
  237. (
  238. input
  239. (
  240. set::type('number'),
  241. set::min(1),
  242. set::name('begin')
  243. ),
  244. span
  245. (
  246. setClass('input-group-addon ghost'),
  247. ' - '
  248. ),
  249. input
  250. (
  251. set::type('number'),
  252. set::min(1),
  253. set::name('end')
  254. )
  255. )
  256. ),
  257. formRow
  258. (
  259. formGroup
  260. (
  261. setClass('w-full'),
  262. set::label($lang->repo->detile),
  263. set::name('steps'),
  264. set::control('editor'),
  265. set::rows(6)
  266. )
  267. ),
  268. formHidden('fromReversion', $v1),
  269. formHidden('revision', $v2),
  270. formHidden('file', $file)
  271. );