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

Allow over 20 watchers selection and set #33

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 13 additions & 1 deletion app/controllers/concerns/issue_templates_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def core_fields_map_by_tracker_id(tracker_id: nil, project_id: nil)

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)
watchers = users_for_new_issue_watchers_with_limit(issue, nil)
value[:field_format] = 'list'

value[:possible_values] = watchers.map { |user| "#{user.name} :#{user.id}" }
Expand Down Expand Up @@ -149,4 +149,16 @@ def custom_fields_map_by_tracker_id(tracker_id = nil)
logger&.info "core_fields_map_by_tracker_id failed due to this error: #{e.message}"
{}
end

# https://github.com/redmine/redmine/blob/master/app/helpers/issues_helper.rb
# Returns an array of users that are proposed as watchers
# on the new issue form
def users_for_new_issue_watchers_with_limit(issue, limit = 21)
users = issue.watcher_users.select{|u| u.status == User::STATUS_ACTIVE}
assignable_watchers = issue.project.principals.assignable_watchers.limit(limit)
if limit.nil? || assignable_watchers.size < limit
users += assignable_watchers.sort
end
users.uniq
end
end
47 changes: 42 additions & 5 deletions assets/javascripts/issue_templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,49 @@ 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
let targets = document.querySelectorAll('input[type="checkbox"][name="issue[watcher_user_ids][]"]')
if (targets.length > 0) {
for (let i = 0; i < targets.length; i++) {
let target = targets[i]
if (values.includes(target.value)) {
target.checked = true
}
}
} else {
let observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (!mutation.addedNodes) return

for (let i = 0; i < mutation.addedNodes.length; i++) {
let node = mutation.addedNodes[i]
console.log(node)
if (node.id === 'new-watcher-form') {
observer.disconnect()

// Check watchers from template setting
let searchTargets = document.querySelectorAll('div#users_for_watcher input[name="watcher[user_ids][]"]')
for (let i = 0; i < searchTargets.length; i++) {
let target = searchTargets[i]
if (values.includes(target.value)) {
target.checked = true
}
}
// Click "Add" button to apply checked watchers and close the dialog
document.querySelector('form#new-watcher-form input[type="submit"]').click()
}
}
})
})

observer.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false
})

// Click "Search for watchers to add" link to open "Add watchers" dialog
document.querySelector('span.search_for_watchers a').click()
}
},
filterTemplate: function (event) {
Expand Down