Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22670 suggestions user preference #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var usersMapping = <%= self.map_users_to_states(users, @issue) %>;
var statuses = <%= self.status_listing %>;
var suggestMentions = <%= User.current.pref.suggest_mentions? %>

window.setInterval(function(){
var text = $('#issue_notes').val();
Expand Down Expand Up @@ -43,7 +44,9 @@
$suggestions.html('');
$suggestions.append('<div class="assignee-suggestion"><input id="issue_suggest_assignee_'+ id + '" data-user-id="' + id + '" type="checkbox" name="issue_suggest_assignee" value="1"><label>Assign issue to ' + user + '</label></div>');
$('#issue_private_notes').before($suggestions);
$('input[name="issue_suggest_assignee"]').prop('checked', true);
if (suggestMentions) {
$('input[name="issue_suggest_assignee"]').prop('checked', true);
}

if (usersMapping[id]) {
for (var index = 0; index < usersMapping[id].length; index++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= labelled_fields_for :pref, @user.pref do |pref_fields| %>
<p><%= pref_fields.check_box :suggest_mentions %></p>
<% end %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# English strings go here for Rails i18n
en:
# my_label: "My label"
field_suggest_mentions: 'Enable mentions suggestions by default'
7 changes: 7 additions & 0 deletions lib/redmine_mentions_suggestions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
IssuesController.send :helper, IssuesControllerHelper
require_dependency 'redmine_mentions_suggestions/hooks'
end

require_dependency 'redmine_mentions_suggestions/patches/user_preference_patch'
ActiveSupport::Reloader.to_prepare do
unless UserPreference.included_modules.include?(RedmineMentionsSuggestions::Patches::UserPreferencePatch)
UserPreference.send :prepend, RedmineMentionsSuggestions::Patches::UserPreferencePatch
end
end
2 changes: 2 additions & 0 deletions lib/redmine_mentions_suggestions/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Hooks < Redmine::Hook::ViewListener
# Additional context fields
# :issue => the issue this is edited
# :f => the form object to create additional fields
render_on :view_my_account_preferences,
partial: 'hooks/redmine_mentions_suggestions/mentions_suggestions_preference'
render_on :view_issues_edit_notes_bottom,
:partial => 'hooks/redmine_mentions_suggestions/edit_mentionable'
render_on :view_issues_form_details_bottom,
Expand Down
29 changes: 29 additions & 0 deletions lib/redmine_mentions_suggestions/patches/user_preference_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_dependency 'user_preference'

module RedmineMentionsSuggestions
module Patches
module UserPreferencePatch

def self.prepended(base)
base.class_eval do
if defined? safe_attributes
safe_attributes :suggest_mentions
end
end
end

def suggest_mentions
self[:suggest_mentions]
end

def suggest_mentions=(val)
self[:suggest_mentions] = val
end

def suggest_mentions?
self[:suggest_mentions]
end

end
end
end