mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.7 KiB
84 lines
2.7 KiB
3 years ago
|
import $ from 'jquery';
|
||
5 months ago
|
import {hideElem, queryElems, showElem} from '../utils/dom.ts';
|
||
|
import {POST} from '../modules/fetch.ts';
|
||
|
import {showErrorToast} from '../modules/toast.ts';
|
||
|
import {sleep} from '../utils.ts';
|
||
3 years ago
|
|
||
7 months ago
|
async function onDownloadArchive(e) {
|
||
|
e.preventDefault();
|
||
|
// there are many places using the "archive-link", eg: the dropdown on the repo code page, the release list
|
||
|
const el = e.target.closest('a.archive-link[href]');
|
||
|
const targetLoading = el.closest('.ui.dropdown') ?? el;
|
||
|
targetLoading.classList.add('is-loading', 'loading-icon-2px');
|
||
9 months ago
|
try {
|
||
7 months ago
|
for (let tryCount = 0; ;tryCount++) {
|
||
|
const response = await POST(el.href);
|
||
|
if (!response.ok) throw new Error(`Invalid server response: ${response.status}`);
|
||
3 years ago
|
|
||
7 months ago
|
const data = await response.json();
|
||
|
if (data.complete) break;
|
||
|
await sleep(Math.min((tryCount + 1) * 750, 2000));
|
||
9 months ago
|
}
|
||
7 months ago
|
window.location.href = el.href; // the archive is ready, start real downloading
|
||
|
} catch (e) {
|
||
|
console.error(e);
|
||
|
showErrorToast(`Failed to download the archive: ${e}`, {duration: 2500});
|
||
|
} finally {
|
||
|
targetLoading.classList.remove('is-loading', 'loading-icon-2px');
|
||
9 months ago
|
}
|
||
3 years ago
|
}
|
||
|
|
||
|
export function initRepoArchiveLinks() {
|
||
7 months ago
|
queryElems('a.archive-link[href]', (el) => el.addEventListener('click', onDownloadArchive));
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
export function initRepoCloneLink() {
|
||
|
const $repoCloneSsh = $('#repo-clone-ssh');
|
||
|
const $repoCloneHttps = $('#repo-clone-https');
|
||
|
const $inputLink = $('#repo-clone-url');
|
||
|
|
||
|
if ((!$repoCloneSsh.length && !$repoCloneHttps.length) || !$inputLink.length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
$repoCloneSsh.on('click', () => {
|
||
3 years ago
|
localStorage.setItem('repo-clone-protocol', 'ssh');
|
||
2 years ago
|
window.updateCloneStates();
|
||
3 years ago
|
});
|
||
3 years ago
|
$repoCloneHttps.on('click', () => {
|
||
|
localStorage.setItem('repo-clone-protocol', 'https');
|
||
2 years ago
|
window.updateCloneStates();
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
2 years ago
|
$inputLink.on('focus', () => {
|
||
2 years ago
|
$inputLink.trigger('select');
|
||
3 years ago
|
});
|
||
|
}
|
||
|
|
||
|
export function initRepoCommonBranchOrTagDropdown(selector) {
|
||
3 years ago
|
$(selector).each(function () {
|
||
3 years ago
|
const $dropdown = $(this);
|
||
|
$dropdown.find('.reference.column').on('click', function () {
|
||
2 years ago
|
hideElem($dropdown.find('.scrolling.reference-list-menu'));
|
||
|
showElem($($(this).data('target')));
|
||
3 years ago
|
return false;
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function initRepoCommonFilterSearchDropdown(selector) {
|
||
3 years ago
|
const $dropdown = $(selector);
|
||
8 months ago
|
if (!$dropdown.length) return;
|
||
|
|
||
3 years ago
|
$dropdown.dropdown({
|
||
3 years ago
|
fullTextSearch: 'exact',
|
||
3 years ago
|
selectOnKeydown: false,
|
||
|
onChange(_text, _value, $choice) {
|
||
8 months ago
|
if ($choice[0].getAttribute('data-url')) {
|
||
|
window.location.href = $choice[0].getAttribute('data-url');
|
||
3 years ago
|
}
|
||
|
},
|
||
8 months ago
|
message: {noResults: $dropdown[0].getAttribute('data-no-results')},
|
||
3 years ago
|
});
|
||
|
}
|