From a1c5e61827c9ef7f81afe072257f2a5cf7844c0a Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Wed, 2 Jul 2014 02:22:55 -0300 Subject: [PATCH 1/6] Update plugin to latest Redmine version --- app/models/stuff_to_do.rb | 40 +++++++++++++------------------ assets/javascripts/stuff-to-do.js | 2 +- config/routes.rb | 4 +--- init.rb | 6 +---- lib/stuff_to_do_array_patch.rb | 8 ------- lib/stuff_to_do_issue_patch.rb | 24 ++++++------------- 6 files changed, 26 insertions(+), 58 deletions(-) delete mode 100644 lib/stuff_to_do_array_patch.rb diff --git a/app/models/stuff_to_do.rb b/app/models/stuff_to_do.rb index 85f19f7e..09da8440 100644 --- a/app/models/stuff_to_do.rb +++ b/app/models/stuff_to_do.rb @@ -15,12 +15,8 @@ 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' - } + scope :doing_now, ->(user) { + where(user_id: user.id).limit(5).order('position ASC') } # TODO: Rails bug @@ -30,13 +26,8 @@ class StuffToDo < ActiveRecord::Base # # http://dev.rubyonrails.org/ticket/7257 # - named_scope :recommended, lambda { |user| - { - :conditions => { :user_id => user.id }, - :limit => self.count, - :offset => 5, - :order => 'position ASC' - } + scope :recommended, ->(user) { + where(user_id: user.id).limit(StuffToDo.count).offset(5).order('position ASC') } # Filters the issues that are available to be added for a user. @@ -53,10 +44,11 @@ def self.available(user, filter=nil) if filter.is_a?(Project) potential_stuff_to_do = active_and_visible_projects.sort else - potential_stuff_to_do = Issue.find(:all, - :include => [:status, :priority, :project], - :conditions => conditions_for_available(filter), - :order => "#{Issue.table_name}.created_on DESC") + potential_stuff_to_do = filter_issues( + Issue.includes(:status, :priority, :project). + order("#{Issue.table_name}.created_on DESC"), + filter + ).all end stuff_to_do = StuffToDo.find(:all, :conditions => { :user_id => user.id }).collect(&:stuff) @@ -113,7 +105,7 @@ 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 = Hash[*ids.map{|v| [ids.index(v), v]}.flatten] issue_ids = {} project_ids = {} @@ -191,18 +183,18 @@ def self.use_setting USE.index(Setting.plugin_stuff_to_do_plugin['use_as_stuff_to_do']) 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]) + def self.filter_issues(dataset, filter_by) + dataset = dataset.where("#{IssueStatus.table_name}.is_closed" => false). + where("#{Project.table_name}.status" => Project::STATUS_ACTIVE) case when filter_by.is_a?(User) - conditions_builder.add(["assigned_to_id = ?", filter_by.id]) + dataset = dataset.where(assigned_to_id: 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]) + dataset = dataset.where("#{table_name}.id" => filter_by.id) end - conditions_builder.conditions + dataset end end diff --git a/assets/javascripts/stuff-to-do.js b/assets/javascripts/stuff-to-do.js index 9a830d8d..f274e3f2 100644 --- a/assets/javascripts/stuff-to-do.js +++ b/assets/javascripts/stuff-to-do.js @@ -87,7 +87,7 @@ jQuery(function($) { $.ajax({ type: "POST", - url: 'stuff_to_do/reorder.js', + url: '/stuff_to_do/reorder.js', data: data, success: function(response) { $('#panes').html(response); diff --git a/config/routes.rb b/config/routes.rb index 7864ff84..6b611b04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1 @@ -ActionController::Routing::Routes.draw do |map| - map.connect 'stuff_to_do/:action.:format', :controller => 'stuff_to_do' -end +match ':controller/:action', via: [:get, :post], controller: /stuff_to_do/ diff --git a/init.rb b/init.rb index ba77ae29..81e8dad1 100644 --- a/init.rb +++ b/init.rb @@ -7,13 +7,9 @@ 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 +ActionDispatch::Callbacks.to_prepare do require_dependency 'project' require_dependency 'issue' require_dependency 'user' diff --git a/lib/stuff_to_do_array_patch.rb b/lib/stuff_to_do_array_patch.rb deleted file mode 100644 index 49535710..00000000 --- a/lib/stuff_to_do_array_patch.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Array - # converts an array to a hash with the key = index in Array - def to_hash - Hash[*self.collect {|v| - [self.index(v),v] - }.flatten] - end unless respond_to?(:to_hash) -end diff --git a/lib/stuff_to_do_issue_patch.rb b/lib/stuff_to_do_issue_patch.rb index 4d48a389..a5f87103 100644 --- a/lib/stuff_to_do_issue_patch.rb +++ b/lib/stuff_to_do_issue_patch.rb @@ -13,26 +13,16 @@ 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] - } + scope :with_time_entries_for_user, ->(user_id) { + includes(:time_entries).where("#{TimeEntry.table_name}.user_id" => user_id) } - 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}] - } + scope :with_time_entries_within_date, ->(date_from, date_to) { + includes(:time_entries). + where("#{TimeEntry.table_name}.spent_on > (:from) AND + #{TimeEntry.table_name}.spent_on < (:to)", + from: date_from, to: date_to) } - - # 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) } } - end end end From d3298828d6c818880c1a9ba5a255e4775281cadb Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Thu, 3 Jul 2014 16:03:44 -0300 Subject: [PATCH 2/6] Use relative path for reorder.js In case Redmine is mounted on /redmine for instance. --- assets/javascripts/stuff-to-do.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/stuff-to-do.js b/assets/javascripts/stuff-to-do.js index f274e3f2..8d7f8e98 100644 --- a/assets/javascripts/stuff-to-do.js +++ b/assets/javascripts/stuff-to-do.js @@ -87,7 +87,7 @@ jQuery(function($) { $.ajax({ type: "POST", - url: '/stuff_to_do/reorder.js', + url: 'reorder.js', data: data, success: function(response) { $('#panes').html(response); From edcaf1048d1587693de4d0e0b0f808e6ecc82d33 Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Wed, 9 Jul 2014 11:00:03 -0300 Subject: [PATCH 3/6] fix pt-BR translations --- config/locales/pt-BR.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 5e263b25..8429d52a 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1,18 +1,18 @@ pt-BR: - stuff_to_do_title: Coisas A Fazer + stuff_to_do_title: Tarefas stuff_to_do_what_im_doing_now: "O que estou fazendo agora" - stuff_to_do_what_is_recommended: "O que é recomendado fazer depois" - stuff_to_do_what_is_available: "O que há disponivel" + stuff_to_do_what_is_recommended: "O que é recomendado fazer depois" + stuff_to_do_what_is_available: "O que há disponível" stuff_to_do_text_order_im_doing_it: "Em ordem do que estou fazendo" stuff_to_do_text_by_project_manager: Pelo Gerente do Projeto - stuff_to_do_label_view_user_list: "Ver outra lista do usuário:" + stuff_to_do_label_view_user_list: "Ver outra lista do usuário:" stuff_to_do_text_total_progress: "Progresso Total" stuff_to_do_text_total_estimates: "Estimativa Total" stuff_to_do_label_project_manager_emails: Emails Gerente de Projeto stuff_to_do_label_threshold: Limiar - stuff_to_do_label_email_to: Endereços de Email - stuff_to_do_text_settings: "Um email será enviado para o Gerente de Projeto quando a contagem de item Recomendado ao usuário alcançar o limiar abaixo. Multiplos recipientes de email pode ser especificado por separar os endereços com virgulas." + stuff_to_do_label_email_to: Endereços de Email + stuff_to_do_text_settings: "Um email será enviado para o Gerente de Projeto quando a contagem de item Recomendado ao usuário alcançar o limiar abaixo. Múltiplos recipientes de email pode ser especificado por separar os endereços com vírgulas." stuff_to_do_label_filter: Filtro stuff_to_do_label_filter_by: Filtro por ... stuff_to_do_drag_issue_create_list: Solte tickets aqui para criar uma nova lista. - stuff_to_do_drag_issue_remove_list: Solte tickets aqui para remove-la da lista. + stuff_to_do_drag_issue_remove_list: Solte tickets aqui para removê-la da lista. From 757400e4b6bcf8789ab0ffe4f1f267c4ab6daa8c Mon Sep 17 00:00:00 2001 From: Rodrigo Rosenfeld Rosas Date: Thu, 10 Jul 2014 07:44:33 -0300 Subject: [PATCH 4/6] Fix time-grid support --- app/views/stuff_to_do/_time_grid.html.erb | 2 +- .../stuff_to_do/_time_grid_form.html.erb | 31 +++++++------------ app/views/stuff_to_do/index.html.erb | 6 ++-- assets/javascripts/stuff-to-do.js | 18 +++++++++++ 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/views/stuff_to_do/_time_grid.html.erb b/app/views/stuff_to_do/_time_grid.html.erb index acd7ddd8..0ec59322 100644 --- a/app/views/stuff_to_do/_time_grid.html.erb +++ b/app/views/stuff_to_do/_time_grid.html.erb @@ -79,7 +79,7 @@