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 end
group :test do 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 # get test coverage info on codeclimate
gem 'codeclimate-test-reporter', '1.0.7', group: :test, require: nil 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 end

View file

@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
include Common include Common
helper_method :current_user, :prefs, :format_date helper_method :current_user, :prefs, :format_date
layout proc{ |controller| controller.mobile? ? "mobile" : "application" } layout proc { |controller| controller.mobile? ? "mobile" : "application" }
# exempt_from_layout /\.js\.erb$/ # exempt_from_layout /\.js\.erb$/
before_action :set_session_expiration before_action :set_session_expiration
@ -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 ||= 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'] 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 I18n.locale = locale
else else
I18n.locale = I18n.default_locale 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 # 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 # under session control) or if we checked the box to keep logged in on
# login don't set the session expiry time. # 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 # Get expiry time (allow ten seconds window for the case where we have
# none) # none)
@ -50,11 +50,11 @@ class ApplicationController < ActionController::Base
reset_session reset_session
else else
# Okay, you get another hour # Okay, you get another hour
session['expiry_time'] = now + (60*60) session['expiry_time'] = now + (60 * 60)
end end
end end
def render_failure message, status = 404 def render_failure(message, status = 404)
render :body => message, :status => status render :body => message, :status => status
end end
@ -101,8 +101,8 @@ class ApplicationController < ActionController::Base
def for_autocomplete(coll, substr) def for_autocomplete(coll, substr)
if substr # protect agains empty request if substr # protect agains empty request
filtered = coll.find_all{ |item| item.name.downcase.include? substr.downcase } filtered = coll.find_all { |item| item.name.downcase.include? substr.downcase }
json_elems = Array[*filtered.map{ |e| { :id => e.id.to_s, :value => e.name } }].to_json json_elems = Array[*filtered.map { |e| { :id => e.id.to_s, :value => e.name } }].to_json
return json_elems return json_elems
else else
return "" return ""
@ -272,7 +272,7 @@ class ApplicationController < ActionController::Base
def done_todos_for(object) def done_todos_for(object)
object_name = object.class.name.downcase # context or project object_name = object.class.name.downcase # context or project
@source_view = "done" @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) @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) @done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(object.todos)

View file

@ -15,7 +15,7 @@ class CalendarController < ApplicationController
format.html format.html
format.m { cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } } format.m { cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } }
format.ics { render :action => 'show', :layout => false, :content_type => Mime[:ics] } format.ics { render :action => 'show', :layout => false, :content_type => Mime[:ics] }
format.xml { render :xml => @due_all.to_xml( *[todo_xml_params[0].merge({ :root => :todos })] ) } format.xml { render :xml => @due_all.to_xml(*[todo_xml_params[0].merge({ :root => :todos })]) }
end end
end end
end end

View file

@ -98,7 +98,7 @@ class ContextsController < ApplicationController
@context.attributes = context_params @context.attributes = context_params
@saved = @context.save @saved = @context.save
@state_saved = set_state_for_update(@new_state) @state_saved = set_state_for_update(@new_state)
@saved = @saved && @state_saved @saved &&= @state_saved
if @saved if @saved
@state_changed = (@original_context_state != @context.state) @state_changed = (@original_context_state != @context.state)
@ -148,7 +148,7 @@ class ContextsController < ApplicationController
# #
def order def order
context_ids = params["container_context"] context_ids = params["container_context"]
@projects = current_user.contexts.update_positions( context_ids ) @projects = current_user.contexts.update_positions(context_ids)
head :ok head :ok
rescue rescue
notify :error, $! notify :error, $!

View file

@ -5,8 +5,7 @@ class DataController < ApplicationController
@page_title = "TRACKS::Export" @page_title = "TRACKS::Export"
end end
def import def import; end
end
def csv_map def csv_map
if params[:file].blank? if params[:file].blank?
@ -16,17 +15,17 @@ class DataController < ApplicationController
@import_to = params[:import_to] @import_to = params[:import_to]
begin begin
#get column headers and format as [['name', column_number]...] # Get column headers and format as [['name', column_number]...]
i = -1 i = -1
@headers = import_headers(params[:file].path).collect { |v| [v, i+=1] } @headers = import_headers(params[:file].path).collect { |v| [v, i += 1] }
@headers.unshift ['',i] @headers.unshift ['', i]
rescue Exception => e rescue Exception => e
flash[:error] = "Invalid CVS: could not read headers: #{e}" flash[:error] = "Invalid CVS: could not read headers: #{e}"
redirect_to :back redirect_to :back
return return
end end
#save file for later # Save file for later
begin begin
uploaded_file = params[:file] uploaded_file = params[:file]
@filename = sanitize_filename(uploaded_file.original_filename) @filename = sanitize_filename(uploaded_file.original_filename)
@ -94,17 +93,17 @@ class DataController < ApplicationController
all_tables['projects'] = current_user.projects.load all_tables['projects'] = current_user.projects.load
todo_tag_ids = Tag.find_by_sql([ todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+ "SELECT DISTINCT tags.id
"FROM tags, taggings, todos "+ FROM tags, taggings, todos
"WHERE todos.user_id=? "+ WHERE todos.user_id = ?
"AND tags.id = taggings.tag_id " + AND tags.id = taggings.tag_id
"AND taggings.taggable_id = todos.id ", current_user.id]) AND taggings.taggable_id = todos.id", current_user.id])
rec_todo_tag_ids = Tag.find_by_sql([ rec_todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+ "SELECT DISTINCT tags.id
"FROM tags, taggings, recurring_todos "+ FROM tags, taggings, recurring_todos
"WHERE recurring_todos.user_id=? "+ WHERE recurring_todos.user_id = ?
"AND tags.id = taggings.tag_id " + AND tags.id = taggings.tag_id
"AND taggings.taggable_id = recurring_todos.id ", current_user.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) 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) 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 all_tables['recurring_todos'] = current_user.recurring_todos.load
result = all_tables.to_yaml 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') send_data(result, :filename => "tracks_backup.yml", :type => 'text/plain')
end end
@ -129,7 +129,7 @@ class DataController < ApplicationController
csv << [todo.id, todo.context.name, csv << [todo.id, todo.context.name,
todo.project_id.nil? ? "" : todo.project.name, todo.project_id.nil? ? "" : todo.project.name,
todo.description, todo.description,
todo.notes, todo.tags.collect{|t| t.name}.join(', '), todo.notes, todo.tags.collect { |t| t.name }.join(', '),
todo.created_at.to_formatted_s(:db), todo.created_at.to_formatted_s(:db),
todo.due? ? todo.due.to_formatted_s(:db) : "", todo.due? ? todo.due.to_formatted_s(:db) : "",
todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "", todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "",
@ -163,17 +163,17 @@ class DataController < ApplicationController
def xml_export def xml_export
todo_tag_ids = Tag.find_by_sql([ todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+ "SELECT DISTINCT tags.id
"FROM tags, taggings, todos "+ FROM tags, taggings, todos
"WHERE todos.user_id=? "+ WHERE todos.user_id = ?
"AND tags.id = taggings.tag_id " + AND tags.id = taggings.tag_id
"AND taggings.taggable_id = todos.id ", current_user.id]) AND taggings.taggable_id = todos.id", current_user.id])
rec_todo_tag_ids = Tag.find_by_sql([ rec_todo_tag_ids = Tag.find_by_sql([
"SELECT DISTINCT tags.id "+ "SELECT DISTINCT tags.id
"FROM tags, taggings, recurring_todos "+ FROM tags, taggings, recurring_todos
"WHERE recurring_todos.user_id=? "+ WHERE recurring_todos.user_id = ?
"AND tags.id = taggings.tag_id " + AND tags.id = taggings.tag_id
"AND taggings.taggable_id = recurring_todos.id ", current_user.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) 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) 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 # adjusts time to utc
def adjust_time(timestring) def adjust_time(timestring)
if (timestring == '') or (timestring == nil) if (timestring == '') || (timestring == nil)
return nil return nil
else else
return Time.parse(timestring + 'UTC') return Time.parse(timestring + 'UTC')

View file

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

View file

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

View file

@ -14,7 +14,7 @@ class MailgunController < ApplicationController
todo = MessageGateway.receive(params['body-mime']) todo = MessageGateway.receive(params['body-mime'])
if todo if todo
render :xml => todo.to_xml( *todo_xml_params ) render :xml => todo.to_xml(*todo_xml_params)
else else
render_failure "Todo not saved", 406 render_failure "Todo not saved", 406
end end

View file

@ -8,7 +8,7 @@ class NotesController < ApplicationController
@source_view = 'note_list' @source_view = 'note_list'
respond_to do |format| respond_to do |format|
format.html format.html
format.xml { render :xml => @all_notes.to_xml(:root => :notes, :except => :user_id) } format.xml { render :xml => @all_notes.to_xml(:root => :notes, :except => :user_id) }
end end
end end

View file

@ -153,7 +153,7 @@ class ProjectsController < ApplicationController
else else
@project_default_context = t('projects.default_context', :context => @project.default_context.name) @project_default_context = t('projects.default_context', :context => @project.default_context.name)
end end
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
@mobile_from_project = @project.id @mobile_from_project = @project.id
end end
format.xml do format.xml do
@ -245,7 +245,7 @@ class ProjectsController < ApplicationController
respond_to do |format| respond_to do |format|
format.js { render :template => template } format.js { render :template => template }
format.html { redirect_to :action => 'index'} format.html { redirect_to :action => 'index' }
format.xml do format.xml do
if @saved if @saved
render :xml => @project.to_xml(:except => :user_id) render :xml => @project.to_xml(:except => :user_id)

View file

@ -39,7 +39,7 @@ module RecurringTodos
def method_missing(method, *args) def method_missing(method, *args)
# delegate daily_xxx to daily_pattern, weekly_xxx to weekly_pattern, etc. # delegate daily_xxx to daily_pattern, weekly_xxx to weekly_pattern, etc.
if method.to_s =~ /^([^_]+)_(.+)$/ if method.to_s =~ /^([^_]+)_(.+)$/
return @method_map[$1][:method].send(@method_map[$1][:prefix]+$2, *args) unless @method_map[$1].nil? return @method_map[$1][:method].send(@method_map[$1][:prefix] + $2, *args) unless @method_map[$1].nil?
end end
# no match, let @recurring_todo handle it, or fail # no match, let @recurring_todo handle it, or fail

View file

@ -18,11 +18,9 @@ class RecurringTodosController < ApplicationController
@new_recurring_todo = RecurringTodo.new @new_recurring_todo = RecurringTodo.new
end end
def new def new; end
end
def show def show; end
end
def done def done
@source_view = params['_source_view'] || 'recurring_todo' @source_view = params['_source_view'] || 'recurring_todo'
@ -171,7 +169,7 @@ class RecurringTodosController < ApplicationController
context_name: :context_name, context_name: :context_name,
project_name: :project_name, project_name: :project_name,
tag_list: :tag_list tag_list: :tag_list
}.each do |target,source| }.each do |target, source|
move_into_recurring_todo_param(params, target, source) move_into_recurring_todo_param(params, target, source)
end end
recurring_todo_params recurring_todo_params
@ -189,14 +187,14 @@ class RecurringTodosController < ApplicationController
tag_list: :edit_recurring_todo_tag_list, tag_list: :edit_recurring_todo_tag_list,
end_date: :recurring_todo_edit_end_date, end_date: :recurring_todo_edit_end_date,
start_from: :recurring_todo_edit_start_from start_from: :recurring_todo_edit_start_from
}.each do |target,source| }.each do |target, source|
move_into_recurring_todo_param(params, target, source) move_into_recurring_todo_param(params, target, source)
end end
# make sure that we set weekly_return_xxx to empty (space) when they are # make sure that we set weekly_return_xxx to empty (space) when they are
# not checked (and thus not present in params["recurring_todo"]) # not checked (and thus not present in params["recurring_todo"])
%w{monday tuesday wednesday thursday friday saturday sunday}.each do |day| %w{monday tuesday wednesday thursday friday saturday sunday}.each do |day|
params["recurring_todo"]["weekly_return_#{day}"]=' ' if params["recurring_todo"]["weekly_return_#{day}"].nil? params["recurring_todo"]["weekly_return_#{day}"] = ' ' if params["recurring_todo"]["weekly_return_#{day}"].nil?
end end
recurring_todo_params recurring_todo_params
@ -207,9 +205,15 @@ class RecurringTodosController < ApplicationController
end end
def init def init
@days_of_week = (0..6).map{|i| [t('date.day_names')[i], i] } @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] } @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) @projects = current_user.projects.includes(:default_context)
@contexts = current_user.contexts @contexts = current_user.contexts
end end
@ -221,10 +225,10 @@ class RecurringTodosController < ApplicationController
def find_and_inactivate def find_and_inactivate
# find active recurring todos without active todos and inactivate them # find active recurring todos without active todos and inactivate them
current_user.recurring_todos.active. current_user.recurring_todos.active
select("recurring_todos.id, recurring_todos.state"). .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')"). .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"). .where("fai_todos.id IS NULL")
each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! } .each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
end end
end end

View file

@ -1,5 +1,5 @@
class StatsController < ApplicationController class StatsController < ApplicationController
SECONDS_PER_DAY = 86_400; SECONDS_PER_DAY = 86_400
helper :todos, :projects, :recurring_todos helper :todos, :projects, :recurring_todos
append_before_action :init, :except => :index append_before_action :init, :except => :index
@ -23,15 +23,15 @@ class StatsController < ApplicationController
# less than the minimum completed_at, so no reason to check minimum completed_at # less than the minimum completed_at, so no reason to check minimum completed_at
# convert to array and fill in non-existing months # convert to array and fill in non-existing months
@actions_done_last_months_array = put_events_into_month_buckets(actions_last_months, month_count+1, :completed_at) @actions_done_last_months_array = put_events_into_month_buckets(actions_last_months, month_count + 1, :completed_at)
@actions_created_last_months_array = put_events_into_month_buckets(actions_last_months, month_count+1, :created_at) @actions_created_last_months_array = put_events_into_month_buckets(actions_last_months, month_count + 1, :created_at)
# find max for graph in both hashes # find max for graph in both hashes
@max = (@actions_done_last_months_array + @actions_created_last_months_array).max @max = (@actions_done_last_months_array + @actions_created_last_months_array).max
# set running avg # set running avg
@actions_done_avg_last_months_array = compute_running_avg_array(@actions_done_last_months_array,month_count + 1) @actions_done_avg_last_months_array = compute_running_avg_array(@actions_done_last_months_array, month_count + 1)
@actions_created_avg_last_months_array = compute_running_avg_array(@actions_created_last_months_array,month_count + 1) @actions_created_avg_last_months_array = compute_running_avg_array(@actions_created_last_months_array, month_count + 1)
# interpolate avg for this month. # interpolate avg for this month.
@interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last_months_array) @interpolated_actions_created_this_month = interpolate_avg_for_current_month(@actions_created_last_months_array)
@ -57,7 +57,7 @@ class StatsController < ApplicationController
# last bar of the chart is selected. avtr is used for all other bars # last bar of the chart is selected. avtr is used for all other bars
week_from = params['index'].to_i week_from = params['index'].to_i
week_to = week_from+1 week_to = week_from + 1
@chart = Stats::Chart.new('actions_visible_running_time_data') @chart = Stats::Chart.new('actions_visible_running_time_data')
@page_title = t('stats.actions_selected_from_week') @page_title = t('stats.actions_selected_from_week')
@ -117,7 +117,7 @@ class StatsController < ApplicationController
@last_completed_projects = current_user.projects.completed.limit(10).reorder('completed_at DESC').includes(:todos, :notes) @last_completed_projects = current_user.projects.completed.limit(10).reorder('completed_at DESC').includes(:todos, :notes)
@last_completed_contexts = [] @last_completed_contexts = []
@last_completed_recurring_todos = current_user.recurring_todos.completed.limit(10).reorder('completed_at DESC').includes(:tags, :taggings) @last_completed_recurring_todos = current_user.recurring_todos.completed.limit(10).reorder('completed_at DESC').includes(:tags, :taggings)
#TODO: @last_completed_contexts = current_user.contexts.completed.all(:limit => 10, :order => 'completed_at DESC') # TODO: @last_completed_contexts = current_user.contexts.completed.all(:limit => 10, :order => 'completed_at DESC')
end end
private private
@ -135,7 +135,7 @@ class StatsController < ApplicationController
@cut_off_30days = 30.days.ago.beginning_of_day @cut_off_30days = 30.days.ago.beginning_of_day
end end
def get_ids_from (actions, week_from, week_to, at_end) def get_ids_from(actions, week_from, week_to, at_end)
selected_todo_ids = [] selected_todo_ids = []
actions.each do |r| actions.each do |r|

View file

@ -25,7 +25,8 @@ module Todos
elsif params[:todo] elsif params[:todo]
@attributes = todo_params(params) @attributes = todo_params(params)
end 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 end
def filter_tags def filter_tags
@ -41,7 +42,7 @@ module Todos
def filter_starred def filter_starred
if @params[:new_todo_starred] if @params[:new_todo_starred]
@attributes["starred"] = (@params[:new_todo_starred]||"").include? "true" @attributes["starred"] = (@params[:new_todo_starred] || "").include? "true"
end end
end end
@ -77,7 +78,7 @@ module Todos
@params['predecessor_list'] @params['predecessor_list']
end end
def parse_dates() def parse_dates
@attributes['show_from'] = @user.prefs.parse_date(show_from) @attributes['show_from'] = @user.prefs.parse_date(show_from)
@attributes['due'] = @user.prefs.parse_date(due) @attributes['due'] = @user.prefs.parse_date(due)
@attributes['due'] ||= '' @attributes['due'] ||= ''

View file

