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

Some fixes #7

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ You can setup options in administration menu.

## Compatibility

This version supports redmine 3.x.
This version supports redmine 4.x.
4 changes: 2 additions & 2 deletions app/controllers/reminder_configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ReminderConfigurationController < ApplicationController

layout 'admin'

before_filter :require_admin
before_action :require_admin

def edit
@configuration = ReminderConfiguration.instance
Expand All @@ -23,7 +23,7 @@ def update
def permitted_conf_params
params.required(:reminder_configuration).permit(
:days, :issue_status_selector, :project_selector, :tracker_selector, :send_to_author,
:send_to_assigned_to, :send_to_watcher, :send_to_custom_user,
:send_to_assigned_to, :use_due_day, :send_to_watcher, :send_to_custom_user,
{ issue_status_ids: [] },
{ project_ids: [] },
{ tracker_ids: [] }
Expand Down
9 changes: 5 additions & 4 deletions app/models/reminder_all_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ReminderAllMailer < Mailer
helper :reminder_all

def reminder_all(user, assigned_issues, auth_issues, watched_issues, custom_user_issues, days)
def reminder_all(user, assigned_issues, auth_issues, watched_issues, custom_user_issues, without_due_day, days)
recipients = user.mail
day_tag = [l(:mail_reminder_all_day1), l(:mail_reminder_all_day2),
l(:mail_reminder_all_day2), l(:mail_reminder_all_day2),
Expand All @@ -25,6 +25,7 @@ def reminder_all(user, assigned_issues, auth_issues, watched_issues, custom_user
@auth_issues = auth_issues
@watched_issues = watched_issues
@custom_user_issues = custom_user_issues
@without_due_day = without_due_day
@days = days
@issues_url = url_for(
controller: 'issues',
Expand All @@ -35,9 +36,9 @@ def reminder_all(user, assigned_issues, auth_issues, watched_issues, custom_user
mail to: recipients, subject: subject
end

def self.deliver_reminder_all_if_any(user, assigned_issues, auth_issues, watched_issues, custom_user_issues, days)
issues_count = (assigned_issues + auth_issues + watched_issues + custom_user_issues).uniq.size
def self.deliver_reminder_all_if_any(user, assigned_issues, auth_issues, watched_issues, custom_user_issues, without_due_day, days)
issues_count = (assigned_issues + auth_issues + watched_issues + custom_user_issues + without_due_day).uniq.size
reminder_all(user, assigned_issues, auth_issues, watched_issues,
custom_user_issues, days).deliver if issues_count > 0
custom_user_issues, without_due_day, days).deliver_later if issues_count > 0
end
end
1 change: 1 addition & 0 deletions app/models/reminder_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def set_default_values
self.send_to_assigned_to = true if self.send_to_assigned_to.nil?
self.send_to_watcher = true if self.send_to_watcher.nil?
self.send_to_custom_user ||= false
self.use_due_day ||= false
true
end
end
4 changes: 4 additions & 0 deletions app/views/reminder_all_mailer/reminder_all.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
issues: @custom_user_issues,
message: l_mail_body_reminder_custom_user(@custom_user_issues.size, @days) } %>

<%= render partial: 'issues', locals: {
issues: @without_due_day,
message: l(:mail_body_reminder_assigned_set, @without_due_day.size) } %>

<p><%= link_to l(:label_issue_view_all), @issues_url %></p>
4 changes: 4 additions & 0 deletions app/views/reminder_all_mailer/reminder_all.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
issues: @custom_user_issues,
message: l_mail_body_reminder_custom_user(@custom_user_issues.size, @days) } %>

<%= render partial: 'issues', locals: {
issues: @without_due_day,
message: l(:mail_body_reminder_assigned_set, @without_due_day.size) } %>

<%= @issues_url %>
4 changes: 4 additions & 0 deletions app/views/reminder_configuration/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

<%= f.check_box :send_to_author %>
<%= f.label :send_to_author, l(:field_author) %>
<br/>

<%= f.check_box :use_due_day %>
<%= f.label :use_due_day, l(:field_use_due_day) %>
<br/>

<%= f.check_box :send_to_assigned_to %>
Expand Down
4 changes: 2 additions & 2 deletions assets/javascripts/reminder_configuration.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var toggleExplicitList = function(selector, list, explicit_value) {
var fnToggleList = function() {
if ($(selector).getValue() == explicit_value) {
if ($(selector).val() == explicit_value) {
$(list).show();
} else {
$(list).hide();
}
};

$(selector).observe('change', fnToggleList);
$(selector).on('change', fnToggleList);

fnToggleList();
};
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ en:
mail_body_reminder_assigned5: "%{count} issues that are assigned to you are due in the next %{days} %{day}:"
mail_body_reminder_watched5: "%{count} issues that are watched by you are due in the next %{days} %{day}:"
mail_body_reminder_custom_user5: "%{count} issues in which you are mentioned are due in the next %{days} %{day}:"
mail_body_reminder_assigned_set: "%{count} issues that are assigned to you which don't have end date set:"

label_reminder_options: "Reminder options"
label_criteria_task: "Criteria task"
Expand All @@ -37,3 +38,4 @@ en:
explicit: "tasks from selected trackers"

field_custom_user: "User from custom field"
field_use_due_day: "Send tasks which have end date only"
39 changes: 39 additions & 0 deletions config/locales/pl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
pl:
mail_reminder_all_day1: "dnia"
mail_reminder_all_day2: "dni"
mail_reminder_all_day5: "dni"
mail_subject_reminder_all1: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}"
mail_body_reminder_auth1: "%{count} zadań do wykonania w ciągu %{days} %{day}, których jesteś autorem:"
mail_body_reminder_assigned1: "%{count} zadań do wykonania w ciągu %{days} %{day}, do których jesteś przypisany:"
mail_body_reminder_watched1: "%{count} zadań do wykonania w ciągu %{days} %{day}, których jesteś obserwatorem:"
mail_body_reminder_custom_user1: "%{count} zadań do wykonania w ciągu %{days} %{day}, w których o Tobie wspomniano:"
mail_subject_reminder_all2: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}"
mail_body_reminder_auth2: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, których jesteś autorem:"
mail_body_reminder_assigned2: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, do których jesteś przypisany:"
mail_body_reminder_watched2: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, których jesteś obserwatorem:"
mail_body_reminder_custom_user2: "%{count} issues in which you are mentioned are due in the next %{days} %{day}:"
mail_subject_reminder_all5: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}"
mail_body_reminder_auth5: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, których jesteś autorem:"
mail_body_reminder_assigned5: "%{count} issues that are assigned to you are due in the next %{days} %{day}:"
mail_body_reminder_watched5: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, których jesteś obserwatorem:"
mail_body_reminder_custom_user5: "%{count} zadań do wykonania w ciągu następnych %{days} %{day}, w których o Tobie wspomniano:"

