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

Redmine 2.x plus enhancement #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Issue Due Date will set the Issue due dates to the due dates of versions or deli

== Getting the plugin

A copy of the plugin can be downloaded from {Little Stream Software}[https://projects.littlestreamsoftware.com/projects/redmine-misc/files] or from {GitHub}[http://github.com/edavis10/redmine_issue_due_date]
A copy of the plugin can be downloaded from {GitHub}[http://github.com/dra/redmine_issue_due_date]


== Installation and Setup

1. Follow the Redmine plugin installation steps at: http://www.redmine.org/wiki/redmine/Plugins
2. Restart your Redmine web servers (e.g. mongrel, thin, mod_rails)
3. (optional step) If you would like to convert of the existing issues, backup your database and run the rake task:
3. Run rake redmine:plugins:migrate
4. (optional step) If you would like to convert of the existing issues, backup your database and run the rake task:

rake issue_due_date_plugin:update_due_dates RAILS_ENV=production

Expand All @@ -26,8 +27,10 @@ When an issue is edited, the plugin will check:
* If the issue's due date has been set on the Issue or
* the deliverable has a due date or
* the version has a due date
* the issues project has default_days_due set

If any of those are true, the issue will have it's due date updated. If multiple of them are true, the first one will be used.
Hint: At the moment there is no way to set Project.default_days_due via Redmine, one has to do it directly to the database.

=== Version or Deliverable edits

Expand Down
9 changes: 9 additions & 0 deletions db/migrate/001_add_default_days_due.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddDefaultDaysDue < ActiveRecord::Migration
def self.up
add_column :projects, :default_days_due, :integer
end

def self.down
remove_column :projects, :default_days_due
end
end
17 changes: 16 additions & 1 deletion lib/issue_due_date_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ module InstanceMethods
def update_due_date
if deliverable_defined? && (due_date.blank? || due_date_set_by_deliverable?)
set_due_date_from_deliverable
elsif due_date.blank? || due_date_set_by_version?
elsif due_date.blank? && due_date_set_by_version?
set_due_date_from_version
elsif due_date.blank? && due_date_set_by_project?
set_due_date_from_project
end

return true
Expand All @@ -33,6 +35,12 @@ def set_due_date_from_version
end
end

# Set the +due_date+ based on the projects due_date default
def set_due_date_from_project
self.due_date = (Time.now + self.project.default_days_due.to_i.days).change(:sec => 0).change(:min => 0).change(:hour => 0)
return true
end

# Set the +due_date+ based on the deliverable's due_date
def set_due_date_from_deliverable
if (deliverable_defined? && deliverable && deliverable.due != due_date)
Expand All @@ -52,6 +60,13 @@ def due_date_set_by_version?
orig_issue.fixed_version.due_date == self.due_date)
end

# Is the issue's +due_date+ defined by project settings?
def due_date_set_by_project?
return false if project.default_days_due.nil?
return true
end


# Is the issue's +due_date+ the same as it's old deliverable?
def due_date_set_by_deliverable?
orig_issue = Issue.find_by_id(self.id)
Expand Down
3 changes: 1 addition & 2 deletions rails/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
require 'version_due_date_patch'
require 'deliverable_due_patch'

require 'dispatcher'
Dispatcher.to_prepare do
Rails.configuration.to_prepare do
Issue.send(:include, IssueDueDate::IssuePatch)
Version.send(:include, IssueDueDate::VersionPatch)
Deliverable.send(:include, IssueDueDate::DeliverablePatch) if Object.const_defined?("Deliverable")
Expand Down