More code style fixes

This commit is contained in:
Jyri-Petteri Paloposki 2020-10-27 21:39:19 +02:00
parent 465419f46a
commit d4c9041ccd
61 changed files with 406 additions and 422 deletions

1
.ruby-version Normal file
View file

@ -0,0 +1 @@
2.5

17
Gemfile
View file

@ -56,16 +56,15 @@ group :development, :test do
end
group :test do
gem 'rails-controller-testing'
gem 'rails-dom-testing', '~> 2.0.0'
gem 'factory_bot_rails'
gem 'rspec-expectations'
gem 'database_cleaner'
gem 'mocha', :require => false
gem 'minitest-stub-const'
gem 'simplecov'
# get test coverage info on codeclimate
gem 'codeclimate-test-reporter', '1.0.7', group: :test, require: nil
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'mocha', :require => false
gem 'minitest-stub-const'
gem 'rails-controller-testing'
gem 'rails-dom-testing', '~> 2.0.0'
gem 'rspec-expectations'
gem 'simplecov'
end

View file

@ -27,7 +27,7 @@ class ApplicationController < ActionController::Base
locale ||= prefs.locale unless current_user.nil? # otherwise, the locale of the currently logged in user takes over
locale ||= request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first if request.env['HTTP_ACCEPT_LANGUAGE']
if locale && I18n::available_locales.map(&:to_s).include?(locale.to_s)
if locale && I18n.available_locales.map(&:to_s).include?(locale.to_s)
I18n.locale = locale
else
I18n.locale = I18n.default_locale
@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base
# 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"
return if session.nil? || controller_name == 'feed' || session['noexpiry'] == "on"
# Get expiry time (allow ten seconds window for the case where we have
# none)
@ -54,7 +54,7 @@ class ApplicationController < ActionController::Base
end
end
def render_failure message, status = 404
def render_failure(message, status = 404)
render :body => message, :status => status
end
@ -272,7 +272,7 @@ class ApplicationController < ActionController::Base
def done_todos_for(object)
object_name = object.class.name.downcase # context or project
@source_view = "done"
eval("@#{object_name} = object")
eval("@#{object_name} = object", binding, __FILE__, __LINE__)
@page_title = t("#{object_name.pluralize}.completed_tasks_title", "#{object_name}_name".to_sym => object.name)
@done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(object.todos)

View file

@ -98,7 +98,7 @@ class ContextsController < ApplicationController
@context.attributes = context_params
@saved = @context.save
@state_saved = set_state_for_update(@new_state)
@saved = @saved && @state_saved
@saved &&= @state_saved
if @saved
@state_changed = (@original_context_state != @context.state)

View file

@ -5,8 +5,7 @@ class DataController < ApplicationController
@page_title = "TRACKS::Export"
end
def import
end
def import; end
def csv_map
if params[:file].blank?
@ -16,7 +15,7 @@ class DataController < ApplicationController
@import_to = params[:import_to]
begin
#get column headers and format as [['name', column_number]...]
# Get column headers and format as [['name', column_number]...]
i = -1
@headers = import_headers(params[:file].path).collect { |v| [v, i += 1] }
@headers.unshift ['', i]
@ -26,7 +25,7 @@ class DataController < ApplicationController
return
end
#save file for later
# Save file for later
begin
uploaded_file = params[:file]
@filename = sanitize_filename(uploaded_file.original_filename)
@ -94,17 +93,17 @@ class DataController < ApplicationController
all_tables['projects'] = current_user.projects.load
todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
"FROM tags, taggings, todos "+
"WHERE todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = todos.id ", current_user.id])
"SELECT DISTINCT tags.id
FROM tags, taggings, todos
WHERE todos.user_id = ?
AND tags.id = taggings.tag_id
AND taggings.taggable_id = todos.id", current_user.id])
rec_todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
"FROM tags, taggings, recurring_todos "+
"WHERE recurring_todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
"SELECT DISTINCT tags.id
FROM tags, taggings, recurring_todos
WHERE recurring_todos.user_id = ?
AND tags.id = taggings.tag_id
AND taggings.taggable_id = recurring_todos.id", current_user.id])
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
@ -114,7 +113,8 @@ class DataController < ApplicationController
all_tables['recurring_todos'] = current_user.recurring_todos.load
result = all_tables.to_yaml
result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings
# TODO: general functionality for line endings
result.gsub!(/\n/, "\r\n")
send_data(result, :filename => "tracks_backup.yml", :type => 'text/plain')
end
@ -163,17 +163,17 @@ class DataController < ApplicationController
def xml_export
todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
"FROM tags, taggings, todos "+
"WHERE todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = todos.id ", current_user.id])
"SELECT DISTINCT tags.id
FROM tags, taggings, todos
WHERE todos.user_id = ?
AND tags.id = taggings.tag_id
AND taggings.taggable_id = todos.id", current_user.id])
rec_todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+
"FROM tags, taggings, recurring_todos "+
"WHERE recurring_todos.user_id=? "+
"AND tags.id = taggings.tag_id " +
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
"SELECT DISTINCT tags.id
FROM tags, taggings, recurring_todos
WHERE recurring_todos.user_id = ?
AND tags.id = taggings.tag_id
AND taggings.taggable_id = recurring_todos.id", current_user.id])
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
@ -195,7 +195,7 @@ class DataController < ApplicationController
# adjusts time to utc
def adjust_time(timestring)
if (timestring == '') or (timestring == nil)
if (timestring == '') || (timestring == nil)
return nil
else
return Time.parse(timestring + 'UTC')

View file

@ -17,8 +17,8 @@ class IntegrationsController < ApplicationController
end
def search_plugin
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read].
pack('m').gsub(/\n/, '')
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read]
.pack('m').gsub(/\n/, '')
end
def cloudmailin
@ -37,7 +37,7 @@ class IntegrationsController < ApplicationController
private
def process_message(message)
MessageGateway::receive(Mail.new(message))
MessageGateway.receive(Mail.new(message))
end
def verify_cloudmailin_signature
@ -48,7 +48,7 @@ class IntegrationsController < ApplicationController
def flatten_params(params, title = nil, result = {})
params.each do |key, value|
if value.kind_of?(Hash)
if value.is_a? Hash
key_name = title ? "#{title}[#{key}]" : key
flatten_params(value, key_name, result)
else

View file