label_reminder_options: "Przypominacz - ustawienia"
label_criteria_task: "Kryteria zadania"
label_completion_date: "Data ukończenia"
label_tasks_due_in: "Zadania, które muszą być ukończonew ciągu następnych"
label_days: "Dni"
label_reminder_recipients: "Odbiorcy przypominacza"

redmine_reminder:
issue_statuses:
all_opened: "Wszystkie otwarte zadania"
explicit: "Zadania z wybranym statusem"
projects:
all: "Zadania ze wszystkich projektów"
explicit: "Zadania z wybranych projektów"
trackers:
all: "Zadania każdego typu"
explicit: "Wybrane typy zadań"

field_custom_user: "Użytkownik z pola niestandardowego"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateReminderConfigurations < ActiveRecord::Migration
class CreateReminderConfigurations < ActiveRecord::Migration[5.1]
def self.up
create_table :reminder_configurations do |t|
t.column :days, :integer
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20120911164322_create_reminder_projects.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateReminderProjects < ActiveRecord::Migration
class CreateReminderProjects < ActiveRecord::Migration[5.1]
def self.up
create_table :reminder_projects do |t|
t.column :reminder_configuration_id, :integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateReminderIssueStatuses < ActiveRecord::Migration
class CreateReminderIssueStatuses < ActiveRecord::Migration[5.1]
def self.up
create_table :reminder_issue_statuses do |t|
t.column :reminder_configuration_id, :integer
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20120918093621_create_reminder_trackers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateReminderTrackers < ActiveRecord::Migration
class CreateReminderTrackers < ActiveRecord::Migration[5.1]
def self.up
create_table :reminder_trackers do |t|
t.column :reminder_configuration_id, :integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AddTrackerSelectorToReminderConfigurations < ActiveRecord::Migration
class AddTrackerSelectorToReminderConfigurations < ActiveRecord::Migration[5.1]
def self.up
unless column_exists? :reminder_configurations, :tracker_selector
add_column :reminder_configurations, :tracker_selector, :string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUseDueDayToReminderConfiguration < ActiveRecord::Migration[5.1]
def change
add_column :reminder_configurations, :use_due_day, :boolean, default: false
end
end
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
menu :admin_menu,
:reminder_options,
{ controller: 'reminder_configuration', action: 'edit' },
html: { class: 'reminder_options_label' }
html: { class: 'icon reminder_options_label' }
end