@ -38,7 +38,7 @@ class TodosController < ApplicationController
@page_title = t('todos.task_list_title') @page_title = t('todos.task_list_title')
# Set count badge to number of not-done, not hidden context items # Set count badge to number of not-done, not hidden context items
@count = current_user.todos.active.not_hidden.count(:all) @count = current_user.todos.active.not_hidden.count(:all)
@todos_without_project = @not_done_todos.select{ |t| t.project.nil? } @todos_without_project = @not_done_todos.select { |t| t.project.nil? }
end end
format.m do format.m do
@page_title = t('todos.mobile_todos_page_title') @page_title = t('todos.mobile_todos_page_title')
@ -49,14 +49,14 @@ class TodosController < ApplicationController
render :action => 'index'.freeze render :action => 'index'.freeze
end end
format.text do format.text do
# somehow passing Mime[:text] using content_type to render does not work # somehow passing Mime[:text] using content_type to render does not work
headers['Content-Type'.freeze] = Mime[:text].to_s headers['Content-Type'.freeze] = Mime[:text].to_s
render :content_type => Mime[:text] render :content_type => Mime[:text]
end end
format.xml do format.xml do
@xml_todos = params[:limit_to_active_todos] ? @not_done_todos : @todos @xml_todos = params[:limit_to_active_todos] ? @not_done_todos : @todos
render :xml => @xml_todos.to_xml( *[todo_xml_params[0].merge({ :root => :todos })] ) render :xml => @xml_todos.to_xml(*[todo_xml_params[0].merge({ :root => :todos })])
end end
format.any(:rss, :atom) do format.any(:rss, :atom) do
@feed_title = 'Tracks Actions'.freeze @feed_title = 'Tracks Actions'.freeze
@ -70,7 +70,7 @@ class TodosController < ApplicationController
@projects = current_user.projects.active @projects = current_user.projects.active
@contexts = current_user.contexts @contexts = current_user.contexts
respond_to do |format| respond_to do |format|
format.m { format.m do
@new_mobile = true @new_mobile = true
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path @return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
@mobile_from_context = current_user.contexts.find(params[:from_context]) if params[:from_context] @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 # we have a project but not a context -> use the default context
@mobile_from_context = @mobile_from_project.default_context @mobile_from_context = @mobile_from_project.default_context
end end
} end
end end
end end
@ -174,7 +174,8 @@ class TodosController < ApplicationController
# first build all todos and check if they would validate on save # first build all todos and check if they would validate on save
params[:todo][:multiple_todos].split("\n").map do |line| 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 }) @todo = current_user.todos.build({ :description => line, :context_id => p.context_id, :project_id => p.project_id })
validates &&= @todo.valid? validates &&= @todo.valid?
@ -245,12 +246,12 @@ class TodosController < ApplicationController
@tag_name = params['_tag_name'] @tag_name = params['_tag_name']
respond_to do |format| respond_to do |format|
format.js format.js
format.m { format.m do
@projects = current_user.projects.active @projects = current_user.projects.active
@contexts = current_user.contexts @contexts = current_user.contexts
@edit_mobile = true @edit_mobile = true
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path @return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
} end
end end
end end
@ -258,7 +259,7 @@ class TodosController < ApplicationController
@todo = current_user.todos.find(params['id']) @todo = current_user.todos.find(params['id'])
respond_to do |format| respond_to do |format|
format.m { render :action => 'show' } format.m { render :action => 'show' }
format.xml { render :xml => @todo.to_xml( *[todo_xml_params[0].merge({ :root => :todo })] ) } format.xml { render :xml => @todo.to_xml(*[todo_xml_params[0].merge({ :root => :todo })]) }
end end
end end
@ -339,7 +340,7 @@ class TodosController < ApplicationController
determine_down_count determine_down_count
determine_completed_count determine_completed_count
determine_deferred_tag_count(params['_tag_name']) if source_view_is(:tag) determine_deferred_tag_count(params['_tag_name']) if source_view_is(:tag)
@wants_redirect_after_complete = @todo.completed? && !@todo.project_id.nil? && current_user.prefs.show_project_on_todo_done && !source_view_is(:project) @wants_redirect_after_complete = @todo.completed? && !@todo.project_id.nil? && current_user.prefs.show_project_on_todo_done && !source_view_is(:project)
if source_view_is :calendar if source_view_is :calendar
@original_item_due_id = get_due_id_for_calendar(@original_item.due) @original_item_due_id = get_due_id_for_calendar(@original_item.due)
@old_due_empty = is_old_due_empty(@original_item_due_id) @old_due_empty = is_old_due_empty(@original_item_due_id)
@ -347,7 +348,7 @@ class TodosController < ApplicationController
end end
render render
end end
format.xml { render :xml => @todo.to_xml( *todo_xml_params ) } format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
format.html do format.html do
if @saved if @saved
# TODO: I think this will work, but can't figure out how to test it # TODO: I think this will work, but can't figure out how to test it
@ -355,10 +356,10 @@ class TodosController < ApplicationController
redirect_to :action => "index" redirect_to :action => "index"
else else
notify(:notice, t("todos.action_marked_complete_error", :description => @todo.description, :completed => @todo.completed? ? 'complete' : 'incomplete'), "index") notify(:notice, t("todos.action_marked_complete_error", :description => @todo.description, :completed => @todo.completed? ? 'complete' : 'incomplete'), "index")
redirect_to :action => "index" redirect_to :action => "index"
end end
end end
format.m { format.m do
if @saved if @saved
if cookies[:mobile_url] if cookies[:mobile_url]
old_path = cookies[:mobile_url] old_path = cookies[:mobile_url]
@ -372,7 +373,7 @@ class TodosController < ApplicationController
else else
render :action => "edit", :format => :m render :action => "edit", :format => :m
end end
} end
end end
end end
@ -382,9 +383,9 @@ class TodosController < ApplicationController
@saved = true # cannot determine error @saved = true # cannot determine error
respond_to do |format| respond_to do |format|
format.js format.js
format.xml { render :xml => @todo.to_xml( *todo_xml_params ) } format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
format.html { redirect_to request.referrer } format.html { redirect_to request.referrer }
format.m { format.m do
if cookies[:mobile_url] if cookies[:mobile_url]
old_path = cookies[:mobile_url] old_path = cookies[:mobile_url]
cookies[:mobile_url] = { :value => nil, :secure => SITE_CONFIG['secure_cookies'] } cookies[:mobile_url] = { :value => nil, :secure => SITE_CONFIG['secure_cookies'] }
@ -394,7 +395,7 @@ class TodosController < ApplicationController
notify(:notice, "Star toggled") notify(:notice, "Star toggled")
onsite_redirect_to todos_path(:format => 'm') onsite_redirect_to todos_path(:format => 'm')
end end
} end
end end
end end
@ -413,7 +414,7 @@ class TodosController < ApplicationController
respond_to do |format| respond_to do |format|
format.js { render :action => :update } format.js { render :action => :update }
format.xml { render :xml => @todo.to_xml( *todo_xml_params ) } format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
end end
end end
@ -437,7 +438,7 @@ class TodosController < ApplicationController
rescue ActiveRecord::RecordInvalid => exception rescue ActiveRecord::RecordInvalid => exception
record = exception.record record = exception.record
if record.is_a?(Dependency) if record.is_a?(Dependency)
record.errors.each { |key,value| @todo.errors[key] << value } record.errors.each { |key, value| @todo.errors[key] << value }
end end
@saved = false @saved = false
end end
@ -462,12 +463,12 @@ class TodosController < ApplicationController
@todo.touch_predecessors if @original_item.description != @todo.description @todo.touch_predecessors if @original_item.description != @todo.description
respond_to do |format| 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 = @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_project') + ' / ' + @status_message if @new_project_created
@status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_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.xml { render :xml => @todo.to_xml(*todo_xml_params) }
format.m do format.m do
if @saved if @saved
do_mobile_todo_redirection do_mobile_todo_redirection
@ -490,7 +491,8 @@ class TodosController < ApplicationController
def destroy def destroy
@source_view = params['_source_view'] || 'todo' @source_view = params['_source_view'] || 'todo'
@todo = current_user.todos.find(params['id']) @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 @context_id = @todo.context_id
@project_id = @todo.project_id @project_id = @todo.project_id
@todo_was_destroyed = true @todo_was_destroyed = true
@ -558,7 +560,7 @@ class TodosController < ApplicationController
format.html format.html
format.xml do format.xml do
completed_todos = current_user.todos.completed completed_todos = current_user.todos.completed
render :xml => completed_todos.to_xml( *[todo_xml_params[0].merge({ :root => :todos })] ) render :xml => completed_todos.to_xml(*[todo_xml_params[0].merge({ :root => :todos })])
end end
end end
end end
@ -581,7 +583,7 @@ class TodosController < ApplicationController
includes = params[:format] == 'xml' ? [:context, :project] : Todo::DEFAULT_INCLUDES includes = params[:format] == 'xml' ? [:context, :project] : Todo::DEFAULT_INCLUDES
@not_done_todos = current_user.todos.deferred.includes(includes).reorder('show_from') + current_user.todos.pending.includes(includes) @not_done_todos = current_user.todos.deferred.includes(includes).reorder('show_from') + current_user.todos.pending.includes(includes)
@todos_without_project = @not_done_todos.select{|t|t.project.nil?} @todos_without_project = @not_done_todos.select { |t| t.project.nil? }
@down_count = @count = @not_done_todos.size @down_count = @count = @not_done_todos.size
respond_to do |format| respond_to do |format|
@ -591,7 +593,7 @@ class TodosController < ApplicationController
init_data_for_sidebar unless mobile? init_data_for_sidebar unless mobile?
end end
format.m format.m
format.xml { render :xml => @not_done_todos.to_xml( *[todo_xml_params[0].merge({ :root => :todos })] ) } format.xml { render :xml => @not_done_todos.to_xml(*[todo_xml_params[0].merge({ :root => :todos })]) }
end end
end end
@ -625,23 +627,23 @@ class TodosController < ApplicationController
todos_with_tag_ids = find_todos_with_tag_expr(@tag_expr) todos_with_tag_ids = find_todos_with_tag_expr(@tag_expr)
@not_done_todos = todos_with_tag_ids. @not_done_todos = todos_with_tag_ids
active.not_hidden. .active.not_hidden
reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')). .reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC'))
includes(Todo::DEFAULT_INCLUDES) .includes(Todo::DEFAULT_INCLUDES)
@hidden_todos = todos_with_tag_ids. @hidden_todos = todos_with_tag_ids
hidden. .hidden
reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC')). .reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC'))
includes(Todo::DEFAULT_INCLUDES) .includes(Todo::DEFAULT_INCLUDES)
@deferred_todos = todos_with_tag_ids. @deferred_todos = todos_with_tag_ids
deferred. .deferred
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')). .reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
includes(Todo::DEFAULT_INCLUDES) .includes(Todo::DEFAULT_INCLUDES)
@pending_todos = todos_with_tag_ids. @pending_todos = todos_with_tag_ids
blocked. .blocked
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')). .reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
includes(Todo::DEFAULT_INCLUDES) .includes(Todo::DEFAULT_INCLUDES)
@todos_without_project = @not_done_todos.select{ |t| t.project.nil? } @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 # If you've set no_completed to zero, the completed items box isn't shown on
# the tag page # the tag page
@ -664,12 +666,8 @@ class TodosController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.m { format.m { cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } }
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } format.text { render :action => 'index', :layout => false, :content_type => Mime[:text] }
}
format.text {
render :action => 'index', :layout => false, :content_type => Mime[:text]
}
end end
end end
@ -706,7 +704,7 @@ class TodosController < ApplicationController
tags_all -= tags_beginning tags_all -= tags_beginning
respond_to do |format| respond_to do |format|
format.autocomplete { render :body => for_autocomplete(tags_beginning+tags_all, params[:term]) } format.autocomplete { render :body => for_autocomplete(tags_beginning + tags_all, params[:term]) }
end end
end end
@ -715,7 +713,8 @@ class TodosController < ApplicationController
numdays = params['days'].to_i numdays = params['days'].to_i
@todo = current_user.todos.find(params[:id]) @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 @todo_deferred_state_changed = true
@new_context_created = false @new_context_created = false
@ -750,7 +749,7 @@ class TodosController < ApplicationController
def list_hidden def list_hidden
@hidden = current_user.todos.hidden @hidden = current_user.todos.hidden
respond_to do |format| respond_to do |format|
format.xml { render :xml => @hidden.to_xml( *[todo_xml_params[0].merge({ :root => :todos })] ) } format.xml { render :xml => @hidden.to_xml(*[todo_xml_params[0].merge({ :root => :todos })]) }
end end
end end
@ -843,7 +842,7 @@ class TodosController < ApplicationController
end end
def tag_title(tag_expr) def tag_title(tag_expr)
and_list = tag_expr.inject([]) { |s,tag_list| s << tag_list.join(',') } and_list = tag_expr.inject([]) { |s, tag_list| s << tag_list.join(',') }
return and_list.join(' AND ') return and_list.join(' AND ')
end end
@ -905,7 +904,7 @@ end
end end
def find_todos_with_tag_expr(tag_expr) 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 if @single_tag
tag = current_user.tags.where(:name => @tag_name).first tag = current_user.tags.where(:name => @tag_name).first
tag_id = tag.nil? ? -1 : tag.id tag_id = tag.nil? ? -1 : tag.id
@ -1184,7 +1183,8 @@ end
def update_tags def update_tags
if params[:tag_list] if params[:tag_list]
@todo.tag_with(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
end end
@ -1197,7 +1197,7 @@ end
end end
def update_date_for_update(key) 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 end
def update_due_and_show_from_dates def update_due_and_show_from_dates
@ -1225,7 +1225,7 @@ end
# assumes @todo.save was called so that the predecessor_list is persistent # assumes @todo.save was called so that the predecessor_list is persistent
original_item_predecessor_list = original_item_predecessor_list =
@original_item.predecessors @original_item.predecessors
.map{ |t| t.specification } .map { |t| t.specification }
.join(', ') .join(', ')
if original_item_predecessor_list != params[:predecessor_list] if original_item_predecessor_list != params[:predecessor_list]

View file

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

View file

@ -10,7 +10,7 @@ module ApplicationHelper
link_to( link_to(
t("layouts.navigation.group_view_by_#{menu_name}"), t("layouts.navigation.group_view_by_#{menu_name}"),
'#', '#',
{ :id => "group_view_by_link", :accesskey => "g", :title => t('layouts.navigation.group_view_by_title'), :x_current_group_by => @group_view_by } ) { :id => "group_view_by_link", :accesskey => "g", :title => t('layouts.navigation.group_view_by_title'), :x_current_group_by => @group_view_by })
end end
end end
@ -44,7 +44,7 @@ module ApplicationHelper
end end
def count_undone_todos_phrase_text(todos_parent) def count_undone_todos_phrase_text(todos_parent)
count_undone_todos_phrase(todos_parent).gsub("&nbsp;"," ").html_safe count_undone_todos_phrase(todos_parent).gsub("&nbsp;", " ").html_safe
end end
def count_undone_todos_and_notes_phrase(project) def count_undone_todos_and_notes_phrase(project)
@ -113,7 +113,7 @@ module ApplicationHelper
recurring_target + recurrence_pattern + recurrence_time_span recurring_target + recurrence_pattern + recurrence_time_span
end end
def date_format_for_date_picker() def date_format_for_date_picker
[ [
['%m', 'mm'], ['%m', 'mm'],
['%b', 'M'], ['%b', 'M'],
@ -126,8 +126,8 @@ module ApplicationHelper
].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) } ].inject(current_user.prefs.date_format) { |str, translation| str.gsub(*translation) }
end end
def sidebar_html_for_titled_list (list, title) def sidebar_html_for_titled_list(list, title)
return content_tag(:h3, title+" (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list)) return content_tag(:h3, title + " (#{list.size})") + content_tag(:ul, sidebar_html_for_list(list))
end end
def link_to_sidebar_item(item) def link_to_sidebar_item(item)
@ -159,7 +159,7 @@ module ApplicationHelper
common.update common.create common.update common.create
common.ajaxError todos.unresolved_dependency common.ajaxError todos.unresolved_dependency
}.each do |s| }.each do |s|
js << "i18n['#{s}'] = '#{ t(s).gsub(/'/, "\\\\'") }';\n" js << "i18n['#{s}'] = '#{t(s).gsub(/'/, "\\\\'")}';\n"
end end
return js.html_safe return js.html_safe
end end
@ -219,7 +219,7 @@ module ApplicationHelper
end end
def link_to_edit(type, object, descriptor) 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)}", :id => "link_edit_#{dom_id(object)}",
:class => "#{type}_edit_settings icon" :class => "#{type}_edit_settings icon"