@ -15,8 +15,8 @@ class LoginController < ApplicationController
cookies[:preferred_auth] = prefered_auth? unless cookies[:preferred_auth]
case request.method
when 'POST'
if @user = User.authenticate(params['user_login'], params['user_password'])
@user.update_attribute(:last_login_at, Time.now)
if (@user = User.authenticate(params['user_login'], params['user_password']))
@user.update_attribute(:last_login_at, Time.zone.now)
return handle_post_success
else
handle_post_failure
@ -43,7 +43,7 @@ class LoginController < ApplicationController
if session
return unless should_expire_sessions?
# Get expiry time (allow ten seconds window for the case where we have none)
time_left = expiry_time - Time.now
time_left = expiry_time - Time.zone.now
@session_expired = (time_left < (10 * 60)) # Session will time out before the next check
end
end
@ -61,7 +61,7 @@ class LoginController < ApplicationController
session['noexpiry'] = params['user_noexpiry']
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
notify :notice, "Login successful: session #{msg}"
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
cookies[:tracks_login] = { :value => @user.login, :expires => Time.zone.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
unless should_expire_sessions?
@user.remember_me
cookies[:auth_token] = { :value => @user.remember_token, :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
@ -79,7 +79,7 @@ class LoginController < ApplicationController
end
def expiry_time
return Time.now + 10 unless session['expiry_time']
return Time.zone.now + 10 unless session['expiry_time']
DateTime.strptime(session['expiry_time'], "%FT%T.%L%Z")
end
end

View file

@ -18,11 +18,9 @@ class RecurringTodosController < ApplicationController
@new_recurring_todo = RecurringTodo.new
end
def new
end
def new; end
def show
end
def show; end
def done
@source_view = params['_source_view'] || 'recurring_todo'
@ -209,7 +207,13 @@ class RecurringTodosController < ApplicationController
def init
@days_of_week = (0..6).map { |i| [t('date.day_names')[i], i] }
@months_of_year = (1..12).map { |i| [t('date.month_names')[i], i] }
@xth_day = [[t('common.first'),1],[t('common.second'),2],[t('common.third'),3],[t('common.fourth'),4],[t('common.last'),5]]
@xth_day = [
[t('common.first'), 1],
[t('common.second'), 2],
[t('common.third'), 3],
[t('common.fourth'), 4],
[t('common.last'),5]
]
@projects = current_user.projects.includes(:default_context)
@contexts = current_user.contexts
end
@ -221,10 +225,10 @@ class RecurringTodosController < ApplicationController
def find_and_inactivate
# find active recurring todos without active todos and inactivate them
current_user.recurring_todos.active.
select("recurring_todos.id, recurring_todos.state").
joins("LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')").
where("fai_todos.id IS NULL").
each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
current_user.recurring_todos.active
.select("recurring_todos.id, recurring_todos.state")
.joins("LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')")
.where("fai_todos.id IS NULL")
.each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
end
end

View file

@ -1,5 +1,5 @@
class StatsController < ApplicationController
SECONDS_PER_DAY = 86_400;
SECONDS_PER_DAY = 86_400
helper :todos, :projects, :recurring_todos
append_before_action :init, :except => :index

View file

@ -25,7 +25,8 @@ module Todos
elsif params[:todo]
@attributes = todo_params(params)
end
@attributes = {} if @attributes.nil? # make sure there is at least an empty hash
# Make sure there is at least an empty hash
@attributes = {} if @attributes.nil?
end
def filter_tags
@ -77,7 +78,7 @@ module Todos
@params['predecessor_list']
end
def parse_dates()
def parse_dates
@attributes['show_from'] = @user.prefs.parse_date(show_from)
@attributes['due'] = @user.prefs.parse_date(due)
@attributes['due'] ||= ''

View file

@ -70,7 +70,7 @@ class TodosController < ApplicationController
@projects = current_user.projects.active
@contexts = current_user.contexts
respond_to do |format|
format.m {
format.m do
@new_mobile = true
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
@mobile_from_context = current_user.contexts.find(params[:from_context]) if params[:from_context]
@ -79,7 +79,7 @@ class TodosController < ApplicationController
# we have a project but not a context -> use the default context
@mobile_from_context = @mobile_from_project.default_context
end
}
end
end
end
@ -174,7 +174,8 @@ class TodosController < ApplicationController
# first build all todos and check if they would validate on save
params[:todo][:multiple_todos].split("\n").map do |line|
if line.present? #ignore blank lines
# Ignore blank lines
if line.present?
@todo = current_user.todos.build({ :description => line, :context_id => p.context_id, :project_id => p.project_id })
validates &&= @todo.valid?
@ -245,12 +246,12 @@ class TodosController < ApplicationController
@tag_name = params['_tag_name']
respond_to do |format|
format.js
format.m {
format.m do
@projects = current_user.projects.active
@contexts = current_user.contexts
@edit_mobile = true
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
}
end
end
end
@ -358,7 +359,7 @@ class TodosController < ApplicationController
redirect_to :action => "index"
end
end
format.m {
format.m do
if @saved
if cookies[:mobile_url]
old_path = cookies[:mobile_url]
@ -372,7 +373,7 @@ class TodosController < ApplicationController
else
render :action => "edit", :format => :m
end
}
end
end
end
@ -384,7 +385,7 @@ class TodosController < ApplicationController
format.js
format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
format.html { redirect_to request.referrer }
format.m {
format.m do
if cookies[:mobile_url]
old_path = cookies[:mobile_url]
cookies[:mobile_url] = { :value => nil, :secure => SITE_CONFIG['secure_cookies'] }
@ -394,7 +395,7 @@ class TodosController < ApplicationController
notify(:notice, "Star toggled")
onsite_redirect_to todos_path(:format => 'm')
end
}
end
end
end
@ -462,11 +463,11 @@ class TodosController < ApplicationController
@todo.touch_predecessors if @original_item.description != @todo.description
respond_to do |format|
format.js {
format.js do
@status_message = @todo.deferred? ? t('todos.action_saved_to_tickler') : t('todos.action_saved')
@status_message = t('todos.added_new_project') + ' / ' + @status_message if @new_project_created
@status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_created
}
end
format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
format.m do
if @saved
@ -490,7 +491,8 @@ class TodosController < ApplicationController
def destroy
@source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id'])
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
# Create a (unsaved) copy of the original todo
@original_item = current_user.todos.build(@todo.attributes)
@context_id = @todo.context_id
@project_id = @todo.project_id
@todo_was_destroyed = true
@ -625,22 +627,22 @@ class TodosController < ApplicationController
todos_with_tag_ids = find_todos_with_tag_expr(@tag_expr)
@not_done_todos = todos_with_tag_ids.
active.not_hidden.
reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')).
includes(Todo::DEFAULT_INCLUDES)
@hidden_todos = todos_with_tag_ids.
hidden.
reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC')).
includes(Todo::DEFAULT_INCLUDES)
@deferred_todos = todos_with_tag_ids.
deferred.
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')).
includes(Todo::DEFAULT_INCLUDES)
@pending_todos = todos_with_tag_ids.
blocked.
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')).
includes(Todo::DEFAULT_INCLUDES)
@not_done_todos = todos_with_tag_ids
.active.not_hidden
.reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC'))
.includes(Todo::DEFAULT_INCLUDES)
@hidden_todos = todos_with_tag_ids
.hidden
.reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC'))
.includes(Todo::DEFAULT_INCLUDES)
@deferred_todos = todos_with_tag_ids
.deferred
.reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
.includes(Todo::DEFAULT_INCLUDES)
@pending_todos = todos_with_tag_ids
.blocked
.reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
.includes(Todo::DEFAULT_INCLUDES)
@todos_without_project = @not_done_todos.select { |t| t.project.nil? }
# If you've set no_completed to zero, the completed items box isn't shown on
@ -664,12 +666,8 @@ class TodosController < ApplicationController
respond_to do |format|
format.html
format.m {
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
}
format.text {
render :action => 'index', :layout => false, :content_type => Mime[:text]
}
format.m { cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } }
format.text { render :action => 'index', :layout => false, :content_type => Mime[:text] }
end
end
@ -715,7 +713,8 @@ class TodosController < ApplicationController
numdays = params['days'].to_i
@todo = current_user.todos.find(params[:id])
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
# Create a (unsaved) copy of the original todo
@original_item = current_user.todos.build(@todo.attributes)
@todo_deferred_state_changed = true
@new_context_created = false
@ -905,7 +904,7 @@ end
end
def find_todos_with_tag_expr(tag_expr)
# optimize for the common case: selecting only one tag
# Optimize for the common case of selecting only one tag
if @single_tag
tag = current_user.tags.where(:name => @tag_name).first
tag_id = tag.nil? ? -1 : tag.id
@ -1184,7 +1183,8 @@ end
def update_tags
if params[:tag_list]
@todo.tag_with(params[:tag_list])
@todo.tags.reload #force a reload for proper rendering
# Force a reload for proper rendering
@todo.tags.reload
end
end
@ -1197,7 +1197,7 @@ end
end
def update_date_for_update(key)
params['todo'][key] = params["todo"].has_key?(key) ? parse_date_for_update(params["todo"][key], t("todos.error.invalid_#{key}_date")) : ""
params['todo'][key] = params["todo"].key?(key) ? parse_date_for_update(params["todo"][key], t("todos.error.invalid_#{key}_date")) : ""
end
def update_due_and_show_from_dates

View file

@ -92,12 +92,12 @@ class UsersController < ApplicationController
return
end
signup_by_admin = true if (@user && @user.is_admin?)
signup_by_admin = true if @user && @user.is_admin?
first_user_signing_up = User.no_users_yet?
user.is_admin = true if first_user_signing_up
if user.save
@user = User.authenticate(user.login, params['user']['password'])
@user.create_preference({ :locale => I18n.locale })
@user.create_preference(:locale => I18n.locale)
@user.save
session['user_id'] = @user.id unless signup_by_admin
notify :notice, t('users.signup_successful', :username => @user.login)
@ -219,10 +219,10 @@ class UsersController < ApplicationController
end
def check_create_user_params
return false unless params.has_key?(:user)
return false unless params[:user].has_key?(:login)
return false unless params.key?(:user)
return false unless params[:user].key?(:login)
return false if params[:user][:login].empty?
return false unless params[:user].has_key?(:password)
return false unless params[:user].key?(:password)
return false if params[:user][:password].empty?
return true
end

View file

@ -113,7 +113,7 @@ module ApplicationHelper
recurring_target + recurrence_pattern + recurrence_time_span
end
def date_format_for_date_picker()
def date_format_for_date_picker
[
['%m', 'mm'],
['%b', 'M'],
@ -219,7 +219,7 @@ module ApplicationHelper
end
def link_to_edit(type, object, descriptor)
link_to(descriptor, self.send("edit_#{type}_path", object),
link_to(descriptor, send("edit_#{type}_path", object),
{
:id => "link_edit_#{dom_id(object)}",
:class => "#{type}_edit_settings icon"

View file

@ -5,7 +5,7 @@ module BootstrapFlashHelper
:error => :danger,
:info => :info,
:warning => :warning
} unless const_defined?(:ALERT_MAPPING)
}.freeze unless const_defined?(:ALERT_MAPPING)
def bootstrap_flash(options = { :close_button => true })
flash_messages = []
@ -15,7 +15,6 @@ module BootstrapFlashHelper
type = type.to_sym
next unless ALERT_MAPPING.keys.include?(type)
tag_class = options.extract!(:class)[:class]
tag_options = {
class: "alert fade in alert-#{ALERT_MAPPING[type]} #{tag_class}"

View file

@ -10,7 +10,7 @@ module DateLabelHelper
:tomorrow => :amber,
:this_week => :orange,
:more_than_a_week => :green
}
}.freeze
def initialize(date, prefs)
@date = date
@ -52,18 +52,14 @@ module DateLabelHelper
return "" if @date.nil?
return content_tag(:a, { :title => @prefs.format_date(@date) }) {
content_tag(:span, {:class => get_color}) {
yield
}
content_tag(:span, { :class => get_color }) { yield }
}
end
def date_mobile_html_wrapper
return "" if @date.nil?
return content_tag(:span, {:class => get_color}) {
yield
}
return content_tag(:span, { :class => get_color }) { yield }
end
end

View file

@ -41,7 +41,7 @@ module FeedlistHelper
protected
def merge_hashes(*hashes)
hashes.inject(Hash.new){ |result, h| result.merge(h) }
hashes.inject({}) { |result, h| result.merge(h) }
end
def user_token_hash

View file

@ -15,5 +15,4 @@ module NotesHelper
:title => t('notes.delete_note_title', :id => note.id), :x_confirm_message => t('notes.delete_note_confirm', :id => note.id) }
)
end
end

