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

show all available watchers in json generator #32

Merged
merged 3 commits into from
Jul 21, 2022
Merged
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
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