Skip to content

Commit

Permalink
Merge branch 'main' into rearrange-clone-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang authored Dec 11, 2024
2 parents 2102d65 + 8a53a39 commit ea6d4a6
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 80 deletions.
4 changes: 2 additions & 2 deletions web_src/js/features/repo-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function initRepoCreateBranchButton() {
for (const el of document.querySelectorAll('.show-create-branch-modal')) {
el.addEventListener('click', () => {
const modalFormName = el.getAttribute('data-modal-form') || '#create-branch-form';
const modalForm = document.querySelector(modalFormName);
const modalForm = document.querySelector<HTMLFormElement>(modalFormName);
if (!modalForm) return;
modalForm.action = `${modalForm.getAttribute('data-base-action')}${el.getAttribute('data-branch-from-urlcomponent')}`;

Expand All @@ -29,7 +29,7 @@ function initRepoRenameBranchButton() {
const target = el.getAttribute('data-modal');
const modal = document.querySelector(target);
const oldBranchName = el.getAttribute('data-old-branch-name');
modal.querySelector('input[name=from]').value = oldBranchName;
modal.querySelector<HTMLInputElement>('input[name=from]').value = oldBranchName;

// display the warning that the branch which is chosen is the default branch
const warn = modal.querySelector('.default-branch-warning');
Expand Down
18 changes: 6 additions & 12 deletions web_src/js/features/repo-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {toAbsoluteUrl} from '../utils.ts';
export const singleAnchorRegex = /^#(L|n)([1-9][0-9]*)$/;
export const rangeAnchorRegex = /^#(L[1-9][0-9]*)-(L[1-9][0-9]*)$/;

function changeHash(hash) {
function changeHash(hash: string) {
if (window.history.pushState) {
window.history.pushState(null, null, hash);
} else {
Expand All @@ -24,7 +24,7 @@ function getLineEls() {
return document.querySelectorAll(`.code-view td.lines-code${isBlame() ? '.blame-code' : ''}`);
}

function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
function selectRange($linesEls, $selectionEndEl, $selectionStartEls?) {
for (const el of $linesEls) {
el.closest('tr').classList.remove('active');
}
Expand All @@ -34,15 +34,15 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
const copyPermalink = document.querySelector('a.copy-line-permalink');
const viewGitBlame = document.querySelector('a.view_git_blame');

const updateIssueHref = function (anchor) {
const updateIssueHref = function (anchor: string) {
if (!refInNewIssue) return;
const urlIssueNew = refInNewIssue.getAttribute('data-url-issue-new');
const urlParamBodyLink = refInNewIssue.getAttribute('data-url-param-body-link');
const issueContent = `${toAbsoluteUrl(urlParamBodyLink)}#${anchor}`; // the default content for issue body
refInNewIssue.setAttribute('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`);
};

const updateViewGitBlameFragment = function (anchor) {
const updateViewGitBlameFragment = function (anchor: string) {
if (!viewGitBlame) return;
let href = viewGitBlame.getAttribute('href');
href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`;
Expand All @@ -52,7 +52,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
viewGitBlame.setAttribute('href', href);
};

const updateCopyPermalinkUrl = function (anchor) {
const updateCopyPermalinkUrl = function (anchor: string) {
if (!copyPermalink) return;
let link = copyPermalink.getAttribute('data-url');
link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`;
Expand Down Expand Up @@ -142,13 +142,7 @@ export function initRepoCodeView() {
});
}
selectRange($(linesEls), $(selectedEls), from ? $(from) : null);

if (window.getSelection) {
window.getSelection().removeAllRanges();
} else {
document.selection.empty();
}

window.getSelection().removeAllRanges();
showLineButton();
});

Expand Down
4 changes: 2 additions & 2 deletions web_src/js/features/repo-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function initRepoCloneButtons() {
queryElems(document, '.clone-buttons-combo', initCloneSchemeUrlSelection);
}

export function initRepoCommonBranchOrTagDropdown(selector) {
export function initRepoCommonBranchOrTagDropdown(selector: string) {
$(selector).each(function () {
const $dropdown = $(this);
$dropdown.find('.reference.column').on('click', function () {
Expand All @@ -118,7 +118,7 @@ export function initRepoCommonBranchOrTagDropdown(selector) {
});
}

export function initRepoCommonFilterSearchDropdown(selector) {
export function initRepoCommonFilterSearchDropdown(selector: string) {
const $dropdown = $(selector);
if (!$dropdown.length) return;

Expand Down
8 changes: 4 additions & 4 deletions web_src/js/features/repo-diff-commit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {hideElem, showElem, toggleElem} from '../utils/dom.ts';
import {GET} from '../modules/fetch.ts';

async function loadBranchesAndTags(area, loadingButton) {
async function loadBranchesAndTags(area: Element, loadingButton: Element) {
loadingButton.classList.add('disabled');
try {
const res = await GET(loadingButton.getAttribute('data-fetch-url'));
Expand All @@ -15,15 +15,15 @@ async function loadBranchesAndTags(area, loadingButton) {
}
}

function addTags(area, tags) {
function addTags(area: Element, tags: Array<Record<string, any>>) {
const tagArea = area.querySelector('.tag-area');
toggleElem(tagArea.parentElement, tags.length > 0);
for (const tag of tags) {
addLink(tagArea, tag.web_link, tag.name);
}
}

function addBranches(area, branches, defaultBranch) {
function addBranches(area: Element, branches: Array<Record<string, any>>, defaultBranch: string) {
const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip');
const branchArea = area.querySelector('.branch-area');
toggleElem(branchArea.parentElement, branches.length > 0);
Expand All @@ -33,7 +33,7 @@ function addBranches(area, branches, defaultBranch) {
}
}

function addLink(parent, href, text, tooltip) {
function addLink(parent: Element, href: string, text: string, tooltip?: string) {
const link = document.createElement('a');
link.classList.add('muted', 'tw-px-1');
link.href = href;
Expand Down
12 changes: 6 additions & 6 deletions web_src/js/features/repo-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function initRepoGraphGit() {
for (const link of document.querySelectorAll('.pagination a')) {
const href = link.getAttribute('href');
if (!href) continue;
const url = new URL(href, window.location);
const url = new URL(href, window.location.href);
const params = url.searchParams;
params.set('mode', 'monochrome');
url.search = `?${params.toString()}`;
Expand All @@ -38,7 +38,7 @@ export function initRepoGraphGit() {
for (const link of document.querySelectorAll('.pagination a')) {
const href = link.getAttribute('href');
if (!href) continue;
const url = new URL(href, window.location);
const url = new URL(href, window.location.href);
const params = url.searchParams;
params.delete('mode');
url.search = `?${params.toString()}`;
Expand All @@ -53,7 +53,7 @@ export function initRepoGraphGit() {
window.history.replaceState({}, '', window.location.pathname);
}
});
const url = new URL(window.location);
const url = new URL(window.location.href);
const params = url.searchParams;
const updateGraph = () => {
const queryString = params.toString();
Expand Down Expand Up @@ -103,15 +103,15 @@ export function initRepoGraphGit() {
},
onAdd(toAdd) {
if (toAdd === '...flow-hide-pr-refs') {
params.set('hide-pr-refs', true);
params.set('hide-pr-refs', 'true');
} else {
params.append('branch', toAdd);
}
updateGraph();
},
});

graphContainer.addEventListener('mouseenter', (e) => {
graphContainer.addEventListener('mouseenter', (e: MouseEvent & {target: HTMLElement}) => {
if (e.target.matches('#rev-list li')) {
const flow = e.target.getAttribute('data-flow');
if (flow === '0') return;
Expand All @@ -132,7 +132,7 @@ export function initRepoGraphGit() {
}
});

graphContainer.addEventListener('mouseleave', (e) => {
graphContainer.addEventListener('mouseleave', (e: MouseEvent & {target: HTMLElement}) => {
if (e.target.matches('#rev-list li')) {
const flow = e.target.getAttribute('data-flow');
if (flow === '0') return;
Expand Down
4 changes: 2 additions & 2 deletions web_src/js/features/repo-home.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {stripTags} from '../utils.ts';
import {hideElem, queryElemChildren, showElem} from '../utils/dom.ts';
import {POST} from '../modules/fetch.ts';
import {showErrorToast} from '../modules/toast.ts';
import {showErrorToast, type Toast} from '../modules/toast.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';

const {appSubUrl} = window.config;
Expand All @@ -13,7 +13,7 @@ export function initRepoTopicBar() {
const editDiv = document.querySelector('#topic_edit');
const viewDiv = document.querySelector('#repo-topics');
const topicDropdown = editDiv.querySelector('.ui.dropdown');
let lastErrorToast;
let lastErrorToast: Toast;

mgrBtn.addEventListener('click', () => {
hideElem(viewDiv);
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-issue-pr-status.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function initRepoPullRequestCommitStatus() {
for (const btn of document.querySelectorAll('.commit-status-hide-checks')) {
const panel = btn.closest('.commit-status-panel');
const list = panel.querySelector('.commit-status-list');
const list = panel.querySelector<HTMLElement>('.commit-status-list');
btn.addEventListener('click', () => {
list.style.maxHeight = list.style.maxHeight ? '' : '0px'; // toggle
btn.textContent = btn.getAttribute(list.style.maxHeight ? 'data-show-all' : 'data-hide-all');
Expand Down
22 changes: 12 additions & 10 deletions web_src/js/features/repo-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function initRepoIssueFilterItemLabel() {

export function initRepoIssueCommentDelete() {
// Delete comment
document.addEventListener('click', async (e) => {
document.addEventListener('click', async (e: MouseEvent & {target: HTMLElement}) => {
if (!e.target.matches('.delete-comment')) return;
e.preventDefault();

Expand All @@ -143,7 +143,7 @@ export function initRepoIssueCommentDelete() {
const counter = document.querySelector('#review-box .review-comments-counter');
let num = parseInt(counter?.getAttribute('data-pending-comment-number')) - 1 || 0;
num = Math.max(num, 0);
counter.setAttribute('data-pending-comment-number', num);
counter.setAttribute('data-pending-comment-number', String(num));
counter.textContent = String(num);
}

Expand Down Expand Up @@ -199,7 +199,7 @@ export function initRepoIssueDependencyDelete() {

export function initRepoIssueCodeCommentCancel() {
// Cancel inline code comment
document.addEventListener('click', (e) => {
document.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => {
if (!e.target.matches('.cancel-code-comment')) return;

const form = e.target.closest('form');
Expand Down Expand Up @@ -268,12 +268,14 @@ export function initRepoPullRequestMergeInstruction() {
export function initRepoPullRequestAllowMaintainerEdit() {
const wrapper = document.querySelector('#allow-edits-from-maintainers');
if (!wrapper) return;
const checkbox = wrapper.querySelector('input[type="checkbox"]');
const checkbox = wrapper.querySelector<HTMLInputElement>('input[type="checkbox"]');
checkbox.addEventListener('input', async () => {
const url = `${wrapper.getAttribute('data-url')}/set_allow_maintainer_edit`;
wrapper.classList.add('is-loading');
try {
const resp = await POST(url, {data: new URLSearchParams({allow_maintainer_edit: checkbox.checked})});
const resp = await POST(url, {data: new URLSearchParams({
allow_maintainer_edit: String(checkbox.checked),
})});
if (!resp.ok) {
throw new Error('Failed to update maintainer edit permission');
}
Expand Down Expand Up @@ -322,7 +324,7 @@ export function initRepoIssueWipTitle() {

const $issueTitle = $('#issue_title');
$issueTitle.trigger('focus');
const value = $issueTitle.val().trim().toUpperCase();
const value = ($issueTitle.val() as string).trim().toUpperCase();

const wipPrefixes = $('.title_wip_desc').data('wip-prefixes');
for (const prefix of wipPrefixes) {
Expand All @@ -338,7 +340,7 @@ export function initRepoIssueWipTitle() {
export function initRepoIssueComments() {
if (!$('.repository.view.issue .timeline').length) return;

document.addEventListener('click', (e) => {
document.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => {
const urlTarget = document.querySelector(':target');
if (!urlTarget) return;

Expand Down Expand Up @@ -490,7 +492,7 @@ export function initRepoPullRequestReview() {

export function initRepoIssueReferenceIssue() {
// Reference issue
$(document).on('click', '.reference-issue', function (event) {
$(document).on('click', '.reference-issue', function (e) {
const target = this.getAttribute('data-target');
const content = document.querySelector(`#${target}`)?.textContent ?? '';
const poster = this.getAttribute('data-poster-username');
Expand All @@ -500,7 +502,7 @@ export function initRepoIssueReferenceIssue() {
const textarea = modal.querySelector('textarea[name="content"]');
textarea.value = `${content}\n\n_Originally posted by @${poster} in ${reference}_`;
$(modal).modal('show');
event.preventDefault();
e.preventDefault();
});
}

Expand Down Expand Up @@ -584,7 +586,7 @@ export function initRepoIssueTitleEdit() {
}

export function initRepoIssueBranchSelect() {
document.querySelector('#branch-select')?.addEventListener('click', (e) => {
document.querySelector('#branch-select')?.addEventListener('click', (e: MouseEvent & {target: HTMLElement}) => {
const el = e.target.closest('.item[data-branch]');
if (!el) return;
const pullTargetBranch = document.querySelector('#pull-target-branch');
Expand Down
28 changes: 14 additions & 14 deletions web_src/js/features/repo-migration.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {hideElem, showElem, toggleElem} from '../utils/dom.ts';

const service = document.querySelector('#service_type');
const user = document.querySelector('#auth_username');
const pass = document.querySelector('#auth_password');
const token = document.querySelector('#auth_token');
const mirror = document.querySelector('#mirror');
const lfs = document.querySelector('#lfs');
const lfsSettings = document.querySelector('#lfs_settings');
const lfsEndpoint = document.querySelector('#lfs_endpoint');
const items = document.querySelectorAll('#migrate_items input[type=checkbox]');
const service = document.querySelector<HTMLInputElement>('#service_type');
const user = document.querySelector<HTMLInputElement>('#auth_username');
const pass = document.querySelector<HTMLInputElement>('#auth_password');
const token = document.querySelector<HTMLInputElement>('#auth_token');
const mirror = document.querySelector<HTMLInputElement>('#mirror');
const lfs = document.querySelector<HTMLInputElement>('#lfs');
const lfsSettings = document.querySelector<HTMLElement>('#lfs_settings');
const lfsEndpoint = document.querySelector<HTMLElement>('#lfs_endpoint');
const items = document.querySelectorAll<HTMLInputElement>('#migrate_items input[type=checkbox]');

export function initRepoMigration() {
checkAuth();
Expand All @@ -25,11 +25,11 @@ export function initRepoMigration() {
});
lfs?.addEventListener('change', setLFSSettingsVisibility);

const cloneAddr = document.querySelector('#clone_addr');
const cloneAddr = document.querySelector<HTMLInputElement>('#clone_addr');
cloneAddr?.addEventListener('change', () => {
const repoName = document.querySelector('#repo_name');
const repoName = document.querySelector<HTMLInputElement>('#repo_name');
if (cloneAddr.value && !repoName?.value) { // Only modify if repo_name input is blank
repoName.value = cloneAddr.value.match(/^(.*\/)?((.+?)(\.git)?)$/)[3];
repoName.value = /^(.*\/)?((.+?)(\.git)?)$/.exec(cloneAddr.value)[3];
}
});
}
Expand All @@ -41,8 +41,8 @@ function checkAuth() {
checkItems(serviceType !== 1);
}

function checkItems(tokenAuth) {
let enableItems;
function checkItems(tokenAuth: boolean) {
let enableItems = false;
if (tokenAuth) {
enableItems = token?.value !== '';
} else {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function initRepoNew() {
const gitignores = $('input[name="gitignores"]').val();
const license = $('input[name="license"]').val();
if (gitignores || license) {
document.querySelector('input[name="auto_init"]').checked = true;
document.querySelector<HTMLInputElement>('input[name="auto_init"]').checked = true;
}
});
}
Expand Down
16 changes: 8 additions & 8 deletions web_src/js/features/repo-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function createNewColumn(url, columnTitle, projectColorInput) {
}
}

async function moveIssue({item, from, to, oldIndex}) {
async function moveIssue({item, from, to, oldIndex}: {item: HTMLElement, from: HTMLElement, to: HTMLElement, oldIndex: number}) {
const columnCards = to.querySelectorAll('.issue-card');
updateIssueCount(from);
updateIssueCount(to);
Expand Down Expand Up @@ -97,14 +97,14 @@ export function initRepoProject() {
return;
}

const _promise = initRepoProjectSortable();
initRepoProjectSortable(); // no await

for (const modal of document.querySelectorAll('.edit-project-column-modal')) {
const projectHeader = modal.closest('.project-column-header');
const projectTitleLabel = projectHeader?.querySelector('.project-column-title-label');
const projectTitleInput = modal.querySelector('.project-column-title-input');
const projectColorInput = modal.querySelector('#new_project_column_color');
const boardColumn = modal.closest('.project-column');
const projectHeader = modal.closest<HTMLElement>('.project-column-header');
const projectTitleLabel = projectHeader?.querySelector<HTMLElement>('.project-column-title-label');
const projectTitleInput = modal.querySelector<HTMLInputElement>('.project-column-title-input');
const projectColorInput = modal.querySelector<HTMLInputElement>('#new_project_column_color');
const boardColumn = modal.closest<HTMLElement>('.project-column');
modal.querySelector('.edit-project-column-button')?.addEventListener('click', async function (e) {
e.preventDefault();
try {
Expand All @@ -119,7 +119,7 @@ export function initRepoProject() {
} finally {
projectTitleLabel.textContent = projectTitleInput?.value;
projectTitleInput.closest('form')?.classList.remove('dirty');
const dividers = boardColumn.querySelectorAll(':scope > .divider');
const dividers = boardColumn.querySelectorAll<HTMLElement>(':scope > .divider');
if (projectColorInput.value) {
const color = contrastColor(projectColorInput.value);
boardColumn.style.setProperty('background', projectColorInput.value, 'important');
Expand Down
Loading

0 comments on commit ea6d4a6

Please sign in to comment.