View file

@ -35,12 +35,11 @@ module ProjectsHelper
project_description = ''
project_description += 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
)
"#{count_undone_todos_phrase(p)}. #{t('projects.project_state', :state => project.state)}".html_safe)
end
def needsreview_class(item)
raise "item must be a Project " unless item.kind_of? Project
raise "item must be a Project " unless item.is_a? Project
return item.needs_review?(current_user) ? "needsreview" : "needsnoreview"
end

View file

@ -168,7 +168,8 @@ module TodosHelper
:class => "icon_delete_item",
:id => dom_id(todo, "delete"),
:x_confirm_message => t('todos.confirm_delete', :description => todo.description),
:title => t('todos.delete_action'));
:title => t('todos.delete_action')
)
end
def remote_defer_menu_item(days, todo)
@ -318,7 +319,7 @@ module TodosHelper
end
def include_context_link(todo, parent_container_type)
return true if (['stats', 'search'].include?(parent_container_type))
return true if ['stats', 'search'].include?(parent_container_type)
# TODO: remove next line if 'project' supports group_view_by
return true if parent_container_type == 'project'
return true if @group_view_by == 'project'
@ -327,7 +328,7 @@ module TodosHelper
def include_project_link(todo, parent_container_type)
return false unless todo.has_project?
return true if (['stats', 'search'].include?(parent_container_type))
return true if ['stats', 'search'].include?(parent_container_type)
# TODO: remove next line if 'context' supports group_view_by
return true if parent_container_type == 'context'
return true if @group_view_by == 'context'
@ -392,7 +393,7 @@ module TodosHelper
def formatted_pagination(total)
s = will_paginate(@todos)
(s.gsub(/(<\/[^<]+>)/, '\1 ')).chomp(' ')
s.gsub(/(<\/[^<]+>)/, '\1 ').chomp(' ')
end
def format_ical_notes(notes)
@ -418,7 +419,8 @@ module TodosHelper
# if the animation needs to be run inside the namespace of an object, set the
# object_name to the name of the object and this name will be prepended to each step
def render_animation(animation, object_name = nil)
object_name += "." unless object_name.nil? # add dot if object_name is given
# Add dot if object_name is given
object_name += "." unless object_name.nil?
# concatenate all steps into functions that call functions
html = animation.map { |step| "#{object_name}#{step}({ go: function() {" }.join("\r\n")
@ -609,29 +611,25 @@ module TodosHelper
raise Exception.new, "no @todo or @successor set" if !todo
source_view do |page|
page.project {
page.project do
return "deferred_pending_container-empty-d" if empty_criteria_met
return todo_container_empty_id(todo)
}
page.tag {
end
page.tag do
return "deferred_pending_container-empty-d" if empty_criteria_met
return "hidden_container-empty-d" if @todo.hidden?
return todo_container_empty_id(todo)
}
page.calendar {
end
page.calendar do
return "deferred_pending_container-empty-d" if empty_criteria_met
return "#{@new_due_id}_container-empty-d"
}
page.context {
end
page.context do
return "deferred_pending_container-empty-d" if empty_criteria_met
return todo_container_empty_id(todo)
}
page.todo {
return todo_container_empty_id(todo)
}
page.deferred {
return todo_container_empty_id(todo)
}
end
page.todo { return todo_container_empty_id(todo) }
page.deferred { return todo_container_empty_id(todo) }
end
return context_container_empty_id(todo)
@ -656,28 +654,28 @@ module TodosHelper
def show_empty_message_in_source_container
container_id = ""
source_view do |page|
page.project {
page.deferred { container_id = todo_container_empty_id(@original_item) if @remaining_in_context == 0 }
page.calendar { container_id = "#{@original_item_due_id}_container-empty-d" if @old_due_empty }
page.todo { container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0 }
page.done { container_id = "completed_#{@original_completed_period}_container-empty-d" if @remaining_in_context == 0 }
page.all_done { container_id = "all-done-empty-nd" if @remaining_in_context == 0 }
page.project do
container_id = project_container_empty_id(@original_item) if @remaining_in_context == 0
container_id = "deferred_pending_container-empty-d" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.deferred { container_id = todo_container_empty_id(@original_item) if @remaining_in_context == 0 }
page.calendar { container_id = "#{@original_item_due_id}_container-empty-d" if @old_due_empty }
page.tag {
end
page.tag do
container_id = "hidden_container-empty-d" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) ||
(@remaining_hidden_count == 0 && @todo.completed? && @original_item.hidden?)
container_id = "deferred_pending_container-empty-d" if (todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0) ||
(@original_item.deferred? && @remaining_deferred_or_pending_count == 0 && (@todo.completed? || @tag_was_removed))
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.context {
end
page.context do
container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0
container_id = "deferred_pending_container-empty-d" if todo_was_removed_from_deferred_or_blocked_container && @remaining_deferred_or_pending_count == 0
container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
}
page.todo { container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0 }
page.done { container_id = "completed_#{@original_completed_period}_container-empty-d" if @remaining_in_context == 0 }
page.all_done { container_id = "all-done-empty-nd" if @remaining_in_context == 0 }
end
end
return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe
end

View file

@ -2,11 +2,12 @@ module UsersHelper
def remote_delete_user(user)
return link_to(
image_tag("blank.png", :title => t('users.destroy_user'), :class => "delete_item"),
url_for({:controller => 'users', :action => 'destroy', :id => user.id}),
{ :id => "delete_user_#{user.id}",
url_for(:controller => 'users', :action => 'destroy', :id => user.id), {
:id => "delete_user_#{user.id}",
:class => "delete_user_button",
:title => t('users.destroy_user'),
:x_confirm_message => t('users.destroy_confirmation', :login => user.login)
})
}
)
end
end