View file

@ -5,9 +5,9 @@ module BootstrapFlashHelper
:error => :danger, :error => :danger,
:info => :info, :info => :info,
:warning => :warning :warning => :warning
} unless const_defined?(:ALERT_MAPPING) }.freeze unless const_defined?(:ALERT_MAPPING)
def bootstrap_flash(options = {:close_button => true}) def bootstrap_flash(options = { :close_button => true })
flash_messages = [] flash_messages = []
flash.each do |type, message| flash.each do |type, message|
# Skip empty messages, e.g. for devise messages set to nothing in a locale file. # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
@ -15,7 +15,6 @@ module BootstrapFlashHelper
type = type.to_sym type = type.to_sym
next unless ALERT_MAPPING.keys.include?(type) next unless ALERT_MAPPING.keys.include?(type)
tag_class = options.extract!(:class)[:class] tag_class = options.extract!(:class)[:class]
tag_options = { tag_options = {
class: "alert fade in alert-#{ALERT_MAPPING[type]} #{tag_class}" class: "alert fade in alert-#{ALERT_MAPPING[type]} #{tag_class}"

View file

@ -1,9 +1,9 @@
module ContextsHelper module ContextsHelper
def show_context_name(context) def show_context_name(context)
if source_view_is :context if source_view_is :context
content_tag(:span, :id => "context_name"){context.name} content_tag(:span, :id => "context_name"){ context.name }
else else
link_to_context( context ) link_to_context(context)
end end
end end
@ -11,7 +11,7 @@ module ContextsHelper
link_to_delete(:context, context, descriptor) link_to_delete(:context, context, descriptor)
end end
def link_to_edit_context (context, descriptor = sanitize(context.name)) def link_to_edit_context(context, descriptor = sanitize(context.name))
link_to_edit(:context, context, descriptor) link_to_edit(:context, context, descriptor)
end end

View file

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

View file

@ -1,6 +1,6 @@
module FeedlistHelper module FeedlistHelper
def linkoptions(format, options) def linkoptions(format, options)
merge_hashes( { :format => format }, options, user_token_hash) merge_hashes({ :format => format }, options, user_token_hash)
end end
def rss_formatted_link(options = {}) def rss_formatted_link(options = {})
@ -41,7 +41,7 @@ module FeedlistHelper
protected protected
def merge_hashes(*hashes) def merge_hashes(*hashes)
hashes.inject(Hash.new){ |result, h| result.merge(h) } hashes.inject({}) { |result, h| result.merge(h) }
end end
def user_token_hash def user_token_hash

View file

@ -11,9 +11,8 @@ module NotesHelper
link_to( link_to(
descriptor, descriptor,
note_path(note, :format => 'js'), note_path(note, :format => 'js'),
{:id => "delete_note_#{note.id}", :class => "delete_note_button", { :id => "delete_note_#{note.id}", :class => "delete_note_button",
:title => t('notes.delete_note_title', :id => note.id), :x_confirm_message => t('notes.delete_note_confirm', :id => note.id)} :title => t('notes.delete_note_title', :id => note.id), :x_confirm_message => t('notes.delete_note_confirm', :id => note.id) }
) )
end end
end end

View file

@ -1,9 +1,9 @@
module ProjectsHelper module ProjectsHelper
def show_project_name(project) def show_project_name(project)
if source_view_is :project if source_view_is :project
content_tag(:span, :id => "project_name"){project.name} content_tag(:span, :id => "project_name") { project.name }
else else
link_to_project( project ) link_to_project(project)
end end
end end
@ -14,7 +14,7 @@ module ProjectsHelper
end end
def project_next_prev def project_next_prev
content_tag(:div, :id=>"project-next-prev") do content_tag(:div, :id => "project-next-prev") do
html = "" html = ""
html << link_to_project(@previous_project, "&laquo; #{@previous_project.shortened_name}".html_safe) if @previous_project html << link_to_project(@previous_project, "&laquo; #{@previous_project.shortened_name}".html_safe) if @previous_project
html << " | " if @previous_project && @next_project html << " | " if @previous_project && @next_project
@ -33,14 +33,13 @@ module ProjectsHelper
def project_summary(project) def project_summary(project)
project_description = '' project_description = ''
project_description += render_text( project.description ) if project.description.present? project_description += render_text(project.description) if project.description.present?
project_description += content_tag(:p, 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 end
def needsreview_class(item) 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" return item.needs_review?(current_user) ? "needsreview" : "needsnoreview"
end end
@ -48,7 +47,7 @@ module ProjectsHelper
link_to_delete(:project, project, descriptor) link_to_delete(:project, project, descriptor)
end end
def link_to_edit_project (project, descriptor = sanitize(project.name)) def link_to_edit_project(project, descriptor = sanitize(project.name))
link_to_edit(:project, project, descriptor) link_to_edit(:project, project, descriptor)
end end
end end

View file

@ -1,8 +1,8 @@
module RecurringTodosHelper module RecurringTodosHelper
def recurring_todo_tag_list def recurring_todo_tag_list
tags_except_starred = @recurring_todo.tags.reject{ |t| t.name == Todo::STARRED_TAG_NAME } tags_except_starred = @recurring_todo.tags.reject { |t| t.name == Todo::STARRED_TAG_NAME }
tag_list = tags_except_starred tag_list = tags_except_starred
.collect{ |t| content_tag(:span,link_to(t.name, tag_path(t.name)), :class => "tag #{t.label}") } .collect { |t| content_tag(:span, link_to(t.name, tag_path(t.name)), :class => "tag #{t.label}") }
.join('') .join('')
return content_tag :span, tag_list.html_safe, :class => "tags" return content_tag :span, tag_list.html_safe, :class => "tags"
end end

View file

@ -21,7 +21,7 @@ module RenderingHelper
def render_text(text) def render_text(text)
rendered = auto_link_message(text) rendered = auto_link_message(text)
rendered = textile(rendered) rendered = textile(rendered)
rendered = auto_link(rendered, link: :urls, html: {target: '_blank'}) rendered = auto_link(rendered, link: :urls, html: { target: '_blank' })
relaxed_config = Sanitize::Config::RELAXED relaxed_config = Sanitize::Config::RELAXED
config = relaxed_config config = relaxed_config

View file

@ -3,17 +3,17 @@ require 'staleness'
module TodosHelper module TodosHelper
# === helpers for rendering container # === helpers for rendering container
def empty_message_holder(container_name, show, title_param = nil) 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(: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) } + content_tag(:h2) { t("todos.no_actions.title", :param => title_param) } +
content_tag(:div, :class => "message") do content_tag(:div, :class => "message") do
content_tag(:p) { t("todos.no_actions.#{container_name}", :param=>title_param) } content_tag(:p) { t("todos.no_actions.#{container_name}", :param => title_param) }
end end
end end
end end
def todos_container_empty_message(container_name, container_id, show_message) def todos_container_empty_message(container_name, container_id, show_message)
content_tag(:div, :id => "#{container_id}-empty-d", :style => "display:#{show_message ? 'block' : 'none'}") do content_tag(:div, :id => "#{container_id}-empty-d", :style => "display:#{show_message ? 'block' : 'none'}") do
content_tag(:div, :class=>"message") do content_tag(:div, :class => "message") do
content_tag(:p) do content_tag(:p) do
t("todos.no_actions.#{container_name}") t("todos.no_actions.#{container_name}")
end end
@ -27,7 +27,7 @@ module TodosHelper
:collapsible => true, :collapsible => true,
:show_empty_containers => @show_empty_containers, :show_empty_containers => @show_empty_containers,
:parent_container_type => @group_view_by :parent_container_type => @group_view_by
})}) }) })
end end
def default_collection_settings def default_collection_settings
@ -73,10 +73,10 @@ module TodosHelper
def show_deferred_pending_todos(deferred_todos, pending_todos, settings = {}) def show_deferred_pending_todos(deferred_todos, pending_todos, settings = {})
settings[:pending] = pending_todos settings[:pending] = pending_todos
settings[:container_name]="deferred_pending" settings[:container_name] = "deferred_pending"
render :partial => "todos/collection", render :partial => "todos/collection",
:object => deferred_todos+pending_todos, :object => deferred_todos + pending_todos,
:locals => { :settings => settings.reverse_merge!(default_collection_settings) } :locals => { :settings => settings.reverse_merge!(default_collection_settings) }
end end
@ -113,7 +113,7 @@ module TodosHelper
settings.reverse_merge!({ settings.reverse_merge!({
:title => t("todos.actions.#{settings[:parent_container_type]}_#{settings[:container_name]}", :param => settings[:title_param]) :title => t("todos.actions.#{settings[:parent_container_type]}_#{settings[:container_name]}", :param => settings[:title_param])
}) })
header = settings[:link_in_header].nil? ? "" : content_tag(:div, :class=>"link_in_container_header"){settings[:link_in_header]} header = settings[:link_in_header].nil? ? "" : content_tag(:div, :class => "link_in_container_header") { settings[:link_in_header] }
header += content_tag(:h2) do header += content_tag(:h2) do
toggle = settings[:collapsible] ? container_toggle("toggle_#{settings[:id]}") : "" toggle = settings[:collapsible] ? container_toggle("toggle_#{settings[:id]}") : ""
"#{toggle} #{settings[:title]} #{settings[:append_descriptor]}".html_safe "#{toggle} #{settings[:title]} #{settings[:append_descriptor]}".html_safe
@ -123,7 +123,7 @@ module TodosHelper
end end
def todos_container_items(collection, settings = {}) def todos_container_items(collection, settings = {})
settings.reverse_merge!({:id => "#{settings[:container_name]}"}) settings.reverse_merge!({ :id => "#{settings[:container_name]}" })
# do not pass :class to partial locals # do not pass :class to partial locals
settings.delete(:class) settings.delete(:class)
@ -140,7 +140,7 @@ module TodosHelper
:collapsible => false, :collapsible => false,
:show_empty_containers => true, :show_empty_containers => true,
:container_name => "#{period}", :container_name => "#{period}",
:title =>t("todos.calendar.#{period}", :month => l(Time.zone.now, :format => "%B"), :next_month => l(1.month.from_now, :format => "%B")) :title => t("todos.calendar.#{period}", :month => l(Time.zone.now, :format => "%B"), :next_month => l(1.month.from_now, :format => "%B"))
} } } }
end end
@ -168,12 +168,13 @@ module TodosHelper
:class => "icon_delete_item", :class => "icon_delete_item",
:id => dom_id(todo, "delete"), :id => dom_id(todo, "delete"),
:x_confirm_message => t('todos.confirm_delete', :description => todo.description), :x_confirm_message => t('todos.confirm_delete', :description => todo.description),
:title => t('todos.delete_action')); :title => t('todos.delete_action')
)
end end
def remote_defer_menu_item(days, todo) def remote_defer_menu_item(days, todo)
url = { :controller => 'todos', :action => 'defer', :id => todo.id, :days => days, url = { :controller => 'todos', :action => 'defer', :id => todo.id, :days => days,
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "") } :_source_view => (@source_view.underscore.gsub(/\s+/, '_') rescue "") }
url[:_tag_name] = @tag_name if @source_view == 'tag' url[:_tag_name] = @tag_name if @source_view == 'tag'
options = { :x_defer_alert => false, :class => "icon_defer_item icon_defer_#{days}_item", :id => "defer_#{days}_#{dom_id(todo)}" } options = { :x_defer_alert => false, :class => "icon_defer_item icon_defer_#{days}_item", :id => "defer_#{days}_#{dom_id(todo)}" }
@ -192,13 +193,13 @@ module TodosHelper
link_to( link_to(
image_tag("blank.png", :title => t('todos.remove_dependency'), :align => "absmiddle", :class => "delete_item"), image_tag("blank.png", :title => t('todos.remove_dependency'), :align => "absmiddle", :class => "delete_item"),
remove_predecessor_todo_path(todo), remove_predecessor_todo_path(todo),
{:class => "delete_dependency_button", :x_predecessors_id => predecessor.id} { :class => "delete_dependency_button", :x_predecessors_id => predecessor.id }
) )
end end
def remote_promote_to_project_menu_item(todo) def remote_promote_to_project_menu_item(todo)
url = {:controller => 'todos', :action => 'convert_to_project', :id => todo.id, url = { :controller => 'todos', :action => 'convert_to_project', :id => todo.id,
:_source_view => (@source_view.underscore.gsub(/\s+/,'_') rescue "")} :_source_view => (@source_view.underscore.gsub(/\s+/, '_') rescue "") }
url[:_tag_name] = @tag_name if @source_view == 'tag' url[:_tag_name] = @tag_name if @source_view == 'tag'
link_to(t('todos.convert_to_project'), url, { :class => "icon_item_to_project", :id => dom_id(todo, "to_project") }) link_to(t('todos.convert_to_project'), url, { :class => "icon_item_to_project", :id => dom_id(todo, "to_project") })
@ -206,7 +207,7 @@ module TodosHelper
def attachment_image(todo) def attachment_image(todo)
link_to( link_to(
image_tag('blank.png', width: 16, height: 16, border:0), image_tag('blank.png', width: 16, height: 16, border: 0),
todo.attachments.first.file.url, todo.attachments.first.file.url,
{ :class => 'todo_attachment', title: 'Get attachments of this todo' } { :class => 'todo_attachment', title: 'Get attachments of this todo' }
) )
@ -214,23 +215,23 @@ module TodosHelper
def collapsed_notes_image(todo) def collapsed_notes_image(todo)
link = link_to( link = link_to(
image_tag( 'blank.png', :width => '16', :height => '16', :border => '0' ), image_tag('blank.png', :width => '16', :height => '16', :border => '0'),
"#", "#",
{ :class => 'show_notes', :title => 'Show notes' }) { :class => 'show_notes', :title => 'Show notes' })
notes = content_tag(:div, { notes = content_tag(:div, {
:class => "todo_notes", :class => "todo_notes",
:id => dom_id(todo, 'notes'), :id => dom_id(todo, 'notes'),
:style => "display:none" }) { raw render_text(todo.notes) } :style => "display:none" }) { raw render_text(todo.notes) }
return link+notes return link + notes
end end
def collapsed_successors_image(todo) def collapsed_successors_image(todo)
link = link_to(image_tag('blank.png', :width => '16', :height => '16', :border => '0' ), "#", { :class => 'show_successors', :title => 'Show successors' }) link = link_to(image_tag('blank.png', :width => '16', :height => '16', :border => '0'), "#", { :class => 'show_successors', :title => 'Show successors' })
successors = content_tag(:div, { :class => "todo_successors", :id => dom_id(todo, 'successors'), :style => "display:none" }) do successors = content_tag(:div, { :class => "todo_successors", :id => dom_id(todo, 'successors'), :style => "display:none" }) do
render :partial => "todos/successor", :collection => todo.pending_successors, render :partial => "todos/successor", :collection => todo.pending_successors,
:locals => { :parent_container_type => parent_container_type, :suppress_dependencies => true, :predecessor => todo } :locals => { :parent_container_type => parent_container_type, :suppress_dependencies => true, :predecessor => todo }
end end
return link+successors return link + successors
end end
def image_tag_for_recurring_todo(todo) def image_tag_for_recurring_todo(todo)
@ -257,9 +258,9 @@ module TodosHelper
def date_span(todo = @todo) def date_span(todo = @todo)
if todo.completed? if todo.completed?
content_tag(:span, { :class => :grey }) { format_date( todo.completed_at ) } content_tag(:span, { :class => :grey }) { format_date(todo.completed_at) }
elsif todo.pending? elsif todo.pending?
title = t('todos.depends_on')+ ": " + todo.uncompleted_predecessors.to_a.map(&:description).join(', ') title = t('todos.depends_on') + ": " + todo.uncompleted_predecessors.to_a.map(&:description).join(', ')
content_tag(:a, { :title => title }) { content_tag(:span, { :class => :orange }) { t('todos.pending') } } content_tag(:a, { :title => title }) { content_tag(:span, { :class => :orange }) { t('todos.pending') } }
elsif todo.deferred? elsif todo.deferred?
show_date(todo.show_from) show_date(todo.show_from)
@ -318,7 +319,7 @@ module TodosHelper
end end
def include_context_link(todo, parent_container_type) 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 # TODO: remove next line if 'project' supports group_view_by
return true if parent_container_type == 'project' return true if parent_container_type == 'project'
return true if @group_view_by == 'project' return true if @group_view_by == 'project'
@ -327,7 +328,7 @@ module TodosHelper
def include_project_link(todo, parent_container_type) def include_project_link(todo, parent_container_type)
return false unless todo.has_project? 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 # TODO: remove next line if 'context' supports group_view_by
return true if parent_container_type == 'context' return true if parent_container_type == 'context'
return true if @group_view_by == 'context' return true if @group_view_by == 'context'
@ -347,9 +348,9 @@ module TodosHelper
case days_stale case days_stale
when 0...start when 0...start
"" ""
when start...start*2 when start...start * 2
" stale_l1" " stale_l1"
when start*2...start*3 when start*2...start * 3
" stale_l2" " stale_l2"
else else
" stale_l3" " stale_l3"
@ -380,19 +381,19 @@ module TodosHelper
def default_contexts_for_autocomplete def default_contexts_for_autocomplete
projects = current_user.projects.uncompleted.includes(:default_context).where('NOT(default_context_id IS NULL)') projects = current_user.projects.uncompleted.includes(:default_context).where('NOT(default_context_id IS NULL)')
Hash[*projects.map{ |p| [escape_javascript(p.name), escape_javascript(p.default_context.name)] }.flatten].to_json Hash[*projects.map { |p| [escape_javascript(p.name), escape_javascript(p.default_context.name)] }.flatten].to_json
end end
def default_tags_for_autocomplete def default_tags_for_autocomplete
projects = current_user.projects.uncompleted.where("NOT(default_tags = '')") projects = current_user.projects.uncompleted.where("NOT(default_tags = '')")
Hash[*projects.map{ |p| [escape_javascript(p.name), p.default_tags] }.flatten].to_json Hash[*projects.map { |p| [escape_javascript(p.name), p.default_tags] }.flatten].to_json
end end
# === various helpers # === various helpers
def formatted_pagination(total) def formatted_pagination(total)
s = will_paginate(@todos) s = will_paginate(@todos)
(s.gsub(/(<\/[^<]+>)/, '\1 ')).chomp(' ') s.gsub(/(<\/[^<]+>)/, '\1 ').chomp(' ')
end end
def format_ical_notes(notes) def format_ical_notes(notes)
@ -418,10 +419,11 @@ module TodosHelper
# if the animation needs to be run inside the namespace of an object, set the # 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 # object_name to the name of the object and this name will be prepended to each step
def render_animation(animation, object_name = nil) 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 # concatenate all steps into functions that call functions
html = animation.map{ |step| "#{object_name}#{step}({ go: function() {" }.join("\r\n") html = animation.map { |step| "#{object_name}#{step}({ go: function() {" }.join("\r\n")
# close all functions # close all functions
html += "}}) " * animation.size + ";" html += "}}) " * animation.size + ";"
@ -474,8 +476,8 @@ module TodosHelper
end end
def todo_container_is_empty def todo_container_is_empty
default_container_empty = ( @down_count == 0 ) default_container_empty = (@down_count == 0)
deferred_container_empty = ( @todo.deferred? && @remaining_deferred_count == 0) deferred_container_empty = (@todo.deferred? && @remaining_deferred_count == 0)
return default_container_empty || deferred_container_empty return default_container_empty || deferred_container_empty
end end
@ -516,12 +518,12 @@ module TodosHelper
def update_needs_to_remove_todo_from_container def update_needs_to_remove_todo_from_container
source_view do |page| source_view do |page|
page.context { return @context_changed || @todo_deferred_state_changed || @todo_pending_state_changed || @todo_should_be_hidden } page.context { return @context_changed || @todo_deferred_state_changed || @todo_pending_state_changed || @todo_should_be_hidden }
page.project { return @context_changed || @todo_deferred_state_changed || @todo_pending_state_changed || @project_changed} page.project { return @context_changed || @todo_deferred_state_changed || @todo_pending_state_changed || @project_changed }
page.deferred { return todo_moved_out_of_container || !(@todo.deferred? || @todo.pending?) } page.deferred { return todo_moved_out_of_container || !(@todo.deferred? || @todo.pending?) }
page.calendar { return @due_date_changed || !@todo.due } page.calendar { return @due_date_changed || !@todo.due }
page.stats { return @todo.completed? } page.stats { return @todo.completed? }
page.tag { return ( (@context_changed | @project_changed) && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed } page.tag { return ((@context_changed | @project_changed) && !@todo.hidden?) || @tag_was_removed || @todo_hidden_state_changed || @todo_deferred_state_changed }
page.todo { return todo_moved_out_of_container || @todo.hidden? || @todo.deferred? || @todo.pending?} page.todo { return todo_moved_out_of_container || @todo.hidden? || @todo.deferred? || @todo.pending? }
page.search { return false } page.search { return false }
end end
return false return false
@ -564,7 +566,7 @@ module TodosHelper
source_view do |page| source_view do |page|
page.context { return @remaining_in_context == 0 } page.context { return @remaining_in_context == 0 }
end end
return @down_count==0 return @down_count == 0
end end
def project_container_id(todo) def project_container_id(todo)
@ -609,29 +611,25 @@ module TodosHelper
raise Exception.new, "no @todo or @successor set" if !todo raise Exception.new, "no @todo or @successor set" if !todo
source_view do |page| source_view do |page|
page.project { page.project do
return "deferred_pending_container-empty-d" if empty_criteria_met return "deferred_pending_container-empty-d" if empty_criteria_met
return todo_container_empty_id(todo) return todo_container_empty_id(todo)
} end
page.tag { page.tag do
return "deferred_pending_container-empty-d" if empty_criteria_met return "deferred_pending_container-empty-d" if empty_criteria_met
return "hidden_container-empty-d" if @todo.hidden? return "hidden_container-empty-d" if @todo.hidden?
return todo_container_empty_id(todo) return todo_container_empty_id(todo)
} end
page.calendar { page.calendar do
return "deferred_pending_container-empty-d" if empty_criteria_met return "deferred_pending_container-empty-d" if empty_criteria_met
return "#{@new_due_id}_container-empty-d" return "#{@new_due_id}_container-empty-d"
} end
page.context { page.context do
return "deferred_pending_container-empty-d" if empty_criteria_met return "deferred_pending_container-empty-d" if empty_criteria_met
return todo_container_empty_id(todo) return todo_container_empty_id(todo)
} end
page.todo { page.todo { return todo_container_empty_id(todo) }
return todo_container_empty_id(todo) page.deferred { return todo_container_empty_id(todo) }
}
page.deferred {
return todo_container_empty_id(todo)
}
end end
return context_container_empty_id(todo) return context_container_empty_id(todo)
@ -656,28 +654,28 @@ module TodosHelper
def show_empty_message_in_source_container def show_empty_message_in_source_container
container_id = "" container_id = ""
source_view do |page| 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 = 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 = "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? container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
} end
page.deferred { container_id = todo_container_empty_id(@original_item) if @remaining_in_context == 0 } page.tag do
page.calendar { container_id = "#{@original_item_due_id}_container-empty-d" if @old_due_empty }
page.tag {
container_id = "hidden_container-empty-d" if (@remaining_hidden_count == 0 && !@todo.hidden? && @todo_hidden_state_changed) || 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?) (@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) || 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)) (@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? container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
} end
page.context { page.context do
container_id = context_container_empty_id(@original_item) if @remaining_in_context == 0 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 = "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? container_id = "completed_container-empty-d" if @completed_count && @completed_count == 0 && !@todo.completed?
} end
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 return container_id.blank? ? "" : "$(\"##{container_id}\").slideDown(100);".html_safe
end end

