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