Skip to content

Commit

Permalink
Merge pull request #2 from kporras07/22670-suggest-statuses
Browse files Browse the repository at this point in the history
22670 suggest statuses
  • Loading branch information
WuCris authored Oct 19, 2020
2 parents bb32c25 + 78d5be1 commit 8d032f5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
38 changes: 38 additions & 0 deletions app/helpers/issues_controller_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
var id = 0;
var user = '';

var usersMapping = <%= self.map_users_to_states(users, @issue) %>;
var statuses = <%= self.status_listing %>;

window.setInterval(function(){
var text = $('#issue_notes').val();
var matches = new RegExp(<%=regex_highlight%>).exec(text);
Expand All @@ -30,24 +33,39 @@
}
}
if (updated) {
var $suggest_assignee = false;
if ($('.issue-suggest-assignee').length) {
$suggest_assignee = $('.issue-suggest-assignee');
var $suggestions = false;
if ($('.issue-suggestions').length) {
$suggestions = $('.issue-suggestions');
}
else {
$suggest_assignee = $('<div class="issue-suggest-assignee"/>');
$suggestions = $('<div class="issue-suggestions"/>');
}
$suggest_assignee.html('');
$suggest_assignee.append('<input id="issue_suggest_assignee_'+ id + '" data-user-id="' + id + '" type="checkbox" name="issue_suggest_assignee" value="1">');
$suggest_assignee.append('<label>Assign issue to ' + user + '</label>');
$('#issue_private_notes').before($suggest_assignee);
$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 (usersMapping[id]) {
for (var index = 0; index < usersMapping[id].length; index++) {
statusId = usersMapping[id][index];
statusName = statuses[statusId];

$suggestions.append('<div class="status-suggestion"><input id="issue_suggest_status_'+ statusId + '" data-status-id="' + statusId + '" type="radio" name="issue_suggest_status" value="' + statusId + '"><label>Change status to ' + statusName + '</label></div>');
}
$suggestions.append('<div class="status-suggestion"><input id="issue_suggest_status_0" data-status-id="0" type="radio" name="issue_suggest_status" value="0"><label>Do not change status</label></div>');
$('#issue_suggest_status_0').prop('checked', true);

}

$('#issue-form').submit(function() {
if ($('input[name="issue_suggest_assignee"]').is(':checked')) {
var id = $('input[name="issue_suggest_assignee"]').attr('data-user-id');
$('#issue_assigned_to_id').val(id);
}
if ($('input[name="issue_suggest_status"]:checked').val()) {
var statusId = $('input[name="issue_suggest_status"]:checked').val();
$('#issue_status_id').val(statusId);
}
});
}
}, 2000);
Expand Down
3 changes: 2 additions & 1 deletion init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_dependency 'redmine_mentions_suggestions/hooks'
require_dependency 'redmine_mentions_suggestions'

Redmine::Plugin.register :redmine_mentions_suggestions do
name 'Redmine Mentions Suggestions plugin'
Expand All @@ -8,3 +8,4 @@
url 'https://github.com/evolvingweb/redmine_mentions_suggestions'
author_url 'https://evolvingweb.ca'
end

5 changes: 5 additions & 0 deletions lib/redmine_mentions_suggestions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Rails.configuration.to_prepare do

IssuesController.send :helper, IssuesControllerHelper
require_dependency 'redmine_mentions_suggestions/hooks'
end
2 changes: 1 addition & 1 deletion lib/redmine_mentions_suggestions/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class Hooks < Redmine::Hook::ViewListener
render_on :view_issues_form_details_bottom,
:partial => 'hooks/redmine_mentions_suggestions/edit_mentionable'
end
end
end

0 comments on commit 8d032f5

Please sign in to comment.