header.review.html.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <?php
  2. /* get last review info in this file. */
  3. $lastReview = $this->repo->getLastReviewInfo($file);
  4. $repoModule = isset($lastReview) && isset($lastReview->module) ? $lastReview->module : '';
  5. /* Get product pairs. */
  6. if($repo->product)
  7. {
  8. $products = $this->dao->select('id,name')->from(TABLE_PRODUCT)->where('`id`')->in($repo->product)->fetchPairs();
  9. }
  10. else
  11. {
  12. $products = $this->loadModel('product')->getPairs('', 0, '', 'all');
  13. }
  14. /* get product by cookie or last review in this file. */
  15. $repoProduct = isset($_COOKIE['repoPairs'][$repoID]) ? $_COOKIE['repoPairs'][$repoID] : '';
  16. $repoProduct = isset($lastReview) && isset($lastReview->product) ? $lastReview->product : $repoProduct;
  17. $repoProduct = isset($products[$repoProduct]) ? $repoProduct : key($products);
  18. $executions = $this->repo->getExecutionPairs($repoProduct);
  19. $modules = $this->loadModel('tree')->getOptionMenu($repoProduct, $viewType = 'bug', $startModuleID = 0);
  20. $users = $this->loadModel('user')->getPairs('devfirst|nodeleted|noclosed');
  21. $products = array('' => '') + $products;
  22. $executions = array('' => '') + $executions;
  23. $cwd = getcwd();
  24. $commiters = $this->user->getCommiters();
  25. $blamePairs = array();
  26. if($suffix and $suffix != 'binary' and strpos($this->config->repo->images, "|$suffix|") === false)
  27. {
  28. $blames = $this->scm->blame($entry, $info->revision);
  29. foreach($blames as $line => $blame)
  30. {
  31. if(!isset($blame['committer']))
  32. {
  33. if(isset($blamePairs[$line - 1])) $blamePairs[$line] = $blamePairs[$line - 1];
  34. continue;
  35. }
  36. $blamePairs[$line] = zget($commiters, $blame['committer'], $blame['committer']);
  37. }
  38. }
  39. chdir($cwd);
  40. $infoRevision = isset($info->revision) ? $info->revision : '';
  41. $v1 = isset($oldRevision) ? str_replace('-', '*', $oldRevision) : 0;
  42. $v2 = str_replace('-', '*', $infoRevision);
  43. $reviews = $this->repo->getReview($repoID, $file, $v2);
  44. $bugUrl = $this->repo->createLink('addBug', "repoID=$repoID&file=$file&v1=$v1&v2=$v2");
  45. $commentUrl = $this->repo->createLink('addComment');
  46. $productSelect = html::select('product', $products, $repoProduct, 'class="product form-control chosen" onchange="changeProduct(this)"');
  47. $branches = $this->loadModel('branch')->getPairs($repoProduct);
  48. $moduleSelect = html::select('module', $modules, $repoModule, 'class="form-control chosen"');
  49. $executionSelect = html::select('execution', $executions, '', 'class="form-control chosen"');
  50. $typeSelect = html::select('repoType', $lang->repo->typeList, '', 'class="form-control chosen"');
  51. $userSelect = html::select('assignedTo', $users, '', 'class="form-control chosen assignedTo"');
  52. $bugs = array();
  53. foreach($reviews as $line => $lineReview)
  54. {
  55. $lineBugs = array();
  56. foreach ($lineReview['bugs'] as $bugID => $bug)
  57. {
  58. $lineBug = array();
  59. $lineBug['id'] = $bugID;
  60. $lineBug['line'] = $line;
  61. $lineBug['title'] = $bug->title;
  62. $lineBug['steps'] = $bug->steps;
  63. $lineBug['realname'] = $bug->realname;
  64. $lineBug['openedDate'] = substr($bug->openedDate, 5, 11);
  65. $lineBug['lines'] = $bug->lines;
  66. $lineBug['file'] = $bug->entry;
  67. if($bug->edit) $lineBug['edit'] = true;
  68. if(!empty($bug->delete)) $lineBug['delete'] = true;
  69. if(isset($lineReview['comments']))
  70. {
  71. if(isset($lineReview['comments'][$bugID]))
  72. {
  73. $comments = $lineReview['comments'][$bugID];
  74. $bugComments = array();
  75. foreach ($comments as $commentID => $comment)
  76. {
  77. $bugComment = array(
  78. 'id' => $comment->id,
  79. 'edit' => $comment->edit,
  80. 'realname' => $comment->realname,
  81. 'user' => $comment->user,
  82. 'date' => substr($comment->date, 5, 11),
  83. 'comment' => $comment->comment,
  84. );
  85. $bugComments[] = $bugComment;
  86. }
  87. $lineBug['comments'] = $bugComments;
  88. }
  89. }
  90. $lineBugs[] = $lineBug;
  91. }
  92. $bugs[$line] = $lineBugs;
  93. }
  94. $browser = helper::getBrowser();
  95. js::set('browser', $browser['name']);
  96. js::set('bugs', $bugs);
  97. js::set('productError', $lang->repo->error->product);
  98. js::set('contentError', $lang->repo->error->commentText);
  99. js::set('titleError', $lang->repo->error->title);
  100. js::set('commentError', $lang->repo->error->comment);
  101. js::set('submit', $lang->repo->submit);
  102. js::set('cancel', $lang->repo->cancel);
  103. js::set('confirmDelete', $lang->repo->notice->deleteBug);
  104. js::set('confirmDeleteComment', $lang->repo->notice->deleteComment);
  105. js::set('repoID', $repoID);
  106. js::set('revision', $infoRevision);
  107. js::set('file', $file);
  108. js::set('blamePairs', $blamePairs);
  109. js::set('isonlybody', isonlybody());
  110. ?>
  111. <?php if(common::hasPriv('repo', 'addBug')):?>
  112. <form id="bugForm" class="bugForm main-form hide" method="post" action="<?php echo $bugUrl?>">
  113. <div class="bugFormContainer">
  114. <table class='table table-form'>
  115. <tr>
  116. <?php if($this->app->tab == 'project' && $objectID):?>
  117. <?php echo html::hidden('project', $objectID);?>
  118. <?php endif;?>
  119. <th><?php echo $lang->repo->product?></th>
  120. <td>
  121. <div class='input-group'>
  122. <?php echo $productSelect;?>
  123. <?php if($branches) echo html::select('branch', $branches, '', "class='form-control' style='width:95px' onchange='loadBranch(this)'");?>
  124. </div>
  125. </td>
  126. </tr>
  127. <tr>
  128. <th><?php echo $lang->repo->execution?></th>
  129. <td>
  130. <div class='input-group'>
  131. <?php echo $executionSelect;?>
  132. <span class="input-group-addon fix-border"><?php echo $lang->repo->module;?></span>
  133. <?php echo $moduleSelect?>
  134. </div>
  135. </td>
  136. </tr>
  137. <tr>
  138. <th><?php echo $lang->repo->title?></th>
  139. <td><?php echo html::input('title', '', "class='form-control'");?></td>
  140. </tr>
  141. <tr>
  142. <th><?php echo $lang->repo->type?></th>
  143. <td><?php echo $typeSelect?></td>
  144. </tr>
  145. <tr>
  146. <th><?php echo $lang->repo->assign?></th>
  147. <td><?php echo $userSelect?></td>
  148. </tr>
  149. <tr>
  150. <th><?php echo $lang->repo->lines?></th>
  151. <td class='lines'>
  152. <div class="input-group">
  153. <input class="line form-control" type="number" min="1" name="begin">
  154. <span class="input-group-addon fix-border">-</span>
  155. <input class="line form-control" type="number" min="1" name="end">
  156. </div>
  157. </td>
  158. </tr>
  159. <tr>
  160. <th><?php echo $lang->repo->detile?></th>
  161. <td><textarea id="commentText" name="commentText" class="commentInput form-control" spellcheck="false"></textarea></td>
  162. </tr>
  163. <tr>
  164. <td colspan="2" class='form-actions text-center'>
  165. <?php echo html::hidden('entry');?>
  166. <?php echo html::submitButton($lang->repo->submit, '', 'btn btn-wide btn-primary bugSubmit');?>
  167. <?php echo html::commonButton($lang->cancel, "onclick='hiddenForm()'", 'btn btn-wide');?>
  168. </td>
  169. </tr>
  170. </table>
  171. <div class="optional"></div>
  172. </div>
  173. </form>
  174. <?php else:?>
  175. <form id='bugForm' class='bugForm hide'>
  176. <?php printf($lang->user->errorDeny, $lang->repo->common, $lang->repo->addBug);?>
  177. </form>
  178. <?php endif;?>
  179. <div class='panel panel-sm hide panel-bug' id='bugPanel'>
  180. <div class='panel-heading'>
  181. <div class="bug-title">
  182. <i class='icon-bug text-muted'></i>
  183. <?php if(common::hasPriv('bug', 'view')):?>
  184. <a href='javascript:;' class='view-bug' target='_blank'>Bug #<span class='bugid'></span></a>
  185. <?php else:?>
  186. Bug #<span class='bugid'></span>
  187. <?php endif;?>
  188. <span class="bug-lines"><?php echo $lang->repo->lines?> <strong class='code-lines'></strong></span>
  189. </div>
  190. <div class='panel-actions pull-right'>
  191. <?php if(common::hasPriv('bug', 'edit')):?>
  192. <a href='javascript:;' target='_blank' class='edit bugEdit' data-width="95%"><i class='icon icon-pencil'></i></a>
  193. <?php endif;?>
  194. <?php if(common::hasPriv('repo', 'deleteBug')):?>
  195. <a href='javascript:;' class='delete bugDelete'><i class='icon icon-remove'></i></a>
  196. <?php endif;?>
  197. <a href="javascript:;"><i class='icon-chevron-down'></i></a>
  198. </div>
  199. </div>
  200. <?php if(common::hasPriv('repo', 'addComment')):?>
  201. <div class='panel-body'>
  202. <div class='comments'></div>
  203. <button class='btn btn-sm addComment' type='button'><?php echo $lang->repo->addComment?></button>
  204. <form class='commentForm not-watch' method='post' action='<?php echo $commentUrl?>' id='commentForm'>
  205. <textarea name='comment' class='commentText form-control mgb-10' spellcheck='false' placeholder='<?php echo $lang->repo->notice->commentContent?>'></textarea>
  206. <input class='commentSubmit btn btn-sm btn-primary' type='submit' value='<?php echo $lang->repo->submit?>'>
  207. <input class='commentCancel btn btn-sm' type='button' value='<?php echo $lang->repo->cancel?>'>
  208. <input type='hidden' name='objectID' value=''>
  209. <div class='optional'></div>
  210. </form>
  211. </div>
  212. <?php endif;?>
  213. </div>
  214. <div class='comment hide' id='commentCell'>
  215. <div>
  216. <span class="avatar has-img avatar-circle pull-left"></span>
  217. <span class='text-muted comment-date'>&nbsp;
  218. <i class='icon-time'></i>
  219. <span class='date'></span>
  220. </span>
  221. <a href='javascript:;' class='edit commentEdit pull-right'>
  222. <i class='icon-pencil'></i>
  223. </a>
  224. </div>
  225. <div>
  226. <strong class='realname'></strong>
  227. <strong> <?php echo $lang->repo->commited . ' ' . $lang->repo->comment;?></strong>
  228. </div>
  229. <strong class='comment-content text-content'></strong>
  230. <div class="comment-form-div">
  231. <form method='post' class='comment-edit-form not-watch' action=''>
  232. <textarea name='commentText' class='commentInput form-control mgb-10'></textarea>
  233. <button type='submit' class='btn btn-sm btn-primary commentEditSubmit'><?php echo $lang->repo->submit?></button>
  234. <button type='button' class='btn btn-sm commentEditCancel'><?php echo $lang->repo->cancel?></button>
  235. </form>
  236. </div>
  237. </div>
  238. <div class='dropdown' id="bugsPreview">
  239. <ul class='dropdown-menu fade'>
  240. <li class='dropdown-header'><?php echo $lang->repo->line?><strong class='code-line'></strong> &nbsp; <i class='icon-bug'></i> <strong class='bug-count'>0</strong> &nbsp; <i class='icon-comments-alt'></i> <strong class='comment-count'>0</strong></li>
  241. </ul>
  242. </div>
  243. <div id='rowTip' class='hide'><div class='row-tip'><i class='icon-chat preview-icon'></i><div class='on-expand tip'><span><?php echo $lang->repo->expand?> </span><i class='icon-chevron-down'></i></div><div class='on-collapse tip'><span><?php echo $lang->repo->collapse?> </span><i class='icon-chevron-up'></i></div></div></div>
  244. <script>
  245. function changeProduct(select)
  246. {
  247. loadProductBranches(select);
  248. productID = $(select).children('option:selected').val();
  249. link = createLink('repo', 'ajaxGetExecutions', 'productID=' + productID);
  250. $.get(link, function(data)
  251. {
  252. $(select).closest('.bugFormContainer').find('#execution_chosen').remove();
  253. $(select).closest('.bugFormContainer').find('select[name=execution]').replaceWith(data);
  254. $(select).closest('.bugFormContainer').find('select[name=execution]').chosen();
  255. })
  256. moduleLink = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=0&rootModuleID=0&returnType=html');
  257. $.get(moduleLink, function(data)
  258. {
  259. $(select).closest('.bugFormContainer').find('#module_chosen').remove();
  260. $(select).closest('.bugFormContainer').find('select[name=module]').replaceWith(data).chosen();
  261. $(select).closest('.bugFormContainer').find('select[name=module]').chosen();
  262. })
  263. }
  264. function loadProductBranches(select)
  265. {
  266. $(select).closest('.input-group').find('#branch').remove();
  267. productID = $(select).children('option:selected').val();
  268. $.get(createLink('branch', 'ajaxGetBranches', "productID=" + productID), function(data)
  269. {
  270. if(data)
  271. {
  272. $(select).closest('.input-group').append(data);
  273. $(select).closest('.input-group').find('#branch').css('width', '95px');
  274. }
  275. });
  276. }
  277. function loadBranch(select)
  278. {
  279. branch = $(select).val();
  280. productID = $(select).closest('.input-group').find('#product').val();
  281. link = createLink('repo', 'ajaxGetExecutions', 'productID=' + productID + '&branch=' + branch);
  282. $.get(link, function(data)
  283. {
  284. $(select).closest('.bugFormContainer').find('#execution_chosen').remove();
  285. $(select).closest('.bugFormContainer').find('select[name=execution]').replaceWith(data);
  286. $(select).closest('.bugFormContainer').find('select[name=execution]').chosen();
  287. })
  288. moduleLink = createLink('tree', 'ajaxGetOptionMenu', 'productID=' + productID + '&viewtype=bug&branch=' + branch + '&rootModuleID=0&returnType=html');
  289. $.get(moduleLink, function(data)
  290. {
  291. $(select).closest('.bugFormContainer').find('#module_chosen').remove();
  292. $(select).closest('.bugFormContainer').find('select[name=module]').replaceWith(data).chosen();
  293. $(select).closest('.bugFormContainer').find('select[name=module]').chosen();
  294. })
  295. }
  296. function hiddenForm()
  297. {
  298. if(browser == 'ie') $('.with-action-row').removeClass('with-action-row');
  299. if(browser != 'ie')
  300. {
  301. var widgetid = $('#bugForm').parent().attr('widgetid');
  302. if(!widgetid) return;
  303. var line = parseInt(widgetid.substr(7));
  304. $('#bugForm').parent().remove();
  305. editor.changeViewZones(function (changeAccessor) {
  306. changeAccessor.removeZone(viewZoneId);
  307. });
  308. editor.revealLine(line);
  309. }
  310. }
  311. /* remove a function */
  312. function loadModuleRelated(){}
  313. </script>