mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
Code style fixes
This commit is contained in:
parent
c6bbc67dab
commit
d8acf60049
72 changed files with 458 additions and 594 deletions
|
|
@ -1,6 +1,18 @@
|
|||
engines:
|
||||
brakeman:
|
||||
enabled: true
|
||||
fixme:
|
||||
enabled: true
|
||||
flog:
|
||||
enabled: true
|
||||
reek:
|
||||
enabled: true
|
||||
rubocop:
|
||||
enabled: true
|
||||
checks:
|
||||
Rubocop/Style/StringLiterals:
|
||||
enabled: false
|
||||
Rubocop/Style/TrailingCommaInLiteral:
|
||||
enabled: false
|
||||
Rubocop/Style/HashSyntax:
|
||||
enabled: false
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ class ApplicationController < ActionController::Base
|
|||
# Returns a count of next actions in the given context or project The result
|
||||
# is count and a string descriptor, correctly pluralised if there are no
|
||||
# actions or multiple actions
|
||||
#
|
||||
def count_undone_todos_phrase(todos_parent)
|
||||
count = count_undone_todos(todos_parent)
|
||||
deferred_count = count_deferred_todos(todos_parent)
|
||||
|
|
@ -83,13 +82,13 @@ class ApplicationController < ActionController::Base
|
|||
init_hidden_todo_counts(['context']) if !@context_hidden_todo_counts
|
||||
count = @context_hidden_todo_counts[todos_parent.id]
|
||||
else
|
||||
count = eval "@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]"
|
||||
count = eval("@#{todos_parent.class.to_s.downcase}_not_done_counts[#{todos_parent.id}]", binding, __FILE__, __LINE__)
|
||||
end
|
||||
count || 0
|
||||
end
|
||||
|
||||
def count_deferred_todos(todos_parent)
|
||||
return todos_parent.nil? ? 0 : eval("@#{todos_parent.class.to_s.downcase}_deferred_counts[#{todos_parent.id}]") || 0
|
||||
return todos_parent.nil? ? 0 : eval("@#{todos_parent.class.to_s.downcase}_deferred_counts[#{todos_parent.id}]", binding, __FILE__, __LINE__) || 0
|
||||
end
|
||||
|
||||
# Convert a date object to the format specified in the user's preferences in
|
||||
|
|
@ -222,14 +221,14 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def init_not_done_counts(parents=['project', 'context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts ||= current_user.todos.active.count_by_group('#{parent}_id')")
|
||||
eval("@#{parent}_deferred_counts ||= current_user.todos.deferred.count_by_group('#{parent}_id')")
|
||||
eval("@#{parent}_not_done_counts ||= current_user.todos.active.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
eval("@#{parent}_deferred_counts ||= current_user.todos.deferred.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
end
|
||||
end
|
||||
|
||||
def init_hidden_todo_counts(parents=['project', 'context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')")
|
||||
eval("@#{parent}_hidden_todo_counts ||= current_user.todos.active_or_hidden.count_by_group('#{parent}_id')", binding, __FILE__, __LINE__)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -263,8 +262,8 @@ class ApplicationController < ActionController::Base
|
|||
@source_view = "all_done"
|
||||
@page_title = t("#{object_name.pluralize}.all_completed_tasks_title", "#{object_name}_name".to_sym => object.name)
|
||||
|
||||
@done = object.todos.completed.reorder('completed_at DESC').includes(Todo::DEFAULT_INCLUDES).
|
||||
paginate(:page => params[:page], :per_page => 20)
|
||||
@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
|
||||
|
|
@ -284,5 +283,4 @@ class ApplicationController < ActionController::Base
|
|||
def set_group_view_by
|
||||
@group_view_by = params['_group_view_by'] || cookies['group_view_by'] || 'context'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class ContextsController < ApplicationController
|
||||
|
||||
helper :todos
|
||||
|
||||
before_action :init, :except => [:index, :create, :destroy, :order]
|
||||
|
|
@ -93,7 +92,6 @@ class ContextsController < ApplicationController
|
|||
end
|
||||
|
||||
# Edit the details of the context
|
||||
#
|
||||
def update
|
||||
process_params_for_update
|
||||
|
||||
|
|
@ -270,5 +268,4 @@ class ContextsController < ApplicationController
|
|||
return false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class DataController < ApplicationController
|
||||
|
||||
require 'csv'
|
||||
|
||||
def index
|
||||
|
|
@ -7,7 +6,6 @@ class DataController < ApplicationController
|
|||
end
|
||||
|
||||
def import
|
||||
|
||||
end
|
||||
|
||||
def csv_map
|
||||
|
|
@ -147,8 +145,7 @@ class DataController < ApplicationController
|
|||
def csv_notes
|
||||
content_type = 'text/csv'
|
||||
CSV.generate(result = "") do |csv|
|
||||
csv << ["id", "User ID", "Project", "Note",
|
||||
"Created at", "Updated at"]
|
||||
csv << ["id", "User ID", "Project", "Note", "Created at", "Updated at"]
|
||||
# had to remove project include because it's association order is leaking
|
||||
# through and causing an ambiguous column ref even with_exclusive_scope
|
||||
# didn't seem to help -JamesKebinger
|
||||
|
|
@ -210,8 +207,8 @@ class DataController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def sanitize_filename(filename)
|
||||
filename.gsub(/[^0-9A-z.\-]/, '_')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class FeedlistController < ApplicationController
|
||||
|
||||
helper :feedlist
|
||||
|
||||
def index
|
||||
|
|
@ -41,5 +40,4 @@ class FeedlistController < ApplicationController
|
|||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -59,6 +59,4 @@ class IntegrationsController < ApplicationController
|
|||
|
||||
return result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -82,5 +82,4 @@ class LoginController < ApplicationController
|
|||
return Time.now + 10 unless session['expiry_time']
|
||||
DateTime.strptime(session['expiry_time'], "%FT%T.%L%Z")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
require 'openssl'
|
||||
|
||||
class MailgunController < ApplicationController
|
||||
|
||||
skip_before_action :login_required, :only => [:mailgun]
|
||||
before_action :verify, :only => [:mailgun]
|
||||
protect_from_forgery with: :null_session
|
||||
|
|
@ -34,5 +33,4 @@ class MailgunController < ApplicationController
|
|||
return
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class NotesController < ApplicationController
|
||||
|
||||
before_action :set_source_view
|
||||
|
||||
def index
|
||||
|
|
@ -75,5 +74,4 @@ class NotesController < ApplicationController
|
|||
def note_params
|
||||
params.require(:note).permit(:project_id, :body)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class PreferencesController < ApplicationController
|
||||
|
||||
def index
|
||||
@page_title = t('preferences.page_title')
|
||||
@prefs = current_user.prefs
|
||||
|
|
@ -52,5 +51,4 @@ private
|
|||
notify :notice, t('preferences.updated')
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class ProjectsController < ApplicationController
|
||||
|
||||
helper :application, :todos, :notes
|
||||
before_action :set_source_view
|
||||
before_action :set_project_from_params, :only => [:update, :destroy, :show, :edit, :set_reviewed]
|
||||
|
|
@ -133,10 +132,10 @@ class ProjectsController < ApplicationController
|
|||
@projects_to_show = [@project]
|
||||
|
||||
@done = {}
|
||||
@done = @project.todos.completed.
|
||||
reorder("todos.completed_at DESC").
|
||||
limit(current_user.prefs.show_number_completed).
|
||||
includes(Todo::DEFAULT_INCLUDES) unless @max_completed == 0
|
||||
@done = @project.todos.completed
|
||||
.reorder("todos.completed_at DESC")
|
||||
.limit(current_user.prefs.show_number_completed)
|
||||
.includes(Todo::DEFAULT_INCLUDES) unless @max_completed == 0
|
||||
|
||||
@down_count = @not_done_todos.size + @deferred_todos.size + @pending_todos.size
|
||||
@count = @down_count
|
||||
|
|
@ -197,7 +196,6 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
# Edit the details of the project
|
||||
#
|
||||
def update
|
||||
template = ""
|
||||
|
||||
|
|
@ -350,5 +348,4 @@ class ProjectsController < ApplicationController
|
|||
def project_params
|
||||
params.require(:project).permit(:name, :position, :user_id, :description, :state, :default_context_id, :default_tags)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class FormHelper
|
||||
|
||||
def initialize(recurring_todo)
|
||||
@recurring_todo = recurring_todo
|
||||
|
||||
|
|
@ -47,7 +45,5 @@ module RecurringTodos
|
|||
# no match, let @recurring_todo handle it, or fail
|
||||
@recurring_todo.send(method, *args)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
class RecurringTodosController < ApplicationController
|
||||
|
||||
helper :todos, :recurring_todos
|
||||
|
||||
append_before_action :init, :only => [:index, :new, :edit, :create]
|
||||
|
|
@ -98,7 +97,6 @@ class RecurringTodosController < ApplicationController
|
|||
@completed_remaining = current_user.recurring_todos.completed.count
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
format.html do
|
||||
if @saved
|
||||
notify :notice, t('todos.recurring_deleted_success')
|
||||
|
|
@ -107,7 +105,6 @@ class RecurringTodosController < ApplicationController
|
|||
end
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
format.js do
|
||||
render
|
||||
end
|
||||
|
|
@ -230,5 +227,4 @@ class RecurringTodosController < ApplicationController
|
|||
where("fai_todos.id IS NULL").
|
||||
each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class SearchController < ApplicationController
|
||||
|
||||
helper :todos, :application, :notes, :projects, :contexts
|
||||
|
||||
def results
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
class StatsController < ApplicationController
|
||||
|
||||
SECONDS_PER_DAY = 86400;
|
||||
SECONDS_PER_DAY = 86_400;
|
||||
|
||||
helper :todos, :projects, :recurring_todos
|
||||
append_before_action :init, :except => :index
|
||||
|
|
@ -52,7 +51,6 @@ class StatsController < ApplicationController
|
|||
|
||||
case params['id']
|
||||
when 'avrt', 'avrt_end' # actions_visible_running_time
|
||||
|
||||
# HACK: because open flash chart uses & to denote the end of a parameter,
|
||||
# we cannot use URLs with multiple parameters (that would use &). So we
|
||||
# revert to using two id's for the same selection. avtr_end means that the
|
||||
|
|
@ -72,9 +70,9 @@ class StatsController < ApplicationController
|
|||
end
|
||||
|
||||
# get all running actions that are visible
|
||||
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked.
|
||||
select("todos.id, todos.created_at").
|
||||
reorder("todos.created_at DESC")
|
||||
@actions_running_time = current_user.todos.not_completed.not_hidden.not_deferred_or_blocked
|
||||
.select("todos.id, todos.created_at")
|
||||
.reorder("todos.created_at DESC")
|
||||
|
||||
selected_todo_ids = get_ids_from(@actions_running_time, week_from, week_to, params['id'] == 'avrt_end')
|
||||
@selected_actions = selected_todo_ids.size == 0 ? [] : current_user.todos.where("id in (" + selected_todo_ids.join(",") + ")")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
module Todos
|
||||
class TodoCreateParamsHelper
|
||||
|
||||
attr_reader :new_project_created, :new_context_created, :attributes
|
||||
|
||||
def initialize(params, user)
|
||||
|
|
@ -160,6 +159,5 @@ module Todos
|
|||
rescue
|
||||
@errors << { :attribute => group_type, :message => "unknown" }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class TodosController < ApplicationController
|
||||
|
||||
skip_before_action :login_required, :only => [:index, :tag, :list_deferred, :show, :list_hidden, :done]
|
||||
prepend_before_action :login_or_feed_token_required, :only => [:index, :tag, :list_deferred, :show, :list_hidden, :done]
|
||||
append_before_action :find_and_activate_ready, :only => [:index, :list_deferred]
|
||||
|
|
@ -519,7 +518,6 @@ class TodosController < ApplicationController
|
|||
@new_recurring_todo = check_for_next_todo(@todo) if @saved
|
||||
|
||||
respond_to do |format|
|
||||
|
||||
format.html do
|
||||
if @saved
|
||||
message = t('todos.action_deleted_success')
|
||||
|
|
@ -533,7 +531,6 @@ class TodosController < ApplicationController
|
|||
redirect_to :action => 'index'
|
||||
end
|
||||
end
|
||||
|
||||
format.js do
|
||||
if @saved
|
||||
determine_down_count
|
||||
|
|
@ -546,9 +543,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
render
|
||||
end
|
||||
|
||||
format.xml { render :body => '200 OK. Action deleted.', :status => 200 }
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -650,10 +645,10 @@ class TodosController < ApplicationController
|
|||
|
||||
# If you've set no_completed to zero, the completed items box isn't shown on
|
||||
# the tag page
|
||||
@done = todos_with_tag_ids.completed.
|
||||
limit(current_user.prefs.show_number_completed).
|
||||
reorder('todos.completed_at DESC').
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
@done = todos_with_tag_ids.completed
|
||||
.limit(current_user.prefs.show_number_completed)
|
||||
.reorder('todos.completed_at DESC')
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
|
||||
@projects = current_user.projects
|
||||
@contexts = current_user.contexts
|
||||
|
|
@ -705,7 +700,6 @@ class TodosController < ApplicationController
|
|||
@tag = Tag.where(:name => @tag_name).first_or_create
|
||||
end
|
||||
|
||||
|
||||
def tags
|
||||
tags_beginning = current_user.tags.where(Tag.arel_table[:name].matches("#{params[:term]}%"))
|
||||
tags_all = current_user.tags.where(Tag.arel_table[:name].matches("%#{params[:term]}%"))
|
||||
|
|
@ -765,14 +759,14 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def get_not_completed_for_predecessor(relation, todo_id=nil)
|
||||
items = relation.todos.not_completed.
|
||||
where('(LOWER(todos.description) ' + Common.like_operator + '?)', "%#{params[:term].downcase}%")
|
||||
items = relation.todos.not_completed
|
||||
.where('(LOWER(todos.description) ' + Common.like_operator + '?)', "%#{params[:term].downcase}%")
|
||||
items = items.where("AND NOT(todos.id=?)", todo_id) unless todo_id.nil?
|
||||
|
||||
items.
|
||||
includes(:context, :project).
|
||||
reorder('description ASC').
|
||||
limit(10)
|
||||
items
|
||||
.includes(:context, :project)
|
||||
.reorder('description ASC')
|
||||
.limit(10)
|
||||
end
|
||||
|
||||
def auto_complete_for_predecessor
|
||||
|
|
@ -1096,7 +1090,6 @@ end
|
|||
date_to_check ||= Time.zone.now
|
||||
|
||||
if recurring_todo.active? && recurring_todo.continues_recurring?(date_to_check)
|
||||
|
||||
# shift the reference date to yesterday if date_to_check is furher in
|
||||
# the past. This is to make sure we do not get older todos for overdue
|
||||
# todos. I.e. checking a daily todo that is overdue with 5 days will
|
||||
|
|
@ -1179,7 +1172,6 @@ end
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def update_context
|
||||
@context_changed = false
|
||||
if params['todo']['context_id'].blank? && params['context_name'].present?
|
||||
|
|
@ -1322,5 +1314,4 @@ end
|
|||
redirect_to(uri.path)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class UsersController < ApplicationController
|
||||
|
||||
before_action :admin_login_required, :only => [:index, :show]
|
||||
before_action :admin_or_self_login_required, :only => [:destroy]
|
||||
skip_before_action :login_required, :only => [:new, :create]
|
||||
|
|
@ -223,5 +222,4 @@ class UsersController < ApplicationController
|
|||
return false if params[:user][:password].empty?
|
||||
return true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -208,9 +208,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def link_to_delete(type, object, descriptor=sanitize(object.name))
|
||||
link_to(
|
||||
descriptor,
|
||||
self.send("#{type}_path", object, :format => 'js'),
|
||||
link_to(descriptor, self.send("#{type}_path", object, :format => 'js'),
|
||||
{
|
||||
:id => "delete_#{type}_#{object.id}",
|
||||
:class => "delete_#{type}_button icon",
|
||||
|
|
@ -250,5 +248,4 @@ module ApplicationHelper
|
|||
def js_error_messages_for(object)
|
||||
escape_javascript(get_list_of_error_messages_for(object))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module ContextsHelper
|
||||
|
||||
def show_context_name(context)
|
||||
if source_view_is :context
|
||||
content_tag(:span, :id => "context_name"){context.name}
|
||||
|
|
@ -19,5 +18,4 @@ module ContextsHelper
|
|||
def context_summary(context, undone_todo_count)
|
||||
content_tag(:p, "#{undone_todo_count}. Context is #{context.hidden? ? 'Hidden' : 'Active'}.".html_safe)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module DateLabelHelper
|
||||
|
||||
class GenericDateView
|
||||
include ActionView::Context
|
||||
include ActionView::Helpers
|
||||
|
|
@ -66,11 +65,9 @@ module DateLabelHelper
|
|||
yield
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class DueDateView < GenericDateView
|
||||
|
||||
def due_text
|
||||
case @days_sym
|
||||
when :overdue_by_one
|
||||
|
|
@ -100,11 +97,9 @@ module DateLabelHelper
|
|||
def due_date_mobile_html
|
||||
date_mobile_html_wrapper { @prefs.format_date(@due) }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class ShowFromDateView < GenericDateView
|
||||
|
||||
def show_from_text
|
||||
case @days_sym
|
||||
when :overdue_by_more_than_one, :overdue_by_one
|
||||
|
|
@ -127,7 +122,5 @@ module DateLabelHelper
|
|||
def show_from_date_html
|
||||
date_html_wrapper { show_from_text }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module FeedlistHelper
|
||||
|
||||
def linkoptions(format, options)
|
||||
merge_hashes( { :format => format }, options, user_token_hash)
|
||||
end
|
||||
|
|
@ -48,6 +47,4 @@ module FeedlistHelper
|
|||
def user_token_hash
|
||||
{ :token => current_user.token }
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
module LoginHelper
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module PreferencesHelper
|
||||
|
||||
def pref(model, pref_name, &block)
|
||||
s = content_tag(:label, Preference.human_attribute_name(pref_name), :for => model + "_" + pref_name)
|
||||
s << yield
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module ProjectsHelper
|
||||
|
||||
def show_project_name(project)
|
||||
if source_view_is :project
|
||||
content_tag(:span, :id => "project_name"){project.name}
|
||||
|
|
@ -52,5 +51,4 @@ module ProjectsHelper
|
|||
def link_to_edit_project (project, descriptor = sanitize(project.name))
|
||||
link_to_edit(:project, project, descriptor)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
module RecurringTodosHelper
|
||||
|
||||
def recurring_todo_tag_list
|
||||
tags_except_starred = @recurring_todo.tags.reject{ |t| t.name == Todo::STARRED_TAG_NAME }
|
||||
tag_list = tags_except_starred.
|
||||
collect{|t| content_tag(:span,link_to(t.name, tag_path(t.name)), :class => "tag #{t.label}")}.
|
||||
join('')
|
||||
tag_list = tags_except_starred
|
||||
.collect{ |t| content_tag(:span,link_to(t.name, tag_path(t.name)), :class => "tag #{t.label}") }
|
||||
.join('')
|
||||
return content_tag :span, tag_list.html_safe, :class => "tags"
|
||||
end
|
||||
|
||||
def recurring_todo_remote_delete_icon
|
||||
link_to( image_tag_for_delete,
|
||||
recurring_todo_path(@recurring_todo), :id => "delete_icon_"+@recurring_todo.id.to_s,
|
||||
link_to(image_tag_for_delete, recurring_todo_path(@recurring_todo),
|
||||
:id => "delete_icon_" + @recurring_todo.id.to_s,
|
||||
:class => "icon delete_icon", :title => t('todos.delete_recurring_action_title'), :x_confirm_message => t('todos.delete_recurring_action_confirm', :description => @recurring_todo.description))
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module StatsHelper
|
||||
|
||||
def font_size(cloud, tag)
|
||||
9 + 2 * cloud.relative_size(tag)
|
||||
end
|
||||
|
|
@ -19,5 +18,4 @@ module StatsHelper
|
|||
def array_of_month_labels(count)
|
||||
Array.new(count) { |i| month_label(i) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
require 'staleness'
|
||||
|
||||
module TodosHelper
|
||||
|
||||
# === helpers for rendering container
|
||||
|
||||
def empty_message_holder(container_name, show, title_param=nil)
|
||||
content_tag(:div, :id => "no_todos_in_view", :class => "container #{container_name}", :style => "display:" + (show ? "block" : "none") ) do
|
||||
content_tag(:h2) { t("todos.no_actions.title", :param=>title_param) } +
|
||||
|
|
@ -143,8 +141,7 @@ module TodosHelper
|
|||
:show_empty_containers => true,
|
||||
:container_name => "#{period}",
|
||||
:title =>t("todos.calendar.#{period}", :month => l(Time.zone.now, :format => "%B"), :next_month => l(1.month.from_now, :format => "%B"))
|
||||
}
|
||||
}
|
||||
} }
|
||||
end
|
||||
|
||||
# === helpers for rendering a todo
|
||||
|
|
@ -684,5 +681,4 @@ module TodosHelper
|
|||
end
|
||||
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class Context < ApplicationRecord
|
||||
|
||||
has_many :todos, -> { order(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")).includes(:project) }, :dependent => :delete_all
|
||||
has_many :recurring_todos, :dependent => :delete_all
|
||||
belongs_to :user
|
||||
|
|
@ -15,7 +14,6 @@ class Context < ApplicationRecord
|
|||
include AASM
|
||||
|
||||
aasm :column => :state do
|
||||
|
||||
state :active, :initial => true
|
||||
state :closed
|
||||
state :hidden
|
||||
|
|
@ -48,11 +46,9 @@ class Context < ApplicationRecord
|
|||
def no_active_todos?
|
||||
return todos.active.count == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class NullContext
|
||||
|
||||
def nil?
|
||||
true
|
||||
end
|
||||
|
|
@ -64,5 +60,4 @@ class NullContext
|
|||
def name
|
||||
''
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
class Dependency < ApplicationRecord
|
||||
|
||||
# touch to make sure todo caches for predecessor and successor are invalidated
|
||||
|
||||
belongs_to :predecessor, :foreign_key => 'predecessor_id', :class_name => 'Todo', :touch => true
|
||||
belongs_to :successor, :foreign_key => 'successor_id', :class_name => 'Todo', :touch => true
|
||||
|
||||
validate :check_circular_dependencies
|
||||
|
||||
def check_circular_dependencies
|
||||
unless predecessor.nil? or successor.nil?
|
||||
unless predecessor.nil? || successor.nil?
|
||||
errors.add("Depends on:", "Adding '#{successor.specification}' would create a circular dependency") if successor.is_successor?(predecessor)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class MessageGateway < ActionMailer::Base
|
||||
|
||||
def receive(email)
|
||||
user = get_receiving_user_from_email_address(email)
|
||||
return false if user.nil?
|
||||
|
|
|
|||
|
|
@ -32,5 +32,4 @@ class Preference < ApplicationRecord
|
|||
def format_date(date)
|
||||
return date ? date.in_time_zone(time_zone).strftime("#{date_format}") : ''
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ class Project < ApplicationRecord
|
|||
include AASM
|
||||
|
||||
aasm :column => :state do
|
||||
|
||||
state :active, :initial => true
|
||||
state :hidden
|
||||
state :completed, :enter => :set_completed_at_date, :exit => :clear_completed_at_date
|
||||
|
|
@ -145,11 +144,9 @@ class Project < ApplicationRecord
|
|||
end
|
||||
count
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class NullProject
|
||||
|
||||
def hidden?
|
||||
false
|
||||
end
|
||||
|
|
@ -169,5 +166,4 @@ class NullProject
|
|||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class RecurringTodo < ApplicationRecord
|
|||
validates_presence_of :description, :recurring_period, :target, :ends_on, :context
|
||||
|
||||
validates_length_of :description, :maximum => 100
|
||||
validates_length_of :notes, :maximum => 60000, :allow_nil => true
|
||||
validates_length_of :notes, :maximum => 60_000, :allow_nil => true
|
||||
|
||||
validate :period_validation
|
||||
validate :pattern_specific_validations
|
||||
|
|
@ -72,7 +72,7 @@ class RecurringTodo < ApplicationRecord
|
|||
|
||||
def pattern
|
||||
if valid_period?
|
||||
@pattern = eval("RecurringTodos::#{recurring_period.capitalize}RecurrencePattern.new(user)")
|
||||
@pattern = eval("RecurringTodos::#{recurring_period.capitalize}RecurrencePattern.new(user)", binding, __FILE__, __LINE__)
|
||||
@pattern.build_from_recurring_todo(self)
|
||||
end
|
||||
@pattern
|
||||
|
|
@ -138,5 +138,4 @@ class RecurringTodo < ApplicationRecord
|
|||
def continues_recurring?(previous)
|
||||
pattern.continues_recurring?(previous)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class AbstractRecurrencePattern
|
||||
|
||||
attr_accessor :attributes
|
||||
|
||||
def initialize(user)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class AbstractRecurringTodosBuilder
|
||||
|
||||
attr_reader :mapped_attributes, :pattern
|
||||
|
||||
def initialize(user, attributes, pattern_class)
|
||||
|
|
@ -10,8 +8,8 @@ module RecurringTodos
|
|||
|
||||
@attributes = attributes
|
||||
@selector = get_selector(selector_key)
|
||||
@filterred_attributes = filter_attributes(@attributes)
|
||||
@mapped_attributes = map_attributes(@filterred_attributes)
|
||||
@filtered_attributes = filter_attributes(@attributes)
|
||||
@mapped_attributes = map_attributes(@filtered_attributes)
|
||||
|
||||
@pattern = pattern_class.new(user)
|
||||
@pattern.attributes = @mapped_attributes
|
||||
|
|
@ -60,11 +58,11 @@ module RecurringTodos
|
|||
|
||||
def filter_attributes(attributes)
|
||||
# get pattern independend attributes
|
||||
filterred_attributes = filter_generic_attributes(attributes)
|
||||
filtered_attributes = filter_generic_attributes(attributes)
|
||||
# append pattern specific attributes
|
||||
attributes_to_filter.each{|key| filterred_attributes[key]= attributes[key] if attributes.key?(key)}
|
||||
attributes_to_filter.each{ |key| filtered_attributes[key]= attributes[key] if attributes.key?(key) }
|
||||
|
||||
filterred_attributes
|
||||
filtered_attributes
|
||||
end
|
||||
|
||||
def filter_generic_attributes(attributes)
|
||||
|
|
@ -89,7 +87,7 @@ module RecurringTodos
|
|||
|
||||
def map_attributes
|
||||
# should be overwritten by subclasses to map attributes to activerecord model attributes
|
||||
@filterred_attributes
|
||||
@filtered_attributes
|
||||
end
|
||||
|
||||
# helper method to be used in mapped_attributes in subclasses
|
||||
|
|
@ -129,7 +127,7 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def save_tags
|
||||
@recurring_todo.tag_with(@filterred_attributes[:tag_list]) if @filterred_attributes[:tag_list].present?
|
||||
@recurring_todo.tag_with(@filtered_attributes[:tag_list]) if @filtered_attributes[:tag_list].present?
|
||||
@recurring_todo.reload
|
||||
end
|
||||
|
||||
|
|
@ -145,7 +143,5 @@ module RecurringTodos
|
|||
# avoid nil
|
||||
attributes[:tag_list].blank? ? "" : attributes[:tag_list].strip
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class DailyRecurrencePattern < AbstractRecurrencePattern
|
||||
|
||||
def initialize(user)
|
||||
super user
|
||||
end
|
||||
|
|
@ -47,6 +45,5 @@ module RecurringTodos
|
|||
return previous == nil ? start : start + every_x_days.day - 1.day
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module RecurringTodos
|
||||
|
||||
class DailyRecurringTodosBuilder < AbstractRecurringTodosBuilder
|
||||
attr_reader :recurring_todo, :pattern
|
||||
|
||||
|
|
@ -29,7 +28,5 @@ module RecurringTodos
|
|||
def valid_selector?(selector)
|
||||
%w{daily_every_x_day daily_every_work_day}.include?(selector)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class MonthlyRecurrencePattern < AbstractRecurrencePattern
|
||||
|
||||
def initialize(user)
|
||||
super user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module RecurringTodos
|
||||
|
||||
class MonthlyRecurringTodosBuilder < AbstractRecurringTodosBuilder
|
||||
attr_reader :recurring_todo
|
||||
|
||||
|
|
@ -40,7 +39,5 @@ module RecurringTodos
|
|||
def valid_selector?(selector)
|
||||
%w{monthly_every_x_day monthly_every_xth_day}.include?(selector)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class RecurringTodosBuilder
|
||||
|
||||
attr_reader :builder, :project, :context, :tag_list, :user
|
||||
|
||||
def initialize (user, attributes)
|
||||
|
|
@ -17,7 +15,7 @@ module RecurringTodos
|
|||
|
||||
def create_builder(selector)
|
||||
raise "Unknown recurrence selector in :recurring_period (#{selector})" unless valid_selector? selector
|
||||
eval("RecurringTodos::#{selector.capitalize}RecurringTodosBuilder.new(@user, @attributes)")
|
||||
eval("RecurringTodos::#{selector.capitalize}RecurringTodosBuilder.new(@user, @attributes)", binding, __FILE__, __LINE__)
|
||||
end
|
||||
|
||||
def build
|
||||
|
|
@ -72,7 +70,5 @@ module RecurringTodos
|
|||
def parse_context
|
||||
@context, @new_context_created = @attributes.parse_collection(:context, @user.contexts)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class WeeklyRecurrencePattern < AbstractRecurrencePattern
|
||||
|
||||
def initialize(user)
|
||||
super user
|
||||
end
|
||||
|
|
@ -79,8 +77,5 @@ module RecurringTodos
|
|||
end
|
||||
-1
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module RecurringTodos
|
||||
|
||||
class WeeklyRecurringTodosBuilder < AbstractRecurringTodosBuilder
|
||||
attr_reader :recurring_todo
|
||||
|
||||
|
|
@ -37,7 +36,5 @@ module RecurringTodos
|
|||
def valid_selector?(key)
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module RecurringTodos
|
||||
|
||||
class YearlyRecurrencePattern < AbstractRecurrencePattern
|
||||
|
||||
def initialize(user)
|
||||
super user
|
||||
end
|
||||
|
|
@ -104,6 +102,5 @@ module RecurringTodos
|
|||
|
||||
the_next
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module RecurringTodos
|
||||
|
||||
class YearlyRecurringTodosBuilder < AbstractRecurringTodosBuilder
|
||||
attr_reader :recurring_todo
|
||||
|
||||
|
|
@ -39,7 +38,5 @@ module RecurringTodos
|
|||
def get_every_other2
|
||||
{ 0 => :yearly_month_of_year, 1 => :yearly_month_of_year2 }[get_recurrence_selector]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module Search
|
||||
|
||||
class SearchResults
|
||||
attr_reader :results
|
||||
|
||||
|
|
@ -27,16 +26,16 @@ module Search
|
|||
|
||||
def incomplete_todos(terms)
|
||||
@user.todos.
|
||||
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND todos.completed_at IS NULL", terms, terms).
|
||||
includes(Todo::DEFAULT_INCLUDES).
|
||||
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
|
||||
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND todos.completed_at IS NULL", terms, terms)
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
.reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
|
||||
end
|
||||
|
||||
def complete_todos(terms)
|
||||
@user.todos.
|
||||
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND NOT (todos.completed_at IS NULL)", terms, terms).
|
||||
includes(Todo::DEFAULT_INCLUDES).
|
||||
reorder("todos.completed_at DESC")
|
||||
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND NOT (todos.completed_at IS NULL)", terms, terms)
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
.reorder("todos.completed_at DESC")
|
||||
end
|
||||
|
||||
def todo_tags_by_name(terms)
|
||||
|
|
@ -48,7 +47,5 @@ module Search
|
|||
"WHERE todos.user_id=? " +
|
||||
"AND tags.name " + Common.like_operator + " ? ", @user.id, terms])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
module Stats
|
||||
class Actions
|
||||
|
||||
SECONDS_PER_DAY = 86400;
|
||||
SECONDS_PER_DAY = 86_400
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
|
||||
|
|
@ -171,9 +171,9 @@ module Stats
|
|||
# - actions not deferred (show_from must be null)
|
||||
# - actions not pending/blocked
|
||||
|
||||
@actions_running_time = @user.todos.not_completed.not_hidden.not_deferred_or_blocked.
|
||||
select("todos.created_at").
|
||||
reorder("todos.created_at DESC")
|
||||
@actions_running_time = @user.todos.not_completed.not_hidden.not_deferred_or_blocked
|
||||
.select("todos.created_at")
|
||||
.reorder("todos.created_at DESC")
|
||||
|
||||
@max_weeks = difference_in_weeks(@today, @actions_running_time.last.created_at)
|
||||
@actions_running_per_week_array = convert_to_weeks_from_today_array(@actions_running_time, @max_weeks + 1, :created_at)
|
||||
|
|
@ -202,9 +202,9 @@ module Stats
|
|||
end
|
||||
|
||||
def open_per_week_data
|
||||
@actions_started = @user.todos.created_after(@today-53.weeks).
|
||||
select("todos.created_at, todos.completed_at").
|
||||
reorder("todos.created_at DESC")
|
||||
@actions_started = @user.todos.created_after(@today - 53.weeks)
|
||||
.select("todos.created_at, todos.completed_at")
|
||||
.reorder("todos.created_at DESC")
|
||||
|
||||
@max_weeks = difference_in_weeks(@today, @actions_started.last.created_at)
|
||||
|
||||
|
|
@ -373,7 +373,7 @@ module Stats
|
|||
a = []
|
||||
start_week = difference_in_weeks(@today, record.created_at)
|
||||
end_week = record.completed_at ? difference_in_weeks(@today, record.completed_at) : 0
|
||||
end_week.upto(start_week) { |i| a << i };
|
||||
end_week.upto(start_week) { |i| a << i }
|
||||
return a
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
module Stats
|
||||
|
||||
class Chart
|
||||
|
||||
attr_reader :action, :height, :width
|
||||
|
||||
def initialize(action, dimensions = {})
|
||||
@action = action
|
||||
@height = dimensions.fetch(:height) { 250 }
|
||||
|
|
@ -12,7 +11,5 @@ module Stats
|
|||
def dimensions
|
||||
"#{width}x#{height}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class Contexts
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class Projects
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
|
@ -24,6 +24,5 @@ module Stats
|
|||
projects = user.projects.order('created_at ASC')
|
||||
projects.sort_by{ |p| p.running_time }.reverse.take(10)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
# http://www.juixe.com/techknow/index.php/2006/07/15/acts-as-taggable-tag-cloud/
|
||||
module Stats
|
||||
class TagCloud
|
||||
|
||||
attr_reader :levels, :tags
|
||||
|
||||
def initialize(tags)
|
||||
@levels = 10
|
||||
@tags = tags.sort_by { |tag| tag.name.downcase }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class TagCloudQuery
|
||||
|
||||
attr_reader :user, :cutoff
|
||||
|
||||
def initialize(user, cutoff = nil)
|
||||
@user = user
|
||||
@cutoff = cutoff
|
||||
|
|
@ -19,7 +19,7 @@ module Stats
|
|||
|
||||
def sql
|
||||
# TODO: parameterize limit
|
||||
query = "SELECT tags.id, tags.name AS name, count(*) AS count"
|
||||
query = "SELECT tags.id, tags.name AS name, COUNT(*) AS count"
|
||||
query << " FROM taggings, tags, todos"
|
||||
query << " WHERE tags.id = tag_id"
|
||||
query << " AND todos.user_id = ? "
|
||||
|
|
@ -33,6 +33,5 @@ module Stats
|
|||
query << " ORDER BY count DESC, name "
|
||||
query << " LIMIT 100"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
module Stats
|
||||
class TimeToComplete
|
||||
|
||||
SECONDS_PER_DAY = 86400;
|
||||
SECONDS_PER_DAY = 86_400
|
||||
|
||||
attr_reader :actions
|
||||
|
||||
def initialize(actions)
|
||||
@actions = actions
|
||||
end
|
||||
|
|
@ -58,6 +58,5 @@ module Stats
|
|||
def arbitrary_day
|
||||
@arbitrary_day ||= Time.utc(2000, 1, 1, 0, 0)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# and visible contexts will be included.
|
||||
module Stats
|
||||
class TopContextsQuery
|
||||
|
||||
attr_reader :user, :running, :limit
|
||||
|
||||
def initialize(user, options = {})
|
||||
@user = user
|
||||
@running = options.fetch(:running) { false }
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# or completed since that cutoff will be included.
|
||||
module Stats
|
||||
class TopProjectsQuery
|
||||
|
||||
attr_reader :user, :cutoff
|
||||
|
||||
def initialize(user, cutoff = nil)
|
||||
@user = user
|
||||
@cutoff = cutoff
|
||||
|
|
@ -34,6 +34,5 @@ module Stats
|
|||
query << "ORDER BY count DESC "
|
||||
query << "LIMIT 10"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class Totals
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
|
@ -83,6 +83,5 @@ module Stats
|
|||
def tag_ids
|
||||
@tag_ids ||= Stats::UserTagsQuery.new(user).result.map(&:id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class UserStats
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
|
@ -38,6 +38,5 @@ module Stats
|
|||
end
|
||||
@tag_cloud_90days
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
module Stats
|
||||
class UserTagsQuery
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
|
@ -21,6 +21,5 @@ module Stats
|
|||
AND todos.user_id = ?
|
||||
SQL
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class Tag < ApplicationRecord
|
||||
|
||||
has_many :taggings
|
||||
has_many :taggable, :through => :taggings
|
||||
|
||||
|
|
@ -29,5 +28,4 @@ class Tag < ApplicationRecord
|
|||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
# The Tagging join model.
|
||||
|
||||
class Tagging < ApplicationRecord
|
||||
|
||||
belongs_to :tag
|
||||
belongs_to :taggable, :polymorphic => true, :touch => true
|
||||
|
||||
|
|
@ -13,5 +10,4 @@ class Tagging < ApplicationRecord
|
|||
def delete_orphaned_tag
|
||||
tag.destroy if tag and tag.taggings.count == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
class Todo < ApplicationRecord
|
||||
|
||||
MAX_DESCRIPTION_LENGTH = 300
|
||||
MAX_NOTES_LENGTH = 60000
|
||||
MAX_NOTES_LENGTH = 60_000
|
||||
|
||||
after_save :save_predecessors
|
||||
|
||||
|
|
@ -36,10 +35,10 @@ class Todo < ApplicationRecord
|
|||
scope :pending, -> { where 'todos.state = ?', 'pending' }
|
||||
scope :deferred_or_blocked, -> { where '(todos.state = ?) OR (todos.state = ?)', 'deferred', 'pending' }
|
||||
scope :hidden, -> {
|
||||
joins('INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id').
|
||||
joins('LEFT OUTER JOIN projects p_hidden ON p_hidden.id = todos.project_id').
|
||||
where('(c_hidden.state = ? OR p_hidden.state = ?)', 'hidden', 'hidden').
|
||||
where('NOT todos.state = ?', 'completed') }
|
||||
joins('INNER JOIN contexts c_hidden ON c_hidden.id = todos.context_id')
|
||||
.joins('LEFT OUTER JOIN projects p_hidden ON p_hidden.id = todos.project_id')
|
||||
.where('(c_hidden.state = ? OR p_hidden.state = ?)', 'hidden', 'hidden')
|
||||
.where('NOT todos.state = ?', 'completed') }
|
||||
scope :not_hidden, -> { not_context_hidden.not_project_hidden }
|
||||
scope :not_deferred_or_blocked, -> { where '(NOT todos.state=?) AND (NOT todos.state = ?)', 'deferred', 'pending' }
|
||||
scope :not_project_hidden, -> { joins('LEFT OUTER JOIN projects p ON p.id = todos.project_id').where('p.id IS NULL OR NOT(p.state = ?)', 'hidden') }
|
||||
|
|
@ -50,12 +49,12 @@ class Todo < ApplicationRecord
|
|||
scope :are_due, -> { where 'NOT (todos.due IS NULL)' }
|
||||
scope :due_today, -> { where("todos.due <= ?", Time.zone.now) }
|
||||
scope :with_tag, lambda { |tag_id| joins("INNER JOIN taggings ON todos.id = taggings.taggable_id").where("taggings.tag_id = ? AND taggings.taggable_type='Todo'", tag_id) }
|
||||
scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * from taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) }
|
||||
scope :with_tags, lambda { |tag_ids| where("EXISTS(SELECT * FROM taggings t WHERE t.tag_id IN (?) AND t.taggable_id=todos.id AND t.taggable_type='Todo')", tag_ids) }
|
||||
scope :completed_after, lambda { |date| where("todos.completed_at > ?", date) }
|
||||
scope :completed_before, lambda { |date| where("todos.completed_at < ?", date) }
|
||||
scope :created_after, lambda { |date| where("todos.created_at > ?", date) }
|
||||
scope :created_before, lambda { |date| where("todos.created_at < ?", date) }
|
||||
scope :created_or_completed_after, lambda { |date| where("todos.created_at > ? or todos.completed_at > ?", date, date) }
|
||||
scope :created_or_completed_after, lambda { |date| where("todos.created_at > ? OR todos.completed_at > ?", date, date) }
|
||||
|
||||
def self.due_after(date)
|
||||
where('todos.due > ?', date)
|
||||
|
|
@ -73,7 +72,6 @@ class Todo < ApplicationRecord
|
|||
aasm_initial_state = Proc.new { (self.show_from && self.user && (self.show_from > self.user.date)) ? :deferred : :active }
|
||||
|
||||
aasm :column => :state do
|
||||
|
||||
state :active
|
||||
state :completed, :before_enter => Proc.new { self.completed_at = Time.zone.now }, :before_exit => Proc.new { self.completed_at = nil }
|
||||
state :deferred, :before_exit => Proc.new { self[:show_from] = nil }
|
||||
|
|
@ -124,7 +122,7 @@ class Todo < ApplicationRecord
|
|||
end
|
||||
|
||||
def no_uncompleted_predecessors_or_deferral?
|
||||
no_deferral = show_from.blank? or Time.zone.now > show_from
|
||||
no_deferral = show_from.blank? || Time.zone.now > show_from
|
||||
return (no_deferral && no_uncompleted_predecessors?)
|
||||
end
|
||||
|
||||
|
|
@ -284,14 +282,14 @@ class Todo < ApplicationRecord
|
|||
|
||||
# activate todos that should be activated if the current todo is completed
|
||||
def activate_pending_todos
|
||||
pending_todos = successors.select { |t| t.uncompleted_predecessors.empty? and !t.completed? }
|
||||
pending_todos = successors.select { |t| t.uncompleted_predecessors.empty? && !t.completed? }
|
||||
pending_todos.each { |t| t.activate! }
|
||||
return pending_todos
|
||||
end
|
||||
|
||||
# Return todos that should be blocked if the current todo is undone
|
||||
def block_successors
|
||||
active_successors = successors.select {|t| t.active? or t.deferred?}
|
||||
active_successors = successors.select { |t| t.active? || t.deferred? }
|
||||
active_successors.each { |t| t.block! }
|
||||
return active_successors
|
||||
end
|
||||
|
|
@ -387,5 +385,4 @@ class Todo < ApplicationRecord
|
|||
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
module Todos
|
||||
class Calendar
|
||||
|
||||
attr_reader :user, :included_tables
|
||||
|
||||
def initialize(user)
|
||||
|
|
@ -53,6 +52,5 @@ module Todos
|
|||
def actions
|
||||
user.todos.not_completed.includes(included_tables).reorder("due")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ module Todos
|
|||
end
|
||||
|
||||
not_done_todos = not_done_todos.
|
||||
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")).
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
|
||||
not_done_todos = not_done_todos.limit(sanitize(params[:limit])) if params[:limit]
|
||||
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ class User < ApplicationRecord
|
|||
dependent: :delete_all
|
||||
|
||||
has_many(:deferred_todos,
|
||||
-> { where('state = ?', 'deferred').
|
||||
order('show_from ASC, todos.created_at DESC')},
|
||||
-> { where('state = ?', 'deferred')
|
||||
.order('show_from ASC, todos.created_at DESC') },
|
||||
:class_name => 'Todo') do
|
||||
def find_and_activate_ready
|
||||
where('show_from <= ?', Time.current).collect { |t| t.activate! }
|
||||
|
|
@ -218,5 +218,4 @@ protected
|
|||
taggings = Tagging.where(taggable_id: ids).pluck(:id)
|
||||
Tagging.where(id: taggings).delete_all
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -72,5 +72,4 @@ class RichMessageExtractor
|
|||
def fix_date_string yymmdd
|
||||
"20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class TodoFromRichMessage
|
||||
|
||||
attr_reader :user, :default_context_id, :description, :notes
|
||||
|
||||
def initialize(user, default_context_id, description, notes)
|
||||
|
|
@ -21,8 +20,9 @@ class TodoFromRichMessage
|
|||
|
||||
context_id = default_context_id
|
||||
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
|
||||
# TODO: Should this use ILIKE on Postgres?
|
||||
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
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ require "dispatcher"
|
|||
|
||||
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
|
||||
Dispatcher.dispatch
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue