More code cleanups

This commit is contained in:
Alexander Meindl
2020-08-09 10:11:52 +02:00
parent 39ee9e4805
commit cc26243a64
11 changed files with 38 additions and 38 deletions

View File

@@ -8,7 +8,7 @@ module AdditionalsFontawesomeHelper
# post_text # post_text
# title # title
def font_awesome_icon(name, options = {}) def font_awesome_icon(name, options = {})
info = AdditionalsFontAwesome.value_info(name) info = AdditionalsFontAwesome.value_info name
return '' if info.blank? return '' if info.blank?
post_text = '' post_text = ''
@@ -23,18 +23,18 @@ module AdditionalsFontawesomeHelper
if options[:pre_text].present? if options[:pre_text].present?
s << options[:pre_text] s << options[:pre_text]
s << ' ' s << ' '
options.delete(:pre_text) options.delete :pre_text
end end
if options[:post_text].present? if options[:post_text].present?
post_text = options[:post_text] post_text = options[:post_text]
options.delete(:post_text) options.delete :post_text
end end
s << tag.span(options) s << tag.span(options)
if post_text.present? if post_text.present?
s << ' ' s << ' '
s << post_text s << post_text
end end
safe_join(s) safe_join s
end end
def additionals_fontawesome_select(form, selected, options = {}) def additionals_fontawesome_select(form, selected, options = {})
@@ -56,7 +56,7 @@ module AdditionalsFontawesomeHelper
s << additionals_fontawesome_loader(options, html_options) if loader s << additionals_fontawesome_loader(options, html_options) if loader
safe_join(s) safe_join s
end end
def additionals_fontawesome_add_selected(selected) def additionals_fontawesome_add_selected(selected)

View File

@@ -7,7 +7,7 @@ module AdditionalsIssuesHelper
unless entity.nil? unless entity.nil?
current_author_found = authors.detect { |u| u.id == entity.author_id_was } current_author_found = authors.detect { |u| u.id == entity.author_id_was }
if current_author_found.blank? if current_author_found.blank?
current_author = User.find_by(id: entity.author_id_was) current_author = User.find_by id: entity.author_id_was
authors << current_author if current_author authors << current_author if current_author
end end
end end
@@ -23,7 +23,7 @@ module AdditionalsIssuesHelper
s << tag.option(entity.author, value: entity.author_id, selected: true) if entity.author && authors.exclude?(entity.author) s << tag.option(entity.author, value: entity.author_id, selected: true) if entity.author && authors.exclude?(entity.author)
s << options_from_collection_for_select(authors, 'id', 'name', entity.author_id) s << options_from_collection_for_select(authors, 'id', 'name', entity.author_id)
end end
safe_join(s) safe_join s
end end
def show_issue_change_author?(issue) def show_issue_change_author?(issue)

View File

@@ -48,7 +48,7 @@ module AdditionalsJournalsHelper
entity_type = entity.model_name.param_key entity_type = entity.model_name.param_key
safe_join([link_to(l(:button_edit), safe_join [link_to(l(:button_edit),
send("edit_#{entity_type}_journal_path", journal), send("edit_#{entity_type}_journal_path", journal),
remote: true, remote: true,
method: 'get', method: 'get',
@@ -59,6 +59,6 @@ module AdditionalsJournalsHelper
remote: true, remote: true,
method: 'put', data: { confirm: l(:text_are_you_sure) }, method: 'put', data: { confirm: l(:text_are_you_sure) },
title: l(:button_delete), title: l(:button_delete),
class: 'icon-only icon-del')], ' ') class: 'icon-only icon-del')], ' '
end end
end end

View File

