2023-02-18 21:06:14 -07:00
|
|
|
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
|
2022-01-28 14:00:11 -07:00
|
|
|
|
2024-02-19 15:34:35 -07: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-27 19:36:37 -06:00
|
|
|
|
2022-12-23 09:03:11 -07:00
|
|
|
export function initRepoMigration() {
|
2020-08-27 19:36:37 -06:00
|
|
|
checkAuth();
|
2021-04-08 16:25:57 -06:00
|
|
|
setLFSSettingsVisibility();
|
2020-08-27 19:36:37 -06:00
|
|
|
|
2024-02-19 15:34:35 -07: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-27 19:36:37 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAuth() {
|
2024-02-19 15:34:35 -07:00
|
|
|
if (!service) return;
|
|
|
|
const serviceType = Number(service.value);
|
2020-08-27 19:36:37 -06:00
|
|
|
|
2020-09-09 12:29:10 -06:00
|
|
|
checkItems(serviceType !== 1);
|
2020-08-27 19:36:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkItems(tokenAuth) {
|
|
|
|
let enableItems;
|
|
|
|
if (tokenAuth) {
|
2024-02-19 15:34:35 -07:00
|
|
|
enableItems = token?.value !== '';
|
2020-08-27 19:36:37 -06:00
|
|
|
} else {
|
2024-02-19 15:34:35 -07:00
|
|
|
enableItems = user?.value !== '' || pass?.value !== '';
|
2020-08-27 19:36:37 -06:00
|
|
|
}
|
2024-02-19 15:34:35 -07:00
|
|
|
if (enableItems && Number(service?.value) > 1) {
|
|
|
|
if (mirror?.checked) {
|
|
|
|
for (const item of items) {
|
|
|
|
item.disabled = item.name !== 'wiki';
|
|
|
|
}
|
2020-09-21 16:42:22 -06:00
|
|
|
return;
|
|
|
|
}
|
2024-02-19 15:34:35 -07:00
|
|
|
for (const item of items) item.disabled = false;
|
2020-08-27 19:36:37 -06:00
|
|
|
} else {
|
2024-02-19 15:34:35 -07:00
|
|
|
for (const item of items) item.disabled = true;
|
2020-08-27 19:36:37 -06:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 16:25:57 -06:00
|
|
|
|
|
|
|
function setLFSSettingsVisibility() {
|
2024-02-19 15:34:35 -07:00
|
|
|
if (!lfs) return;
|
|
|
|
const visible = lfs.checked;
|
|
|
|
toggleElem(lfsSettings, visible);
|
|
|
|
hideElem(lfsEndpoint);
|
2021-04-08 16:25:57 -06:00
|
|
|
}
|