ajaxgeteditorcontent.html.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * The ajaxgeteditorcontent 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 https://www.zentao.net
  10. */
  11. namespace zin;
  12. $canLinkStory = common::hasPriv('repo', 'linkStory');
  13. $canLinkBug = common::hasPriv('repo', 'linkBug');
  14. $canLinkTask = common::hasPriv('repo', 'linkTask');
  15. $canUnlinkObject = common::hasPriv('repo', 'unlink');
  16. jsVar('unlinkTitle', $this->lang->repo->unlink);
  17. jsVar('canUnlinkObject', $canUnlinkObject);
  18. jsVar('fileExt', $this->config->repo->fileExt);
  19. jsVar('file', $pathInfo);
  20. jsVar('filePath', $entry);
  21. jsVar('blameTmpl', $lang->repo->blameTmpl);
  22. jsVar('repoID', $repoID);
  23. jsVar('showEditor', $showEditor);
  24. jsVar('canLinkStory', $canLinkStory);
  25. jsVar('canLinkBug', $canLinkBug);
  26. jsVar('canLinkTask', $canLinkTask);
  27. jsVar('objectID', 0);
  28. jsVar('objectType', 'story');
  29. jsVar('pageType', $type);
  30. jsVar('revision', $revision);
  31. jsVar('sourceRevision', $oldRevision);
  32. jsVar('encodePath', $this->repo->encodePath($entry));
  33. if($showEditor) jsVar('codeContent', $content);
  34. $lang = 'php';
  35. foreach($this->config->repo->fileExt as $langName => $exts)
  36. {
  37. foreach($exts as $ext) if(isset($pathInfo['extension']) && strpos('.' . $pathInfo['extension'], $ext) !== false) $lang = $langName;
  38. }
  39. if(strpos($config->repo->images, "|$suffix|") !== false)
  40. {
  41. $wg = div
  42. (
  43. set::className('image'),
  44. img(set::src('data:image/' . $suffix . ';base64,' . $content))
  45. );
  46. }
  47. elseif($suffix == 'binary')
  48. {
  49. $wg = div
  50. (
  51. set::className('binary'),
  52. a
  53. (
  54. set('data-link', $this->repo->createLink('download', "repoID=$repoID&path=" . $this->repo->encodePath($entry) . "&fromRevision=$revision")),
  55. icon('download'),
  56. on::click('downloadCode'),
  57. set::title($this->lang->repo->download)
  58. )
  59. );
  60. }
  61. else
  62. {
  63. $options = array(
  64. 'language' => $lang,
  65. 'readOnly' => true,
  66. 'autoIndent' => true,
  67. 'contextmenu' => true,
  68. 'automaticLayout' => true,
  69. 'EditorMinimapOptions' => array('enabled' => false)
  70. );
  71. if($type == 'diff') $options['EditorMinimapOptions'] = array('enabled' => false);
  72. if($type != 'diff') $options['value'] = $content;
  73. $wg = monaco
  74. (
  75. set::id('codeContainer'),
  76. set::options($options),
  77. set::action($type == 'diff' ? 'diff' : 'create'),
  78. $type == 'diff' ? set::diffContent(jsRaw('parent.getDiffs(filePath)')) : null,
  79. set::onMouseDown('window.onMouseDown')
  80. );
  81. }
  82. $dropMenus = array();
  83. if($canLinkStory) $dropMenus[] = array('id' => 'linkStory', 'text' => $this->lang->repo->linkStory, 'icon' => 'lightbulb');
  84. if($canLinkBug) $dropMenus[] = array('id' => 'linkBug', 'text' => $this->lang->repo->linkBug, 'icon' => 'bug');
  85. if($canLinkTask) $dropMenus[] = array('id' => 'linkTask', 'text' => $this->lang->repo->linkTask, 'icon' => 'todo');
  86. $logWg = div
  87. (
  88. set::id('log'),
  89. div(set::className('history')),
  90. div
  91. (
  92. set::className('action-btn pull-right'),
  93. div(set::className('btn btn-close pull-right ghost text-black bg-gray-200 bg-opacity-50'), icon('close')),
  94. !empty($dropMenus) ? dropdown
  95. (
  96. set::arrow(false),
  97. set::staticMenu(true),
  98. btn
  99. (
  100. setClass('ghost text-black bg-gray-200 bg-opacity-50'),
  101. set::icon('ellipsis-v rotate-90')
  102. ),
  103. set::items
  104. (
  105. $dropMenus
  106. )
  107. ) : ''
  108. )
  109. );
  110. $relatedWg = div
  111. (
  112. set::id('related'),
  113. div(set::className('btn btn-left pull-left'), icon('chevron-left')),
  114. div(set::className('btn btn-right pull-right'), icon('chevron-right')),
  115. div
  116. (
  117. set::className('panel-title'),
  118. tabs
  119. (
  120. set::id('relationTabs'),
  121. setClass('mt-1 ml-2'),
  122. tabPane
  123. (
  124. set::key('tab1'),
  125. set::title(''),
  126. tableData()
  127. )
  128. )
  129. ),
  130. div(set::className('table-empty-tip'), p($this->lang->repo->notRelated))
  131. );
  132. div
  133. (
  134. set::id('monacoEditor'),
  135. set::className('repoCode'),
  136. $wg,
  137. $logWg,
  138. $relatedWg
  139. );
  140. set::zui(true);
  141. render('pageBase');