2024-07-07 15:32:30 +00:00
|
|
|
import {hideElem, showElem, toggleElem} from '../utils/dom.ts';
|
2022-01-28 21:00:11 +00:00
|
|
|
|
2024-06-10 20:49:33 +00:00
|
|
|
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');
|
2024-02-19 22:34:35 +00:00
|
|
|
const items = document.querySelectorAll('#migrate_items input[type=checkbox]');
|
2020-08-28 01:36:37 +00:00
|
|
|
|
2022-12-23 16:03:11 +00:00
|
|
|
export function initRepoMigration() {
|
2020-08-28 01:36:37 +00:00
|
|
|
checkAuth();
|
2021-04-08 22:25:57 +00:00
|
|
|
setLFSSettingsVisibility();
|
2020-08-28 01:36:37 +00:00
|
|
|
|
2024-02-19 22:34:35 +00:00
|
|
|
user?.addEventListener('input', () => {checkItems(false)});
|
|
|
|
pass?.addEventListener('input', () => {checkItems(false)});
|
|
|
|
token?.addEventListener('input', () => {checkItems(true)});
|
|
|
|
mirror?.addEventListener('change', () => {checkItems(true)});
|
2024-06-10 20:49:33 +00:00
|
|
|
document.querySelector('#lfs_settings_show')?.addEventListener('click', (e) => {
|
2024-02-19 22:34:35 +00:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
showElem(lfsEndpoint);
|
|
|
|
});
|
|
|
|
lfs?.addEventListener('change', setLFSSettingsVisibility);
|
|
|
|
|
2024-06-10 20:49:33 +00:00
|
|
|
const cloneAddr = document.querySelector('#clone_addr');
|
2024-02-19 22:34:35 +00:00
|
|
|
cloneAddr?.addEventListener('change', () => {
|
2024-06-10 20:49:33 +00:00
|
|
|
const repoName = document.querySelector('#repo_name');
|
2024-02-19 22:34:35 +00:00
|
|
|
if (cloneAddr.value && !repoName?.value) { // Only modify if repo_name input is blank
|
|
|
|
repoName.value = cloneAddr.value.match(/^(.*\/)?((.+?)(\.git)?)$/)[3];
|
2020-08-28 01:36:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAuth() {
|
2024-02-19 22:34:35 +00:00
|
|
|
if (!service) return;
|
|
|
|
const serviceType = Number(service.value);
|
2020-08-28 01:36:37 +00:00
|
|
|
|
2020-09-09 18:29:10 +00:00
|
|
|
checkItems(serviceType !== 1);
|
2020-08-28 01:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkItems(tokenAuth) {
|
|
|
|
let enableItems;
|
|
|
|
if (tokenAuth) {
|
2024-02-19 22:34:35 +00:00
|
|
|
enableItems = token?.value !== '';
|
2020-08-28 01:36:37 +00:00
|
|
|
} else {
|
2024-02-19 22:34:35 +00:00
|
|
|
enableItems = user?.value !== '' || pass?.value !== '';
|
2020-08-28 01:36:37 +00:00
|
|
|
}
|
2024-02-19 22:34:35 +00:00
|
|
|
if (enableItems && Number(service?.value) > 1) {
|
|
|
|
if (mirror?.checked) {
|
|
|
|
for (const item of items) {
|
|
|
|
item.disabled = item.name !== 'wiki';
|
|
|
|
}
|
2020-09-21 22:42:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-02-19 22:34:35 +00:00
|
|
|
for (const item of items) item.disabled = false;
|
2020-08-28 01:36:37 +00:00
|
|
|
} else {
|
2024-02-19 22:34:35 +00:00
|
|
|
for (const item of items) item.disabled = true;
|
2020-08-28 01:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 22:25:57 +00:00
|
|
|
|
|
|
|
function setLFSSettingsVisibility() {
|
2024-02-19 22:34:35 +00:00
|
|
|
if (!lfs) return;
|
|
|
|
const visible = lfs.checked;
|
|
|
|
toggleElem(lfsSettings, visible);
|
|
|
|
hideElem(lfsEndpoint);
|
2021-04-08 22:25:57 +00:00
|
|
|
}
|