2018-08-18 11:19:57 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-05 01:25:38 +00:00
|
|
|
module FormHelper
|
2020-03-02 18:07:42 +00:00
|
|
|
def form_errors(model, type: 'form', truncate: [])
|
2016-04-05 01:25:38 +00:00
|
|
|
return unless model.errors.any?
|
|
|
|
|
2019-04-04 17:05:25 +00:00
|
|
|
headline = n_('The %{type} contains the following error:', 'The %{type} contains the following errors:', model.errors.count) % { type: type }
|
2020-03-02 18:07:42 +00:00
|
|
|
truncate = Array.wrap(truncate)
|
2016-04-05 01:25:38 +00:00
|
|
|
|
|
|
|
content_tag(:div, class: 'alert alert-danger', id: 'error_explanation') do
|
|
|
|
content_tag(:h4, headline) <<
|
2016-12-15 22:14:20 +00:00
|
|
|
content_tag(:ul) do
|
2020-03-02 18:07:42 +00:00
|
|
|
messages = model.errors.map do |attribute, message|
|
2020-07-24 15:09:39 +00:00
|
|
|
message = html_escape_once(model.errors.full_message(attribute, message)).html_safe
|
2020-03-02 18:07:42 +00:00
|
|
|
message = content_tag(:span, message, class: 'str-truncated-100') if truncate.include?(attribute)
|
|
|
|
|
|
|
|
content_tag(:li, message)
|
|
|
|
end
|
|
|
|
|
|
|
|
messages.join.html_safe
|
2016-12-15 22:14:20 +00:00
|
|
|
end
|
2016-04-05 01:25:38 +00:00
|
|
|
end
|
|
|
|
end
|
2017-05-04 12:11:15 +00:00
|
|
|
|
2019-04-07 18:35:16 +00:00
|
|
|
def assignees_dropdown_options(issuable_type)
|
|
|
|
dropdown_data = {
|
2017-05-04 20:55:36 +00:00
|
|
|
toggle_class: 'js-user-search js-assignee-search js-multiselect js-save-user-data',
|
2017-05-04 12:11:15 +00:00
|
|
|
title: 'Select assignee',
|
|
|
|
filter: true,
|
|
|
|
dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-assignee',
|
2019-04-04 17:05:25 +00:00
|
|
|
placeholder: _('Search users'),
|
2017-05-04 12:11:15 +00:00
|
|
|
data: {
|
|
|
|
first_user: current_user&.username,
|
|
|
|
null_user: true,
|
|
|
|
current_user: true,
|
2019-04-07 18:35:16 +00:00
|
|
|
project_id: (@target_project || @project)&.id,
|
|
|
|
field_name: "#{issuable_type}[assignee_ids][]",
|
2017-06-11 16:38:10 +00:00
|
|
|
default_label: 'Unassigned',
|
2017-05-04 12:11:15 +00:00
|
|
|
'max-select': 1,
|
|
|
|
'dropdown-header': 'Assignee',
|
2017-05-04 20:55:36 +00:00
|
|
|
multi_select: true,
|
|
|
|
'input-meta': 'name',
|
|
|
|
'always-show-selectbox': true,
|
2017-09-19 18:22:43 +00:00
|
|
|
current_user_info: UserSerializer.new.represent(current_user)
|
2017-05-04 12:11:15 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-07 18:35:16 +00:00
|
|
|
|
|
|
|
type = issuable_type.to_s
|
|
|
|
|
|
|
|
if type == 'issue' && issue_supports_multiple_assignees? ||
|
|
|
|
type == 'merge_request' && merge_request_supports_multiple_assignees?
|
|
|
|
dropdown_data = multiple_assignees_dropdown_options(dropdown_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
dropdown_data
|
|
|
|
end
|
|
|
|
|
2020-09-14 12:09:34 +00:00
|
|
|
def reviewers_dropdown_options(issuable_type)
|
2020-10-07 15:08:40 +00:00
|
|
|
dropdown_data = {
|
2020-09-14 12:09:34 +00:00
|
|
|
toggle_class: 'js-reviewer-search js-multiselect js-save-user-data',
|
|
|
|
title: 'Request review from',
|
|
|
|
filter: true,
|
|
|
|
dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-reviewer',
|
|
|
|
placeholder: _('Search users'),
|
|
|
|
data: {
|
|
|
|
first_user: current_user&.username,
|
|
|
|
null_user: true,
|
|
|
|
current_user: true,
|
|
|
|
project_id: (@target_project || @project)&.id,
|
|
|
|
field_name: "#{issuable_type}[reviewer_ids][]",
|
|
|
|
default_label: 'Unassigned',
|
2020-10-07 15:08:40 +00:00
|
|
|
'max-select': 1,
|
|
|
|
'dropdown-header': 'Reviewer',
|
2020-09-14 12:09:34 +00:00
|
|
|
multi_select: true,
|
|
|
|
'input-meta': 'name',
|
|
|
|
'always-show-selectbox': true,
|
|
|
|
current_user_info: UserSerializer.new.represent(current_user)
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 15:08:40 +00:00
|
|
|
|
|
|
|
if merge_request_supports_multiple_reviewers?
|
|
|
|
dropdown_data = multiple_reviewers_dropdown_options(dropdown_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
dropdown_data
|
2020-09-14 12:09:34 +00:00
|
|
|
end
|
|
|
|
|
2019-04-07 18:35:16 +00:00
|
|
|
# Overwritten
|
|
|
|
def issue_supports_multiple_assignees?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Overwritten
|
|
|
|
def merge_request_supports_multiple_assignees?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2020-10-07 15:08:40 +00:00
|
|
|
# Overwritten
|
|
|
|
def merge_request_supports_multiple_reviewers?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2019-04-07 18:35:16 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def multiple_assignees_dropdown_options(options)
|
|
|
|
new_options = options.dup
|
|
|
|
|
|
|
|
new_options[:title] = 'Select assignee(s)'
|
|
|
|
new_options[:data][:'dropdown-header'] = 'Assignee(s)'
|
|
|
|
new_options[:data].delete(:'max-select')
|
|
|
|
|
|
|
|
new_options
|
2017-05-04 12:11:15 +00:00
|
|
|
end
|
2020-10-07 15:08:40 +00:00
|
|
|
|
|
|
|
def multiple_reviewers_dropdown_options(options)
|
|
|
|
new_options = options.dup
|
|
|
|
|
|
|
|
new_options[:title] = _('Select reviewer(s)')
|
|
|
|
new_options[:data][:'dropdown-header'] = _('Reviewer(s)')
|
|
|
|
new_options[:data].delete(:'max-select')
|
|
|
|
|
|
|
|
new_options
|
|
|
|
end
|
2016-04-05 01:25:38 +00:00
|
|
|
end
|
2020-05-14 12:08:21 +00:00
|
|
|
|
|
|
|
FormHelper.prepend_if_ee('::EE::FormHelper')
|