View file

@ -31,9 +31,7 @@ class Context < ApplicationRecord
end
end
validates_presence_of :name, :message => "context must have a name"
validates_length_of :name, :maximum => 255, :message => "context name must be less than 256 characters"
validates_uniqueness_of :name, :message => "already exists", :scope => "user_id", :case_sensitive => false
validates :name, presence: { message: "context must have a name" }, length: { maximum: 255, message: "context name must be less than 256 characters" }, uniqueness: { message: "already exists", scope: "user_id", case_sensitive: false }
def self.null_object
NullContext.new

View file

@ -99,7 +99,7 @@ class MessageGateway < ActionMailer::Base
end
def sender_is_in_mailmap?(user, email)
if SITE_CONFIG['mailmap'].is_a? Hash and SITE_CONFIG['email_dispatch'] == 'to'
if (SITE_CONFIG['mailmap'].is_a? Hash) && SITE_CONFIG['email_dispatch'] == 'to'
# Look for the sender in the map of allowed senders
SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0]
else

View file

@ -16,9 +16,7 @@ class Project < ApplicationRecord
before_create :set_last_reviewed_now
validates_presence_of :name
validates_length_of :name, :maximum => 255
validates_uniqueness_of :name, :scope => "user_id", :case_sensitive => true
validates :name, presence: true, length: { maximum: 255 }, uniqueness: { scope: :user_id }
acts_as_list :scope => 'user_id = #{user_id} AND state = \'#{state}\'', :top_of_list => 0
@ -95,14 +93,14 @@ class Project < ApplicationRecord
def blocked?
## mutually exclusive for stalled and blocked
# blocked is uncompleted project with deferred or pending todos, but no next actions
return false if self.completed?
return !self.todos.deferred_or_blocked.empty? && self.todos.active.empty?
return false if completed?
return !todos.deferred_or_blocked.empty? && todos.active.empty?
end
def stalled?
# Stalled projects are active projects with no active next actions
return false if self.completed? || self.hidden?
return !self.todos.deferred_or_blocked.exists? && !self.todos.active.exists?
return false if completed? || hidden?
return !todos.deferred_or_blocked.exists? && !todos.active.exists?
end
def shortened_name(length = 40)

