From 5dd7596fe75b01a7596266296501c9aeeff3a5d8 Mon Sep 17 00:00:00 2001 From: Burak Ikiler Date: Thu, 6 Apr 2023 16:32:05 +0300 Subject: [PATCH 1/3] Redmine 5 Compatibility: Autoloder fix with to_prepare. --- init.rb | 5 +++-- lib/redmine_mentions_suggestions.rb | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/init.rb b/init.rb index b0fe81d..1c8523e 100644 --- a/init.rb +++ b/init.rb @@ -1,5 +1,6 @@ -require_dependency 'redmine_mentions_suggestions' - +Rails.configuration.to_prepare do + require_dependency 'redmine_mentions_suggestions' +end Redmine::Plugin.register :redmine_mentions_suggestions do name 'Redmine Mentions Suggestions plugin' author 'Evolving Web' diff --git a/lib/redmine_mentions_suggestions.rb b/lib/redmine_mentions_suggestions.rb index b2dff5c..a45c961 100644 --- a/lib/redmine_mentions_suggestions.rb +++ b/lib/redmine_mentions_suggestions.rb @@ -3,3 +3,5 @@ IssuesController.send :helper, IssuesControllerHelper require_dependency 'redmine_mentions_suggestions/hooks' end +module RedmineMentionsSuggestions +end \ No newline at end of file From ab2c503fe8a30194539dd1c4c14503efd91af7ab Mon Sep 17 00:00:00 2001 From: Burak Ikiler Date: Tue, 16 May 2023 15:36:23 +0300 Subject: [PATCH 2/3] IssueController Helper removed. Functionality is now inside template file. --- app/helpers/issues_controller_helper.rb | 38 ------------------- .../_edit_mentionable.html.erb | 36 ++++++++++++++++-- lib/redmine_mentions_suggestions.rb | 1 - 3 files changed, 32 insertions(+), 43 deletions(-) delete mode 100644 app/helpers/issues_controller_helper.rb diff --git a/app/helpers/issues_controller_helper.rb b/app/helpers/issues_controller_helper.rb deleted file mode 100644 index fbeedb1..0000000 --- a/app/helpers/issues_controller_helper.rb +++ /dev/null @@ -1,38 +0,0 @@ -module IssuesControllerHelper - def map_users_to_states(users, issue) - mapping = {} - journals = Journal.where("journalized_type = 'issue' AND journalized_id = :id", {id: issue.id}) - journals.each do |journal| - details = JournalDetail.where("journal_id = :id", {id: journal.id}) - assignee = nil - status = nil - details.each do |detail| - if detail.prop_key == 'status_id' - status = detail.value - end - if detail.prop_key == 'assigned_to_id' - assignee = detail.value - end - end - if assignee && status - if !mapping.key?(assignee) - mapping[assignee] = [] - end - unless mapping[assignee].include? status - mapping[assignee].push(status) - end - end - end - mapping.to_json.html_safe - end - - def status_listing - statuses = IssueStatus.order("position") - listing = {} - statuses.each do |status| - listing[status.id] = "#{status.name}" - end - listing.to_json.html_safe - end - -end \ No newline at end of file diff --git a/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb b/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb index a1e7345..dfa9941 100644 --- a/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb +++ b/app/views/hooks/redmine_mentions_suggestions/_edit_mentionable.html.erb @@ -1,18 +1,46 @@ -<% regex_find = '/\B'+Setting.plugin_redmine_mentions['trigger']+'(\w*)$/i'%> +<% regex_find = '/\B'+'@'+'(\w*)$/i'%> <% if @project %> <% users = @project.users.to_a.delete_if{|u| (u.type != 'User' || u.mail.empty?)}%> <% else %> <% users = User.active.to_a.delete_if{|u| (u.type != 'User' || u.mail.empty?)}%> <% end %> -<% users_regex = users.collect{|u| "#{Setting.plugin_redmine_mentions['trigger']}#{u.login}"}.join('|')%> +<% users_regex = users.collect{|u| "#{'@'}#{u.login}"}.join('|')%> <% regex_highlight = '/\B('+users_regex+')\b/g' %> + +<% mapping = {} %> +<% journals = Journal.where("journalized_type = 'issue' AND journalized_id = :id", {id: @issue.id}) %> +<% journals.each do |journal| %> +<% details = JournalDetail.where("journal_id = :id", {id: journal.id}) %> +<% assignee = nil %> +<% status = nil %> +<% details.each do |detail| %> +<% if detail.prop_key == 'status_id' %> +<% status = detail.value %> +<% end %> +<% if detail.prop_key == 'assigned_to_id' %> +<% assignee = detail.value %> +<% end %> +<% end %> +<% if assignee && status %> +<% if !mapping.key?(assignee) %> +<% mapping[assignee] = [] %> +<% end %> +<% unless mapping[assignee].include? status %> +<% mapping[assignee].push(status) %> +<% end %> +<% end %> +<% end %> + +<% listing = {} %> +<% IssueStatus.order("position").each { |status| listing[status.id] = "#{status.name}" } %> +