View file

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

View file

@ -31,9 +31,7 @@ class Context < ApplicationRecord
end end
end end
validates_presence_of :name, :message => "context must have a name" 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 }
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
def self.null_object def self.null_object
NullContext.new NullContext.new

View file

@ -75,7 +75,7 @@ class MessageGateway < ActionMailer::Base
def get_receiving_user_from_mail_header(email) def get_receiving_user_from_mail_header(email)
user = get_receiving_user_from_sms_email(get_address(email)) user = get_receiving_user_from_sms_email(get_address(email))
Rails.logger.info(user.nil? ? "User unknown": "Email belongs to #{user.login}") Rails.logger.info(user.nil? ? "User unknown" : "Email belongs to #{user.login}")
return user return user
end end
@ -98,8 +98,8 @@ class MessageGateway < ActionMailer::Base
return true return true
end end
def sender_is_in_mailmap?(user,email) 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 # Look for the sender in the map of allowed senders
SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0] SITE_CONFIG['mailmap'][user.preference.sms_email].include? email.from[0]
else else

View file

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

View file

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

View file

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

View file

@ -60,7 +60,7 @@ module RecurringTodos
# get pattern independend attributes # get pattern independend attributes
filtered_attributes = filter_generic_attributes(attributes) filtered_attributes = filter_generic_attributes(attributes)
# append pattern specific attributes # append pattern specific attributes
attributes_to_filter.each{ |key| filtered_attributes[key]= attributes[key] if attributes.key?(key) } attributes_to_filter.each { |key| filtered_attributes[key] = attributes[key] if attributes.key?(key) }
filtered_attributes filtered_attributes
end end

