diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/form_helper.rb | 33 | ||||
-rw-r--r-- | app/helpers/issuables_helper.rb | 10 |
2 files changed, 43 insertions, 0 deletions
diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb index 1182939f656..639a720b024 100644 --- a/app/helpers/form_helper.rb +++ b/app/helpers/form_helper.rb @@ -15,4 +15,37 @@ module FormHelper end end end + + def issue_dropdown_options(issuable, has_multiple_assignees = true) + options = { + toggle_class: 'js-user-search js-assignee-search', + title: 'Select assignee', + filter: true, + dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-assignee', + placeholder: 'Search users', + data: { + first_user: current_user&.username, + null_user: true, + current_user: true, + project_id: issuable.project.try(:id), + field_name: "#{issuable.class.model_name.param_key}[assignee_ids][]", + default_label: 'Assignee', + 'max-select': 1, + 'dropdown-header': 'Assignee', + } + } + + if has_multiple_assignees + options[:toggle_class] += ' js-multiselect js-save-user-data' + options[:title] = 'Select assignee(s)' + options[:data][:multi_select] = true + options[:data][:'input-meta'] = 'name' + options[:data][:'always-show-selectbox'] = true + options[:data][:current_user_info] = current_user.to_json(only: [:id, :name]) + options[:data][:'dropdown-header'] = 'Assignee(s)' + options[:data].delete(:'max-select') + end + + options + end end diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index 0b13dbf5f8d..7656929efe7 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -63,6 +63,16 @@ module IssuablesHelper end end + def users_dropdown_label(selected_users) + if selected_users.length == 0 + "Unassigned" + elsif selected_users.length == 1 + selected_users[0].name + else + "#{selected_users[0].name} + #{selected_users.length - 1} more" + end + end + def user_dropdown_label(user_id, default_label) return default_label if user_id.nil? return "Unassigned" if user_id == "0" |