Skip to content

Commit

Permalink
Merge branch 'main' into enhance/bleve_fuzziness
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Mar 23, 2024
2 parents f32bb1c + 1cdc6c3 commit fd25f6a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
5 changes: 3 additions & 2 deletions routers/web/repo/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/context"
)

Expand All @@ -17,7 +18,7 @@ const (
// FindFiles render the page to find repository files
func FindFiles(ctx *context.Context) {
path := ctx.Params("*")
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + path
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + path
ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path)
ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path)
ctx.HTML(http.StatusOK, tplFindFiles)
}
6 changes: 4 additions & 2 deletions web_src/js/features/imagediff.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ export function initImageDiff() {
const text = await resp.text();
const bounds = getDefaultSvgBoundsIfUndefined(text, info.path);
if (bounds) {
info.$images.attr('width', bounds.width);
info.$images.attr('height', bounds.height);
info.$images.each(function() {
this.setAttribute('width', bounds.width);
this.setAttribute('height', bounds.height);
});
hideElem(info.$boundsInfo);
}
}
Expand Down
23 changes: 13 additions & 10 deletions web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@ import {POST, GET} from '../modules/fetch.js';
const {pageData, i18n} = window.config;

function initRepoDiffReviewButton() {
const $reviewBox = $('#review-box');
const $counter = $reviewBox.find('.review-comments-counter');
const reviewBox = document.getElementById('review-box');
if (!reviewBox) return;

const $reviewBox = $(reviewBox);
const counter = reviewBox.querySelector('.review-comments-counter');
if (!counter) return;

$(document).on('click', 'button[name="pending_review"]', (e) => {
const $form = $(e.target).closest('form');
// Watch for the form's submit event.
$form.on('submit', () => {
const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1;
$counter.attr('data-pending-comment-number', num);
$counter.text(num);
const num = parseInt(counter.getAttribute('data-pending-comment-number')) + 1 || 1;
counter.setAttribute('data-pending-comment-number', num);
counter.textContent = num;
// Force the browser to reflow the DOM. This is to ensure that the browser replay the animation
$reviewBox.removeClass('pulse');
$reviewBox.width();
Expand Down Expand Up @@ -65,7 +69,7 @@ function initRepoDiffConversationForm() {
formData.append(submitter.name, submitter.value);
}

const response = await POST($form.attr('action'), {data: formData});
const response = await POST(e.target.getAttribute('action'), {data: formData});
const $newConversationHolder = $(await response.text());
const {path, side, idx} = $newConversationHolder.data();

Expand Down Expand Up @@ -118,7 +122,7 @@ export function initRepoDiffConversationNav() {
const index = $conversations.index($conversation);
const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
const $previousConversation = $conversations.eq(previousIndex);
const anchor = $previousConversation.find('.comment').first().attr('id');
const anchor = $previousConversation.find('.comment').first()[0].getAttribute('id');
window.location.href = `#${anchor}`;
});
$(document).on('click', '.next-conversation', (e) => {
Expand All @@ -127,7 +131,7 @@ export function initRepoDiffConversationNav() {
const index = $conversations.index($conversation);
const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
const $nextConversation = $conversations.eq(nextIndex);
const anchor = $nextConversation.find('.comment').first().attr('id');
const anchor = $nextConversation.find('.comment').first()[0].getAttribute('id');
window.location.href = `#${anchor}`;
});
}
Expand Down Expand Up @@ -173,8 +177,7 @@ function initRepoDiffShowMore() {
$(document).on('click', 'a#diff-show-more-files', (e) => {
e.preventDefault();

const $target = $(e.target);
const linkLoadMore = $target.attr('data-href');
const linkLoadMore = e.target.getAttribute('data-href');
loadMoreFiles(linkLoadMore);
});

Expand Down
30 changes: 16 additions & 14 deletions web_src/js/features/repo-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ const {appSubUrl, csrfToken} = window.config;

export function initRepoSettingsCollaboration() {
// Change collaborator access mode
$('.page-content.repository .ui.dropdown.access-mode').each((_, e) => {
const $dropdown = $(e);
$('.page-content.repository .ui.dropdown.access-mode').each((_, el) => {
const $dropdown = $(el);
const $text = $dropdown.find('> .text');
$dropdown.dropdown({
async action(_text, value) {
const lastValue = $dropdown.attr('data-last-value');
const lastValue = el.getAttribute('data-last-value');
try {
$dropdown.attr('data-last-value', value);
el.setAttribute('data-last-value', value);
$dropdown.dropdown('hide');
const data = new FormData();
data.append('uid', $dropdown.attr('data-uid'));
data.append('uid', el.getAttribute('data-uid'));
data.append('mode', value);
await POST($dropdown.attr('data-url'), {data});
await POST(el.getAttribute('data-url'), {data});
} catch {
$text.text('(error)'); // prevent from misleading users when error occurs
$dropdown.attr('data-last-value', lastValue);
el.setAttribute('data-last-value', lastValue);
}
},
onChange(_value, text, _$choice) {
Expand All @@ -32,9 +32,9 @@ export function initRepoSettingsCollaboration() {
onHide() {
// set to the really selected value, defer to next tick to make sure `action` has finished its work because the calling order might be onHide -> action
setTimeout(() => {
const $item = $dropdown.dropdown('get item', $dropdown.attr('data-last-value'));
const $item = $dropdown.dropdown('get item', el.getAttribute('data-last-value'));
if ($item) {
$dropdown.dropdown('set selected', $dropdown.attr('data-last-value'));
$dropdown.dropdown('set selected', el.getAttribute('data-last-value'));
} else {
$text.text('(none)'); // prevent from misleading users when the access mode is undefined
}
Expand All @@ -45,11 +45,13 @@ export function initRepoSettingsCollaboration() {
}

export function initRepoSettingSearchTeamBox() {
const $searchTeamBox = $('#search-team-box');
$searchTeamBox.search({
const searchTeamBox = document.getElementById('search-team-box');
if (!searchTeamBox) return;

$(searchTeamBox).search({
minCharacters: 2,
apiSettings: {
url: `${appSubUrl}/org/${$searchTeamBox.attr('data-org-name')}/teams/-/search?q={query}`,
url: `${appSubUrl}/org/${searchTeamBox.getAttribute('data-org-name')}/teams/-/search?q={query}`,
headers: {'X-Csrf-Token': csrfToken},
onResponse(response) {
const items = [];
Expand Down Expand Up @@ -77,11 +79,11 @@ export function initRepoSettingGitHook() {
export function initRepoSettingBranches() {
if (!$('.repository.settings.branches').length) return;
$('.toggle-target-enabled').on('change', function () {
const $target = $($(this).attr('data-target'));
const $target = $(this.getAttribute('data-target'));
$target.toggleClass('disabled', !this.checked);
});
$('.toggle-target-disabled').on('change', function () {
const $target = $($(this).attr('data-target'));
const $target = $(this.getAttribute('data-target'));
if (this.checked) $target.addClass('disabled'); // only disable, do not auto enable
});
$('#dismiss_stale_approvals').on('change', function () {
Expand Down

0 comments on commit fd25f6a

Please sign in to comment.