View file

@ -36,8 +36,8 @@ module RecurringTodos
if only_work_days? if only_work_days?
# jump over weekend if necessary # jump over weekend if necessary
return start + 2.day if start.wday() == 6 # saturday return start + 2.day if start.wday == 6 # saturday
return start + 1.day if start.wday() == 0 # sunday return start + 1.day if start.wday == 0 # sunday
return start return start
else else
# if there was no previous todo, do not add n: the first todo starts on # 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 def validate
super super
validate_not_blank(every_x_week, "Every other nth week may not be empty for weekly recurrence setting") 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 errors[:base] << "You must specify at least one day on which the todo recurs" unless something_set
end end
@ -41,19 +41,19 @@ module RecurringTodos
# we did not find anything this week, so check the nth next, starting from # we did not find anything this week, so check the nth next, starting from
# sunday # 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) start = find_first_day_in_this_week(start)
return start unless start == -1 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 end
private private
def determine_start_date(previous) def determine_start_date(previous)
if previous.nil? if previous.nil?
return self.start_from || Time.zone.now return start_from || Time.zone.now
else else
start = previous + 1.day start = previous + 1.day
if start.wday == 0 if start.wday == 0
@ -61,10 +61,10 @@ module RecurringTodos
# that week. Note that we already went into the next week, so -1 # that week. Note that we already went into the next week, so -1
start += (every_x_week - 1).week start += (every_x_week - 1).week
end end
unless self.start_from.nil? unless start_from.nil?
# check if the start_from date is later than previous. If so, use # check if the start_from date is later than previous. If so, use
# start_from as start to search for next date # 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 end
return start return start
end end

