From bf204a96d0b3fe46fa09a07dc594399ea9dbc679 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 29 Aug 2022 15:27:35 +0800 Subject: [PATCH 1/2] * Fix bug #26981. --- module/repo/control.php | 5 +++-- module/repo/js/monaco.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index 875182431b..ac1c5dc3bc 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -1786,8 +1786,9 @@ class repo extends control */ public function ajaxGetFileTree($repoID, $branch = '') { - $repo = $this->repo->getRepoByID($repoID); - $files = $this->repo->getFileTree($repo, $branch); + $branch = base64_decode($branch); + $repo = $this->repo->getRepoByID($repoID); + $files = $this->repo->getFileTree($repo, $branch); return print($files); } diff --git a/module/repo/js/monaco.js b/module/repo/js/monaco.js index a0f4e363b4..222310eb6f 100644 --- a/module/repo/js/monaco.js +++ b/module/repo/js/monaco.js @@ -87,7 +87,7 @@ $(function() */ function refreshFiles(branchOrTag) { - var link = createLink('repo', 'ajaxGetFileTree', 'repoID=' + repoID + '&branch=' + branchOrTag); + var link = createLink('repo', 'ajaxGetFileTree', 'repoID=' + repoID + '&branch=' + Base64.encode(branchOrTag)); $.get(link, function(data) { $('#modules').remove(); From dd7283082eefea237d849b5a7ad4d48ea0b22a32 Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 29 Aug 2022 16:44:40 +0800 Subject: [PATCH 2/2] * Optimize repo view style. --- module/repo/control.php | 7 +- module/repo/css/ajaxgeteditorcontent.css | 4 + module/repo/js/common.js | 2 + module/repo/js/monaco.js | 8 +- module/repo/lang/zh-cn.php | 2 +- .../repo/view/ajaxgeteditorcontent.html.php | 119 ++++++++++-------- 6 files changed, 81 insertions(+), 61 deletions(-) diff --git a/module/repo/control.php b/module/repo/control.php index ac1c5dc3bc..44a49ed495 100644 --- a/module/repo/control.php +++ b/module/repo/control.php @@ -263,7 +263,7 @@ class repo extends control { $file = $entry; $repo = $this->repo->getRepoByID($repoID); - $entry = $this->repo->decodePath($entry); + $entry = urldecode($this->repo->decodePath($entry)); $revision = str_replace('*', '-', $revision); $this->scm->setEngine($repo); @@ -303,9 +303,10 @@ class repo extends control $this->view->entry = $entry; $this->view->path = $entry; $this->view->suffix = $suffix; - $this->view->content = $content; + $this->view->content = $content ? $content : ''; $this->view->pathInfo = $pathInfo; - $this->view->blames = $blames; + $this->view->blames = $blames ? $blames : array(); + $this->view->showEditor = (strpos($this->config->repo->images, "|$suffix|") === false and $suffix != 'binary') ? true : false; $this->display(); } diff --git a/module/repo/css/ajaxgeteditorcontent.css b/module/repo/css/ajaxgeteditorcontent.css index 2b38f47225..5c5656e3d1 100644 --- a/module/repo/css/ajaxgeteditorcontent.css +++ b/module/repo/css/ajaxgeteditorcontent.css @@ -16,3 +16,7 @@ #related .content, #related .btn {background-color: #F4F5F7; border: none;} #related .nav-tabs > li.active > a:before {background: none; height: 0;} #related .table-empty-tip {padding: 35px 10px;} +.repoCode .binary a .icon-download {font-size: 50px;} +.repoCode .binary, .repoCode .image {text-align: center;} +.repoCode .binary a {margin: 100px 0px; display: block;} +.repoCode .image {margin-top: 10px;} diff --git a/module/repo/js/common.js b/module/repo/js/common.js index e1ca5fdf60..645f1ea834 100644 --- a/module/repo/js/common.js +++ b/module/repo/js/common.js @@ -74,6 +74,8 @@ var distance = 0; */ function arrowTabs(domID, shift, hideRightBtn) { + if($('#' + domID).html() == '') return; + $('.btn-right, .btn-left').show(); if(hideRightBtn) $('.btn-right').hide(); diff --git a/module/repo/js/monaco.js b/module/repo/js/monaco.js index 222310eb6f..8857a112e5 100644 --- a/module/repo/js/monaco.js +++ b/module/repo/js/monaco.js @@ -13,7 +13,7 @@ $(function() */ function createTab(filename, filepath) { - $('[data-path="' + filepath + '"]').closest('li').addClass('selected'); + $('[data-path="' + decodeURIComponent(filepath) + '"]').closest('li').addClass('selected'); var tabID = Base64.encode(filepath).replaceAll('=', '-'); return { title: filename, @@ -40,7 +40,7 @@ $(function() $(document).on('click', '.repoFileName', function() { - var path = $(this).data('path'); + var path = encodeURIComponent($(this).data('path')); var name = $(this).text(); var $tabs = $('#fileTabs').data('zui.tabs'); if(openedFiles.indexOf(path) == -1) openedFiles.push(path); @@ -52,7 +52,7 @@ $(function() /* Remove file path for opened files. */ $('#fileTabs').on('onClose', function(event, tab) { - var filepath = Base64.decode(tab.id.replaceAll('-', '=')); + var filepath = decodeURIComponent(Base64.decode(tab.id.replaceAll('-', '='))); var index = openedFiles.indexOf(filepath); if(index > -1) { @@ -66,7 +66,7 @@ $(function() /* Append file path into the title. */ $('#fileTabs').on('onLoad', function(event, tab) { var filepath = Base64.decode(tab.id.replaceAll('-', '=')); - $('#tab-nav-item-' + tab.id).attr('title', filepath); + $('#tab-nav-item-' + tab.id).attr('title', decodeURIComponent(filepath)); }); var link = createLink('repo', 'ajaxGetBranchesAndTags', 'repoID=' + repoID + '&oldRevision=' + branchID); diff --git a/module/repo/lang/zh-cn.php b/module/repo/lang/zh-cn.php index b43d338247..4d69c3030b 100644 --- a/module/repo/lang/zh-cn.php +++ b/module/repo/lang/zh-cn.php @@ -26,7 +26,7 @@ $lang->repo->branch = '分支'; $lang->repo->tag = '标签'; $lang->repo->addWebHook = '添加Webhook'; $lang->repo->apiGetRepoByUrl = '接口:通过URL获取代码库'; -$lang->repo->blamTmpl = '%time 由%name提交%version %comment'; +$lang->repo->blamTmpl = '%time 由 %name 提交 %version %comment'; $lang->repo->notRelated = '暂时没有关联禅道对象'; $lang->repo->browseAction = '浏览代码库'; diff --git a/module/repo/view/ajaxgeteditorcontent.html.php b/module/repo/view/ajaxgeteditorcontent.html.php index b87d3a53e6..2843e0687d 100644 --- a/module/repo/view/ajaxgeteditorcontent.html.php +++ b/module/repo/view/ajaxgeteditorcontent.html.php @@ -13,11 +13,15 @@ include '../../common/view/header.lite.html.php'; js::set('jsRoot', $jsRoot); js::set('clientLang', $app->clientLang); js::set('fileExt', $this->config->repo->fileExt); -js::set('codeContent', trim($content)); js::set('file', $pathInfo); -js::set('blames', $blames); js::set('blameTmpl', $lang->repo->blamTmpl); js::set('repoID', $repoID); +js::set('showEditor', $showEditor); +if($showEditor) +{ + js::set('codeContent', trim($content)); + js::set('blames', $blames); +} js::import($jsRoot . '/zui/tabs/tabs.min.js'); js::import($jsRoot . 'monaco-editor/min/vs/loader.js'); $canLinkStory = common::hasPriv('repo', 'linkStory'); @@ -25,8 +29,14 @@ $canLinkBug = common::hasPriv('repo', 'linkBug'); $canLinkTask = common::hasPriv('repo', 'linkTask'); $canUnlinkObject = common::hasPriv('repo', 'unlinkObject'); ?> -
+
+ repo->images, "|$suffix|") !== false):?> +
+ +
repo->createLink('download', "repoID=$repoID&path=" . $this->repo->encodePath($entry) . "&fromRevision=$revision"), "", 'hiddenwin', "title='{$lang->repo->download}'"); ?>
+
+
@@ -149,59 +159,62 @@ $(function() $('.btn-left').click(function() {arrowTabs('relationTabs', 1);}); $('.btn-right').click(function() {arrowTabs('relationTabs', -2);}); - require.config({ - paths: {vs: jsRoot + 'monaco-editor/min/vs'}, - 'vs/nls': { - availableLanguages: { - '*': clientLang - } - } - }); - - require(['vs/editor/editor.main'], function () + if(showEditor) { - var lang = 'php'; - $.each(fileExt, function(langName, ext) - { - if(ext.indexOf('.' + file.extension) !== -1) lang = langName; - }); - - var editor = monaco.editor.create(document.getElementById('codeContainer'), - { - autoIndent: true, - value: codeContent, - language: lang, - contextmenu: true, - EditorMinimapOptions: { - enabled: false - }, - readOnly: true, - automaticLayout: true - }); - - editor.onMouseDown(function(obj) - { - var line = obj.target.position.lineNumber; - - var blame = blames[line]; - var p_line = parseInt(line); - while(!blame.revision) - { - p_line--; - blame = blames[p_line]; + require.config({ + paths: {vs: jsRoot + 'monaco-editor/min/vs'}, + 'vs/nls': { + availableLanguages: { + '*': clientLang + } } - if($('#log').data('line') == p_line) return; + }); - var time = blame.time != 'unknown' ? blame.time : ''; - var user = blame.committer != 'unknown' ? blame.committer : ''; - var version = blame.revision.toString().substring(0, 10); - var content = blameTmpl.replace('%time', time).replace('%name', user).replace('%version', version).replace('%comment', blame.message); - $('.history').text(content); - $('#log').data('line', p_line); - $('#log').css('display', 'flex'); - getRelation(blame.revision); - }) - }); + require(['vs/editor/editor.main'], function () + { + var lang = 'php'; + $.each(fileExt, function(langName, ext) + { + if(ext.indexOf('.' + file.extension) !== -1) lang = langName; + }); + + var editor = monaco.editor.create(document.getElementById('codeContainer'), + { + autoIndent: true, + value: codeContent, + language: lang, + contextmenu: true, + EditorMinimapOptions: { + enabled: false + }, + readOnly: true, + automaticLayout: true + }); + + editor.onMouseDown(function(obj) + { + var line = obj.target.position.lineNumber; + + var blame = blames[line]; + var p_line = parseInt(line); + while(!blame.revision) + { + p_line--; + blame = blames[p_line]; + } + if($('#log').data('line') == p_line) return; + + var time = blame.time != 'unknown' ? blame.time : ''; + var user = blame.committer != 'unknown' ? blame.committer : ''; + var version = blame.revision.toString().substring(0, 10); + var content = blameTmpl.replace('%time', time).replace('%name', user).replace('%version', version).replace('%comment', blame.message); + $('.history').text(content); + $('#log').data('line', p_line); + $('#log').css('display', 'flex'); + getRelation(blame.revision); + }) + }); + } $('#linkStory a, #linkBug a, #linkTask a').on('click', function() {