aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js
diff options
context:
space:
mode:
authorTyrone Yeh <tyrone_yeh@draytek.com>2023-05-07 23:44:16 +0800
committerGitHub <noreply@github.com>2023-05-07 23:44:16 +0800
commit1144b1d129de530b2c07dfdfaf55de383cd82212 (patch)
tree24da6cc110d2df310ce2284620cab4e8721ca082 /web_src/js
parent0bb52883eb8f866821fb7cb91e535bb4d051dbfb (diff)
downloadgitea-1144b1d129de530b2c07dfdfaf55de383cd82212.tar.gz
gitea-1144b1d129de530b2c07dfdfaf55de383cd82212.zip
Add goto issue id function (#24479)
for https://github.com/go-gitea/gitea/issues/4109#issuecomment-1527104992 Supports format: `#1234` `Org/Repo#1234` --------- Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'web_src/js')
-rw-r--r--web_src/js/features/repo-issue.js29
-rw-r--r--web_src/js/index.js3
2 files changed, 31 insertions, 1 deletions
diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js
index 265eceab59..7e1249ed2f 100644
--- a/web_src/js/features/repo-issue.js
+++ b/web_src/js/features/repo-issue.js
@@ -4,6 +4,7 @@ import {showTemporaryTooltip, createTippy} from '../modules/tippy.js';
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
import {setFileFolding} from './file-fold.js';
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
+import {parseIssueHref} from '../utils.js';
const {appSubUrl, csrfToken} = window.config;
@@ -636,3 +637,31 @@ export function initRepoIssueBranchSelect() {
};
$('#branch-select > .item').on('click', changeBranchSelect);
}
+
+export function initRepoIssueGotoID() {
+ const issueidre = /^(?:\w+\/\w+#\d+|#\d+|\d+)$/;
+ const isGlobalIssuesArea = $('.repo.name.item').length > 0; // for global issues area or repository issues area
+ $('form.list-header-search').on('submit', (e) => {
+ const qval = e.target.q.value;
+ const aElm = document.activeElement;
+ if (!$('#hashtag-button').length || aElm.id === 'search-button' || (aElm.name === 'q' && !qval.includes('#')) || (isGlobalIssuesArea && !qval.includes('/')) || !issueidre.test(qval)) return;
+ const pathname = window.location.pathname;
+ let gotoUrl = qval.includes('/') ? `${qval.replace('#', '/issues/')}` : `${pathname}/${qval.replace('#', '')}`;
+ if (appSubUrl.length) {
+ gotoUrl = qval.includes('/') ? `/${appSubUrl}/${qval.replace('#', '/issues/')}` : `/${appSubUrl}/${pathname}/${qval.replace('#', '')}`;
+ }
+ const {owner, repo, type, index} = parseIssueHref(gotoUrl);
+ if (owner && repo && type && index) {
+ e.preventDefault();
+ window.location.href = gotoUrl;
+ }
+ });
+ $('form.list-header-search input[name=q]').on('input', (e) => {
+ const qval = e.target.value;
+ if (isGlobalIssuesArea && qval.includes('/') && issueidre.test(qval) || !isGlobalIssuesArea && issueidre.test(qval)) {
+ showElem($('#hashtag-button'));
+ } else {
+ hideElem($('#hashtag-button'));
+ }
+ });
+}
diff --git a/web_src/js/index.js b/web_src/js/index.js
index f7cbb24e85..10e2ecd289 100644
--- a/web_src/js/index.js
+++ b/web_src/js/index.js
@@ -30,7 +30,7 @@ import {
initRepoIssueWipTitle,
initRepoPullRequestMergeInstruction,
initRepoPullRequestAllowMaintainerEdit,
- initRepoPullRequestReview, initRepoIssueSidebarList,
+ initRepoPullRequestReview, initRepoIssueSidebarList, initRepoIssueGotoID
} from './features/repo-issue.js';
import {
initRepoEllipsisButton,
@@ -175,4 +175,5 @@ onDomReady(() => {
initUserAuthWebAuthnRegister();
initUserSettings();
initRepoDiffView();
+ initRepoIssueGotoID();
});