View file

@ -24,10 +24,12 @@ class RecurringTodo < ApplicationRecord
end
end
validates_presence_of :description, :recurring_period, :target, :ends_on, :context
validates_length_of :description, :maximum => 100
validates_length_of :notes, :maximum => 60_000, :allow_nil => true
validates :description, presence: true, length: { maximum: 100 }
validates :notes, length: { maximum: 60_000, allow_nil: true }
validates :recurring_period, presence: true
validates :target, presence: true
validates :ends_on, presence: true
validates :context, presence: true
validate :period_validation
validate :pattern_specific_validations
@ -118,12 +120,12 @@ class RecurringTodo < ApplicationRecord
def remove_from_project!
self.project = nil
self.save
save
end
def clear_todos_association
unless todos.nil?
self.todos.each do |t|
todos.each do |t|
t.recurring_todo = nil
t.save
end
@ -132,7 +134,7 @@ class RecurringTodo < ApplicationRecord
def increment_occurrences
self.occurrences_count += 1
self.save
save
end
def continues_recurring?(previous)

View file

@ -158,13 +158,13 @@ module RecurringTodos
def continues_recurring?(previous)
return @recurring_todo.occurrences_count < @recurring_todo.number_of_occurrences unless @recurring_todo.number_of_occurrences.nil?
return true if self.end_date.nil? || self.ends_on == 'no_end_date'
return true if end_date.nil? || ends_on == 'no_end_date'
case self.target
case target
when 'due_date'
get_due_date(previous) <= self.end_date
get_due_date(previous) <= end_date
when 'show_from_date'
get_show_from_date(previous) <= self.end_date
get_show_from_date(previous) <= end_date
end
end
@ -175,7 +175,7 @@ module RecurringTodos
# offset needs to be 1.day for daily patterns or the start will be the
# same day as the previous
def determine_start(previous, offset = 0.day)
start = self.start_from || NullTime.new
start = start_from || NullTime.new
if previous
# check if the start_from date is later than previous. If so, use
# start_from as start to search for next date

View file

@ -36,8 +36,8 @@ module RecurringTodos
if only_work_days?
# jump over weekend if necessary
return start + 2.day if start.wday() == 6 # saturday
return start + 1.day if start.wday() == 0 # sunday
return start + 2.day if start.wday == 6 # saturday
return start + 1.day if start.wday == 0 # sunday
return start
else
# if there was no previous todo, do not add n: the first todo starts on

View file

@ -29,7 +29,7 @@ module RecurringTodos
def validate
super
validate_not_blank(every_x_week, "Every other nth week may not be empty for weekly recurrence setting")
something_set = %w{ sunday monday tuesday wednesday thursday friday saturday }.inject(false) { |set, day| set || self.send("on_#{day}") }
something_set = %w{ sunday monday tuesday wednesday thursday friday saturday }.inject(false) { |set, day| set || send("on_#{day}") }
errors[:base] << "You must specify at least one day on which the todo recurs" unless something_set
end
@ -41,19 +41,19 @@ module RecurringTodos
# we did not find anything this week, so check the nth next, starting from
# sunday
start = start + self.every_x_week.week - (start.wday).days
start = start + every_x_week.week - (start.wday).days
start = find_first_day_in_this_week(start)
return start unless start == -1
raise Exception.new, "unable to find next weekly date (#{self.every_day})"
raise Exception.new, "unable to find next weekly date (#{every_day})"
end
private
def determine_start_date(previous)
if previous.nil?
return self.start_from || Time.zone.now
return start_from || Time.zone.now
else
start = previous + 1.day
if start.wday == 0
@ -61,10 +61,10 @@ module RecurringTodos
# that week. Note that we already went into the next week, so -1
start += (every_x_week - 1).week
end
unless self.start_from.nil?
unless start_from.nil?
# check if the start_from date is later than previous. If so, use
# start_from as start to search for next date
start = self.start_from if self.start_from > previous
start = start_from if start_from > previous
end
return start
end

View file