View file

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

View file

@ -19,33 +19,33 @@ module Search
end end
def number_of_finds def number_of_finds
results[:todos].size + results[:projects].size + results[:notes].size + results[:contexts].size + results[:tags].size results[:todos].size + results[:projects].size + results[:notes].size + results[:contexts].size + results[:tags].size
end end
private private
def incomplete_todos(terms) def incomplete_todos(terms)
@user.todos. @user.todos
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND todos.completed_at IS NULL", terms, terms) .where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND todos.completed_at IS NULL", terms, terms)
.includes(Todo::DEFAULT_INCLUDES) .includes(Todo::DEFAULT_INCLUDES)
.reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC")) .reorder(Arel.sql("todos.due IS NULL, todos.due ASC, todos.created_at ASC"))
end end
def complete_todos(terms) def complete_todos(terms)
@user.todos. @user.todos
where("(todos.description " + Common.like_operator + " ? OR todos.notes " + Common.like_operator + " ?) AND NOT (todos.completed_at IS NULL)", terms, terms) .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) .includes(Todo::DEFAULT_INCLUDES)
.reorder("todos.completed_at DESC") .reorder("todos.completed_at DESC")
end end
def todo_tags_by_name(terms) def todo_tags_by_name(terms)
Tagging.find_by_sql([ Tagging.find_by_sql(["
"SELECT DISTINCT tags.name as name " + SELECT DISTINCT tags.name as name
"FROM tags " + FROM tags
"LEFT JOIN taggings ON tags.id = taggings.tag_id " + LEFT JOIN taggings ON tags.id = taggings.tag_id
"LEFT JOIN todos ON taggings.taggable_id = todos.id " + LEFT JOIN todos ON taggings.taggable_id = todos.id
"WHERE todos.user_id=? " + WHERE todos.user_id = ?
"AND tags.name " + Common.like_operator + " ? ", @user.id, terms]) AND tags.name " + Common.like_operator + " ? ", @user.id, terms])
end end
end end
end end

View file

@ -362,7 +362,7 @@ module Stats
end end
def convert_to_weeks_running_array(records, array_size) def convert_to_weeks_running_array(records, array_size)
return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)]} return convert_to_array(records, array_size) { |r| [difference_in_weeks(r.completed_at, r.created_at)] }
end end
def convert_to_weeks_running_from_today_array(records, array_size) def convert_to_weeks_running_from_today_array(records, array_size)
@ -391,7 +391,7 @@ module Stats
def convert_to_cumulative_array(array, max) def convert_to_cumulative_array(array, max)
# calculate fractions # calculate fractions
a = Array.new(array.size) {|i| array[i] * 100.0 / max} a = Array.new(array.size) { |i| array[i] * 100.0 / max }
# make cumulative # make cumulative
1.upto(array.size - 1) { |i| a[i] += a[i - 1] } 1.upto(array.size - 1) { |i| a[i] += a[i - 1] }
return a return a
@ -422,7 +422,7 @@ module Stats
def compute_running_avg_array(set, upper_bound) def compute_running_avg_array(set, upper_bound)
result = set_three_month_avg(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 - 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[0] = "null"
result result
end # unsolved, not triggered, edge case for set.length == upper_bound + 1 end # unsolved, not triggered, edge case for set.length == upper_bound + 1

View file

@ -22,7 +22,7 @@ module Stats
def find_top10_longest_running_projects def find_top10_longest_running_projects
projects = user.projects.order('created_at ASC') projects = user.projects.order('created_at ASC')
projects.sort_by{ |p| p.running_time }.reverse.take(10) projects.sort_by { |p| p.running_time }.reverse.take(10)
end end
end end
end end

View file

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

View file

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

View file

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

View file

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

View file

@ -17,7 +17,7 @@ class RichMessageExtractor
DUE_MARKER, DUE_MARKER,
TAG_MARKER, TAG_MARKER,
STAR_MARKER STAR_MARKER
] ].freeze
def initialize(message) def initialize(message)
@message = message @message = message
@ -44,7 +44,7 @@ class RichMessageExtractor
# Regex only matches one tag, so recurse until we have them all # Regex only matches one tag, so recurse until we have them all
while string.match /#(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/ while string.match /#(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/
tags << sanitize($1) tags << sanitize($1)
string.gsub!(/##{$1}/,'') string.gsub!(/##{$1}/, '')
end end
tags.empty? ? nil : tags tags.empty? ? nil : tags
end end
@ -65,11 +65,11 @@ class RichMessageExtractor
private private
def select_for symbol def select_for(symbol)
@message.match /#{symbol}(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/ @message.match /#{symbol}(.*?)(?=[#{ALL_MARKERS.join}]|\Z)/
end end
def fix_date_string yymmdd def fix_date_string(yymmdd)
"20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00" "20#{yymmdd[0..1]}-#{yymmdd[2..3]}-#{yymmdd[4..5]} 00:00"
end end
end end

View file

@ -1,14 +1,12 @@
xml.instruct! xml.instruct!
xml.OpenSearchDescription 'xmlns' => "http://a9.com/-/spec/opensearch/1.1/" do xml.OpenSearchDescription 'xmlns' => "http://a9.com/-/spec/opensearch/1.1/" do
xml.ShortName Tracks xml.ShortName Tracks
xml.Description t('integrations.opensearch_description') xml.Description t('integrations.opensearch_description')
xml.InputEncoding 'UTF-8' xml.InputEncoding 'UTF-8'
xml.Image("data:image/x-icon;base64," + @icon_data, xml.Image("data:image/x-icon;base64," + @icon_data,
'width' => '16', 'height' => '16') 'width' => '16', 'height' => '16')
xml.Url 'type' => 'text/html', 'method' => 'GET', xml.Url 'type' => 'text/html', 'method' => 'GET',
'template' => url_for(:controller => 'search', :action => 'results', 'template' => url_for(:controller => 'search', :action => 'results',
:only_path => false) + '?search={searchTerms}' :only_path => false) + '?search={searchTerms}'
end end

View file

@ -11,7 +11,7 @@
text_area_tag( "recurring_todo[notes]", @form_helper.notes, {:cols => 29, :rows => 6}) -%> text_area_tag( "recurring_todo[notes]", @form_helper.notes, {:cols => 29, :rows => 6}) -%>
<label for="edit_recurring_todo_project_name"><%= Todo.human_attribute_name('project') %></label> <label for="edit_recurring_todo_project_name"><%= Todo.human_attribute_name('project') %></label>
<input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" size="30" type="text" value="<%= @form_helper.project.nil? ? '' : @form_helper.project.name.gsub(/"/,"&quot;") %>" /> <input id="edit_recurring_todo_project_name" name="project_name" autocomplete="off" size="30" type="text" value="<%= @form_helper.project.nil? ? '' : @form_helper.project.name.gsub(/"/, "&quot;") %>" />
<div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div> <div class="page_name_auto_complete" id="edit_project_list" style="display:none"></div>
<label for="edit_recurring_todo_context_name"><%= Todo.human_attribute_name('context') %></label> <label for="edit_recurring_todo_context_name"><%= Todo.human_attribute_name('context') %></label>

View file

@ -63,7 +63,7 @@
</div> </div>
<%= source_view_tag( @source_view ) %> <%= source_view_tag( @source_view ) %>
<%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %> <%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/, '_') if source_view_is :tag %>
<button type="submit" class="btn btn-success" id="todo_new_action_submit"> <button type="submit" class="btn btn-success" id="todo_new_action_submit">
<%= t('shared.add_action') %> <%= t('shared.add_action') %>

