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