diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0f0ac5af..f98ac793 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -45,23 +45,20 @@ class ApplicationController < ActionController::Base def set_session_expiration # http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions - unless session == nil - return if self.controller_name == 'feed' or session['noexpiry'] == "on" - # If the method is called by the feed controller (which we don't have - # under session control) or if we checked the box to keep logged in on - # login don't set the session expiry time. - if session - # Get expiry time (allow ten seconds window for the case where we have - # none) - expiry_time = session['expiry_time'] || Time.now + 10 - if expiry_time < Time.now - # Too late, matey... bang goes your session! - reset_session - else - # Okay, you get another hour - session['expiry_time'] = Time.now + (60*60) - end - end + # If the method is called by the feed controller (which we don't have + # under session control) or if we checked the box to keep logged in on + # login don't set the session expiry time. + return if session.nil? || self.controller_name == 'feed' || session['noexpiry'] == "on" + + # Get expiry time (allow ten seconds window for the case where we have + # none) + expiry_time = session['expiry_time'] || Time.now + 10 + if expiry_time < Time.now + # Too late, matey... bang goes your session! + reset_session + else + # Okay, you get another hour + session['expiry_time'] = Time.now + (60*60) end end @@ -159,7 +156,7 @@ class ApplicationController < ActionController::Base super # handle xml http auth via our own login code end end - + def sanitize(arg) ActionController::Base.helpers.sanitize(arg) end @@ -272,10 +269,11 @@ class ApplicationController < ActionController::Base def all_done_todos_for(object) object_name = object.class.name.downcase # context or project - @source_view = object_name + @source_view = object_name @page_title = t("#{object_name.pluralize}.all_completed_tasks_title", "#{object_name}_name".to_sym => object.name) - @done = object.todos.completed.paginate :page => params[:page], :per_page => 20, :order => 'completed_at DESC', :include => Todo::DEFAULT_INCLUDES + @done = object.todos.completed.reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES). + paginate(:page => params[:page], :per_page => 20) @count = @done.size render :template => 'todos/all_done' end diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index e14996c2..f6071b21 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -18,11 +18,7 @@ class ContextsController < ApplicationController format.html &render_contexts_html format.m &render_contexts_mobile format.xml { render :xml => @all_contexts.to_xml( :except => :user_id ) } - format.rss do - @feed_title = 'Tracks Contexts' - @feed_description = "Lists all the contexts for #{current_user.display_name}" - end - format.atom do + format.any(:rss, :atom) do @feed_title = 'Tracks Contexts' @feed_description = "Lists all the contexts for #{current_user.display_name}" end diff --git a/app/controllers/preferences_controller.rb b/app/controllers/preferences_controller.rb index 36ba8342..40f9c26f 100644 --- a/app/controllers/preferences_controller.rb +++ b/app/controllers/preferences_controller.rb @@ -12,7 +12,7 @@ class PreferencesController < ApplicationController user_updated = current_user.update_attributes(user_params) prefs_updated = current_user.preference.update_attributes(prefs_params) if (user_updated && prefs_updated) - if !params['user']['password'].blank? # password updated? + if params['user']['password'].present? # password updated? logout_user t('preferences.password_changed') else preference_updated diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 7552cc6d..4c417f00 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -38,11 +38,7 @@ class ProjectsController < ApplicationController cookies[:mobile_url]= {:value => request.fullpath, :secure => SITE_CONFIG['secure_cookies']} end format.xml { render :xml => @projects.to_xml( :except => :user_id ) } - format.rss do - @feed_title = I18n.t('models.project.feed_title') - @feed_description = I18n.t('models.project.feed_description', :username => current_user.display_name) - end - format.atom do + format.any(:rss, :atom) do @feed_title = I18n.t('models.project.feed_title') @feed_description = I18n.t('models.project.feed_description', :username => current_user.display_name) end @@ -339,7 +335,7 @@ class ProjectsController < ApplicationController default_context_name = p['default_context_name'] p.delete('default_context_name') - unless default_context_name.blank? + if default_context_name.present? default_context = current_user.contexts.where(:name => default_context_name).first_or_create p['default_context_id'] = default_context.id end diff --git a/app/controllers/recurring_todos_controller.rb b/app/controllers/recurring_todos_controller.rb index 854b20b4..fe8f6132 100644 --- a/app/controllers/recurring_todos_controller.rb +++ b/app/controllers/recurring_todos_controller.rb @@ -72,7 +72,7 @@ class RecurringTodosController < ApplicationController end # update context - if params['recurring_todo']['context_id'].blank? && !params['context_name'].blank? + if params['recurring_todo']['context_id'].blank? && params['context_name'].present? context = current_user.contexts.where(:name => params['context_name'].strip).first unless context context = current_user.contexts.build @@ -129,7 +129,7 @@ class RecurringTodosController < ApplicationController end @saved = @recurring_todo.save - unless (@saved == false) || p.tag_list.blank? + if @saved && p.tag_list.present? @recurring_todo.tag_with(p.tag_list) @recurring_todo.tags.reload end @@ -255,14 +255,14 @@ class RecurringTodosController < ApplicationController end def project_specified_by_name? - return false unless @attributes['project_id'].blank? + return false if @attributes['project_id'].present? return false if project_name.blank? return false if project_name == 'None' true end def context_specified_by_name? - return false unless @attributes['context_id'].blank? + return false if @attributes['context_id'].present? return false if context_name.blank? true end diff --git a/app/controllers/todos/todo_create_params_helper.rb b/app/controllers/todos/todo_create_params_helper.rb index 22cf6274..2831d201 100644 --- a/app/controllers/todos/todo_create_params_helper.rb +++ b/app/controllers/todos/todo_create_params_helper.rb @@ -89,7 +89,7 @@ module Todos end def sequential? - return !@params[:todos_sequential].blank? && @params[:todos_sequential]=='true' + return @params[:todos_sequential].present? && @params[:todos_sequential]=='true' end def specified_by_name?(group_type) @@ -98,18 +98,18 @@ module Todos def specified_by_id?(group_type) group_id = send("#{group_type}_id") - !group_id.blank? + group_id.present? end def project_specified_by_name? - return false unless @attributes['project_id'].blank? + return false if @attributes['project_id'].present? return false if project_name.blank? return false if project_name == 'None' true end def context_specified_by_name? - return false unless @attributes['context_id'].blank? + return false if @attributes['context_id'].present? return false if context_name.blank? true end diff --git a/app/controllers/todos_controller.rb b/app/controllers/todos_controller.rb index 99566671..c4eb7a3e 100644 --- a/app/controllers/todos_controller.rb +++ b/app/controllers/todos_controller.rb @@ -50,8 +50,7 @@ class TodosController < ApplicationController render :content_type => Mime::TEXT end format.xml { render :xml => @todos.to_xml( *todo_xml_params ) } - format.rss { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" } - format.atom { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" } + format.any(:rss, :atom) { @feed_title, @feed_description = 'Tracks Actions', "Actions for #{current_user.display_name}" } format.ics end end @@ -76,7 +75,7 @@ class TodosController < ApplicationController def create @source_view = params['_source_view'] || 'todo' @default_context = current_user.contexts.where(:name => params['default_context_name']).first - @default_project = current_user.projects.where(:name => params['default_project_name']).first unless params['default_project_name'].blank? + @default_project = current_user.projects.where(:name => params['default_project_name']).first if params['default_project_name'].present? @tag_name = params['_tag_name'] @@ -94,7 +93,7 @@ class TodosController < ApplicationController if @todo.errors.empty? @todo.add_predecessor_list(p.predecessor_list) @saved = @todo.save - @todo.tag_with(tag_list) if @saved && !tag_list.blank? + @todo.tag_with(tag_list) if @saved && tag_list.present? @todo.update_state_from_project if @saved @todo.block! if @todo.should_be_blocked? else @@ -159,7 +158,7 @@ class TodosController < ApplicationController # first build all todos and check if they would validate on save params[:todo][:multiple_todos].split("\n").map do |line| - unless line.blank? #ignore blank lines + if line.present? #ignore blank lines @todo = current_user.todos.build({:description => line, :context_id => p.context_id, :project_id => p.project_id}) validates &&= @todo.valid? @@ -177,8 +176,8 @@ class TodosController < ApplicationController todo.add_predecessor(@predecessor) todo.block! end - - todo.tag_with(tag_list) unless (@saved == false) || tag_list.blank? + + todo.tag_with(tag_list) if @saved && tag_list.present? @todos << todo @not_done_todos << todo if p.new_context_created || p.new_project_created @@ -205,7 +204,7 @@ class TodosController < ApplicationController else @multiple_error = @todos.size > 0 ? "" : t('todos.next_action_needed') @saved = false - @default_tags = current_user.projects.where(:name => @initial_project_name).default_tags unless @initial_project_name.blank? + @default_tags = current_user.projects.where(:name => @initial_project_name).default_tags if @initial_project_name.present? end @status_message = @todos.size > 1 ? t('todos.added_new_next_action_plural') : t('todos.added_new_next_action_singular') @@ -1170,7 +1169,7 @@ end def update_context @context_changed = false - if params['todo']['context_id'].blank? && !params['context_name'].blank? + if params['todo']['context_id'].blank? && params['context_name'].present? context = current_user.contexts.where(:name => params['context_name'].strip).first unless context @new_context = current_user.contexts.build @@ -1278,21 +1277,21 @@ end # all completed todos [today@00:00, today@now] def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_day = Time.zone.now.beginning_of_day - completed_todos.completed_after(start_of_this_day).all(includes) + completed_todos.completed_after(start_of_this_day).includes(includes[:include]) end # all completed todos [begin_of_week, start_of_today] def get_done_rest_of_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_week = Time.zone.now.beginning_of_week start_of_this_day = Time.zone.now.beginning_of_day - completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).all(includes) + completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).includes(includes[:include]) end # all completed todos [begin_of_month, begin_of_week] def get_done_rest_of_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES}) start_of_this_month = Time.zone.now.beginning_of_month start_of_this_week = Time.zone.now.beginning_of_week - completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).all(includes) + completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).includes(includes[:include]) end def get_not_done_todos diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 5b41d62a..52349699 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -51,10 +51,10 @@ module ProjectsHelper next_project = content_tag(:li, link_to_project_mobile(@next_project, "6", @next_project.shortened_name), :class=>"next") if @next_project return content_tag(:ul, "#{prev_project}#{next_project}".html_safe, :class=>"next-prev-project") end - + def project_summary(project) project_description = '' - project_description += Tracks::Utils.render_text( project.description ) unless project.description.blank? + project_description += Tracks::Utils.render_text( project.description ) if project.description.present? project_description += content_tag(:p, "#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe ) diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index e6e44aac..df100aaa 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -398,7 +398,7 @@ module TodosHelper end def format_ical_notes(notes) - unless notes.nil? || notes.blank? + if notes.present? split_notes = notes.split(/\n/) joined_notes = split_notes.join("\\n") end @@ -416,7 +416,7 @@ module TodosHelper def render_animation(animation) html = "" animation.each do |step| - unless step.blank? + if step.present? html += step + "({ go: function() {\r\n" end end diff --git a/app/models/todo.rb b/app/models/todo.rb index 67a76a48..85597ffd 100644 --- a/app/models/todo.rb +++ b/app/models/todo.rb @@ -97,7 +97,7 @@ class Todo < ActiveRecord::Base end event :unhide do - transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| !t.show_from.blank? } + transitions :to => :deferred, :from => [:project_hidden], :guard => Proc.new{|t| t.show_from.present? } transitions :to => :pending, :from => [:project_hidden], :guard => :uncompleted_predecessors? transitions :to => :active, :from => [:project_hidden] end @@ -119,7 +119,7 @@ class Todo < ActiveRecord::Base def check_show_from_in_future if show_from_changed? # only check on change of show_from - if !show_from.blank? && (show_from < user.date) + if show_from.present? && (show_from < user.date) errors.add("show_from", I18n.t('models.todo.error_date_must_be_future')) end end @@ -270,7 +270,7 @@ class Todo < ActiveRecord::Base # (see http://stackoverflow.com/questions/682920/persisting-the-state-column-on-transition-using-rubyist-aasm-acts-as-state-machi) self[:show_from] = date - defer if active? && !date.blank? && show_from > user.date + defer if active? && date.present? && show_from > user.date end end @@ -305,7 +305,7 @@ class Todo < ActiveRecord::Base return unless predecessor_list.kind_of? String @predecessor_array=predecessor_list.split(",").inject([]) do |list, todo_id| - predecessor = self.user.todos.find( todo_id.to_i ) unless todo_id.blank? + predecessor = self.user.todos.find( todo_id.to_i ) if todo_id.present? list << predecessor unless predecessor.nil? list end @@ -347,7 +347,7 @@ class Todo < ActiveRecord::Base # value will be a string. In that case convert to array deps = [deps] unless deps.class == Array - deps.each { |dep| self.add_predecessor(self.user.todos.find(dep.to_i)) unless dep.blank? } + deps.each { |dep| self.add_predecessor(self.user.todos.find(dep.to_i)) if dep.present? } end alias_method :original_context=, :context= diff --git a/app/models/user.rb b/app/models/user.rb index 87726741..90f59d16 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -217,7 +217,7 @@ protected end def password_required? - auth_type == 'database' && crypted_password.blank? || !password.blank? + auth_type == 'database' && crypted_password.blank? || password.present? end end diff --git a/app/services/todo_from_rich_message.rb b/app/services/todo_from_rich_message.rb index 6efc1c8d..f919b0bb 100644 --- a/app/services/todo_from_rich_message.rb +++ b/app/services/todo_from_rich_message.rb @@ -16,7 +16,7 @@ class TodoFromRichMessage project = extractor.project context_id = default_context_id - unless context.blank? + if context.present? found_context = user.contexts.active.where("name like ?", "%#{context}%").first found_context = user.contexts.where("name like ?", "%#{context}%").first if !found_context context_id = found_context.id if found_context @@ -27,7 +27,7 @@ class TodoFromRichMessage end project_id = nil - unless project.blank? + if project.present? if project[0..3].downcase == "new:" found_project = user.projects.build found_project.name = project[4..259].strip diff --git a/app/views/projects/index.text.erb b/app/views/projects/index.text.erb index d9ae429d..99d62aa4 100644 --- a/app/views/projects/index.text.erb +++ b/app/views/projects/index.text.erb @@ -1,6 +1,6 @@ <% @projects.each do |p| -%> <%= p.name.upcase %> -<%= p.description + "\n" unless p.description.blank? -%> +<%= p.description + "\n" if p.description.present? -%> <%= count_undone_todos_phrase_text(p)%>. Project is <%= p.state %>. -<% end -%> \ No newline at end of file +<% end -%> diff --git a/app/views/projects/show.m.erb b/app/views/projects/show.m.erb index 3e672eae..8250b462 100644 --- a/app/views/projects/show.m.erb +++ b/app/views/projects/show.m.erb @@ -1,7 +1,7 @@ <% project = @project %> <%= project_next_prev_mobile %>