@ -31,7 +31,7 @@ module RecurringTodos
end
def recurrence_pattern
if self.recurrence_selector == 0
if recurrence_selector == 0
I18n.t("todos.recurrence.pattern.every_year_on", :date => date_as_month_day)
else
I18n.t("todos.recurrence.pattern.every_year_on",
@ -94,11 +94,11 @@ module RecurringTodos
the_next = start.month > month ? Time.zone.local(start.year + 1, month, 1) : start
# get the xth day of the month
the_next = get_xth_day_of_month(self.every_xth_day, day_of_week, month, the_next.year)
the_next = get_xth_day_of_month(every_xth_day, day_of_week, month, the_next.year)
# if the_next is before previous, we went back into the past, so try next
# year
the_next = get_xth_day_of_month(self.every_xth_day, day_of_week, month, start.year + 1) if the_next <= start
the_next = get_xth_day_of_month(every_xth_day, day_of_week, month, start.year + 1) if the_next <= start
the_next
end

View file

@ -25,27 +25,27 @@ module Search
private
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)
@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"))
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)
@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")
end
def todo_tags_by_name(terms)
Tagging.find_by_sql([
"SELECT DISTINCT tags.name as name " +
"FROM tags " +
"LEFT JOIN taggings ON tags.id = taggings.tag_id " +
"LEFT JOIN todos ON taggings.taggable_id = todos.id " +
"WHERE todos.user_id=? " +
"AND tags.name " + Common.like_operator + " ? ", @user.id, terms])
Tagging.find_by_sql(["
SELECT DISTINCT tags.name as name
FROM tags
LEFT JOIN taggings ON tags.id = taggings.tag_id
LEFT JOIN todos ON taggings.taggable_id = todos.id
WHERE todos.user_id = ?
AND tags.name " + Common.like_operator + " ? ", @user.id, terms])
end
end
end

View file

@ -422,7 +422,7 @@ module Stats
def compute_running_avg_array(set, upper_bound)
result = set_three_month_avg(set, upper_bound)
result[upper_bound - 1] = result[upper_bound - 1] * 3 if upper_bound == set.length
result[upper_bound - 2] = result[upper_bound - 2] * 3 / 2 if upper_bound > 1 and upper_bound == set.length
result[upper_bound - 2] = result[upper_bound - 2] * 3 / 2 if upper_bound > 1 && upper_bound == set.length
result[0] = "null"
result
end # unsolved, not triggered, edge case for set.length == upper_bound + 1

View file

@ -9,8 +9,7 @@ class Tag < ApplicationRecord
# If database speed becomes an issue, you could remove these validations and
# rescue the ActiveRecord database constraint errors instead.
validates_presence_of :name
validates_uniqueness_of :name, :scope => "user_id", :case_sensitive => false
validates :name, presence: true, uniqueness: { :scope => "user_id", :case_sensitive => false }
before_create :before_create

View file

@ -8,6 +8,6 @@ class Tagging < ApplicationRecord
private
def delete_orphaned_tag
tag.destroy if tag and tag.taggings.count == 0
tag.destroy if tag && tag.taggings.count == 0
end
end

View file

@ -69,7 +69,7 @@ class Todo < ApplicationRecord
# state machine
include AASM
aasm_initial_state = Proc.new { (self.show_from && self.user && (self.show_from > self.user.date)) ? :deferred : :active }
aasm_initial_state = Proc.new { (show_from && user && (show_from > user.date)) ? :deferred : :active }
aasm :column => :state do
state :active
@ -100,11 +100,11 @@ class Todo < ApplicationRecord
# Description field can't be empty, and must be < 100 bytes Notes must be <
# 60,000 bytes (65,000 actually, but I'm being cautious)
validates_presence_of :description
validates_length_of :description, :maximum => MAX_DESCRIPTION_LENGTH
validates_length_of :notes, :maximum => MAX_NOTES_LENGTH, :allow_nil => true
validates_presence_of :show_from, :if => :deferred?
validates_presence_of :context
validates :description, presence: true, length: { maximum: MAX_DESCRIPTION_LENGTH }
validates :notes, length: { maximum: MAX_NOTES_LENGTH, allow_nil: true }
validates :show_from, presence: true, if: :deferred?
validates :context, presence: true
validate :check_show_from_in_future
def check_show_from_in_future
@ -139,18 +139,18 @@ class Todo < ApplicationRecord
end
def not_part_of_hidden_container?
!((self.project && self.project.hidden?) || self.context.hidden?)
!((project && project.hidden?) || context.hidden?)
end
# Returns a string with description <context, project>
def specification
project_name = self.project.is_a?(NullProject) ? "(none)" : self.project.name
return "\'#{self.description}\' <\'#{self.context.title}\'; \'#{project_name}\'>"
project_name = project.is_a?(NullProject) ? "(none)" : project.name
return "\'#{description}\' <\'#{context.title}\'; \'#{project_name}\'>"
end
def save_predecessors
unless @predecessor_array.nil? # Only save predecessors if they changed
current_array = self.predecessors
current_array = predecessors
remove_array = current_array - @predecessor_array
add_array = @predecessor_array - current_array
@ -158,13 +158,13 @@ class Todo < ApplicationRecord
remove_array.each do |todo|
unless todo.nil?
@removed_predecessors << todo
self.predecessors.delete(todo)
predecessors.delete(todo)
end
end
add_array.each do |todo|
unless todo.nil?
self.predecessors << todo unless self.predecessors.include?(todo)
predecessors << todo unless predecessors.include?(todo)
else
logger.error "Could not find #{todo.description}" # Unexpected since validation passed
end
@ -173,7 +173,7 @@ class Todo < ApplicationRecord
end
def touch_predecessors
self.touch
touch
predecessors.each(&:touch_predecessors)
end
@ -183,10 +183,10 @@ class Todo < ApplicationRecord
# remove predecessor and activate myself if it was the last predecessor
def remove_predecessor(predecessor)
self.predecessors.delete(predecessor)
if self.predecessors.empty?
self.reload # reload predecessors
self.activate!
predecessors.delete(predecessor)
if predecessors.empty?
reload # reload predecessors
activate!
else
save!
end
@ -196,10 +196,10 @@ class Todo < ApplicationRecord
def is_successor?(todo)
if self == todo
return true
elsif self.successors.empty?
elsif successors.empty?
return false
else
self.successors.each do |item|
successors.each do |item|
if item.is_successor?(todo)
return true
end
@ -213,7 +213,7 @@ class Todo < ApplicationRecord
end
def hidden?
self.project.hidden? || self.context.hidden?
project.hidden? || context.hidden?
end
def toggle_completion!
@ -229,7 +229,7 @@ class Todo < ApplicationRecord
activate
else
# parse Date objects into the proper timezone
date = date.in_time_zone.beginning_of_day if (date.is_a? Date)
date = date.in_time_zone.beginning_of_day if date.is_a? Date
# show_from needs to be set before state_change because of "bug" in aasm.
# If show_from is not set, the todo will not validate and thus aasm will not save
@ -258,14 +258,14 @@ class Todo < ApplicationRecord
end
def from_recurring_todo?
return self.recurring_todo_id != nil
return recurring_todo_id != nil
end
def add_predecessor_list(predecessor_list)
return unless predecessor_list.kind_of? String
return unless predecessor_list.is_a? String
@predecessor_array = predecessor_list.split(",").inject([]) do |list, todo_id|
predecessor = self.user.todos.find(todo_id.to_i) if todo_id.present?
predecessor = user.todos.find(todo_id.to_i) if todo_id.present?
list << predecessor unless predecessor.nil?
list
end
@ -307,7 +307,7 @@ class Todo < ApplicationRecord
# 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)) if dep.present? }
deps.each { |dep| add_predecessor(user.todos.find(dep.to_i)) if dep.present? }
end
alias_method :original_context=, :context=
@ -376,7 +376,7 @@ class Todo < ApplicationRecord
def destroy
# activate successors if they only depend on this action
self.pending_successors.each do |successor|
pending_successors.each do |successor|
successor.uncompleted_predecessors.delete(self)
if successor.uncompleted_predecessors.empty?
successor.activate!

View file

@ -5,7 +5,6 @@ class User < ApplicationRecord
# Virtual attribute for the unencrypted password
attr_accessor :password
#for will_paginate plugin
cattr_accessor :per_page
@@per_page = 25
@ -15,11 +14,11 @@ class User < ApplicationRecord
end
def update_positions(context_ids)
context_ids.each_with_index { |id, position|
context = self.detect { |c| c.id == id.to_i }
context_ids.each_with_index do |id, position|
context = detect { |c| c.id == id.to_i }
raise I18n.t('models.user.error_context_not_associated', :context => id, :user => @user.id) if context.nil?
context.update_attribute(:position, position + 1)
}
end
end
end
@ -29,27 +28,27 @@ class User < ApplicationRecord
end
def update_positions(project_ids)
project_ids.each_with_index { |id, position|
project = self.find_by(id: id.to_i)
project_ids.each_with_index do |id, position|
project = find_by(id: id.to_i)
raise I18n.t('models.user.error_project_not_associated', :project => id, :user => @user.id) if project.nil?
project.update_attribute(:position, position + 1)
}
end
end
def projects_in_state_by_position(state)
self.select { |p| p.state == state }.sort_by { |p| p.position }
select { |p| p.state == state }.sort_by { |p| p.position }
end
def next_from(project)
self.offset_from(project, 1)
offset_from(project, 1)
end
def previous_from(project)
self.offset_from(project, -1)
offset_from(project, -1)
end
def offset_from(project, offset)
projects = self.projects_in_state_by_position(project.state)
projects = projects_in_state_by_position(project.state)
position = projects.index(project)
return nil if position == 0 && offset < 0
projects.at(position + offset)
@ -57,7 +56,7 @@ class User < ApplicationRecord
def cache_note_counts
project_note_counts = Note.group(:project_id).count
self.each do |project|
each do |project|
project.cached_note_count = project_note_counts[project.id] || 0
end
end
@ -65,7 +64,7 @@ class User < ApplicationRecord
def alphabetize(scope_conditions = {})
projects = where(scope_conditions)
projects = projects.sort_by { |project| project.name.downcase }
self.update_positions(projects.map(&:id))
update_positions(projects.map(&:id))
return projects
end
@ -75,7 +74,7 @@ class User < ApplicationRecord
todos_in_project.reject { |p| p.todos.active.count > 0 }
sorted_project_ids = todos_in_project.map(&:id)
all_project_ids = self.map(&:id)
all_project_ids = map(&:id)
other_project_ids = all_project_ids - sorted_project_ids
update_positions(sorted_project_ids + other_project_ids)
@ -108,19 +107,19 @@ class User < ApplicationRecord
has_one :preference, dependent: :destroy
has_many :attachments, through: :todos
validates_presence_of :login
validates_presence_of :password, if: :password_required?
validates_length_of :password, within: 5..72, if: :password_required?
validates_presence_of :password_confirmation, if: :password_required?
validates_confirmation_of :password
validates_length_of :login, within: 3..80
validates :login, presence: true, length: { within: 3..80 }
validates_uniqueness_of :login, on: :create, :case_sensitive => false
validates :password, presence: true, length: { within: 5..72 }, if: :password_required?
validates :password_confirmation, presence: true, if: :password_required?
validates :password, confirmation: true
validates :email, allow_blank: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validate :validate_auth_type
validates :email, :allow_blank => true, format: { with: URI::MailTo::EMAIL_REGEXP }
before_create :crypt_password, :generate_token
before_update :crypt_password
before_destroy :destroy_dependencies, :delete_taggings, prepend: true # run before deleting todos, projects, contexts, etc.
# Run before deleting todos, projects, contexts, etc.
before_destroy :destroy_dependencies, :delete_taggings, prepend: true
def validate_auth_type
unless Tracks::Config.auth_schemes.include?(auth_type)
@ -136,8 +135,8 @@ class User < ApplicationRecord
return nil if candidate.nil?
if Tracks::Config.auth_schemes.include?('database')
return candidate if candidate.auth_type == 'database' and
candidate.password_matches? pass
return candidate if (candidate.auth_type == 'database' && candidate.password_matches?(pass))
end
return nil
@ -177,11 +176,11 @@ class User < ApplicationRecord
end
def generate_token
self.token = Digest::SHA1.hexdigest "#{Time.now.to_i}#{rand}"
self.token = Digest::SHA1.hexdigest "#{Time.zone.now.to_i}#{rand}"
end
def remember_token?
remember_token_expires_at && Time.now.utc < remember_token_expires_at
remember_token_expires_at && Time.zone.now.utc < remember_token_expires_at
end
# These create and unset the fields required for remembering users between browser closes
@ -209,7 +208,7 @@ class User < ApplicationRecord
def crypt_password
return if password.blank?
write_attribute("crypted_password", self.create_hash(password)) if password == password_confirmation
write_attribute("crypted_password", create_hash(password)) if password == password_confirmation
end
def password_required?

View file

@ -17,7 +17,7 @@ class RichMessageExtractor
DUE_MARKER,
TAG_MARKER,
STAR_MARKER
]
].freeze
def initialize(message)
@message = message
@ -65,11 +65,11 @@ class RichMessageExtractor
private
def select_for symbol
def select_for(symbol)
@message.match /#{symbol}(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/
end
def fix_date_string yymmdd
def fix_date_string(yymmdd)
"20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00"
end
end

