Commit 254c5aaa authored by James Lopez's avatar James Lopez

few fixes based on MR feedback

parent 173b1128
......@@ -10,24 +10,24 @@
ImporterStatus.prototype.initStatusPage = function() {
$('.js-add-to-import').off('click').on('click', (function(_this) {
return function(e) {
var $btn, $namespace_input, $target_field, $tr, id, target_namespace;
var $btn, $namespace_input, $target_field, $tr, id, target_namespace, newName;
$btn = $(e.currentTarget);
$tr = $btn.closest('tr');
$target_field = $tr.find('.import-target');
$namespace_input = $target_field.find('.js-select-namespace option:selected');
id = $tr.attr('id').replace('repo_', '');
target_namespace = null;
new_name = null;
newName = null;
if ($namespace_input.length > 0) {
target_namespace = $namespace_input[0].innerHTML;
new_name = $target_field.find('#path').prop('value');
$target_field.empty().append(target_namespace + "/" + new_name);
newName = $target_field.find('#path').prop('value');
$target_field.empty().append(target_namespace + "/" + newName);
}
$btn.disable().addClass('is-loading');
return $.post(_this.import_url, {
repo_id: id,
target_namespace: target_namespace,
new_name: new_name
new_name: newName
}, {
dataType: 'script'
});
......
module NamespacesHelper
def namespaces_options(selected = :current_user, extra_groups = [], display_path: false)
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil)
groups = current_user.owned_groups + current_user.masters_groups
groups += process_extra_groups(extra_groups) if extra_groups.any?
groups << extra_group if extra_group && !Group.exists?(name: extra_group.name)
users = [current_user.namespace]
......@@ -28,15 +28,6 @@ module NamespacesHelper
grouped_options_for_select(options, selected)
end
def process_extra_groups(extra_groups)
# Remove duplicate groups - we either keep the ones that exist for the user
# (already in groups) or ignore those that do not belong to the user.
duplicated_groups = extra_groups.map { |name| Namespace.where(name: name).pluck(:name) }
extra_groups = extra_groups - duplicated_groups.flatten
extra_groups.map { |name| Group.new(name: name) }
end
def namespace_icon(namespace, size = 40)
if namespace.kind_of?(Group)
group_icon(namespace)
......
......@@ -48,10 +48,10 @@
%fieldset.row
.input-group
.col-xs-11.col-sm-5.project-path
- if current_user.can_select_namespace? && !current_user.can_create_group?
= select_tag :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {class: 'project-path select2 js-select-namespace', tabindex: 1}
- elsif current_user.can_create_group?
= select_tag :namespace_id, namespaces_options(params[:namespace_id] || :current_user, [repo.owner.login]), {class: 'project-path select2 js-select-namespace', tabindex: 1}
- if current_user.can_select_namespace?
- selected = params[:namespace_id] || :current_user
- opts = current_user.can_create_group? ? { extra_groups: [repo.owner.login] } : { display_path: true }
= select_tag :namespace_id, namespaces_options(selected, opts), {class: 'project-path select2 js-select-namespace', tabindex: 1}
- else
= text_field_tag :path, current_user.namespace_path, class: "form-control", tabindex: 2, autofocus: true, disabled: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment