2022-01-29 02:30:11 +05:30
|
|
|
import $ from 'jquery';
|
|
|
|
|
2020-08-28 07:06:37 +05:30
|
|
|
const $service = $('#service_type');
|
|
|
|
const $user = $('#auth_username');
|
|
|
|
const $pass = $('#auth_password');
|
|
|
|
const $token = $('#auth_token');
|
2020-09-22 04:12:22 +05:30
|
|
|
const $mirror = $('#mirror');
|
2021-04-09 03:55:57 +05:30
|
|
|
const $lfs = $('#lfs');
|
|
|
|
const $lfsSettings = $('#lfs_settings');
|
|
|
|
const $lfsEndpoint = $('#lfs_endpoint');
|
2020-09-22 04:12:22 +05:30
|
|
|
const $items = $('#migrate_items').find('input[type=checkbox]');
|
2020-08-28 07:06:37 +05:30
|
|
|
|
2021-11-09 14:57:25 +05:30
|
|
|
export default function initRepoMigration() {
|
2020-08-28 07:06:37 +05:30
|
|
|
checkAuth();
|
2021-04-09 03:55:57 +05:30
|
|
|
setLFSSettingsVisibility();
|
2020-08-28 07:06:37 +05:30
|
|
|
|
|
|
|
$user.on('keyup', () => {checkItems(false)});
|
|
|
|
$pass.on('keyup', () => {checkItems(false)});
|
|
|
|
$token.on('keyup', () => {checkItems(true)});
|
2020-09-22 04:12:22 +05:30
|
|
|
$mirror.on('change', () => {checkItems(true)});
|
2021-04-09 03:55:57 +05:30
|
|
|
$('#lfs_settings_show').on('click', () => { $lfsEndpoint.show(); return false });
|
|
|
|
$lfs.on('change', setLFSSettingsVisibility);
|
2020-08-28 07:06:37 +05:30
|
|
|
|
|
|
|
const $cloneAddr = $('#clone_addr');
|
|
|
|
$cloneAddr.on('change', () => {
|
|
|
|
const $repoName = $('#repo_name');
|
|
|
|
if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
|
|
|
|
$repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkAuth() {
|
|
|
|
const serviceType = $service.val();
|
|
|
|
|
2020-09-09 23:59:10 +05:30
|
|
|
checkItems(serviceType !== 1);
|
2020-08-28 07:06:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function checkItems(tokenAuth) {
|
|
|
|
let enableItems;
|
|
|
|
if (tokenAuth) {
|
|
|
|
enableItems = $token.val() !== '';
|
|
|
|
} else {
|
|
|
|
enableItems = $user.val() !== '' || $pass.val() !== '';
|
|
|
|
}
|
|
|
|
if (enableItems && $service.val() > 1) {
|
2020-09-22 04:12:22 +05:30
|
|
|
if ($mirror.is(':checked')) {
|
|
|
|
$items.not('[name="wiki"]').attr('disabled', true);
|
|
|
|
$items.filter('[name="wiki"]').attr('disabled', false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$items.attr('disabled', false);
|
2020-08-28 07:06:37 +05:30
|
|
|
} else {
|
2020-09-22 04:12:22 +05:30
|
|
|
$items.attr('disabled', true);
|
2020-08-28 07:06:37 +05:30
|
|
|
}
|
|
|
|
}
|
2021-04-09 03:55:57 +05:30
|
|
|
|
|
|
|
function setLFSSettingsVisibility() {
|
|
|
|
const visible = $lfs.is(':checked');
|
|
|
|
$lfsSettings.toggle(visible);
|
|
|
|
$lfsEndpoint.hide();
|
|
|
|
}
|