View file

@ -1,7 +1,6 @@
xml.instruct!
xml.OpenSearchDescription 'xmlns' => "http://a9.com/-/spec/opensearch/1.1/" do
xml.ShortName Tracks
xml.Description t('integrations.opensearch_description')
xml.InputEncoding 'UTF-8'
@ -11,4 +10,3 @@ xml.OpenSearchDescription 'xmlns' => "http://a9.com/-/spec/opensearch/1.1/" do
'template' => url_for(:controller => 'search', :action => 'results',
:only_path => false) + '?search={searchTerms}'
end

View file

@ -35,7 +35,6 @@ require 'activeresource'
# http://blog.pepperdust.org/2007/2/13/enabling-wire-level-debug-output-for-activeresource
module Tracks
class Base < ActiveResource::Base
self.site = ENV["SITE"] || "http://username:password@localhost:3000/"
end
@ -56,5 +55,4 @@ module Tracks
return Todo.find(:all, :params => { :project_id => id })
end
end
end

View file

@ -2,7 +2,6 @@ require 'net/https'
require File.expand_path(File.dirname(__FILE__) + '/tracks_xml_builder')
module TracksCli
class TracksAPI
def initialize(options)
@options = options
@ -11,7 +10,8 @@ module TracksCli
def get_http(uri)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https" # enable SSL/TLS
# Enable SSL/TLS
if uri.scheme == "https"
http.use_ssl = true
http.ca_path = "/etc/ssl/certs/" # Debian based path
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
@ -57,7 +57,5 @@ module TracksCli
def get_context(context_id)
get(context_uri_for(context_id))
end
end
end

