Skip to content

Commit

Permalink
show all available watchers in json generator (agileware-jp#32)
Browse files Browse the repository at this point in the history
* show all available watchers in json generator

* add available group watchers

* fix checkSelectedWatchers
  • Loading branch information
maimai77 authored Jul 21, 2022
1 parent aea59f3 commit 80c9ebf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions app/controllers/concerns/issue_templates_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ def core_fields_map_by_tracker_id(tracker_id: nil, project_id: nil)
end

if field == 'watcher_user_ids' && project_id.present?
issue = Issue.new(tracker_id: tracker_id, project_id: project_id)
watchers = helpers.users_for_new_issue_watchers(issue)
project_principals = if Watcher.reflections['user'].class_name == 'Principal'
Project.find(project_id).principals.where(type: %w[User Group])
else # Redmine 4.1.x or earlier
Project.find(project_id).users
end
watchers = project_principals.active.visible.sort
value[:field_format] = 'list'

value[:possible_values] = watchers.map { |user| "#{user.name} :#{user.id}" }
Expand Down
18 changes: 11 additions & 7 deletions assets/javascripts/issue_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,17 @@ ISSUE_TEMPLATE.prototype = {
document.getElementById('issue_template').dispatchEvent(changeEvent)
},
checkSelectedWatchers: function (values) {
let targets = document.querySelectorAll('input[name="issue[watcher_user_ids][]"]')
for (let i = 0; i < targets.length; i++) {
let target = targets[i]
if (values.includes(target.value)) {
target.checked = true
}
}
// HACK: want to get this url and params in a stable way.
const rootPath = $('a.home').attr('href');
const projectPath = $('a.overview')?.attr('href') ?? `/projects/${$('#issue_project_id').val()}`;
const { projectId } = /projects\/(?<projectId>.+)/.exec(projectPath).groups;
$.post({
url: `${rootPath}watchers/append.js`,
data: {
project_id: projectId,
watcher: { user_ids: values }
},
});
},
filterTemplate: function (event) {
let cols = document.getElementsByClassName('template_data')
Expand Down

0 comments on commit 80c9ebf

Please sign in to comment.