![Filipa Lacerda](/assets/img/avatar_default.png)
* master: (623 commits) Fix issues with pdf-js dependencies fix missing changelog entries for security release on 2017-01-23 Update top bar issues icon Fix pipeline icon in contextual nav for projects Since mysql is not a priority anymore, test it less Fix order of CI lint ace editor loading Add container registry and spam logs icons Fix different Markdown styles Backport to CE for: Make new dropdown dividers full width Fix spec Fix spec Fix spec Bump GITLAB_SHELL_VERSION and GITALY_VERSION to support unhiding refs Add changelog Install yarn via apt in update guides Use long curl options fix Add a spec for concurrent process Remove monkey-patched Array.prototype.first() and last() methods ...
67 lines
1.8 KiB
JavaScript
67 lines
1.8 KiB
JavaScript
let hasUserDefinedProjectPath = false;
|
|
|
|
const deriveProjectPathFromUrl = ($projectImportUrl, $projectPath) => {
|
|
if (hasUserDefinedProjectPath) {
|
|
return;
|
|
}
|
|
|
|
let importUrl = $projectImportUrl.val().trim();
|
|
if (importUrl.length === 0) {
|
|
return;
|
|
}
|
|
|
|
/*
|
|
\/?: remove trailing slash
|
|
(\.git\/?)?: remove trailing .git (with optional trailing slash)
|
|
(\?.*)?: remove query string
|
|
(#.*)?: remove fragment identifier
|
|
*/
|
|
importUrl = importUrl.replace(/\/?(\.git\/?)?(\?.*)?(#.*)?$/, '');
|
|
|
|
// extract everything after the last slash
|
|
const pathMatch = /\/([^/]+)$/.exec(importUrl);
|
|
if (pathMatch) {
|
|
$projectPath.val(pathMatch[1]);
|
|
}
|
|
};
|
|
|
|
const bindEvents = () => {
|
|
const $newProjectForm = $('#new_project');
|
|
const $projectImportUrl = $('#project_import_url');
|
|
const $projectPath = $('#project_path');
|
|
|
|
if ($newProjectForm.length !== 1) {
|
|
return;
|
|
}
|
|
|
|
$('.how_to_import_link').on('click', (e) => {
|
|
e.preventDefault();
|
|
$('.how_to_import_link').next('.modal').show();
|
|
});
|
|
|
|
$('.modal-header .close').on('click', () => {
|
|
$('.modal').hide();
|
|
});
|
|
|
|
$('.btn_import_gitlab_project').on('click', () => {
|
|
const importHref = $('a.btn_import_gitlab_project').attr('href');
|
|
$('.btn_import_gitlab_project').attr('href', `${importHref}?namespace_id=${$('#project_namespace_id').val()}&path=${$projectPath.val()}`);
|
|
});
|
|
|
|
$newProjectForm.on('submit', () => {
|
|
$projectPath.val($projectPath.val().trim());
|
|
});
|
|
|
|
$projectPath.on('keyup', () => {
|
|
hasUserDefinedProjectPath = $projectPath.val().trim().length > 0;
|
|
});
|
|
|
|
$projectImportUrl.keyup(() => deriveProjectPathFromUrl($projectImportUrl, $projectPath));
|
|
};
|
|
|
|
document.addEventListener('DOMContentLoaded', bindEvents);
|
|
|
|
export default {
|
|
bindEvents,
|
|
deriveProjectPathFromUrl,
|
|
};
|