From 03753cbc0ff68cc4eee0a65b556e6d86a8f1c63f Mon Sep 17 00:00:00 2001 From: Rafael Heard Date: Thu, 14 Mar 2024 14:20:54 -0400 Subject: [PATCH 1/8] enable tailwind nesting (#29746) Currently, if you implement native CSS nesting within a Vue component a warning will appear in the terminal. It states `Nested CSS was detected, but CSS nesting has not been configured correctly. Please enable a CSS nesting plugin *before* Tailwind in your configuration.` To fix this error we need to enable the built-in [tailwinds nesting config](https://tailwindcss.com/docs/using-with-preprocessors#nesting). Example code to trigger the warning within a vue component: ```CSS ``` --------- Co-authored-by: rafh Co-authored-by: silverwind --- package-lock.json | 49 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 1 + webpack.config.js | 8 +++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a6eb4b947836..f75e3068b85da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,6 +43,7 @@ "pdfobject": "2.3.0", "postcss": "8.4.35", "postcss-loader": "8.1.1", + "postcss-nesting": "12.1.0", "pretty-ms": "9.0.0", "sortablejs": "1.15.2", "swagger-ui-dist": "5.11.8", @@ -528,11 +529,31 @@ "@csstools/css-tokenizer": "^2.2.3" } }, + "node_modules/@csstools/selector-resolve-nested": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@csstools/selector-resolve-nested/-/selector-resolve-nested-1.1.0.tgz", + "integrity": "sha512-uWvSaeRcHyeNenKg8tp17EVDRkpflmdyvbE0DHo6D/GdBb6PDnCYYU6gRpXhtICMGMcahQmj2zGxwFM/WC8hCg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "engines": { + "node": "^14 || ^16 || >=18" + }, + "peerDependencies": { + "postcss-selector-parser": "^6.0.13" + } + }, "node_modules/@csstools/selector-specificity": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@csstools/selector-specificity/-/selector-specificity-3.0.2.tgz", "integrity": "sha512-RpHaZ1h9LE7aALeQXmXrJkRG84ZxIsctEN2biEUmFyKpzFM3zZ35eUMcIzZFsw/2olQE6v69+esEqU2f1MKycg==", - "dev": true, "funding": [ { "type": "github", @@ -9816,6 +9837,32 @@ "postcss": "^8.2.14" } }, + "node_modules/postcss-nesting": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/postcss-nesting/-/postcss-nesting-12.1.0.tgz", + "integrity": "sha512-QOYnosaZ+mlP6plQrAxFw09UUp2Sgtxj1BVHN+rSVbtV0Yx48zRt9/9F/ZOoxOKBBEsaJk2MYhhVRjeRRw5yuw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "dependencies": { + "@csstools/selector-resolve-nested": "^1.1.0", + "@csstools/selector-specificity": "^3.0.2", + "postcss-selector-parser": "^6.0.13" + }, + "engines": { + "node": "^14 || ^16 || >=18" + }, + "peerDependencies": { + "postcss": "^8.4" + } + }, "node_modules/postcss-resolve-nested-selector": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/postcss-resolve-nested-selector/-/postcss-resolve-nested-selector-0.1.1.tgz", diff --git a/package.json b/package.json index d5e8170228c8b..26632480e88f9 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "pdfobject": "2.3.0", "postcss": "8.4.35", "postcss-loader": "8.1.1", + "postcss-nesting": "12.1.0", "pretty-ms": "9.0.0", "sortablejs": "1.15.2", "swagger-ui-dist": "5.11.8", diff --git a/webpack.config.js b/webpack.config.js index 3973d85344e6f..d073a3e9f1800 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,8 @@ import {readFileSync} from 'node:fs'; import {env} from 'node:process'; import tailwindcss from 'tailwindcss'; import tailwindConfig from './tailwind.config.js'; +import tailwindcssNesting from 'tailwindcss/nesting/index.js'; +import postcssNesting from 'postcss-nesting'; const {EsbuildPlugin} = EsBuildLoader; const {SourceMapDevToolPlugin, DefinePlugin} = webpack; @@ -145,6 +147,7 @@ export default { sourceMap: sourceMaps === 'true', url: {filter: filterCssImport}, import: {filter: filterCssImport}, + importLoaders: 1, }, }, { @@ -152,7 +155,10 @@ export default { options: { postcssOptions: { map: false, // https://github.com/postcss/postcss/issues/1914 - plugins: [tailwindcss(tailwindConfig)], + plugins: [ + tailwindcssNesting(postcssNesting({edition: '2024-02'})), + tailwindcss(tailwindConfig), + ], }, }, } From ce085b26fc5076b36c55e6a0a30ba8f11105c0bf Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 15 Mar 2024 04:01:16 +0900 Subject: [PATCH 2/8] Improve commit record's ui in comment list (#26619) Before: ![image](https://github.com/go-gitea/gitea/assets/18380374/795f9941-9989-4045-b0fc-d6dd0262269b) ![image](https://github.com/go-gitea/gitea/assets/18380374/f6505f5e-4248-456e-a98d-e714c6484b2f) After: ![image](https://github.com/go-gitea/gitea/assets/18380374/321dda1e-6999-4851-afff-2e6c8d20367b) ![image](https://github.com/go-gitea/gitea/assets/18380374/182f18d1-2295-4004-852b-c0ebb498b411) --------- Co-authored-by: silverwind --- templates/repo/issue/view_content/comments.tmpl | 16 ++++++++-------- web_src/css/repo.css | 6 +----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index db63e2b951984..a9c6bbe31859d 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -148,7 +148,7 @@ {{if eq .RefAction 3}}{{end}} - @@ -160,7 +160,7 @@ {{template "shared/user/authorlink" .Poster}} {{ctx.Locale.Tr "repo.issues.commit_ref_at" .EventTag $createdStr}} -
+
{{svg "octicon-git-commit"}} {{.Content | SanitizeHTML}}
@@ -252,7 +252,7 @@ {{ctx.Locale.Tr "repo.issues.stop_tracking_history" $createdStr}} {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}} -
+
{{svg "octicon-clock"}} {{if .RenderedContent}} {{/* compatibility with time comments made before v1.21 */}} @@ -271,7 +271,7 @@ {{ctx.Locale.Tr "repo.issues.add_time_history" $createdStr}} {{template "repo/issue/view_content/comments_delete_time" dict "ctxData" $ "comment" .}} -
+
{{svg "octicon-clock"}} {{if .RenderedContent}} {{/* compatibility with time comments made before v1.21 */}} @@ -331,7 +331,7 @@ {{ctx.Locale.Tr "repo.issues.dependency.added_dependency" $createdStr}} {{if .DependentIssue}} -
+
{{svg "octicon-plus"}} @@ -354,8 +354,8 @@ {{ctx.Locale.Tr "repo.issues.dependency.removed_dependency" $createdStr}} {{if .DependentIssue}} -
- {{svg "octicon-trash"}} +
+ {{svg "octicon-trash"}} {{if eq .DependentIssue.RepoID .Issue.RepoID}} @@ -506,7 +506,7 @@ {{ctx.Locale.Tr "repo.issues.del_time_history" $createdStr}} -
+
{{svg "octicon-clock"}} {{if .RenderedContent}} {{/* compatibility with time comments made before v1.21 */}} diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 587a3152e5562..c9c27acf3459a 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1065,11 +1065,7 @@ .repository.view.issue .comment-list .event .detail { margin-top: 4px; - margin-left: 14px; -} - -.repository.view.issue .comment-list .event .detail .svg { - margin-right: 2px; + margin-left: 15px; } .repository.view.issue .comment-list .event .segments { From 0679e60c776cd45f32acc12f52fe41b627da57e9 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Thu, 14 Mar 2024 23:36:17 +0200 Subject: [PATCH 3/8] Remove jQuery AJAX from the `repo-issue.js` file (#29776) Removed all jQuery AJAX calls and replaced with our fetch wrapper. Tested the following functionalities and they work as before: - due-date update - comment deletion - branch update by merge or rebase - allow edits from maintainers button - reviewer addition or deletion - WIP toggle button - new diff code comment button - issue title edit button # Demo using `fetch` instead of jQuery AJAX ## Updating the due-date of an issue ![due_date](https://github.com/go-gitea/gitea/assets/20454870/7de395d3-63e8-49e8-9a13-8d14fc26810d) ## Deleting a comment ![comment_delete](https://github.com/go-gitea/gitea/assets/20454870/2814e695-44e3-4548-9ee7-7b437bef4b01) ## Updating a branch in a pull request ![branch_update](https://github.com/go-gitea/gitea/assets/20454870/137da77e-acc4-4984-a1bc-be58583bf52a) ## Checking and unchecking the "Allow edits from maintainers" checkbox ![allow_edits](https://github.com/go-gitea/gitea/assets/20454870/8d4829af-5813-432d-90ef-da057f8cdafc) ## Requesting review and removing review request ![reviewer_addition](https://github.com/go-gitea/gitea/assets/20454870/08f210e0-be3f-41af-b271-214a1dd2d0ba) ## Toggling the WIP status of a pull request ![wip](https://github.com/go-gitea/gitea/assets/20454870/dea5e668-1c89-4f3d-a5d6-4c26aefc4814) ## Clicking the new code comment button on the diff page ![code_comment](https://github.com/go-gitea/gitea/assets/20454870/1d17174e-3bba-4cf8-81fe-c3a2c21f80b9) ## Editing the issue title and target branch ![issue_title](https://github.com/go-gitea/gitea/assets/20454870/7099888e-81c0-47d4-9371-8e4469e9e519) --------- Signed-off-by: Yarden Shoham Co-authored-by: silverwind --- web_src/js/features/repo-issue.js | 198 +++++++++++++++++------------- 1 file changed, 114 insertions(+), 84 deletions(-) diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index 6fb13b0ddae28..01c30a9e53e57 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -6,8 +6,9 @@ import {setFileFolding} from './file-fold.js'; import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js'; import {toAbsoluteUrl} from '../utils.js'; import {initDropzone} from './common-global.js'; +import {POST, GET} from '../modules/fetch.js'; -const {appSubUrl, csrfToken} = window.config; +const {appSubUrl} = window.config; export function initRepoIssueTimeTracking() { $(document).on('click', '.issue-add-time', () => { @@ -40,7 +41,7 @@ export function initRepoIssueTimeTracking() { }); } -function updateDeadline(deadlineString) { +async function updateDeadline(deadlineString) { hideElem($('#deadline-err-invalid-date')); $('#deadline-loader').addClass('loading'); @@ -56,23 +57,21 @@ function updateDeadline(deadlineString) { realDeadline = new Date(newDate); } - $.ajax(`${$('#update-issue-deadline-form').attr('action')}`, { - data: JSON.stringify({ - due_date: realDeadline, - }), - headers: { - 'X-Csrf-Token': csrfToken, - }, - contentType: 'application/json', - type: 'POST', - success() { + try { + const response = await POST($('#update-issue-deadline-form').attr('action'), { + data: {due_date: realDeadline} + }); + + if (response.ok) { window.location.reload(); - }, - error() { - $('#deadline-loader').removeClass('loading'); - showElem($('#deadline-err-invalid-date')); - }, - }); + } else { + throw new Error('Invalid response'); + } + } catch (error) { + console.error(error); + $('#deadline-loader').removeClass('loading'); + showElem($('#deadline-err-invalid-date')); + } } export function initRepoIssueDue() { @@ -156,12 +155,12 @@ export function initRepoIssueSidebarList() { export function initRepoIssueCommentDelete() { // Delete comment - $(document).on('click', '.delete-comment', function () { + $(document).on('click', '.delete-comment', async function () { const $this = $(this); if (window.confirm($this.data('locale'))) { - $.post($this.data('url'), { - _csrf: csrfToken, - }).done(() => { + try { + const response = await POST($this.data('url')); + if (!response.ok) throw new Error('Failed to delete comment'); const $conversationHolder = $this.closest('.conversation-holder'); // Check if this was a pending comment. @@ -186,7 +185,9 @@ export function initRepoIssueCommentDelete() { } $conversationHolder.remove(); } - }); + } catch (error) { + console.error(error); + } } return false; }); @@ -226,22 +227,32 @@ export function initRepoIssueCodeCommentCancel() { export function initRepoPullRequestUpdate() { // Pull Request update button const $pullUpdateButton = $('.update-button > button'); - $pullUpdateButton.on('click', function (e) { + $pullUpdateButton.on('click', async function (e) { e.preventDefault(); const $this = $(this); const redirect = $this.data('redirect'); $this.addClass('loading'); - $.post($this.data('do'), { - _csrf: csrfToken - }).done((data) => { - if (data.redirect) { - window.location.href = data.redirect; - } else if (redirect) { - window.location.href = redirect; - } else { - window.location.reload(); - } - }); + let response; + try { + response = await POST($this.data('do')); + } catch (error) { + console.error(error); + } finally { + $this.removeClass('loading'); + } + let data; + try { + data = await response?.json(); // the response is probably not a JSON + } catch (error) { + console.error(error); + } + if (data?.redirect) { + window.location.href = data.redirect; + } else if (redirect) { + window.location.href = redirect; + } else { + window.location.reload(); + } }); $('.update-button > .dropdown').dropdown({ @@ -267,20 +278,24 @@ export function initRepoPullRequestAllowMaintainerEdit() { const promptError = $checkbox.attr('data-prompt-error'); $checkbox.checkbox({ - 'onChange': () => { + 'onChange': async () => { const checked = $checkbox.checkbox('is checked'); let url = $checkbox.attr('data-url'); url += '/set_allow_maintainer_edit'; $checkbox.checkbox('set disabled'); - $.ajax({url, type: 'POST', - data: {_csrf: csrfToken, allow_maintainer_edit: checked}, - error: () => { - showTemporaryTooltip($checkbox[0], promptError); - }, - complete: () => { - $checkbox.checkbox('set enabled'); - }, - }); + try { + const response = await POST(url, { + data: {allow_maintainer_edit: checked}, + }); + if (!response.ok) { + throw new Error('Failed to update maintainer edit permission'); + } + } catch (error) { + console.error(error); + showTemporaryTooltip($checkbox[0], promptError); + } finally { + $checkbox.checkbox('set enabled'); + } }, }); } @@ -329,17 +344,15 @@ export function initRepoIssueWipTitle() { }); } -export async function updateIssuesMeta(url, action, issueIds, elementId) { - return $.ajax({ - type: 'POST', - url, - data: { - _csrf: csrfToken, - action, - issue_ids: issueIds, - id: elementId, - }, - }); +export async function updateIssuesMeta(url, action, issue_ids, id) { + try { + const response = await POST(url, {data: new URLSearchParams({action, issue_ids, id})}); + if (!response.ok) { + throw new Error('Failed to update issues meta'); + } + } catch (error) { + console.error(error); + } } export function initRepoIssueComments() { @@ -511,15 +524,20 @@ export function initRepoPullRequestReview() { const td = ntr.find(`.add-comment-${side}`); const commentCloud = td.find('.comment-code-cloud'); if (commentCloud.length === 0 && !ntr.find('button[name="pending_review"]').length) { - const html = await $.get($(this).closest('[data-new-comment-url]').attr('data-new-comment-url')); - td.html(html); - td.find("input[name='line']").val(idx); - td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed'); - td.find("input[name='path']").val(path); - - initDropzone(td.find('.dropzone')[0]); - const editor = await initComboMarkdownEditor(td.find('.combo-markdown-editor')); - editor.focus(); + try { + const response = await GET($(this).closest('[data-new-comment-url]').attr('data-new-comment-url')); + const html = await response.text(); + td.html(html); + td.find("input[name='line']").val(idx); + td.find("input[name='side']").val(side === 'left' ? 'previous' : 'proposed'); + td.find("input[name='path']").val(path); + + initDropzone(td.find('.dropzone')[0]); + const editor = await initComboMarkdownEditor(td.find('.combo-markdown-editor')); + editor.focus(); + } catch (error) { + console.error(error); + } } }); } @@ -547,11 +565,19 @@ export function initRepoIssueWipToggle() { const title = toggleWip.getAttribute('data-title'); const wipPrefix = toggleWip.getAttribute('data-wip-prefix'); const updateUrl = toggleWip.getAttribute('data-update-url'); - await $.post(updateUrl, { - _csrf: csrfToken, - title: title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`, - }); - window.location.reload(); + + try { + const params = new URLSearchParams(); + params.append('title', title?.startsWith(wipPrefix) ? title.slice(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`); + + const response = await POST(updateUrl, {data: params}); + if (!response.ok) { + throw new Error('Failed to toggle WIP status'); + } + window.location.reload(); + } catch (error) { + console.error(error); + } }); } @@ -576,39 +602,43 @@ export function initRepoIssueTitleEdit() { $('#edit-title').on('click', editTitleToggle); $('#cancel-edit-title').on('click', editTitleToggle); - $('#save-edit-title').on('click', editTitleToggle).on('click', function () { - const pullrequest_targetbranch_change = function (update_url) { + $('#save-edit-title').on('click', editTitleToggle).on('click', async function () { + const pullrequest_targetbranch_change = async function (update_url) { const targetBranch = $('#pull-target-branch').data('branch'); const $branchTarget = $('#branch_target'); if (targetBranch === $branchTarget.text()) { window.location.reload(); return false; } - $.post(update_url, { - _csrf: csrfToken, - target_branch: targetBranch - }).always(() => { + try { + await POST(update_url, {data: new URLSearchParams({target_branch: targetBranch})}); + } catch (error) { + console.error(error); + } finally { window.location.reload(); - }); + } }; const pullrequest_target_update_url = $(this).attr('data-target-update-url'); if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) { $editInput.val($issueTitle.text()); - pullrequest_targetbranch_change(pullrequest_target_update_url); + await pullrequest_targetbranch_change(pullrequest_target_update_url); } else { - $.post($(this).attr('data-update-url'), { - _csrf: csrfToken, - title: $editInput.val() - }, (data) => { + try { + const params = new URLSearchParams(); + params.append('title', $editInput.val()); + const response = await POST($(this).attr('data-update-url'), {data: params}); + const data = await response.json(); $editInput.val(data.title); $issueTitle.text(data.title); if (pullrequest_target_update_url) { - pullrequest_targetbranch_change(pullrequest_target_update_url); // it will reload the window + await pullrequest_targetbranch_change(pullrequest_target_update_url); // it will reload the window } else { window.location.reload(); } - }); + } catch (error) { + console.error(error); + } } return false; }); From 35def319fdb8c73aa5e2c52fad5230d287e2bd93 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 14 Mar 2024 23:04:33 +0100 Subject: [PATCH 4/8] Fix Safari spinner rendering (#29801) Fixes: https://github.com/go-gitea/gitea/issues/29041 Fixes: https://github.com/go-gitea/gitea/pull/29713 Any of the `width: *-content` properties seem to workaround this Webkit bug, this one seemed most suitable. --- web_src/css/modules/animations.css | 1 + 1 file changed, 1 insertion(+) diff --git a/web_src/css/modules/animations.css b/web_src/css/modules/animations.css index 87eb6a75cf071..d5ddc772f6cc5 100644 --- a/web_src/css/modules/animations.css +++ b/web_src/css/modules/animations.css @@ -20,6 +20,7 @@ left: 50%; top: 50%; height: min(4em, 66.6%); + width: fit-content; /* compat: safari - https://bugs.webkit.org/show_bug.cgi?id=267625 */ aspect-ratio: 1; transform: translate(-50%, -50%); animation: isloadingspin 1000ms infinite linear; From 70e077036f8d3026cecddb746a1de69e02ab9b9a Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Fri, 15 Mar 2024 00:21:14 +0200 Subject: [PATCH 5/8] Remove jQuery AJAX from the diff functions (#29743) - Removed all jQuery AJAX calls and replaced with our fetch wrapper - Tested the review conversation comment, resolve, unresolve, show more files, and load diff functionality and it works as before # Demo using `fetch` instead of jQuery AJAX ![demo](https://github.com/go-gitea/gitea/assets/20454870/cc0bed59-f11f-4e48-bfa3-59ab52d9889e) --------- Signed-off-by: Yarden Shoham Co-authored-by: silverwind --- web_src/js/features/repo-diff.js | 69 +++++++++++++++++++------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index 77691e15e6488..b341583c3e28a 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -8,8 +8,9 @@ import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndC import {initImageDiff} from './imagediff.js'; import {showErrorToast} from '../modules/toast.js'; import {submitEventSubmitter} from '../utils/dom.js'; +import {POST, GET} from '../modules/fetch.js'; -const {csrfToken, pageData, i18n} = window.config; +const {pageData, i18n} = window.config; function initRepoDiffReviewButton() { const $reviewBox = $('#review-box'); @@ -63,8 +64,9 @@ function initRepoDiffConversationForm() { if (isSubmittedByButton && submitter.name) { formData.append(submitter.name, submitter.value); } - const formDataString = String(new URLSearchParams(formData)); - const $newConversationHolder = $(await $.post($form.attr('action'), formDataString)); + + const response = await POST($form.attr('action'), {data: formData}); + const $newConversationHolder = $(await response.text()); const {path, side, idx} = $newConversationHolder.data(); $form.closest('.conversation-holder').replaceWith($newConversationHolder); @@ -75,7 +77,8 @@ function initRepoDiffConversationForm() { } $newConversationHolder.find('.dropdown').dropdown(); initCompReactionSelector($newConversationHolder); - } catch { // here the caught error might be a jQuery AJAX error (thrown by await $.post), which is not good to use for error message handling + } catch (error) { + console.error('Error:', error); showErrorToast(i18n.network_error); } finally { $form.removeClass('is-loading'); @@ -89,15 +92,20 @@ function initRepoDiffConversationForm() { const action = $(this).data('action'); const url = $(this).data('update-url'); - const data = await $.post(url, {_csrf: csrfToken, origin, action, comment_id}); - - if ($(this).closest('.conversation-holder').length) { - const conversation = $(data); - $(this).closest('.conversation-holder').replaceWith(conversation); - conversation.find('.dropdown').dropdown(); - initCompReactionSelector(conversation); - } else { - window.location.reload(); + try { + const response = await POST(url, {data: new URLSearchParams({origin, action, comment_id})}); + const data = await response.text(); + + if ($(this).closest('.conversation-holder').length) { + const conversation = $(data); + $(this).closest('.conversation-holder').replaceWith(conversation); + conversation.find('.dropdown').dropdown(); + initCompReactionSelector(conversation); + } else { + window.location.reload(); + } + } catch (error) { + console.error('Error:', error); } }); } @@ -132,7 +140,7 @@ function onShowMoreFiles() { initImageDiff(); } -export function loadMoreFiles(url) { +export async function loadMoreFiles(url) { const $target = $('a#diff-show-more-files'); if ($target.hasClass('disabled') || pageData.diffFileInfo.isLoadingNewData) { return; @@ -140,10 +148,10 @@ export function loadMoreFiles(url) { pageData.diffFileInfo.isLoadingNewData = true; $target.addClass('disabled'); - $.ajax({ - type: 'GET', - url, - }).done((resp) => { + + try { + const response = await GET(url); + const resp = await response.text(); const $resp = $(resp); // the response is a full HTML page, we need to extract the relevant contents: // 1. append the newly loaded file list items to the existing list @@ -152,10 +160,13 @@ export function loadMoreFiles(url) { $('body').append($resp.find('script#diff-data-script')); onShowMoreFiles(); - }).always(() => { + } catch (error) { + console.error('Error:', error); + showErrorToast('An error occurred while loading more files.'); + } finally { $target.removeClass('disabled'); pageData.diffFileInfo.isLoadingNewData = false; - }); + } } function initRepoDiffShowMore() { @@ -167,7 +178,7 @@ function initRepoDiffShowMore() { loadMoreFiles(linkLoadMore); }); - $(document).on('click', 'a.diff-load-button', (e) => { + $(document).on('click', 'a.diff-load-button', async (e) => { e.preventDefault(); const $target = $(e.target); @@ -178,19 +189,21 @@ function initRepoDiffShowMore() { $target.addClass('disabled'); const url = $target.data('href'); - $.ajax({ - type: 'GET', - url, - }).done((resp) => { + + try { + const response = await GET(url); + const resp = await response.text(); + if (!resp) { - $target.removeClass('disabled'); return; } $target.parent().replaceWith($(resp).find('#diff-file-boxes .diff-file-body .file-body').children()); onShowMoreFiles(); - }).fail(() => { + } catch (error) { + console.error('Error:', error); + } finally { $target.removeClass('disabled'); - }); + } }); } From 607ed27b4fb8ead346f89b379d9788f5c76fb799 Mon Sep 17 00:00:00 2001 From: Daniel YC Lin Date: Fri, 15 Mar 2024 06:54:11 +0800 Subject: [PATCH 6/8] Fix document error about 'make trans-copy' (#29710) Change document to 'make docs' --------- Co-authored-by: techknowlogick --- Makefile | 4 --- .../development/hacking-on-gitea.en-us.md | 7 +--- .../development/hacking-on-gitea.zh-cn.md | 6 +--- docs/scripts/trans-copy.sh | 34 ------------------- 4 files changed, 2 insertions(+), 49 deletions(-) delete mode 100755 docs/scripts/trans-copy.sh diff --git a/Makefile b/Makefile index cedc4b4198369..88bcf0e17cc4c 100644 --- a/Makefile +++ b/Makefile @@ -839,10 +839,6 @@ release-sources: | $(DIST_DIRS) release-docs: | $(DIST_DIRS) docs tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs . -.PHONY: docs -docs: - cd docs; bash scripts/trans-copy.sh; - .PHONY: deps deps: deps-frontend deps-backend deps-tools deps-py diff --git a/docs/content/development/hacking-on-gitea.en-us.md b/docs/content/development/hacking-on-gitea.en-us.md index df8a9047d620e..982dbcf6ead5a 100644 --- a/docs/content/development/hacking-on-gitea.en-us.md +++ b/docs/content/development/hacking-on-gitea.en-us.md @@ -333,14 +333,9 @@ Documentation for the website is found in `docs/`. If you change this you can test your changes to ensure that they pass continuous integration using: ```bash -# from the docs directory within Gitea -make trans-copy clean build +make lint-md ``` -You will require a copy of [Hugo](https://gohugo.io/) to run this task. Please -note: this may generate a number of untracked Git objects, which will need to -be cleaned up. - ## Visual Studio Code A `launch.json` and `tasks.json` are provided within `contrib/ide/vscode` for diff --git a/docs/content/development/hacking-on-gitea.zh-cn.md b/docs/content/development/hacking-on-gitea.zh-cn.md index 2dba3c92b66d3..a31e1dc511c2b 100644 --- a/docs/content/development/hacking-on-gitea.zh-cn.md +++ b/docs/content/development/hacking-on-gitea.zh-cn.md @@ -307,13 +307,9 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build test-sqlite 该网站的文档位于 `docs/` 中。如果你改变了文档内容,你可以使用以下测试方法进行持续集成: ```bash -# 来自 Gitea 中的 docs 目录 -make trans-copy clean build +make lint-md ``` -运行此任务依赖于 [Hugo](https://gohugo.io/)。请注意:这可能会生成一些未跟踪的 Git 对象, -需要被清理干净。 - ## Visual Studio Code `contrib/ide/vscode` 中为 Visual Studio Code 提供了 `launch.json` 和 `tasks.json`。查看 diff --git a/docs/scripts/trans-copy.sh b/docs/scripts/trans-copy.sh deleted file mode 100755 index 7374ab9e73110..0000000000000 --- a/docs/scripts/trans-copy.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -set -e - -# -# This script is used to copy the en-US content to our available locales as a -# fallback to always show all pages when displaying a specific locale that is -# missing some documents to be translated. -# -# Just execute the script without any argument and you will get the missing -# files copied into the content folder. We are calling this script within the CI -# server simply by `make trans-copy`. -# - -declare -a LOCALES=( - "fr-fr" - "nl-nl" - "pt-br" - "zh-cn" - "zh-tw" -) - -ROOT=$(realpath $(dirname $0)/..) - -for SOURCE in $(find ${ROOT}/content -type f -iname *.en-us.md); do - for LOCALE in "${LOCALES[@]}"; do - DEST="${SOURCE%.en-us.md}.${LOCALE}.md" - - if [[ ! -f ${DEST} ]]; then - cp ${SOURCE} ${DEST} - sed -i.bak "s/en\-us/${LOCALE}/g" ${DEST} - rm ${DEST}.bak - fi - done -done From e0b002a4a8fbdb539108ae619772607bef9be23b Mon Sep 17 00:00:00 2001 From: Denys Konovalov Date: Fri, 15 Mar 2024 00:24:59 +0100 Subject: [PATCH 7/8] Unify search boxes (#29530) Unify all but a few search boxes to use uniform style, uniform translations and shared templates where possible. Remove a few duplicated search templates, e. g. code search.
Example after screenshots: ![grafik](https://github.com/go-gitea/gitea/assets/47871822/e20e7d6b-c6be-4a47-b132-672766f41421) ![grafik](https://github.com/go-gitea/gitea/assets/47871822/d5b11b9c-c12f-4a29-8fb0-24e5aa511d18) ![grafik](https://github.com/go-gitea/gitea/assets/47871822/d86bb444-36c7-426d-9cf1-c634963dffb1) ![grafik](https://github.com/go-gitea/gitea/assets/47871822/a76c0319-0518-484a-a840-563d02b61198)
Also includes #29700 Co-authored-by: 6543 <6543@obermui.de> --------- Co-authored-by: 6543 Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: silverwind Co-authored-by: Giteabot --- options/locale/locale_en-US.ini | 55 ++-- routers/web/explore/code.go | 5 +- routers/web/repo/commit.go | 2 +- routers/web/repo/search.go | 7 +- routers/web/user/code.go | 5 +- services/context/pagination.go | 2 +- templates/admin/base/search.tmpl | 23 -- templates/admin/emails/list.tmpl | 5 +- templates/admin/org/list.tmpl | 21 +- templates/admin/packages/list.tmpl | 8 +- templates/admin/repo/unadopted.tmpl | 8 +- templates/admin/user/list.tmpl | 6 +- templates/code/searchcombo.tmpl | 17 -- templates/code/searchform.tmpl | 14 - templates/explore/code.tmpl | 2 +- templates/explore/repo_list.tmpl | 2 +- templates/explore/search.tmpl | 13 +- templates/explore/user_list.tmpl | 4 +- templates/explore/users.tmpl | 2 - templates/org/team/members.tmpl | 2 +- templates/org/team/repositories.tmpl | 2 +- templates/package/shared/list.tmpl | 8 +- templates/package/shared/versionlist.tmpl | 10 +- templates/projects/list.tmpl | 9 +- templates/repo/branch/list.tmpl | 244 +++++++++--------- templates/repo/commits_search_dropdown.tmpl | 8 + templates/repo/commits_table.tmpl | 32 +-- templates/repo/home.tmpl | 8 +- templates/repo/issue/search.tmpl | 4 +- templates/repo/search.tmpl | 54 +--- templates/repo/settings/collaboration.tmpl | 4 +- templates/repo/settings/protected_branch.tmpl | 12 +- templates/repo/settings/tags.tmpl | 4 +- templates/shared/actions/runner_list.tmpl | 6 +- templates/shared/issuelist.tmpl | 2 +- templates/shared/repo_search.tmpl | 15 +- templates/shared/search/button.tmpl | 3 + .../search/code/results.tmpl} | 18 +- templates/shared/search/code/search.tmpl | 15 ++ templates/shared/search/combo.tmpl | 8 + templates/shared/search/combo_fuzzy.tmpl | 10 + templates/shared/search/fuzzy.tmpl | 10 + templates/shared/search/input.tmpl | 4 + templates/shared/searchinput.tmpl | 1 - templates/user/code.tmpl | 4 +- templates/user/dashboard/issues.tmpl | 4 +- templates/user/dashboard/milestones.tmpl | 7 +- templates/user/dashboard/repolist.tmpl | 2 +- web_src/css/base.css | 26 +- web_src/css/form.css | 5 + web_src/js/components/DashboardRepoList.vue | 2 +- 51 files changed, 347 insertions(+), 397 deletions(-) delete mode 100644 templates/admin/base/search.tmpl delete mode 100644 templates/code/searchcombo.tmpl delete mode 100644 templates/code/searchform.tmpl create mode 100644 templates/repo/commits_search_dropdown.tmpl create mode 100644 templates/shared/search/button.tmpl rename templates/{code/searchresults.tmpl => shared/search/code/results.tmpl} (70%) create mode 100644 templates/shared/search/code/search.tmpl create mode 100644 templates/shared/search/combo.tmpl create mode 100644 templates/shared/search/combo_fuzzy.tmpl create mode 100644 templates/shared/search/fuzzy.tmpl create mode 100644 templates/shared/search/input.tmpl delete mode 100644 templates/shared/searchinput.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 836703a480efb..8c014955d0079 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -155,6 +155,27 @@ filter.not_template = Not Template filter.public = Public filter.private = Private +[search] +search = Search... +type_tooltip = Search type +fuzzy = Fuzzy +fuzzy_tooltip = Include results that also match the search term closely +match = Match +match_tooltip = Include only results that match the exact search term +repo_kind = Search repos... +user_kind = Search users... +org_kind = Search orgs... +team_kind = Search teams... +code_kind = Search code... +code_search_unavailable = Code search is currently not available. Please contact the site administrator. +package_kind = Search packages... +project_kind = Search projects... +branch_kind = Search branches... +commit_kind = Search commits... +runner_kind = Search runners... +no_results = No matching results found. +keyword_search_unavailable = Searching by keyword is currently not available. Please contact the site administrator. + [aria] navbar = Navigation Bar footer = Footer @@ -330,7 +351,6 @@ collaborative_repos = Collaborative Repositories my_orgs = My Organizations my_mirrors = My Mirrors view_home = View %s -search_repos = Find a repository… filter = Other Filters filter_by_team_repositories = Filter by team repositories feed_of = Feed of "%s" @@ -351,20 +371,8 @@ issues.in_your_repos = In your repositories repos = Repositories users = Users organizations = Organizations -search = Search go_to = Go to code = Code -search.type.tooltip = Search type -search.fuzzy = Fuzzy -search.fuzzy.tooltip = Include results that also matches the search term closely -search.match = Match -search.match.tooltip = Include only results that matches the exact search term -code_search_unavailable = Currently code search is not available. Please contact your site administrator. -repo_no_results = No matching repositories found. -user_no_results = No matching users found. -org_no_results = No matching organizations found. -code_no_results = No source code matching your search term found. -code_search_results = Search results for "%s" code_last_indexed_at = Last indexed %s relevant_repositories_tooltip = Repositories that are forks or that have no topic, no icon, and no description are hidden. relevant_repositories = Only relevant repositories are being shown,
show unfiltered results. @@ -1324,9 +1332,8 @@ commits.desc = Browse source code change history. commits.commits = Commits commits.no_commits = No commits in common. "%s" and "%s" have entirely different histories. commits.nothing_to_compare = These branches are equal. -commits.search = Search commits… commits.search.tooltip = You can prefix keywords with "author:", "committer:", "after:", or "before:", e.g. "revert author:Alice before:2019-01-13". -commits.find = Search +commits.search_branch = This Branch commits.search_all = All Branches commits.author = Author commits.message = Message @@ -1502,7 +1509,6 @@ issues.filter_sort.moststars = Most stars issues.filter_sort.feweststars = Fewest stars issues.filter_sort.mostforks = Most forks issues.filter_sort.fewestforks = Fewest forks -issues.keyword_search_unavailable = Searching by keyword is currently not available. Please contact your site administrator. issues.action_open = Open issues.action_close = Close issues.action_label = Label @@ -2035,17 +2041,6 @@ contributors.contribution_type.commits = Commits contributors.contribution_type.additions = Additions contributors.contribution_type.deletions = Deletions -search = Search -search.search_repo = Search repository -search.type.tooltip = Search type -search.fuzzy = Fuzzy -search.fuzzy.tooltip = Include results that also matches the search term closely -search.match = Match -search.match.tooltip = Include only results that matches the exact search term -search.results = Search results for "%s" in %s -search.code_no_results = No source code matching your search term found. -search.code_search_unavailable = Currently code search is not available. Please contact your site administrator. - settings = Settings settings.desc = Settings is where you can manage the settings for the repository settings.options = Repository @@ -2206,7 +2201,6 @@ settings.delete_collaborator = Remove settings.collaborator_deletion = Remove Collaborator settings.collaborator_deletion_desc = Removing a collaborator will revoke their access to this repository. Continue? settings.remove_collaborator_success = The collaborator has been removed. -settings.search_user_placeholder = Search user… settings.org_not_allowed_to_be_collaborator = Organizations cannot be added as a collaborator. settings.change_team_access_not_allowed = Changing team access for repository has been restricted to organization owner settings.team_not_in_organization = The team is not in the same organization as the repository @@ -2214,7 +2208,6 @@ settings.teams = Teams settings.add_team = Add Team settings.add_team_duplicate = Team already has the repository settings.add_team_success = The team now have access to the repository. -settings.search_team = Search Team… settings.change_team_permission_tip = Team's permission is set on the team setting page and can't be changed per repository settings.delete_team_tip = This team has access to all repositories and can't be removed settings.remove_team_success = The team's access to the repository has been removed. @@ -2367,9 +2360,7 @@ settings.protect_whitelist_committers = Whitelist Restricted Push settings.protect_whitelist_committers_desc = Only whitelisted users or teams will be allowed to push to this branch (but not force push). settings.protect_whitelist_deploy_keys = Whitelist deploy keys with write access to push. settings.protect_whitelist_users = Whitelisted users for pushing: -settings.protect_whitelist_search_users = Search users… settings.protect_whitelist_teams = Whitelisted teams for pushing: -settings.protect_whitelist_search_teams = Search teams… settings.protect_merge_whitelist_committers = Enable Merge Whitelist settings.protect_merge_whitelist_committers_desc = Allow only whitelisted users or teams to merge pull requests into this branch. settings.protect_merge_whitelist_users = Whitelisted users for merging: @@ -2614,7 +2605,6 @@ branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be branch.restore = Restore Branch "%s" branch.download = Download Branch "%s" branch.rename = Rename Branch "%s" -branch.search = Search Branch branch.included_desc = This branch is part of the default branch branch.included = Included branch.create_new_branch = Create branch from branch: @@ -2760,7 +2750,6 @@ teams.write_permission_desc = This team grants Write access: me teams.admin_permission_desc = This team grants Admin access: members can read from, push to and add collaborators to team repositories. teams.create_repo_permission_desc = Additionally, this team grants Create repository permission: members can create new repositories in organization. teams.repositories = Team Repositories -teams.search_repo_placeholder = Search repository… teams.remove_all_repos_title = Remove all team repositories teams.remove_all_repos_desc = This will remove all repositories from the team. teams.add_all_repos_title = Add all repositories diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index a6bc71ac9cde0..7ba5984002c82 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -34,12 +34,11 @@ func Code(ctx *context.Context) { language := ctx.FormTrim("l") keyword := ctx.FormTrim("q") - queryType := ctx.FormTrim("t") - isFuzzy := queryType != "match" + isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true) ctx.Data["Keyword"] = keyword ctx.Data["Language"] = language - ctx.Data["queryType"] = queryType + ctx.Data["IsFuzzy"] = isFuzzy ctx.Data["PageIsViewCode"] = true if keyword == "" { diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 16da917d222c1..1b99f4183c3b1 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -203,7 +203,7 @@ func SearchCommits(ctx *context.Context) { ctx.Data["Keyword"] = query if all { - ctx.Data["All"] = "checked" + ctx.Data["All"] = true } ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 766dd5726aa8d..16e620f57d4ef 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -24,12 +24,11 @@ func Search(ctx *context.Context) { language := ctx.FormTrim("l") keyword := ctx.FormTrim("q") - queryType := ctx.FormTrim("t") - isFuzzy := queryType != "match" + isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true) ctx.Data["Keyword"] = keyword ctx.Data["Language"] = language - ctx.Data["queryType"] = queryType + ctx.Data["IsFuzzy"] = isFuzzy ctx.Data["PageIsViewCode"] = true if keyword == "" { @@ -54,7 +53,7 @@ func Search(ctx *context.Context) { ctx.Data["CodeIndexerUnavailable"] = !code_indexer.IsAvailable(ctx) } - ctx.Data["SourcePath"] = ctx.Repo.Repository.Link() + ctx.Data["Repo"] = ctx.Repo.Repository ctx.Data["SearchResults"] = searchResults ctx.Data["SearchResultLanguages"] = searchResultLanguages diff --git a/routers/web/user/code.go b/routers/web/user/code.go index 8613d38b65a66..92911edfe9325 100644 --- a/routers/web/user/code.go +++ b/routers/web/user/code.go @@ -39,12 +39,11 @@ func CodeSearch(ctx *context.Context) { language := ctx.FormTrim("l") keyword := ctx.FormTrim("q") - queryType := ctx.FormTrim("t") - isFuzzy := queryType != "match" + isFuzzy := ctx.FormOptionalBool("fuzzy").ValueOrDefault(true) ctx.Data["Keyword"] = keyword ctx.Data["Language"] = language - ctx.Data["queryType"] = queryType + ctx.Data["IsFuzzy"] = isFuzzy ctx.Data["IsCodePage"] = true if keyword == "" { diff --git a/services/context/pagination.go b/services/context/pagination.go index 68237c630c0ae..655a278f9ff92 100644 --- a/services/context/pagination.go +++ b/services/context/pagination.go @@ -53,5 +53,5 @@ func (p *Pagination) SetDefaultParams(ctx *Context) { p.AddParam(ctx, "sort", "SortType") p.AddParam(ctx, "q", "Keyword") // do not add any more uncommon params here! - p.AddParam(ctx, "t", "queryType") + p.AddParam(ctx, "fuzzy", "IsFuzzy") } diff --git a/templates/admin/base/search.tmpl b/templates/admin/base/search.tmpl deleted file mode 100644 index 0fecb61d9e367..0000000000000 --- a/templates/admin/base/search.tmpl +++ /dev/null @@ -1,23 +0,0 @@ - diff --git a/templates/admin/emails/list.tmpl b/templates/admin/emails/list.tmpl index 29fbb5f039759..1e552fba889b8 100644 --- a/templates/admin/emails/list.tmpl +++ b/templates/admin/emails/list.tmpl @@ -6,10 +6,7 @@
diff --git a/templates/repo/commits_search_dropdown.tmpl b/templates/repo/commits_search_dropdown.tmpl new file mode 100644 index 0000000000000..5aa3f4f320b00 --- /dev/null +++ b/templates/repo/commits_search_dropdown.tmpl @@ -0,0 +1,8 @@ + diff --git a/templates/repo/commits_table.tmpl b/templates/repo/commits_table.tmpl index 70f673e27e68a..221ee8d99b98e 100644 --- a/templates/repo/commits_table.tmpl +++ b/templates/repo/commits_table.tmpl @@ -8,27 +8,27 @@ {{ctx.Locale.Tr "repo.commits.no_commits" $.BaseBranch $.HeadBranch}} {{end}}
- + {{end}} +{{if .PageIsCommits}} +
+
+
+ {{template "shared/search/input" dict "Value" .Keyword "Placeholder" (ctx.Locale.Tr "search.commit_kind")}} + {{template "repo/commits_search_dropdown" .}} + {{template "shared/search/button" dict "Tooltip" (ctx.Locale.Tr "repo.commits.search.tooltip")}} +
+
+
+{{end}} + {{if and .Commits (gt .CommitCount 0)}} {{template "repo/commits_list" .}} {{end}} diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index a98dcb8c28db7..ef10904bcc16b 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -15,14 +15,12 @@