@@ -177,7 +177,7 @@ module AdditionalsMenuHelper
s = [] s = []
pages.each_with_index do |item, idx| pages.each_with_index do |item, idx|
s << if item[:title] == '-' s << if item[:title] == '-'
tag.li(tag.hr) tag.li tag.hr
else else
html_options = { class: "help_item_#{idx}" } html_options = { class: "help_item_#{idx}" }
if item[:url].include? '://' if item[:url].include? '://'
@@ -187,7 +187,7 @@ module AdditionalsMenuHelper
tag.li(link_to(item[:title], item[:url], html_options)) tag.li(link_to(item[:title], item[:url], html_options))
end end
end end
safe_join(s) safe_join s
end end
# Plugin help items definition for plugins, # Plugin help items definition for plugins,

View File

@@ -14,8 +14,8 @@ module AdditionalsSettingsHelper
def additionals_settings_checkbox(name, options = {}) def additionals_settings_checkbox(name, options = {})
label_title = options.delete(:label).presence || l("label_#{name}") label_title = options.delete(:label).presence || l("label_#{name}")
value = options.delete(:value) value = options.delete :value
value_is_bool = options.delete(:value_is_bool) value_is_bool = options.delete :value_is_bool
custom_value = if value.nil? custom_value = if value.nil?
value = 1 value = 1
false false
@@ -27,13 +27,13 @@ module AdditionalsSettingsHelper
checked = if custom_value && !value_is_bool checked = if custom_value && !value_is_bool
@settings[name] @settings[name]
else else
Additionals.true?(@settings[name]) Additionals.true? @settings[name]
end end
s = [label_tag("settings[#{name}]", label_title)] s = [label_tag("settings[#{name}]", label_title)]
s << hidden_field_tag("settings[#{name}]", 0, id: nil) if !custom_value || value_is_bool s << hidden_field_tag("settings[#{name}]", 0, id: nil) if !custom_value || value_is_bool
s << check_box_tag("settings[#{name}]", value, checked, options) s << check_box_tag("settings[#{name}]", value, checked, options)
safe_join(s) safe_join s
end end
def additionals_settings_textfield(name, options = {}) def additionals_settings_textfield(name, options = {})

View File

@@ -21,7 +21,7 @@ module AdditionalsTagHelper
' ' ' '
end end
tag.div(safe_join(s, sep), class: 'tags') tag.div safe_join(s, sep), class: 'tags'
end end
# plain list of tags # plain list of tags
@@ -44,7 +44,7 @@ module AdditionalsTagHelper
end end
safe_join(tag_list.map do |tag| safe_join(tag_list.map do |tag|
additionals_tag_link(tag, options) additionals_tag_link tag, options
end, sep) end, sep)
end end
@@ -61,14 +61,14 @@ module AdditionalsTagHelper
tag_name << tag.span("(#{tag_object.count})", class: 'tag-count') if options[:show_count] tag_name << tag.span("(#{tag_object.count})", class: 'tag-count') if options[:show_count]
if options[:tags_without_color] if options[:tags_without_color]
tag.span(link_to(safe_join(tag_name), additionals_tag_url(tag_object.name, options)), tag.span link_to(safe_join(tag_name), additionals_tag_url(tag_object.name, options)),
class: 'tag-label') class: 'tag-label'
else else
tag.span(link_to(safe_join(tag_name), tag.span link_to(safe_join(tag_name),
additionals_tag_url(tag_object.name, options), additionals_tag_url(tag_object.name, options),
style: tag_style), style: tag_style),
class: 'additionals-tag-label-color', class: 'additionals-tag-label-color',
style: tag_style) style: tag_style
end end
end end

View File

@@ -11,7 +11,7 @@ module Additionals
end end
title << options[:name] if options[:name] title << options[:name] if options[:name]
title << h(options[:query].name) if options[:query] && !options[:query].new_record? title << h(options[:query].name) if options[:query] && !options[:query].new_record?
safe_join(title, Additionals::LIST_SEPARATOR) safe_join title, Additionals::LIST_SEPARATOR
end end
def additionals_title_for_locale(title, lang) def additionals_title_for_locale(title, lang)
@@ -139,7 +139,7 @@ module Additionals
Array(module_names).each do |module_name| Array(module_names).each do |module_name|
s << send("additionals_load_#{module_name}") s << send("additionals_load_#{module_name}")
end end
safe_join(s) safe_join s
end end
def system_uptime def system_uptime
@@ -207,7 +207,7 @@ module Additionals
locals: { field_id: sanitize_to_id(name), locals: { field_id: sanitize_to_id(name),
ajax_url: send("#{type}_path", project_id: options[:project], user_id: options[:user_id]), ajax_url: send("#{type}_path", project_id: options[:project], user_id: options[:user_id]),
options: options }) options: options })
safe_join(s) safe_join s
end end
def project_list_css_classes(project, level) def project_list_css_classes(project, level)
@@ -301,8 +301,8 @@ module Additionals
if user.type == 'Group' if user.type == 'Group'
if options[:no_link] if options[:no_link]
user.name user.name
elsif Redmine::Plugin.installed?('redmine_hrm') elsif Redmine::Plugin.installed? 'redmine_hrm'
link_to_hrm_group(user) link_to_hrm_group user
else else
user.name user.name
end end
@@ -314,9 +314,9 @@ module Additionals
s << if options[:no_link] s << if options[:no_link]
user.name user.name
else else
link_to_user(user) link_to_user user
end end
safe_join(s) safe_join s
end end
end end

View File

@@ -28,7 +28,7 @@ module Additionals
raise '<link> is not a Google document.' unless v.start_with? 'https://docs.google.com/' raise '<link> is not a Google document.' unless v.start_with? 'https://docs.google.com/'
src = v.dup src = v.dup
unless src.include?('?') unless src.include? '?'
src << if src.include?('edit') src << if src.include?('edit')
'?rm=minimal' '?rm=minimal'
else else
@@ -47,7 +47,7 @@ module Additionals
class: 'external') class: 'external')
end end
safe_join(s) safe_join s
end end
end end
end end

View File

@@ -36,7 +36,7 @@ module Additionals
if !options[:with_link].nil? && Additionals.true?(options[:with_link]) if !options[:with_link].nil? && Additionals.true?(options[:with_link])
s << link_to(l(:label_open_in_new_windows), src, class: 'external') s << link_to(l(:label_open_in_new_windows), src, class: 'external')
end end
safe_join(s) safe_join s
elsif Setting.protocol == 'https' elsif Setting.protocol == 'https'
raise 'Invalid url provided to iframe (only full URLs with protocol HTTPS are accepted)' raise 'Invalid url provided to iframe (only full URLs with protocol HTTPS are accepted)'
else else

View File

@@ -10,8 +10,8 @@ module Additionals
macro :last_updated_by do |obj, args| macro :last_updated_by do |obj, args|
raise 'The correct usage is {{last_updated_by}}' unless args.empty? raise 'The correct usage is {{last_updated_by}}' unless args.empty?
tag.span(safe_join([avatar(obj.author, size: 14), ' ', link_to_user(obj.author)]), tag.span safe_join([avatar(obj.author, size: 14), ' ', link_to_user(obj.author)]),
class: 'last-updated-by') class: 'last-updated-by'
end end
end end
end end

View File

@@ -25,14 +25,14 @@ module Additionals
user_id = args[0] user_id = args[0]
user = User.find_by(id: user_id) user = User.find_by id: user_id
user ||= User.find_by(login: user_id) user ||= User.find_by(login: user_id)
return if user.nil? return if user.nil?
name = if options[:format].blank? name = if options[:format].blank?
user.name user.name
else else
user.name(options[:format].to_sym) user.name options[:format].to_sym
end end
s = [] s = []
@@ -42,11 +42,11 @@ module Additionals
end end
s << if user.active? s << if user.active?
link_to(h(name), user_url(user, only_path: controller_path != 'mailer'), class: user.css_classes) link_to h(name), user_url(user, only_path: controller_path != 'mailer'), class: user.css_classes
else else
h(name) h name
end end
safe_join(s) safe_join s
end end
end end
end end