View file

@ -35,7 +35,6 @@ require 'activeresource'
# http://blog.pepperdust.org/2007/2/13/enabling-wire-level-debug-output-for-activeresource # http://blog.pepperdust.org/2007/2/13/enabling-wire-level-debug-output-for-activeresource
module Tracks module Tracks
class Base < ActiveResource::Base class Base < ActiveResource::Base
self.site = ENV["SITE"] || "http://username:password@localhost:3000/" self.site = ENV["SITE"] || "http://username:password@localhost:3000/"
end end
@ -46,15 +45,14 @@ module Tracks
class Context < Base class Context < Base
def todos def todos
return attributes["todos"] if attributes.keys.include?("todos") return attributes["todos"] if attributes.keys.include?("todos")
return Todo.find(:all, :params => {:context_id => id}) return Todo.find(:all, :params => { :context_id => id })
end end
end end
class Project < Base class Project < Base
def todos def todos
return attributes["todos"] if attributes.keys.include?("todos") return attributes["todos"] if attributes.keys.include?("todos")
return Todo.find(:all, :params => {:project_id => id}) return Todo.find(:all, :params => { :project_id => id })
end end
end end
end end

View file

@ -2,16 +2,16 @@ require 'net/https'
require File.expand_path(File.dirname(__FILE__) + '/tracks_xml_builder') require File.expand_path(File.dirname(__FILE__) + '/tracks_xml_builder')
module TracksCli module TracksCli
class TracksAPI class TracksAPI
def initialize(options) def initialize(options)
@options = options @options = options
end end
def get_http(uri) def get_http(uri)
http = Net::HTTP.new(uri.host, uri.port) 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.use_ssl = true
http.ca_path = "/etc/ssl/certs/" # Debian based path http.ca_path = "/etc/ssl/certs/" # Debian based path
http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.verify_mode = OpenSSL::SSL::VERIFY_PEER
@ -57,7 +57,5 @@ module TracksCli
def get_context(context_id) def get_context(context_id)
get(context_uri_for(context_id)) get(context_uri_for(context_id))
end end
end end
end end

View file

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

View file

@ -132,7 +132,7 @@ class TemplateParser
line = replace_tokens_in line line = replace_tokens_in line
# line is either todo/dependency or project # line is either todo/dependency or project
if (line[0].chr == "." ) || (line[0].chr == "^") if (line[0].chr == ".") || (line[0].chr == "^")
if @last_project_id.nil? if @last_project_id.nil?
puts "Warning: no project specified for task \"#{line}\". Using default project." puts "Warning: no project specified for task \"#{line}\". Using default project."
end end
@ -153,7 +153,8 @@ class TemplatePoster
password: ENV['GTD_PASSWORD'], password: ENV['GTD_PASSWORD'],
projects_uri: ENV['GTD_PROJECTS_URL'] || 'http://localhost:3000/projects.xml', projects_uri: ENV['GTD_PROJECTS_URL'] || 'http://localhost:3000/projects.xml',
contexts_uri: ENV['GTD_CONTEXT_URL'] || 'http://localhost:3000/contexts.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 @context_id = options[:context_id] ? options[:context_id].to_i : 1
@project_id = options[:project_id] ? options[:project_id].to_i : 1 @project_id = options[:project_id] ? options[:project_id].to_i : 1
end end
@ -265,7 +266,7 @@ class ConsoleOptionsForTemplate
@parser.parse!(args) @parser.parse!(args)
@poster = TemplatePoster.new(@options) @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" puts "ERROR: file #{@filename} doesn't exist"
exit 1 exit 1
end end

View file

@ -4,23 +4,23 @@ class DoneTodos
return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos) return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
end end
def self.done_today(todos, includes={ :include => Todo::DEFAULT_INCLUDES }) def self.done_today(todos, includes = { :include => Todo::DEFAULT_INCLUDES })
# TODO: refactor to remove outer hash from includes param # TODO: refactor to remove outer hash from includes param
todos.completed_after(beginning_of_day).includes(includes[:include]) todos.completed_after(beginning_of_day).includes(includes[:include])
end end
def self.done_rest_of_week(todos, includes={ :include => Todo::DEFAULT_INCLUDES }) def self.done_rest_of_week(todos, includes = { :include => Todo::DEFAULT_INCLUDES })
done_between(todos, includes, beginning_of_day, beginning_of_week) done_between(todos, includes, beginning_of_day, beginning_of_week)
end end
def self.done_rest_of_month(todos, includes={ :include => Todo::DEFAULT_INCLUDES }) def self.done_rest_of_month(todos, includes = { :include => Todo::DEFAULT_INCLUDES })
done_between(todos, includes, beginning_of_week, beginning_of_month) done_between(todos, includes, beginning_of_week, beginning_of_month)
end end
def self.completed_period(date) def self.completed_period(date)
return nil if date.nil? 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 "today" if date.between?(beginning_of_day, end_of_day)
return "rest_of_week" if date >= beginning_of_week return "rest_of_week" if date >= beginning_of_week
return "rest_of_month" if date >= beginning_of_month return "rest_of_month" if date >= beginning_of_month
@ -28,7 +28,7 @@ class DoneTodos
end end
def self.remaining_in_container(todos, period) 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 nil if period.nil?
return count return count
end end

View file

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

View file

@ -12,7 +12,7 @@ module LoginSystem
# Logout the {#current_user} and redirect to login page # Logout the {#current_user} and redirect to login page
# #
# @param [String] message notification to display # @param [String] message notification to display
def logout_user(message=t('login.logged_out')) def logout_user(message = t('login.logged_out'))
@user.forget_me if logged_in? @user.forget_me if logged_in?
cookies.delete :auth_token cookies.delete :auth_token
session['user_id'] = nil session['user_id'] = nil
@ -64,7 +64,7 @@ module LoginSystem
session['user_id'] = user.id session['user_id'] = user.id
set_current_user(user) set_current_user(user)
current_user.remember_me current_user.remember_me
cookies[:auth_token] = { :value => current_user.remember_token , :expires => current_user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] } cookies[:auth_token] = { :value => current_user.remember_token, :expires => current_user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
flash[:notice] = t('login.successful') flash[:notice] = t('login.successful')
end end
end end
@ -72,7 +72,7 @@ module LoginSystem
def login_or_feed_token_required def login_or_feed_token_required
if ['rss', 'atom', 'txt', 'ics', 'xml'].include?(params[:format]) if ['rss', 'atom', 'txt', 'ics', 'xml'].include?(params[:format])
# Login based on the token GET parameter # 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) set_current_user(user)
return true return true
end end
@ -209,8 +209,8 @@ module LoginSystem
end end
def basic_auth_denied def basic_auth_denied
response.headers["WWW-Authenticate"] = "Basic realm=\"'Tracks Login Required'\"" response.headers["WWW-Authenticate"] = "Basic realm=\"'Tracks Login Required'\""
render :body => t('login.unsuccessful'), :status => 401 render :body => t('login.unsuccessful'), :status => 401
end end
private private

View file

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

View file

@ -1,7 +1,7 @@
module Tracks module Tracks
class Config class Config
def self.auth_schemes def self.auth_schemes
SITE_CONFIG['authentication_schemes'] || [] SITE_CONFIG['authentication_schemes'] || []
end end
def self.openid_enabled? def self.openid_enabled?

View file

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