actions.html.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * The actions view file of mr module of ZenTaoPMS.
  4. * @copyright Copyright 2009-2024 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  5. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  6. * @author Yanyi Cao <caoyanyi@easycorp.ltd>
  7. * @package mr
  8. * @link https://www.zentao.net
  9. */
  10. namespace zin;
  11. $hasNoChange = $MR->synced && empty($rawMR->changes_count) ? true : false;
  12. $hasConflict = $MR->synced === '1' ? $rawMR->has_conflicts : !$MR->hasNoConflict;
  13. $mergeStatus = !empty($rawMR->merge_status) ? $rawMR->merge_status : $MR->mergeStatus;
  14. $compileNotSuccess = !empty($compile->id) && $compile->status != 'success';
  15. $mainActions = array();
  16. $suffixActions = array();
  17. foreach($config->mr->view->operateList as $operate)
  18. {
  19. if(!common::hasPriv($app->rawModule, $operate == 'reject' ? 'approval' : $operate)) continue;
  20. if($operate == 'reopen' && (!$MR->synced || $rawMR->state != 'closed')) continue;
  21. if(in_array($rawMR->state, array('closed', 'merged')) && $operate == 'accept') continue;
  22. $action = $config->mr->actionList[$operate];
  23. if($operate === 'edit' || $operate === 'delete')
  24. {
  25. $suffixActions[] = $action;
  26. continue;
  27. }
  28. if($operate == 'accept')
  29. {
  30. if($MR->approvalStatus != 'approved' || $compileNotSuccess)
  31. {
  32. $action['disabled'] = true;
  33. $action['hint'] = $lang->mr->acceptTip;
  34. }
  35. elseif(!$MR->synced || $rawMR->state != 'opened' || $hasConflict)
  36. {
  37. $action['disabled'] = true;
  38. $action['hint'] = $lang->mr->conflictsTip;
  39. }
  40. elseif(!empty($rawMR) && !empty($rawMR->is_draft))
  41. {
  42. $action['disabled'] = true;
  43. $action['hint'] = $lang->mr->draftTips;
  44. }
  45. }
  46. if(in_array($operate, array('approval', 'reject', 'close', 'edit')))
  47. {
  48. if(!$MR->synced || $rawMR->state != 'opened') continue;
  49. if($operate == 'reject' && $MR->approvalStatus == 'rejected') $action['disabled'] = true;
  50. if($operate == 'approval')
  51. {
  52. if($hasNoChange || $hasConflict || $compileNotSuccess || $MR->approvalStatus == 'approved' || $mergeStatus == 'cannot_be_merged')
  53. {
  54. $action['disabled'] = true;
  55. if($compileNotSuccess) $action['hint'] = $lang->mr->compileTip;
  56. if($hasNoChange) $action['hint'] = $lang->mr->noChangesTip;
  57. if($hasConflict) $action['hint'] = $lang->mr->conflictsTip;
  58. if(in_array(strtolower($repo->SCM), array('gogs', 'gitea'))) $action['hint'] = $lang->mr->notifyTip;
  59. }
  60. }
  61. }
  62. if($operate == 'delete' && !$projectOwner && !$this->app->user->admin) $action['disabled'] = true;
  63. if($operate == 'edit' && !$projectEdit && !$this->app->user->admin) $action['disabled'] = true;
  64. $mainActions[] = $action;
  65. }
  66. div
  67. (
  68. setClass('detail-actions center sticky mt-4 bottom-4 z-10'),
  69. floatToolbar
  70. (
  71. set::object($MR),
  72. isAjaxRequest('modal') ? null : to::prefix(backBtn(set::icon('back'), $lang->goback)),
  73. set::main($mainActions),
  74. set::suffix($suffixActions)
  75. )
  76. );