Skip to content
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
70 changes: 48 additions & 22 deletions app/models/stuff_to_do.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,50 @@ class StuffToDo < ActiveRecord::Base
belongs_to :user
acts_as_list :scope => :user

named_scope :doing_now, lambda { |user|
{
:conditions => { :user_id => user.id },
:limit => 5,
:order => 'position ASC'
if Rails::VERSION::MAJOR >= 3
scope :doing_now, lambda { |user|
{
:conditions => { :user_id => user.id },
:order => 'position ASC',
:limit => 5
}
}
}

else
named_scope :doing_now, lambda { |user|
{
:conditions => { :user_id => user.id },
:order => 'position ASC',
:limit => 5
}
}
end

# TODO: Rails bug
#
# ActiveRecord ignores :offset if :limit isn't added also. But since we
# want all the records, we need to provide a limit that will include everything
#
# http://dev.rubyonrails.org/ticket/7257
#
named_scope :recommended, lambda { |user|
{
:conditions => { :user_id => user.id },
:limit => self.count,
:offset => 5,
:order => 'position ASC'
if Rails::VERSION::MAJOR >= 3
scope :recommended, lambda { |user|
{
:conditions => { :user_id => user.id },
:order => 'position ASC',
:limit => self.count,
:offset => 5
}
}
}
else
named_scope :recommended, lambda { |user|
{
:conditions => { :user_id => user.id },
:order => 'position ASC',
:limit => self.count,
:offset => 5
}
}
end

# Filters the issues that are available to be added for a user.
#
Expand Down Expand Up @@ -113,7 +134,13 @@ def self.remove_stale_assignments(issue)
# Project based ids need to be prefixed with +project+
def self.reorder_list(user, ids)
ids ||= []
id_position_mapping = ids.to_hash
#id_position_mapping = ids.to_hash
i = 0
id_position_mapping = {}
ids.each do |value|
id_position_mapping[i] = value
i = i+1
end

issue_ids = {}
project_ids = {}
Expand Down Expand Up @@ -192,17 +219,16 @@ def self.use_setting
end

def self.conditions_for_available(filter_by)
conditions_builder = ARCondition.new(["#{IssueStatus.table_name}.is_closed = ?", false ])
conditions_builder.add(["#{Project.table_name}.status = ?", Project::STATUS_ACTIVE])

scope = self
conditions = "#{IssueStatus.table_name}.is_closed = 0"
conditions << " AND (" << "#{Project.table_name}.status = %d" % [Project::STATUS_ACTIVE] << ")"
case
when filter_by.is_a?(User)
conditions_builder.add(["assigned_to_id = ?", filter_by.id])
conditions << " AND (" << "assigned_to_id = %d" % [filter_by.id] << ")"
when filter_by.is_a?(IssueStatus), filter_by.is_a?(Enumeration)
table_name = filter_by.class.table_name
conditions_builder.add(["#{table_name}.id = (?)", filter_by.id])
conditions << " AND (" << "#{table_name}.id = (%d)" % [filter_by.id] << ")"
end

conditions_builder.conditions
conditions
end
end
30 changes: 20 additions & 10 deletions app/models/stuff_to_do_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
class StuffToDoMailer < Mailer
def recommended_below_threshold(user, number_of_next_items)
recipients Setting.plugin_stuff_to_do_plugin['email_to'].split(',')
subject "What's Recommended is below the threshold"

body(
:threshold => Setting.plugin_stuff_to_do_plugin['threshold'],
:count => number_of_next_items,
:user => user
)
if Rails::VERSION::MAJOR >= 3
@to = Setting.plugin_stuff_to_do_plugin['email_to'].split(',')
@subject = "What's Recommended is below the threshold"

part :content_type => "text/plain", :body => render_message("recommended_below_threshold.erb", body)
part :content_type => "text/html", :body => render_message("recommended_below_threshold.text.html.rhtml", body)
@threshold = Setting.plugin_stuff_to_do_plugin['threshold']
@count = number_of_next_items
@user = user

mail(:to => @to, :subject => @subject, :template_name => "recommended_below_threshold")
else
recipients Setting.plugin_stuff_to_do_plugin['email_to'].split(',')
subject "What's Recommended is below the threshold"

body(
:threshold => Setting.plugin_stuff_to_do_plugin['threshold'],
:count => number_of_next_items,
:user => user
)

part :content_type => "text/plain", :body => render_message("recommended_below_threshold.text.erb", body)
part :content_type => "text/html", :body => render_message("recommended_below_threshold.html.erb", body)
end
end
end
3 changes: 1 addition & 2 deletions app/views/stuff_to_do/_issue.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<li class="stuff-to-do-item <%= issue.css_classes if issue.respond_to?(:css_classes) %> <%= issue_counter.odd? ? "odd" : "even" %>" id="stuff_<%= issue.id %>">
<div class="issue-details">
<%= link_to(image_tag('ticket.png'), :controller => 'issues', :action => 'show', :id => issue) %>
#<%= h(issue.id) %>
<%= link_to(image_tag('ticket.png') + '#' + h(issue.id), :controller => 'issues', :action => 'show', :id => issue) %>
- <%= h(issue.project.name) %> -
<%= h(issue.subject) %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/stuff_to_do/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<div class="menu">
<% if User.current.admin? %>
<div class="user">
<% form_tag({ :controller => 'stuff_to_do', :action => 'index'}, :method => :get, :id => 'user_switch' ) do %>
<%= form_tag({ :controller => 'stuff_to_do', :action => 'index'}, :method => :get, :id => 'user_switch' ) do %>
<label for="user_id"><%= l(:stuff_to_do_label_view_user_list) %></label>
<%= collection_select(:user, :id, @users.sort, :id, :name, { }, { :name => 'user_id'}) %>
<% end %>
</div>

<div class="filter">
<% form_tag({}, :id => 'filter_form') do %>
<%= form_tag({}, :id => 'filter_form') do %>
<label for="filter"><%= l(:stuff_to_do_label_filter) %></label>
<%= select_tag("filter", filter_options(@filters, params[:filter])) %>
<% end %>
Expand Down
3 changes: 0 additions & 3 deletions app/views/stuff_to_do_mailer/recommended_below_threshold.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @userRef = link_to(h(@user.name), :controller => 'users', :action => 'show', :id => @user, :only_path => false) %>
<%= l(:stuff_to_do_below_threshold, :user => @userRef, :count => @count, :threshold => @threshold).html_safe %><p />
<%= link_to l(:stuff_to_do_title), :controller => 'stuff_to_do', :action => 'index', :user_id => @user.id, :only_path => false %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= l(:stuff_to_do_below_threshold, :user => @user, :count => @count, :threshold => @threshold) %>

<%= url_for :controller => 'stuff_to_do', :action => 'index', :user_id => @user.id, :only_path => false %>

This file was deleted.

1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ en:
stuff_to_do_time_grid_save_error: "{{count}} time entries could not be saved."
stuff_to_do_time_grid_save_notice: "{{count}} time entries saved."
stuff_to_do_use_time_grid: "Use Time Grid"
stuff_to_do_below_threshold: "%{user} has only %{count} recommended items left in their Stuff To Do which is below the threshold of %{threshold}."

4 changes: 2 additions & 2 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ ru:
stuff_to_do_label_filter: Фильтр
stuff_to_do_label_filter_by: Фильтровать по ...
stuff_to_do_drag_issue_create_list: "Назначенные задачи"


stuff_to_do_use_time_grid: "Отображать расписание"
stuff_to_do_below_threshold: "У пользователя %{user} осталось %{count} задач, рекомендуемых к исполнению. Дополните этот спиcок до %{threshold}."
23 changes: 21 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
ActionController::Routing::Routes.draw do |map|
map.connect 'stuff_to_do/:action.:format', :controller => 'stuff_to_do'
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html

if Rails::VERSION::MAJOR >= 3
RedmineApp::Application.routes.draw do
match 'stuff_to_do', :to => 'stuff_to_do#index', :via => 'get'
match 'stuff_to_do/:action.:format', :to => 'stuff_to_do', :via => [:get, :post]
end
else
ActionController::Routing::Routes.draw do |map|
map.with_options :controller => 'stuff_to_do' do |stuff_routes|
stuff_routes.with_options :conditions => {:method => :get} do |stuff_views|
stuff_views.connect 'stuff_to_do', :action => 'index'
stuff_views.connect 'stuff_to_do/:action.:format'
end
stuff_routes.with_options :conditions => {:method => :post} do |stuff_views|
stuff_views.connect 'stuff_to_do', :action => 'index'
stuff_views.connect 'stuff_to_do/:action.:format'
end
end
end
end
48 changes: 18 additions & 30 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
require 'redmine'

Dir[File.join(File.dirname(__FILE__),'vendor','plugins','*')].each do |dir|
path = File.join(dir, 'lib')
$LOAD_PATH << path
Dependencies.load_paths << path
Dependencies.load_once_paths.delete(path)
end

# Patches to Ruby, oh my
require 'stuff_to_do_array_patch'

# Patches to the Redmine core.
require 'dispatcher'

Dispatcher.to_prepare do
require_dependency 'project'
require_dependency 'issue'
require_dependency 'user'
# Including dispatcher.rb in case of Rails 2.x
require 'dispatcher' unless Rails::VERSION::MAJOR >= 3

Project.send(:include, StuffToDoProjectPatch)
Issue.send(:include, StuffToDoIssuePatch)
User.send(:include, StuffToDoUserPatch)

# Needed for the compatibility check
begin
require_dependency 'issue_priority'
rescue LoadError
# TimeEntryActivity is not available
if Rails::VERSION::MAJOR >= 3
ActionDispatch::Callbacks.to_prepare do
require 'stuff_to_do_dispatch'
end
else
Dispatcher.to_prepare do
require 'stuff_to_do_dispatch'
end

end

Redmine::Plugin.register :stuff_to_do_plugin do
name 'Stuff To Do Plugin'
author 'Eric Davis'
url 'https://projects.littlestreamsoftware.com/projects/show/redmine-stuff-to-do'
author_url 'http://www.littlestreamsoftware.com'
description "The Stuff To Do plugin allows a user to order and prioritize the issues they are doing into a specific order. It will also allow other privilged users to reorder the user's workload."
version '0.4.0'
description "The Stuff To Do plugin allows a user to order and prioritize the issues they are doing into a specific order. It will also allow other privilged users to reorder the user's workload. compatible redmine 1.x and 2.0"
version '0.4.1'

requires_redmine :version_or_higher => '0.8.0'
requires_redmine :version_or_higher => '1.0.0'

settings(:partial => 'settings/stuff_to_do_settings',
:default => {
Expand All @@ -49,6 +32,11 @@
'use_time_grid' => '0'
})

menu(:top_menu, :stuff_to_do, {:controller => "stuff_to_do", :action => 'index'}, :caption => :stuff_to_do_title, :if => Proc.new{ User.current.logged? })
# A new item is added to the project menu
if Rails::VERSION::MAJOR >= 3
menu :top_menu, :stuff_to_do, { :controller => 'stuff_to_do', :action => 'index'}, :caption => "Stuff_to_do", :if => Proc.new{ User.current.logged? }
else
menu :top_menu, :stuff_to_do, { :controller => 'stuff_to_do', :action => 'index'}, :caption => :stuff_to_do_title, :if => Proc.new{ User.current.logged? }
end

end
3 changes: 3 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ stuff_to_do_use_as_stuff_to_do: Use as Stuff To Do items
stuff_to_do_time_grid: "Time Grid"
stuff_to_do_time_grid_save_error: "%d time entries could not be saved."
stuff_to_do_time_grid_save_notice: "%d time entries saved."
stuff_to_do_use_time_grid: "Use Time Grid"
stuff_to_do_below_threshold: "%{user} has only %{count} recommended items left in their Stuff To Do which is below the threshold of %{threshold}."

2 changes: 2 additions & 0 deletions lang/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ stuff_to_do_label_email_to: Адреса для отсылки
stuff_to_do_text_settings: "Если число следующих задач, заданных для выполнения пользователю, превысит заданное ниже значение, то будет отослано письмо руководителю. Можно задать несколько адресов получателей, разделяя их запятыми"
stuff_to_do_label_filter: Фильтр
stuff_to_do_label_filter_by: Выбрать условие...
stuff_to_do_use_time_grid: "Отображать расписание"
stuff_to_do_below_threshold: "У пользователя %{user} осталось %{count} задач, рекомендуемых к исполнению. Дополните этот спиcок до %{threshold}."
2 changes: 1 addition & 1 deletion lib/stuff_to_do_array_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class Array
def to_hash
Hash[*self.collect {|v|
[self.index(v),v]
}.flatten]
}.flatten(1)]
end unless respond_to?(:to_hash)
end
21 changes: 21 additions & 0 deletions lib/stuff_to_do_dispatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