require_dependency 'redmine_reminder/hooks'
62 changes: 50 additions & 12 deletions lib/redmine_reminder/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,94 @@ def initialize(options)
@options = options
end

def logger
Rails.logger
end

def collect_reminders
reminders = {}

issues = issues_due_in_days
issues.each do |issue|
issues = if options.use_due_day?
issues_due_in_days(true)
else
issues_due_in_days(false)
end

# logger.info issues.count()
issues.each do |issue|
if options.send_to_author?
reminders[issue.author] ||=
RedmineReminder::Reminder.new(issue.author)
RedmineReminder::Reminder.new(issue.author)
reminders[issue.author][:author] << issue
end

if options.send_to_assigned_to? && issue.assigned_to
if options.send_to_assigned_to? && issue.assigned_to && issue.due_date
reminders[issue.assigned_to] ||=
RedmineReminder::Reminder.new(issue.assigned_to)
RedmineReminder::Reminder.new(issue.assigned_to)
reminders[issue.assigned_to][:assigned_to] << issue
#logger.info "v=#{issue}"
#logger.info "v.author=#{issue.author}"
#logger.info "v.assigned_to=#{issue.assigned_to}"
#logger.info "v.due_date=#{issue.due_date}"
end

if options.send_to_watcher?
issue.watchers.each do |watcher|
reminders[watcher.user] ||=
RedmineReminder::Reminder.new(watcher.user)
RedmineReminder::Reminder.new(watcher.user)
reminders[watcher.user][:watcher] << issue
end
end

if options.send_to_custom_user?
issue_custom_users(issue).each do |custom_user|
reminders[custom_user] ||=
RedmineReminder::Reminder.new(custom_user)
RedmineReminder::Reminder.new(custom_user)
reminders[custom_user][:custom_user] << issue
end
end

if !options.use_due_day? && issue.assigned_to && !issue.due_date
#logger.info "v=#{issue}"
#logger.info "v.author=#{issue.author}"
#logger.info "v.assigned_to=#{issue.assigned_to}"
#logger.info "v.due_date=#{issue.due_date}"
reminders[issue.assigned_to] ||=
RedmineReminder::Reminder.new(issue.assigned_to)
reminders[issue.assigned_to][:without_due_day] << issue
end
end
reminders.values.map &:uniq!
reminders.values || []

#reminders.values.each do |v|
# logger.info "v=#{v}"
# logger.info "v.user=#{v.user}"
#end

end

private

# Get issues due in X days
def issues_due_in_days
def issues_due_in_days(use_due_day = true)
due_date = options.days.day.from_now.to_date
sql_condition = ARCondition.new ["#{Issue.table_name}.due_date <= ?", due_date]
sql_condition = if use_due_day
ARCondition.new ["#{Issue.table_name}.due_date <= ?", due_date]
else
ARCondition.new ["#{Issue.table_name}.due_date <= ? OR #{Issue.table_name}.due_date IS NULL", due_date]
end

sql_condition << issue_statuses
sql_condition << projects
sql_condition << trackers
Issue.joins(:status, :assigned_to, :author, :project, :watchers, :tracker).
where(sql_condition.conditions).
order("#{Issue.table_name}.due_date, #{Project.table_name}.name")
scope = Issue.includes(:status, :assigned_to, :author, :project, :watchers, :tracker)
if Redmine::VERSION::MAJOR>=3
scope = scope.references(:status, :assigned_to, :author, :project, :watchers, :tracker)
end

scope.where(sql_condition.conditions).
order("#{Project.table_name}.name, #{Issue.table_name}.due_date")
end

def issue_statuses
Expand Down
28 changes: 19 additions & 9 deletions lib/tasks/reminder_all.rake
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ namespace :redmine do

collector = RedmineReminder::Collector.new(options)
collector.collect_reminders.each do |r|
next unless r.user.active?
users = if r.user.is_a?(User)
[r.user]
else
r.user.users
end
users = users.compact.select{|u| u.active?}
next unless users.blank?
ReminderAllMailer.with_synched_deliveries do
ReminderAllMailer.deliver_reminder_all_if_any(
r.user,
r[:assigned_to],
r[:author],
r[:watcher],
r[:custom_user],
options.days
)
users.each do |user|
ReminderAllMailer.deliver_reminder_all_if_any(
user,
r[:assigned_to],
r[:author],
r[:watcher],
r[:custom_user],
r[:without_due_day],
options.days
)
end

end
end
end
Expand Down