debian-mirror-gitlab/app/assets/javascripts/projects/project_import_gitlab_project.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2020-03-13 15:44:24 +05:30
import { convertToTitleCase, humanize, slugify } from '../lib/utils/text_utility';
2018-03-17 18:26:18 +05:30
import { getParameterValues } from '../lib/utils/url_utility';
2018-11-20 20:47:30 +05:30
import projectNew from './project_new';
2017-09-10 17:25:29 +05:30
2020-03-13 15:44:24 +05:30
const prepareParameters = () => {
const name = getParameterValues('name')[0];
const path = getParameterValues('path')[0];
// If the name param exists but the path doesn't then generate it from the name
if (name && !path) {
return { name, path: slugify(name) };
}
// If the path param exists but the name doesn't then generate it from the path
if (path && !name) {
return { name: convertToTitleCase(humanize(path, '-')), path };
}
return { name, path };
};
2018-03-27 19:54:05 +05:30
export default () => {
2020-03-13 15:44:24 +05:30
let hasUserDefinedProjectName = false;
2018-11-20 20:47:30 +05:30
const $projectName = $('.js-project-name');
2020-03-13 15:44:24 +05:30
const $projectPath = $('.js-path-name');
const { name, path } = prepareParameters();
2018-11-20 20:47:30 +05:30
// get the project name from the URL and set it as input value
2020-03-13 15:44:24 +05:30
$projectName.val(name);
// get the path url and append it in the input
$projectPath.val(path);
2018-11-20 20:47:30 +05:30
// generate slug when project name changes
2020-03-13 15:44:24 +05:30
$projectName.on('keyup', () => {
projectNew.onProjectNameChange($projectName, $projectPath);
hasUserDefinedProjectName = $projectName.val().trim().length > 0;
});
// generate project name from the slug if one isn't set
$projectPath.on('keyup', () =>
projectNew.onProjectPathChange($projectName, $projectPath, hasUserDefinedProjectName),
);
2017-09-10 17:25:29 +05:30
};