require_dependency 'project'
require_dependency 'issue'
require_dependency 'user'

require 'stuff_to_do_project_patch';
require 'stuff_to_do_issue_patch';
require 'stuff_to_do_user_patch';

Project.send(:include, StuffToDoProjectPatch)
Issue.send(:include, StuffToDoIssuePatch)
User.send(:include, StuffToDoUserPatch)

# Needed for the compatibility check
begin
require_dependency 'issue_priority'
rescue LoadError
# TimeEntryActivity is not available
end


50 changes: 37 additions & 13 deletions lib/stuff_to_do_issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,49 @@ def self.included(base) # :nodoc:
has_many :stuff_to_dos, :as => :stuff
has_and_belongs_to_many :time_grid_users, :class_name => 'User', :join_table => 'time_grid_issues_users'

named_scope :with_time_entries_for_user, lambda {|user_id|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.user_id = (?)", user_id]
if Rails::VERSION::MAJOR >= 3
scope :with_time_entries_for_user, lambda {|user_id|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.user_id = (?)", user_id]
}
}
}
else
named_scope :with_time_entries_for_user, lambda {|user_id|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.user_id = (?)", user_id]
}
}
end

named_scope :with_time_entries_within_date, lambda {|date_from, date_to,|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.spent_on > (:from) AND #{TimeEntry.table_name}.spent_on < (:to)",
{:from => date_from, :to => date_to}]
if Rails::VERSION::MAJOR >= 3
scope :with_time_entries_within_date, lambda {|date_from, date_to,|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.spent_on > (:from) AND #{TimeEntry.table_name}.spent_on < (:to)",
{:from => date_from, :to => date_to}]
}
}
}
else
named_scope :with_time_entries_within_date, lambda {|date_from, date_to,|
{
:include => :time_entries,
:conditions => ["#{TimeEntry.table_name}.spent_on > (:from) AND #{TimeEntry.table_name}.spent_on < (:to)",
{:from => date_from, :to => date_to}]
}
}
end

# Redmine 0.8.x compatibility method
unless ::Issue.respond_to?(:visible)
named_scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
if Rails::VERSION::MAJOR >= 3
scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
else
named_scope :visible, lambda {|*args| { :include => :project,
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
end
end
end

Expand Down
Loading