View file

@ -1,9 +1,7 @@
require 'active_support/time_with_zone'
module TracksCli
class TracksXmlBuilder
def xml_for_description(description)
"<description>#{description}</description>"
end
@ -23,7 +21,7 @@ module TracksCli
def xml_for_taglist(taglist)
unless taglist.nil?
tags = taglist.split(",")
if tags.length() > 0
if tags.length > 0
tags = tags.collect { |tag| "<tag><name>#{tag.strip}</name></tag>" unless tag.strip.empty? }.join('')
return "<tags>#{tags}</tags>"
end
@ -61,6 +59,5 @@ module TracksCli
def build_project_xml(project)
"<project><name>#{project[:description]}</name><default-context-id>#{project[:default_context_id]}</default-context-id></project>"
end
end
end

View file

@ -153,7 +153,8 @@ class TemplatePoster
password: ENV['GTD_PASSWORD'],
projects_uri: ENV['GTD_PROJECTS_URL'] || 'http://localhost:3000/projects.xml',
contexts_uri: ENV['GTD_CONTEXT_URL'] || 'http://localhost:3000/contexts.xml',
context_prefix: ENV['GTD_CONTEXT_URL_PREFIX'] || 'http://localhost:3000/contexts/'})
context_prefix: ENV['GTD_CONTEXT_URL_PREFIX'] || 'http://localhost:3000/contexts/'
})
@context_id = options[:context_id] ? options[:context_id].to_i : 1
@project_id = options[:project_id] ? options[:project_id].to_i : 1
end
@ -265,7 +266,7 @@ class ConsoleOptionsForTemplate
@parser.parse!(args)
@poster = TemplatePoster.new(@options)
if !@filename.nil? and not File.exist?(@filename)
if !@filename.nil? && not File.exist?(@filename)
puts "ERROR: file #{@filename} doesn't exist"
exit 1
end

View file

@ -20,7 +20,7 @@ class DoneTodos
def self.completed_period(date)
return nil if date.nil?
return "today" if date >= end_of_day # treat todos with completed_at in future as done today (happens in tests)
return "today" if date >= end_of_day # Treat todos with completed_at in future as done today (happens in tests)
return "today" if date.between?(beginning_of_day, end_of_day)
return "rest_of_week" if date >= beginning_of_week
return "rest_of_month" if date >= beginning_of_month
@ -28,7 +28,7 @@ class DoneTodos
end
def self.remaining_in_container(todos, period)
count = self.send("done_#{period}", todos.completed, {}).count
count = send("done_#{period}", todos.completed, {}).count
return nil if period.nil?
return count
end

View file

@ -6,11 +6,11 @@ module IsTaggable
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings do
def to_s
self.to_a.map(&:name).sort.join(Tag::JOIN_DELIMITER)
to_a.map(&:name).sort.join(Tag::JOIN_DELIMITER)
end
def all_except_starred
self.to_a.reject { |tag| tag.name == Todo::STARRED_TAG_NAME }
to_a.reject { |tag| tag.name == Todo::STARRED_TAG_NAME }
end
end
@ -49,7 +49,7 @@ module IsTaggable
# added following check to prevent empty tags from being saved (which will fail)
if tag_name.present?
begin
tag = self.user.tags.where(:name => tag_name).first_or_create
tag = user.tags.where(:name => tag_name).first_or_create
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
tags << tag
rescue ActiveRecord::StatementInvalid => e
@ -62,7 +62,7 @@ module IsTaggable
# Removes tags from <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
def _remove_tags(outgoing)
outgoing = tag_cast_to_string(outgoing)
tags.destroy(*(self.user.tags.select { |tag| outgoing.include? tag.name }))
tags.destroy(*(user.tags.select { |tag| outgoing.include? tag.name }))
end
def get_tag_name_from_item(item)

View file

@ -72,7 +72,7 @@ module LoginSystem
def login_or_feed_token_required
if ['rss', 'atom', 'txt', 'ics', 'xml'].include?(params[:format])
# Login based on the token GET parameter
if user = User.where(:token => params[:token]).first
if (user = User.where(:token => params[:token]).first)
set_current_user(user)
return true
end

View file

@ -82,7 +82,7 @@ module Tracks
end
def specified_by_name?(object_type)
self.send("#{object_type}_specified_by_name?")
send("#{object_type}_specified_by_name?")
end
def project_specified_by_name?

View file

@ -8,4 +8,3 @@ require "dispatcher"
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
Dispatcher.dispatch