mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-07 09:48:50 +01:00
More code style fixes
This commit is contained in:
parent
465419f46a
commit
d4c9041ccd
61 changed files with 406 additions and 422 deletions
|
|
@ -10,7 +10,7 @@ class ApplicationController < ActionController::Base
|
|||
include Common
|
||||
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$/
|
||||
|
||||
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 ||= request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first if request.env['HTTP_ACCEPT_LANGUAGE']
|
||||
|
||||
if locale && I18n::available_locales.map(&:to_s).include?(locale.to_s)
|
||||
if locale && I18n.available_locales.map(&:to_s).include?(locale.to_s)
|
||||
I18n.locale = locale
|
||||
else
|
||||
I18n.locale = I18n.default_locale
|
||||
|
|
@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base
|
|||
# If the method is called by the feed controller (which we don't have
|
||||
# under session control) or if we checked the box to keep logged in on
|
||||
# login don't set the session expiry time.
|
||||
return if session.nil? || self.controller_name == 'feed' || session['noexpiry'] == "on"
|
||||
return if session.nil? || controller_name == 'feed' || session['noexpiry'] == "on"
|
||||
|
||||
# Get expiry time (allow ten seconds window for the case where we have
|
||||
# none)
|
||||
|
|
@ -50,11 +50,11 @@ class ApplicationController < ActionController::Base
|
|||
reset_session
|
||||
else
|
||||
# Okay, you get another hour
|
||||
session['expiry_time'] = now + (60*60)
|
||||
session['expiry_time'] = now + (60 * 60)
|
||||
end
|
||||
end
|
||||
|
||||
def render_failure message, status = 404
|
||||
def render_failure(message, status = 404)
|
||||
render :body => message, :status => status
|
||||
end
|
||||
|
||||
|
|
@ -101,8 +101,8 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def for_autocomplete(coll, substr)
|
||||
if substr # protect agains empty request
|
||||
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
|
||||
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
|
||||
return json_elems
|
||||
else
|
||||
return ""
|
||||
|
|
@ -272,7 +272,7 @@ class ApplicationController < ActionController::Base
|
|||
def done_todos_for(object)
|
||||
object_name = object.class.name.downcase # context or project
|
||||
@source_view = "done"
|
||||
eval("@#{object_name} = object")
|
||||
eval("@#{object_name} = object", binding, __FILE__, __LINE__)
|
||||
@page_title = t("#{object_name.pluralize}.completed_tasks_title", "#{object_name}_name".to_sym => object.name)
|
||||
|
||||
@done_today, @done_rest_of_week, @done_rest_of_month = DoneTodos.done_todos_for_container(object.todos)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class CalendarController < ApplicationController
|
|||
format.html
|
||||
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.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
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class ContextsController < ApplicationController
|
|||
@context.attributes = context_params
|
||||
@saved = @context.save
|
||||
@state_saved = set_state_for_update(@new_state)
|
||||
@saved = @saved && @state_saved
|
||||
@saved &&= @state_saved
|
||||
|
||||
if @saved
|
||||
@state_changed = (@original_context_state != @context.state)
|
||||
|
|
@ -148,7 +148,7 @@ class ContextsController < ApplicationController
|
|||
#
|
||||
def order
|
||||
context_ids = params["container_context"]
|
||||
@projects = current_user.contexts.update_positions( context_ids )
|
||||
@projects = current_user.contexts.update_positions(context_ids)
|
||||
head :ok
|
||||
rescue
|
||||
notify :error, $!
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ class DataController < ApplicationController
|
|||
@page_title = "TRACKS::Export"
|
||||
end
|
||||
|
||||
def import
|
||||
end
|
||||
def import; end
|
||||
|
||||
def csv_map
|
||||
if params[:file].blank?
|
||||
|
|
@ -16,17 +15,17 @@ class DataController < ApplicationController
|
|||
@import_to = params[:import_to]
|
||||
|
||||
begin
|
||||
#get column headers and format as [['name', column_number]...]
|
||||
# Get column headers and format as [['name', column_number]...]
|
||||
i = -1
|
||||
@headers = import_headers(params[:file].path).collect { |v| [v, i+=1] }
|
||||
@headers.unshift ['',i]
|
||||
@headers = import_headers(params[:file].path).collect { |v| [v, i += 1] }
|
||||
@headers.unshift ['', i]
|
||||
rescue Exception => e
|
||||
flash[:error] = "Invalid CVS: could not read headers: #{e}"
|
||||
redirect_to :back
|
||||
return
|
||||
end
|
||||
|
||||
#save file for later
|
||||
# Save file for later
|
||||
begin
|
||||
uploaded_file = params[:file]
|
||||
@filename = sanitize_filename(uploaded_file.original_filename)
|
||||
|
|
@ -94,17 +93,17 @@ class DataController < ApplicationController
|
|||
all_tables['projects'] = current_user.projects.load
|
||||
|
||||
todo_tag_ids = Tag.find_by_sql([
|
||||
"SELECT DISTINCT tags.id "+
|
||||
"FROM tags, taggings, todos "+
|
||||
"WHERE todos.user_id=? "+
|
||||
"AND tags.id = taggings.tag_id " +
|
||||
"AND taggings.taggable_id = todos.id ", current_user.id])
|
||||
"SELECT DISTINCT tags.id
|
||||
FROM tags, taggings, todos
|
||||
WHERE todos.user_id = ?
|
||||
AND tags.id = taggings.tag_id
|
||||
AND taggings.taggable_id = todos.id", current_user.id])
|
||||
rec_todo_tag_ids = Tag.find_by_sql([
|
||||
"SELECT DISTINCT tags.id "+
|
||||
"FROM tags, taggings, recurring_todos "+
|
||||
"WHERE recurring_todos.user_id=? "+
|
||||
"AND tags.id = taggings.tag_id " +
|
||||
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
|
||||
"SELECT DISTINCT tags.id
|
||||
FROM tags, taggings, recurring_todos
|
||||
WHERE recurring_todos.user_id = ?
|
||||
AND tags.id = taggings.tag_id
|
||||
AND taggings.taggable_id = recurring_todos.id", current_user.id])
|
||||
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
|
||||
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
|
||||
|
||||
|
|
@ -114,7 +113,8 @@ class DataController < ApplicationController
|
|||
all_tables['recurring_todos'] = current_user.recurring_todos.load
|
||||
|
||||
result = all_tables.to_yaml
|
||||
result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings
|
||||
# TODO: general functionality for line endings
|
||||
result.gsub!(/\n/, "\r\n")
|
||||
send_data(result, :filename => "tracks_backup.yml", :type => 'text/plain')
|
||||
end
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ class DataController < ApplicationController
|
|||
csv << [todo.id, todo.context.name,
|
||||
todo.project_id.nil? ? "" : todo.project.name,
|
||||
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.due? ? todo.due.to_formatted_s(:db) : "",
|
||||
todo.completed_at? ? todo.completed_at.to_formatted_s(:db) : "",
|
||||
|
|
@ -163,17 +163,17 @@ class DataController < ApplicationController
|
|||
|
||||
def xml_export
|
||||
todo_tag_ids = Tag.find_by_sql([
|
||||
"SELECT DISTINCT tags.id "+
|
||||
"FROM tags, taggings, todos "+
|
||||
"WHERE todos.user_id=? "+
|
||||
"AND tags.id = taggings.tag_id " +
|
||||
"AND taggings.taggable_id = todos.id ", current_user.id])
|
||||
"SELECT DISTINCT tags.id
|
||||
FROM tags, taggings, todos
|
||||
WHERE todos.user_id = ?
|
||||
AND tags.id = taggings.tag_id
|
||||
AND taggings.taggable_id = todos.id", current_user.id])
|
||||
rec_todo_tag_ids = Tag.find_by_sql([
|
||||
"SELECT DISTINCT tags.id "+
|
||||
"FROM tags, taggings, recurring_todos "+
|
||||
"WHERE recurring_todos.user_id=? "+
|
||||
"AND tags.id = taggings.tag_id " +
|
||||
"AND taggings.taggable_id = recurring_todos.id ", current_user.id])
|
||||
"SELECT DISTINCT tags.id
|
||||
FROM tags, taggings, recurring_todos
|
||||
WHERE recurring_todos.user_id = ?
|
||||
AND tags.id = taggings.tag_id
|
||||
AND taggings.taggable_id = recurring_todos.id", current_user.id])
|
||||
tags = Tag.where("id IN (?) OR id IN (?)", todo_tag_ids, rec_todo_tag_ids)
|
||||
taggings = Tagging.where("tag_id IN (?) OR tag_id IN(?)", todo_tag_ids, rec_todo_tag_ids)
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ class DataController < ApplicationController
|
|||
|
||||
# adjusts time to utc
|
||||
def adjust_time(timestring)
|
||||
if (timestring == '') or (timestring == nil)
|
||||
if (timestring == '') || (timestring == nil)
|
||||
return nil
|
||||
else
|
||||
return Time.parse(timestring + 'UTC')
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ class IntegrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def search_plugin
|
||||
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read].
|
||||
pack('m').gsub(/\n/, '')
|
||||
@icon_data = [File.open(File.join(Rails.root, 'app', 'assets', 'images', 'done.png')).read]
|
||||
.pack('m').gsub(/\n/, '')
|
||||
end
|
||||
|
||||
def cloudmailin
|
||||
|
|
@ -37,18 +37,18 @@ class IntegrationsController < ApplicationController
|
|||
private
|
||||
|
||||
def process_message(message)
|
||||
MessageGateway::receive(Mail.new(message))
|
||||
MessageGateway.receive(Mail.new(message))
|
||||
end
|
||||
|
||||
def verify_cloudmailin_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
|
||||
end
|
||||
|
||||
def flatten_params(params, title = nil, result = {})
|
||||
params.each do |key, value|
|
||||
if value.kind_of?(Hash)
|
||||
if value.is_a? Hash
|
||||
key_name = title ? "#{title}[#{key}]" : key
|
||||
flatten_params(value, key_name, result)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class LoginController < ApplicationController
|
|||
cookies[:preferred_auth] = prefered_auth? unless cookies[:preferred_auth]
|
||||
case request.method
|
||||
when 'POST'
|
||||
if @user = User.authenticate(params['user_login'], params['user_password'])
|
||||
@user.update_attribute(:last_login_at, Time.now)
|
||||
if (@user = User.authenticate(params['user_login'], params['user_password']))
|
||||
@user.update_attribute(:last_login_at, Time.zone.now)
|
||||
return handle_post_success
|
||||
else
|
||||
handle_post_failure
|
||||
|
|
@ -43,8 +43,8 @@ class LoginController < ApplicationController
|
|||
if session
|
||||
return unless should_expire_sessions?
|
||||
# Get expiry time (allow ten seconds window for the case where we have none)
|
||||
time_left = expiry_time - Time.now
|
||||
@session_expired = ( time_left < (10 * 60) ) # Session will time out before the next check
|
||||
time_left = expiry_time - Time.zone.now
|
||||
@session_expired = (time_left < (10 * 60)) # Session will time out before the next check
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
|
|
@ -61,10 +61,10 @@ class LoginController < ApplicationController
|
|||
session['noexpiry'] = params['user_noexpiry']
|
||||
msg = (should_expire_sessions?) ? "will expire after 1 hour of inactivity." : "will not expire."
|
||||
notify :notice, "Login successful: session #{msg}"
|
||||
cookies[:tracks_login] = { :value => @user.login, :expires => Time.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
cookies[:tracks_login] = { :value => @user.login, :expires => Time.zone.now + 1.year, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
unless should_expire_sessions?
|
||||
@user.remember_me
|
||||
cookies[:auth_token] = { :value => @user.remember_token , :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
cookies[:auth_token] = { :value => @user.remember_token, :expires => @user.remember_token_expires_at, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
end
|
||||
redirect_back_or_home
|
||||
end
|
||||
|
|
@ -79,7 +79,7 @@ class LoginController < ApplicationController
|
|||
end
|
||||
|
||||
def expiry_time
|
||||
return Time.now + 10 unless session['expiry_time']
|
||||
return Time.zone.now + 10 unless session['expiry_time']
|
||||
DateTime.strptime(session['expiry_time'], "%FT%T.%L%Z")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class MailgunController < ApplicationController
|
|||
|
||||
todo = MessageGateway.receive(params['body-mime'])
|
||||
if todo
|
||||
render :xml => todo.to_xml( *todo_xml_params )
|
||||
render :xml => todo.to_xml(*todo_xml_params)
|
||||
else
|
||||
render_failure "Todo not saved", 406
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class NotesController < ApplicationController
|
|||
@source_view = 'note_list'
|
||||
respond_to do |format|
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class ProjectsController < ApplicationController
|
|||
else
|
||||
@project_default_context = t('projects.default_context', :context => @project.default_context.name)
|
||||
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
|
||||
end
|
||||
format.xml do
|
||||
|
|
@ -245,7 +245,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.js { render :template => template }
|
||||
format.html { redirect_to :action => 'index'}
|
||||
format.html { redirect_to :action => 'index' }
|
||||
format.xml do
|
||||
if @saved
|
||||
render :xml => @project.to_xml(:except => :user_id)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ module RecurringTodos
|
|||
def method_missing(method, *args)
|
||||
# delegate daily_xxx to daily_pattern, weekly_xxx to weekly_pattern, etc.
|
||||
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
|
||||
|
||||
# no match, let @recurring_todo handle it, or fail
|
||||
|
|
|
|||
|
|
@ -18,11 +18,9 @@ class RecurringTodosController < ApplicationController
|
|||
@new_recurring_todo = RecurringTodo.new
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
def new; end
|
||||
|
||||
def show
|
||||
end
|
||||
def show; end
|
||||
|
||||
def done
|
||||
@source_view = params['_source_view'] || 'recurring_todo'
|
||||
|
|
@ -171,7 +169,7 @@ class RecurringTodosController < ApplicationController
|
|||
context_name: :context_name,
|
||||
project_name: :project_name,
|
||||
tag_list: :tag_list
|
||||
}.each do |target,source|
|
||||
}.each do |target, source|
|
||||
move_into_recurring_todo_param(params, target, source)
|
||||
end
|
||||
recurring_todo_params
|
||||
|
|
@ -189,14 +187,14 @@ class RecurringTodosController < ApplicationController
|
|||
tag_list: :edit_recurring_todo_tag_list,
|
||||
end_date: :recurring_todo_edit_end_date,
|
||||
start_from: :recurring_todo_edit_start_from
|
||||
}.each do |target,source|
|
||||
}.each do |target, source|
|
||||
move_into_recurring_todo_param(params, target, source)
|
||||
end
|
||||
|
||||
# make sure that we set weekly_return_xxx to empty (space) when they are
|
||||
# not checked (and thus not present in params["recurring_todo"])
|
||||
%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
|
||||
|
||||
recurring_todo_params
|
||||
|
|
@ -207,9 +205,15 @@ class RecurringTodosController < ApplicationController
|
|||
end
|
||||
|
||||
def init
|
||||
@days_of_week = (0..6).map{|i| [t('date.day_names')[i], i] }
|
||||
@months_of_year = (1..12).map{|i| [t('date.month_names')[i], i] }
|
||||
@xth_day = [[t('common.first'),1],[t('common.second'),2],[t('common.third'),3],[t('common.fourth'),4],[t('common.last'),5]]
|
||||
@days_of_week = (0..6).map { |i| [t('date.day_names')[i], i] }
|
||||
@months_of_year = (1..12).map { |i| [t('date.month_names')[i], i] }
|
||||
@xth_day = [
|
||||
[t('common.first'), 1],
|
||||
[t('common.second'), 2],
|
||||
[t('common.third'), 3],
|
||||
[t('common.fourth'), 4],
|
||||
[t('common.last'),5]
|
||||
]
|
||||
@projects = current_user.projects.includes(:default_context)
|
||||
@contexts = current_user.contexts
|
||||
end
|
||||
|
|
@ -221,10 +225,10 @@ class RecurringTodosController < ApplicationController
|
|||
def find_and_inactivate
|
||||
# find active recurring todos without active todos and inactivate them
|
||||
|
||||
current_user.recurring_todos.active.
|
||||
select("recurring_todos.id, recurring_todos.state").
|
||||
joins("LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')").
|
||||
where("fai_todos.id IS NULL").
|
||||
each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
|
||||
current_user.recurring_todos.active
|
||||
.select("recurring_todos.id, recurring_todos.state")
|
||||
.joins("LEFT JOIN todos fai_todos ON (recurring_todos.id = fai_todos.recurring_todo_id) AND (NOT fai_todos.state='completed')")
|
||||
.where("fai_todos.id IS NULL")
|
||||
.each { |rt| current_user.recurring_todos.find(rt.id).toggle_completion! }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class StatsController < ApplicationController
|
||||
SECONDS_PER_DAY = 86_400;
|
||||
SECONDS_PER_DAY = 86_400
|
||||
|
||||
helper :todos, :projects, :recurring_todos
|
||||
append_before_action :init, :except => :index
|
||||
|
|
@ -23,15 +23,15 @@ class StatsController < ApplicationController
|
|||
# less than the minimum completed_at, so no reason to check minimum completed_at
|
||||
|
||||
# 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_created_last_months_array = put_events_into_month_buckets(actions_last_months, month_count+1, :created_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)
|
||||
|
||||
# find max for graph in both hashes
|
||||
@max = (@actions_done_last_months_array + @actions_created_last_months_array).max
|
||||
|
||||
# set running avg
|
||||
@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_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)
|
||||
|
||||
# interpolate avg for this month.
|
||||
@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
|
||||
|
||||
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')
|
||||
@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_contexts = []
|
||||
@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
|
||||
|
||||
private
|
||||
|
|
@ -135,7 +135,7 @@ class StatsController < ApplicationController
|
|||
@cut_off_30days = 30.days.ago.beginning_of_day
|
||||
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 = []
|
||||
|
||||
actions.each do |r|
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ module Todos
|
|||
elsif params[:todo]
|
||||
@attributes = todo_params(params)
|
||||
end
|
||||
@attributes = {} if @attributes.nil? # make sure there is at least an empty hash
|
||||
# Make sure there is at least an empty hash
|
||||
@attributes = {} if @attributes.nil?
|
||||
end
|
||||
|
||||
def filter_tags
|
||||
|
|
@ -41,7 +42,7 @@ module Todos
|
|||
|
||||
def filter_starred
|
||||
if @params[:new_todo_starred]
|
||||
@attributes["starred"] = (@params[:new_todo_starred]||"").include? "true"
|
||||
@attributes["starred"] = (@params[:new_todo_starred] || "").include? "true"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ module Todos
|
|||
@params['predecessor_list']
|
||||
end
|
||||
|
||||
def parse_dates()
|
||||
def parse_dates
|
||||
@attributes['show_from'] = @user.prefs.parse_date(show_from)
|
||||
@attributes['due'] = @user.prefs.parse_date(due)
|
||||
@attributes['due'] ||= ''
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class TodosController < ApplicationController
|
|||
@page_title = t('todos.task_list_title')
|
||||
# Set count badge to number of not-done, not hidden context items
|
||||
@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
|
||||
format.m do
|
||||
@page_title = t('todos.mobile_todos_page_title')
|
||||
|
|
@ -49,14 +49,14 @@ class TodosController < ApplicationController
|
|||
|
||||
render :action => 'index'.freeze
|
||||
end
|
||||
format.text do
|
||||
format.text do
|
||||
# somehow passing Mime[:text] using content_type to render does not work
|
||||
headers['Content-Type'.freeze] = Mime[:text].to_s
|
||||
render :content_type => Mime[:text]
|
||||
end
|
||||
format.xml do
|
||||
@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
|
||||
format.any(:rss, :atom) do
|
||||
@feed_title = 'Tracks Actions'.freeze
|
||||
|
|
@ -70,7 +70,7 @@ class TodosController < ApplicationController
|
|||
@projects = current_user.projects.active
|
||||
@contexts = current_user.contexts
|
||||
respond_to do |format|
|
||||
format.m {
|
||||
format.m do
|
||||
@new_mobile = true
|
||||
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
||||
@mobile_from_context = current_user.contexts.find(params[:from_context]) if params[:from_context]
|
||||
|
|
@ -79,7 +79,7 @@ class TodosController < ApplicationController
|
|||
# we have a project but not a context -> use the default context
|
||||
@mobile_from_context = @mobile_from_project.default_context
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -174,7 +174,8 @@ class TodosController < ApplicationController
|
|||
|
||||
# first build all todos and check if they would validate on save
|
||||
params[:todo][:multiple_todos].split("\n").map do |line|
|
||||
if line.present? #ignore blank lines
|
||||
# Ignore blank lines
|
||||
if line.present?
|
||||
@todo = current_user.todos.build({ :description => line, :context_id => p.context_id, :project_id => p.project_id })
|
||||
validates &&= @todo.valid?
|
||||
|
||||
|
|
@ -245,12 +246,12 @@ class TodosController < ApplicationController
|
|||
@tag_name = params['_tag_name']
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.m {
|
||||
format.m do
|
||||
@projects = current_user.projects.active
|
||||
@contexts = current_user.contexts
|
||||
@edit_mobile = true
|
||||
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -258,7 +259,7 @@ class TodosController < ApplicationController
|
|||
@todo = current_user.todos.find(params['id'])
|
||||
respond_to do |format|
|
||||
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
|
||||
|
||||
|
|
@ -339,7 +340,7 @@ class TodosController < ApplicationController
|
|||
determine_down_count
|
||||
determine_completed_count
|
||||
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
|
||||
@original_item_due_id = get_due_id_for_calendar(@original_item.due)
|
||||
@old_due_empty = is_old_due_empty(@original_item_due_id)
|
||||
|
|
@ -347,7 +348,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
render
|
||||
end
|
||||
format.xml { render :xml => @todo.to_xml( *todo_xml_params ) }
|
||||
format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
|
||||
format.html do
|
||||
if @saved
|
||||
# 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"
|
||||
else
|
||||
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
|
||||
format.m {
|
||||
format.m do
|
||||
if @saved
|
||||
if cookies[:mobile_url]
|
||||
old_path = cookies[:mobile_url]
|
||||
|
|
@ -372,7 +373,7 @@ class TodosController < ApplicationController
|
|||
else
|
||||
render :action => "edit", :format => :m
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -382,9 +383,9 @@ class TodosController < ApplicationController
|
|||
@saved = true # cannot determine error
|
||||
respond_to do |format|
|
||||
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.m {
|
||||
format.m do
|
||||
if cookies[:mobile_url]
|
||||
old_path = cookies[:mobile_url]
|
||||
cookies[:mobile_url] = { :value => nil, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
|
|
@ -394,7 +395,7 @@ class TodosController < ApplicationController
|
|||
notify(:notice, "Star toggled")
|
||||
onsite_redirect_to todos_path(:format => 'm')
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -413,7 +414,7 @@ class TodosController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
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
|
||||
|
||||
|
|
@ -437,7 +438,7 @@ class TodosController < ApplicationController
|
|||
rescue ActiveRecord::RecordInvalid => exception
|
||||
record = exception.record
|
||||
if record.is_a?(Dependency)
|
||||
record.errors.each { |key,value| @todo.errors[key] << value }
|
||||
record.errors.each { |key, value| @todo.errors[key] << value }
|
||||
end
|
||||
@saved = false
|
||||
end
|
||||
|
|
@ -462,12 +463,12 @@ class TodosController < ApplicationController
|
|||
@todo.touch_predecessors if @original_item.description != @todo.description
|
||||
|
||||
respond_to do |format|
|
||||
format.js {
|
||||
format.js do
|
||||
@status_message = @todo.deferred? ? t('todos.action_saved_to_tickler') : t('todos.action_saved')
|
||||
@status_message = t('todos.added_new_project') + ' / ' + @status_message if @new_project_created
|
||||
@status_message = t('todos.added_new_context') + ' / ' + @status_message if @new_context_created
|
||||
}
|
||||
format.xml { render :xml => @todo.to_xml( *todo_xml_params ) }
|
||||
end
|
||||
format.xml { render :xml => @todo.to_xml(*todo_xml_params) }
|
||||
format.m do
|
||||
if @saved
|
||||
do_mobile_todo_redirection
|
||||
|
|
@ -490,7 +491,8 @@ class TodosController < ApplicationController
|
|||
def destroy
|
||||
@source_view = params['_source_view'] || 'todo'
|
||||
@todo = current_user.todos.find(params['id'])
|
||||
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
|
||||
# Create a (unsaved) copy of the original todo
|
||||
@original_item = current_user.todos.build(@todo.attributes)
|
||||
@context_id = @todo.context_id
|
||||
@project_id = @todo.project_id
|
||||
@todo_was_destroyed = true
|
||||
|
|
@ -558,7 +560,7 @@ class TodosController < ApplicationController
|
|||
format.html
|
||||
format.xml do
|
||||
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
|
||||
|
|
@ -581,7 +583,7 @@ class TodosController < ApplicationController
|
|||
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)
|
||||
@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
|
||||
|
||||
respond_to do |format|
|
||||
|
|
@ -591,7 +593,7 @@ class TodosController < ApplicationController
|
|||
init_data_for_sidebar unless mobile?
|
||||
end
|
||||
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
|
||||
|
||||
|
|
@ -625,23 +627,23 @@ class TodosController < ApplicationController
|
|||
|
||||
todos_with_tag_ids = find_todos_with_tag_expr(@tag_expr)
|
||||
|
||||
@not_done_todos = todos_with_tag_ids.
|
||||
active.not_hidden.
|
||||
reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')).
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
@hidden_todos = todos_with_tag_ids.
|
||||
hidden.
|
||||
reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC')).
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
@deferred_todos = todos_with_tag_ids.
|
||||
deferred.
|
||||
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')).
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
@pending_todos = todos_with_tag_ids.
|
||||
blocked.
|
||||
reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC')).
|
||||
includes(Todo::DEFAULT_INCLUDES)
|
||||
@todos_without_project = @not_done_todos.select{ |t| t.project.nil? }
|
||||
@not_done_todos = todos_with_tag_ids
|
||||
.active.not_hidden
|
||||
.reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC'))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
@hidden_todos = todos_with_tag_ids
|
||||
.hidden
|
||||
.reorder(Arel.sql('todos.completed_at DESC, todos.created_at DESC'))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
@deferred_todos = todos_with_tag_ids
|
||||
.deferred
|
||||
.reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
@pending_todos = todos_with_tag_ids
|
||||
.blocked
|
||||
.reorder(Arel.sql('todos.show_from ASC, todos.created_at DESC'))
|
||||
.includes(Todo::DEFAULT_INCLUDES)
|
||||
@todos_without_project = @not_done_todos.select { |t| t.project.nil? }
|
||||
|
||||
# If you've set no_completed to zero, the completed items box isn't shown on
|
||||
# the tag page
|
||||
|
|
@ -664,12 +666,8 @@ class TodosController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.m {
|
||||
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
|
||||
}
|
||||
format.text {
|
||||
render :action => 'index', :layout => false, :content_type => Mime[:text]
|
||||
}
|
||||
format.m { cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] } }
|
||||
format.text { render :action => 'index', :layout => false, :content_type => Mime[:text] }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -706,7 +704,7 @@ class TodosController < ApplicationController
|
|||
tags_all -= tags_beginning
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -715,7 +713,8 @@ class TodosController < ApplicationController
|
|||
numdays = params['days'].to_i
|
||||
|
||||
@todo = current_user.todos.find(params[:id])
|
||||
@original_item = current_user.todos.build(@todo.attributes) # create a (unsaved) copy of the original todo
|
||||
# Create a (unsaved) copy of the original todo
|
||||
@original_item = current_user.todos.build(@todo.attributes)
|
||||
|
||||
@todo_deferred_state_changed = true
|
||||
@new_context_created = false
|
||||
|
|
@ -750,7 +749,7 @@ class TodosController < ApplicationController
|
|||
def list_hidden
|
||||
@hidden = current_user.todos.hidden
|
||||
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
|
||||
|
||||
|
|
@ -843,7 +842,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
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 ')
|
||||
end
|
||||
|
||||
|
|
@ -905,7 +904,7 @@ end
|
|||
end
|
||||
|
||||
def find_todos_with_tag_expr(tag_expr)
|
||||
# optimize for the common case: selecting only one tag
|
||||
# Optimize for the common case of selecting only one tag
|
||||
if @single_tag
|
||||
tag = current_user.tags.where(:name => @tag_name).first
|
||||
tag_id = tag.nil? ? -1 : tag.id
|
||||
|
|
@ -1184,7 +1183,8 @@ end
|
|||
def update_tags
|
||||
if params[:tag_list]
|
||||
@todo.tag_with(params[:tag_list])
|
||||
@todo.tags.reload #force a reload for proper rendering
|
||||
# Force a reload for proper rendering
|
||||
@todo.tags.reload
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1197,7 +1197,7 @@ end
|
|||
end
|
||||
|
||||
def update_date_for_update(key)
|
||||
params['todo'][key] = params["todo"].has_key?(key) ? parse_date_for_update(params["todo"][key], t("todos.error.invalid_#{key}_date")) : ""
|
||||
params['todo'][key] = params["todo"].key?(key) ? parse_date_for_update(params["todo"][key], t("todos.error.invalid_#{key}_date")) : ""
|
||||
end
|
||||
|
||||
def update_due_and_show_from_dates
|
||||
|
|
@ -1225,7 +1225,7 @@ end
|
|||
# assumes @todo.save was called so that the predecessor_list is persistent
|
||||
original_item_predecessor_list =
|
||||
@original_item.predecessors
|
||||
.map{ |t| t.specification }
|
||||
.map { |t| t.specification }
|
||||
.join(', ')
|
||||
|
||||
if original_item_predecessor_list != params[:predecessor_list]
|
||||
|
|
|
|||
|
|
@ -92,12 +92,12 @@ class UsersController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
signup_by_admin = true if (@user && @user.is_admin?)
|
||||
signup_by_admin = true if @user && @user.is_admin?
|
||||
first_user_signing_up = User.no_users_yet?
|
||||
user.is_admin = true if first_user_signing_up
|
||||
if user.save
|
||||
@user = User.authenticate(user.login, params['user']['password'])
|
||||
@user.create_preference({ :locale => I18n.locale })
|
||||
@user.create_preference(:locale => I18n.locale)
|
||||
@user.save
|
||||
session['user_id'] = @user.id unless signup_by_admin
|
||||
notify :notice, t('users.signup_successful', :username => @user.login)
|
||||
|
|
@ -219,10 +219,10 @@ class UsersController < ApplicationController
|
|||
end
|
||||
|
||||
def check_create_user_params
|
||||
return false unless params.has_key?(:user)
|
||||
return false unless params[:user].has_key?(:login)
|
||||
return false unless params.key?(:user)
|
||||
return false unless params[:user].key?(:login)
|
||||
return false if params[:user][:login].empty?
|
||||
return false unless params[:user].has_key?(:password)
|
||||
return false unless params[:user].key?(:password)
|
||||
return false if params[:user][:password].empty?
|
||||
return true
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue