summaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/application_helper.rb10
-rw-r--r--app/helpers/avatars_helper.rb61
-rw-r--r--app/helpers/icons_helper.rb25
-rw-r--r--app/helpers/issues_helper.rb1
-rw-r--r--app/helpers/journals_helper.rb8
-rw-r--r--app/helpers/messages_helper.rb1
-rw-r--r--app/helpers/news_helper.rb1
-rw-r--r--app/helpers/principal_memberships_helper.rb18
-rw-r--r--app/helpers/projects_helper.rb4
-rw-r--r--app/helpers/queries_helper.rb2
-rw-r--r--app/helpers/reactions_helper.rb100
-rw-r--r--app/helpers/reports_helper.rb4
-rw-r--r--app/helpers/routes_helper.rb62
-rw-r--r--app/helpers/settings_helper.rb3
-rw-r--r--app/helpers/watchers_helper.rb4
15 files changed, 219 insertions, 85 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 7835bf235..ab418fb38 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -128,7 +128,7 @@ module ApplicationHelper
# * :download - Force download (default: false)
def link_to_attachment(attachment, options={})
text = options.delete(:text) || attachment.filename
- icon = options.fetch(:icon, false)
+ icon = options.delete(:icon)
if options.delete(:download)
route_method = :download_named_attachment_url
@@ -518,6 +518,8 @@ module ApplicationHelper
def render_flash_messages
s = +''
flash.each do |k, v|
+ next unless v.is_a?(String)
+
s << content_tag('div', notice_icon(k) + v.html_safe, :class => "flash #{k}", :id => "flash_#{k}")
end
s.html_safe
@@ -789,7 +791,7 @@ module ApplicationHelper
end
def other_formats_links(&)
- concat('<p class="other-formats">'.html_safe + l(:label_export_to))
+ concat('<p class="other-formats hide-when-print">'.html_safe + l(:label_export_to))
yield Redmine::Views::OtherFormatsBuilder.new(self)
concat('</p>'.html_safe)
end
@@ -1386,7 +1388,7 @@ module ApplicationHelper
<|
$)
}x
- HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
+ HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/im unless const_defined?(:HEADING_RE)
def parse_sections(text, project, obj, attr, only_path, options)
return unless options[:edit_section_links]
@@ -1805,7 +1807,7 @@ module ApplicationHelper
if Setting.wiki_tablesort_enabled?
tags << javascript_include_tag('tablesort-5.2.1.min.js', 'tablesort-5.2.1.number.min.js')
end
- tags << javascript_include_tag('application', 'responsive')
+ tags << javascript_include_tag('application-legacy', 'responsive')
unless User.current.pref.warn_on_leaving_unsaved == '0'
warn_text = escape_javascript(l(:text_warn_on_leaving_unsaved))
tags <<
diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb
index b39427bda..67567fd8d 100644
--- a/app/helpers/avatars_helper.rb
+++ b/app/helpers/avatars_helper.rb
@@ -38,24 +38,9 @@ module AvatarsHelper
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
def avatar(user, options = {})
if Setting.gravatar_enabled?
- options[:default] = Setting.gravatar_default
- options[:class] = GravatarHelper::DEFAULT_OPTIONS[:class] + " " + options[:class] if options[:class]
- email = nil
- if user.respond_to?(:mail)
- email = user.mail
- options[:title] = user.name unless options[:title]
- elsif user.to_s =~ %r{<(.+?)>}
- email = $1
- end
- if email.present?
- gravatar(email.to_s.downcase, options) rescue nil
- elsif user.is_a?(AnonymousUser)
- anonymous_avatar(options)
- elsif user.is_a?(Group)
- group_avatar(options)
- else
- nil
- end
+ gravatar_avatar_tag(user, options)
+ elsif user.respond_to?(:initials)
+ initials_avatar_tag(user, options)
else
''
end
@@ -69,8 +54,6 @@ module AvatarsHelper
end
end
- private
-
def anonymous_avatar(options={})
image_tag 'anonymous.png', GravatarHelper::DEFAULT_OPTIONS.except(:default, :rating, :ssl).merge(options)
end
@@ -78,4 +61,42 @@ module AvatarsHelper
def group_avatar(options={})
image_tag 'group.png', GravatarHelper::DEFAULT_OPTIONS.except(:default, :rating, :ssl).merge(options)
end
+
+ private
+
+ def gravatar_avatar_tag(user, options)
+ options[:default] = Setting.gravatar_default
+ options[:class] = [GravatarHelper::DEFAULT_OPTIONS[:class], options[:class]].compact.join(' ')
+
+ email = extract_email_from_user(user)
+
+ if user.respond_to?(:mail)
+ options[:title] ||= user.name
+ options[:initials] = user.initials if options[:default] == "initials" && user.initials.present?
+ end
+
+ if email.present?
+ gravatar(email.to_s.downcase, options) rescue nil
+ elsif user.is_a?(AnonymousUser)
+ anonymous_avatar(options)
+ elsif user.is_a?(Group)
+ group_avatar(options)
+ end
+ end
+
+ def initials_avatar_tag(user, options)
+ size = (options.delete(:size) || GravatarHelper::DEFAULT_OPTIONS[:size]).to_i
+
+ css_class = ["avatar-color-#{user.id % 8}", 'avatar', "s#{size}", options[:class]].compact.join(' ')
+
+ content_tag('span', user.initials, role: 'img', class: css_class, title: options[:title])
+ end
+
+ def extract_email_from_user(user)
+ if user.respond_to?(:mail)
+ user.mail
+ elsif user.to_s =~ %r{<(.+?)>}
+ $1
+ end
+ end
end
diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb
index 077bae158..6afb84537 100644
--- a/app/helpers/icons_helper.rb
+++ b/app/helpers/icons_helper.rb
@@ -21,10 +21,10 @@ module IconsHelper
DEFAULT_ICON_SIZE = "18"
DEFAULT_SPRITE = "icons"
- def sprite_icon(icon_name, label = nil, icon_only: false, size: DEFAULT_ICON_SIZE, css_class: nil, sprite: DEFAULT_SPRITE, plugin: nil, rtl: false)
+ def sprite_icon(icon_name, label = nil, icon_only: false, size: DEFAULT_ICON_SIZE, style: :outline, css_class: nil, sprite: DEFAULT_SPRITE, plugin: nil, rtl: false)
sprite = plugin ? "plugin_assets/#{plugin}/#{sprite}.svg" : "#{sprite}.svg"
- svg_icon = svg_sprite_icon(icon_name, size: size, css_class: css_class, sprite: sprite, rtl: rtl)
+ svg_icon = svg_sprite_icon(icon_name, size: size, style: style, css_class: css_class, sprite: sprite, rtl: rtl)
if label
label_classes = ["icon-label"]
@@ -36,23 +36,23 @@ module IconsHelper
end
end
- def file_icon(entry, name, **options)
+ def file_icon(entry, name, **)
if entry.is_dir?
- sprite_icon("folder", name, **options)
+ sprite_icon("folder", name, **)
else
icon_name = icon_for_mime_type(Redmine::MimeType.css_class_of(name))
- sprite_icon(icon_name, name, **options)
+ sprite_icon(icon_name, name, **)
end
end
- def principal_icon(principal, **options)
+ def principal_icon(principal, **)
raise ArgumentError, "First argument has to be a Principal, was #{principal.inspect}" unless principal.is_a?(Principal)
principal_class = principal.class.name.downcase
- sprite_icon('group', **options) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class)
+ sprite_icon('group', **) if ['groupanonymous', 'groupnonmember', 'group'].include?(principal_class)
end
- def activity_event_type_icon(event_type, **options)
+ def activity_event_type_icon(event_type, **)
icon_name = case event_type
when 'reply'
'comments'
@@ -64,7 +64,7 @@ module IconsHelper
event_type
end
- sprite_icon(icon_name, **options)
+ sprite_icon(icon_name, **)
end
def scm_change_icon(action, name, **options)
@@ -79,7 +79,7 @@ module IconsHelper
sprite_icon(icon_name, name, size: 14)
end
- def notice_icon(type, **options)
+ def notice_icon(type, **)
icon_name = case type
when 'notice'
'checked'
@@ -87,13 +87,14 @@ module IconsHelper
'warning'
end
- sprite_icon(icon_name, **options)
+ sprite_icon(icon_name, **)
end
private
- def svg_sprite_icon(icon_name, size: DEFAULT_ICON_SIZE, sprite: DEFAULT_SPRITE, css_class: nil, rtl: false)
+ def svg_sprite_icon(icon_name, size: DEFAULT_ICON_SIZE, style: :outline, sprite: DEFAULT_SPRITE, css_class: nil, rtl: false)
css_classes = "s#{size} icon-svg"
+ css_classes += " icon-svg-filled" if style == :filled
css_classes += " #{css_class}" unless css_class.nil?
css_classes += " icon-rtl" if rtl
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index 6586a1b7e..ce3607a5d 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -22,6 +22,7 @@ module IssuesHelper
include Redmine::Export::PDF::IssuesPdfHelper
include IssueStatusesHelper
include QueriesHelper
+ include ReactionsHelper
def issue_list(issues, &)
ancestors = []
diff --git a/app/helpers/journals_helper.rb b/app/helpers/journals_helper.rb
index 6c22fc4ca..0ddbc34b8 100644
--- a/app/helpers/journals_helper.rb
+++ b/app/helpers/journals_helper.rb
@@ -19,6 +19,7 @@
module JournalsHelper
include Redmine::QuoteReply::Helper
+ include ReactionsHelper
# Returns the attachments of a journal that are displayed as thumbnails
def journal_thumbnail_attachments(journal)
@@ -40,10 +41,12 @@ module JournalsHelper
)
end
+ links << reaction_button(journal)
+
if journal.notes.present?
if options[:reply_links]
url = quoted_issue_path(issue, :journal_id => journal, :journal_indice => indice)
- links << quote_reply(url, "#journal-#{journal.id}-notes", icon_only: true)
+ links << quote_reply_button(url: url, icon_only: true)
end
if journal.editable_by?(User.current)
links << link_to(sprite_icon('edit', l(:button_edit)),
@@ -66,7 +69,8 @@ module JournalsHelper
end
def render_notes(issue, journal, options={})
- content_tag('div', textilizable(journal, :notes), :id => "journal-#{journal.id}-notes", :class => "wiki")
+ content_tag('div', textilizable(journal, :notes),
+ id: "journal-#{journal.id}-notes", class: "wiki journal-note", data: { quote_reply_target: 'content' })
end
def render_private_notes_indicator(journal)
diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb
index fd9ba3bcb..92f788d0c 100644
--- a/app/helpers/messages_helper.rb
+++ b/app/helpers/messages_helper.rb
@@ -19,4 +19,5 @@
module MessagesHelper
include Redmine::QuoteReply::Helper
+ include ReactionsHelper
end
diff --git a/app/helpers/news_helper.rb b/app/helpers/news_helper.rb
index a5c50fdfd..cd7b6734a 100644
--- a/app/helpers/news_helper.rb
+++ b/app/helpers/news_helper.rb
@@ -18,4 +18,5 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module NewsHelper
+ include ReactionsHelper
end
diff --git a/app/helpers/principal_memberships_helper.rb b/app/helpers/principal_memberships_helper.rb
index d9caf4f50..e69324247 100644
--- a/app/helpers/principal_memberships_helper.rb
+++ b/app/helpers/principal_memberships_helper.rb
@@ -38,27 +38,27 @@ module PrincipalMembershipsHelper
end
end
- def new_principal_membership_path(principal, *args)
+ def new_principal_membership_path(principal, *)
if principal.is_a?(Group)
- new_group_membership_path(principal, *args)
+ new_group_membership_path(principal, *)
else
- new_user_membership_path(principal, *args)
+ new_user_membership_path(principal, *)
end
end
- def edit_principal_membership_path(principal, *args)
+ def edit_principal_membership_path(principal, *)
if principal.is_a?(Group)
- edit_group_membership_path(principal, *args)
+ edit_group_membership_path(principal, *)
else
- edit_user_membership_path(principal, *args)
+ edit_user_membership_path(principal, *)
end
end
- def principal_membership_path(principal, membership, *args)
+ def principal_membership_path(principal, membership, *)
if principal.is_a?(Group)
- group_membership_path(principal, membership, *args)
+ group_membership_path(principal, membership, *)
else
- user_membership_path(principal, membership, *args)
+ user_membership_path(principal, membership, *)
end
end
end
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 01a5452f7..bae1c4e3a 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -80,8 +80,8 @@ module ProjectsHelper
classes += %w(icon icon-bookmarked-project) if bookmarked_project_ids.include?(project.id)
s = link_to_project(project, {}, :class => classes.uniq.join(' '))
- s << sprite_icon('user', l(:label_my_projects), icon_only: true) if User.current.member_of?(project)
- s << sprite_icon('bookmarked', l(:label_my_bookmarks), icon_only: true) if bookmarked_project_ids.include?(project.id)
+ s << tag.span(sprite_icon('user', l(:label_my_projects), icon_only: true), class: 'icon-only icon-user my-project') if User.current.member_of?(project)
+ s << tag.span(sprite_icon('bookmarked', l(:label_my_bookmarks), icon_only: true), class: 'icon-only icon-bookmarked-project') if bookmarked_project_ids.include?(project.id)
if project.description.present?
s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
end
diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb
index ca7168f27..3aef7083a 100644
--- a/app/helpers/queries_helper.rb
+++ b/app/helpers/queries_helper.rb
@@ -169,7 +169,7 @@ module QueriesHelper
group_name = format_object(group)
end
group_name ||= ""
- group_count = result_count_by_group ? result_count_by_group[group] : nil
+ group_count = result_count_by_group&.[](group)
group_totals = totals_by_group.map {|column, t| total_tag(column, t[group] || 0)}.join(" ").html_safe
end
end
diff --git a/app/helpers/reactions_helper.rb b/app/helpers/reactions_helper.rb
new file mode 100644
index 000000000..e02e1c9f9
--- /dev/null
+++ b/app/helpers/reactions_helper.rb
@@ -0,0 +1,100 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006- Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module ReactionsHelper
+ # Maximum number of users to display in the reaction button tooltip
+ DISPLAY_REACTION_USERS_LIMIT = 10
+
+ def reaction_button(object)
+ return unless Redmine::Reaction.visible?(object, User.current)
+
+ detail = object.reaction_detail
+
+ user_reaction = detail.user_reaction
+ count = detail.reaction_count
+ visible_user_names = detail.visible_users.take(DISPLAY_REACTION_USERS_LIMIT).map(&:name)
+
+ tooltip = build_reaction_tooltip(visible_user_names, count)
+
+ if Redmine::Reaction.editable?(object, User.current)
+ if user_reaction.present?
+ reaction_button_reacted(object, user_reaction, count, tooltip)
+ else
+ reaction_button_not_reacted(object, count, tooltip)
+ end
+ else
+ reaction_button_readonly(object, count, tooltip)
+ end
+ end
+
+ def reaction_id_for(object)
+ dom_id(object, :reaction)
+ end
+
+ private
+
+ def reaction_button_reacted(object, reaction, count, tooltip)
+ reaction_button_wrapper object do
+ link_to(
+ sprite_icon('thumb-up-filled', count.nonzero?, style: :filled),
+ reaction_path(reaction, object_type: object.class.name, object_id: object),
+ remote: true, method: :delete,
+ class: ['icon', 'reaction-button', 'reacted'],
+ title: tooltip
+ )
+ end
+ end
+
+ def reaction_button_not_reacted(object, count, tooltip)
+ reaction_button_wrapper object do
+ link_to(
+ sprite_icon('thumb-up', count.nonzero?),
+ reactions_path(object_type: object.class.name, object_id: object),
+ remote: true, method: :post,
+ class: 'icon reaction-button',
+ title: tooltip
+ )
+ end
+ end
+
+ def reaction_button_readonly(object, count, tooltip)
+ reaction_button_wrapper object do
+ tag.span(class: 'icon reaction-button readonly', title: tooltip) do
+ sprite_icon('thumb-up', count.nonzero?)
+ end
+ end
+ end
+
+ def reaction_button_wrapper(object, &)
+ tag.span(class: 'reaction-button-wrapper', data: { 'reaction-button-id': reaction_id_for(object) }, &)
+ end
+
+ def build_reaction_tooltip(visible_user_names, count)
+ return if count.zero?
+
+ display_user_names = visible_user_names.dup
+ others = count - visible_user_names.size
+
+ if others.positive?
+ display_user_names << I18n.t(:reaction_text_x_other_users, count: others)
+ end
+
+ display_user_names.to_sentence(locale: I18n.locale)
+ end
+end
diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb
index 6390ecbdb..f8df59b00 100644
--- a/app/helpers/reports_helper.rb
+++ b/app/helpers/reports_helper.rb
@@ -34,9 +34,9 @@ module ReportsHelper
a
end
- def aggregate_link(data, criteria, *args)
+ def aggregate_link(data, criteria, *)
a = aggregate data, criteria
- a > 0 ? link_to(h(a), *args) : '-'
+ a > 0 ? link_to(h(a), *) : '-'
end
def aggregate_path(project, field, row, options={})
diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb
index f5d6dbd38..a27ea783e 100644
--- a/app/helpers/routes_helper.rb
+++ b/app/helpers/routes_helper.rb
@@ -20,83 +20,83 @@
module RoutesHelper
# Returns the path to project issues or to the cross-project
# issue list if project is nil
- def _project_issues_path(project, *args)
+ def _project_issues_path(project, *)
if project
- project_issues_path(project, *args)
+ project_issues_path(project, *)
else
- issues_path(*args)
+ issues_path(*)
end
end
- def _project_issues_url(project, *args)
+ def _project_issues_url(project, *)
if project
- project_issues_url(project, *args)
+ project_issues_url(project, *)
else
- issues_url(*args)
+ issues_url(*)
end
end
- def _project_news_path(project, *args)
+ def _project_news_path(project, *)
if project
- project_news_index_path(project, *args)
+ project_news_index_path(project, *)
else
- news_index_path(*args)
+ news_index_path(*)
end
end
- def _new_project_issue_path(project, *args)
+ def _new_project_issue_path(project, *)
if project
- new_project_issue_path(project, *args)
+ new_project_issue_path(project, *)
else
- new_issue_path(*args)
+ new_issue_path(*)
end
end
- def _project_calendar_path(project, *args)
- project ? project_calendar_path(project, *args) : issues_calendar_path(*args)
+ def _project_calendar_path(project, *)
+ project ? project_calendar_path(project, *) : issues_calendar_path(*)
end
- def _project_gantt_path(project, *args)
- project ? project_gantt_path(project, *args) : issues_gantt_path(*args)
+ def _project_gantt_path(project, *)
+ project ? project_gantt_path(project, *) : issues_gantt_path(*)
end
- def _time_entries_path(project, issue, *args)
+ def _time_entries_path(project, issue, *)
if project
- project_time_entries_path(project, *args)
+ project_time_entries_path(project, *)
else
- time_entries_path(*args)
+ time_entries_path(*)
end
end
- def _report_time_entries_path(project, issue, *args)
+ def _report_time_entries_path(project, issue, *)
if project
- report_project_time_entries_path(project, *args)
+ report_project_time_entries_path(project, *)
else
- report_time_entries_path(*args)
+ report_time_entries_path(*)
end
end
- def _new_time_entry_path(project, issue, *args)
+ def _new_time_entry_path(project, issue, *)
if issue
- new_issue_time_entry_path(issue, *args)
+ new_issue_time_entry_path(issue, *)
elsif project
- new_project_time_entry_path(project, *args)
+ new_project_time_entry_path(project, *)
else
- new_time_entry_path(*args)
+ new_time_entry_path(*)
end
end
# Returns the path to bulk update issues or to issue path
# if only one issue is selected for bulk update
- def _bulk_update_issues_path(issue, *args)
+ def _bulk_update_issues_path(issue, *)
if issue
- issue_path(issue, *args)
+ issue_path(issue, *)
else
- bulk_update_issues_path(*args)
+ bulk_update_issues_path(*)
end
end
- def board_path(board, *args)
- project_board_path(board.project, board, *args)
+ def board_path(board, *)
+ project_board_path(board.project, board, *)
end
end
diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb
index 39a836a03..c1f989805 100644
--- a/app/helpers/settings_helper.rb
+++ b/app/helpers/settings_helper.rb
@@ -244,6 +244,7 @@ module SettingsHelper
['Mystery man', 'mm'],
['Retro', 'retro'],
['Robohash', 'robohash'],
- ['Wavatars', 'wavatar']]
+ ['Wavatars', 'wavatar'],
+ ['Initials', 'initials']]
end
end
diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb
index 6e6366846..bfed8adf2 100644
--- a/app/helpers/watchers_helper.rb
+++ b/app/helpers/watchers_helper.rb
@@ -48,7 +48,9 @@ module WatchersHelper
def watchers_list(object)
remove_allowed = User.current.allowed_to?(:"delete_#{object.class.name.underscore}_watchers", object.project)
content = ''.html_safe
- lis = object.watcher_users.sorted.collect do |user|
+ scope = object.watcher_users
+ scope = scope.includes(:email_address) if Setting.gravatar_enabled?
+ lis = scope.sorted.collect do |user|
s = ''.html_safe
s << avatar(user, :size => "16").to_s if user.is_a?(User)
s << link_to_principal(user, class: user.class.to_s.downcase)