Coding style fixes

This commit is contained in:
Jyri-Petteri Paloposki 2020-10-27 19:35:01 +02:00
parent 4fe600a916
commit 371f8d5adf
14 changed files with 132 additions and 179 deletions

View file

@ -24,8 +24,8 @@ class ApplicationController < ActionController::Base
def set_locale
locale = params[:locale] # specifying a locale in the request takes precedence
locale = locale || prefs.locale unless current_user.nil? # otherwise, the locale of the currently logged in user takes over
locale = locale || request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first if request.env['HTTP_ACCEPT_LANGUAGE']
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)
I18n.locale = locale
@ -43,13 +43,14 @@ class ApplicationController < ActionController::Base
# Get expiry time (allow ten seconds window for the case where we have
# none)
expiry_time = session['expiry_time'] || Time.now + 10
if expiry_time < Time.now
now = Time.zone.now
expiry_time = session['expiry_time'] || now + 10
if expiry_time < now
# Too late, matey... bang goes your session!
reset_session
else
# Okay, you get another hour
session['expiry_time'] = Time.now + (60*60)
session['expiry_time'] = now + (60*60)
end
end
@ -109,7 +110,7 @@ class ApplicationController < ActionController::Base
end
def format_dependencies_as_json_for_auto_complete(entries)
json_elems = Array[*entries.map{ |e| { :value => e.id.to_s, :label => e.specification } }].to_json
json_elems = Array[*entries.map { |e| { :value => e.id.to_s, :label => e.specification } }].to_json
return json_elems
end

View file

@ -13,15 +13,9 @@ class CalendarController < ApplicationController
respond_to do |format|
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.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 })] ) }
end
end
end

View file

@ -40,7 +40,7 @@ class ContextsController < ApplicationController
@max_completed = current_user.prefs.show_number_completed
@done = @context.todos.completed.limit(@max_completed).reorder(Arel.sql("todos.completed_at DESC, todos.created_at DESC")).includes(Todo::DEFAULT_INCLUDES)
@not_done_todos = @context.todos.active_or_hidden.not_project_hidden.reorder(Arel.sql('todos.due IS NULL, todos.due ASC, todos.created_at ASC')).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? }
@deferred_todos = @context.todos.deferred.includes(Todo::DEFAULT_INCLUDES)
@pending_todos = @context.todos.pending.includes(Todo::DEFAULT_INCLUDES)
@ -110,13 +110,13 @@ class ContextsController < ApplicationController
respond_to do |format|
format.js
format.xml {
format.xml do
if @saved
render :xml => @context.to_xml(:except => :user_id)
else
render :body => "Error on update: #{@context.errors.full_messages.inject("") { |v, e| v + e + " " }}", :status => 409
end
}
end
end
end
@ -202,17 +202,17 @@ class ContextsController < ApplicationController
@active_contexts = current_user.contexts.active
@hidden_contexts = current_user.contexts.hidden
@down_count = @active_contexts.size + @hidden_contexts.size
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
render
end
end
def render_context_mobile
lambda do
@page_title = "TRACKS::List actions in "+@context.name
@not_done = @not_done_todos.select {|t| t.context_id == @context.id }
@page_title = "TRACKS::List actions in " + @context.name
@not_done = @not_done_todos.select { |t| t.context_id == @context.id }
@down_count = @not_done.size
cookies[:mobile_url]= { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
@mobile_from_context = @context.id
render
end

View file

@ -34,7 +34,7 @@ class ProjectsController < ApplicationController
format.m do
@completed_projects = current_user.projects.completed
@down_count = @active_projects.size + @hidden_projects.size + @completed_projects.size
cookies[:mobile_url]= {:value => request.fullpath, :secure => SITE_CONFIG['secure_cookies']}
cookies[:mobile_url] = { :value => request.fullpath, :secure => SITE_CONFIG['secure_cookies'] }
end
format.xml { render :xml => @projects.to_xml(:root => :projects, :except => :user_id) }
format.any(:rss, :atom) do
@ -43,7 +43,7 @@ class ProjectsController < ApplicationController
end
format.text do
# somehow passing Mime[:text] using content_type to render does not work
headers['Content-Type']=Mime[:text].to_s
headers['Content-Type'] = Mime[:text].to_s
end
format.autocomplete do
projects = current_user.projects.active + current_user.projects.hidden
@ -60,7 +60,7 @@ class ProjectsController < ApplicationController
@projects_to_review = projects.select { |p| p.needs_review?(current_user) }
@stalled_projects = projects.select { |p| p.stalled? }
@blocked_projects = projects.select { |p| p.blocked? }
@current_projects = projects.uncompleted.select { |p| not (p.needs_review?(current_user)) }.sort_by { |p| p.last_reviewed || Time.zone.at(0) }
@current_projects = projects.uncompleted.select { |p| not p.needs_review?(current_user) }.sort_by { |p| p.last_reviewed || Time.zone.at(0) }
init_not_done_counts(['project'])
init_hidden_todo_counts(['project'])
@ -112,11 +112,11 @@ class ProjectsController < ApplicationController
def projects_and_actions
@projects = current_user.projects.active
respond_to do |format|
format.text {
format.text do
# somehow passing Mime[:text] using content_type to render does not work
headers['Content-Type'] = Mime[:text].to_s
render :action => 'index_text_projects_and_actions', :layout => false, :content_type => Mime[:text]
}
end
end
end
@ -246,15 +246,14 @@ class ProjectsController < ApplicationController
respond_to do |format|
format.js { render :template => template }
format.html { redirect_to :action => 'index'}
format.xml {
format.xml do
if @saved
render :xml => @project.to_xml( :except => :user_id )
render :xml => @project.to_xml(:except => :user_id)
else
render :body => "Error on update: #{@project.errors.full_messages.inject("") { |v, e| v + e + " " }}", :status => 409
end
}
end
end
end
def edit
@ -268,10 +267,10 @@ class ProjectsController < ApplicationController
@project.destroy
respond_to do |format|
format.js {
format.js do
@down_count = current_user.projects.size
update_state_counts
}
end
format.xml { render :body => "Deleted project #{@project.name}" }
end
end

View file

@ -703,7 +703,7 @@ class TodosController < ApplicationController
def tags
tags_beginning = current_user.tags.where(Tag.arel_table[:name].matches("#{params[:term]}%"))
tags_all = current_user.tags.where(Tag.arel_table[:name].matches("%#{params[:term]}%"))
tags_all = tags_all - tags_beginning
tags_all -= tags_beginning
respond_to do |format|
format.autocomplete { render :body => for_autocomplete(tags_beginning+tags_all, params[:term]) }
@ -731,30 +731,26 @@ class TodosController < ApplicationController
determine_down_count
determine_remaining_in_container_count(@todo)
source_view do |page|
page.project {
page.project do
@remaining_undone_in_project = current_user.projects.find(@todo.project_id).todos.not_completed.count
}
page.tag {
determine_deferred_tag_count(params['_tag_name'])
}
end
page.tag { determine_deferred_tag_count(params['_tag_name']) }
end
respond_to do |format|
format.html { redirect_to :back }
format.js { render :action => 'update' }
format.m {
format.m do
notify(:notice, t("todos.action_deferred", :description => @todo.description))
do_mobile_todo_redirection
}
end
end
end
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
@ -801,12 +797,8 @@ class TodosController < ApplicationController
@todo = current_user.todos.find(params['id'])
@return_path = cookies[:mobile_url] ? cookies[:mobile_url] : mobile_path
respond_to do |format|
format.html {
redirect_to home_path, "Viewing note of todo is not implemented"
}
format.m {
render :action => "show_notes"
}
format.html { redirect_to home_path, "Viewing note of todo is not implemented" }
format.m { render :action => "show_notes" }
end
end
@ -866,9 +858,9 @@ class TodosController < ApplicationController
# Additional tag condition(s) handled as AND.
@tag_expr << params[:and].split(',') if params[:and]
i = 1
while params['and'+i.to_s]
@tag_expr << params['and'+i.to_s].split(',')
i=i+1
while params['and' + i.to_s]
@tag_expr << params['and' + i.to_s].split(',')
i += 1
end
@single_tag = @tag_expr.size == 1 && @tag_expr[0].size == 1
@ -986,17 +978,17 @@ end
def determine_remaining_in_container_count(todo = @todo)
source_view do |from|
from.deferred {
from.deferred do
todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo)
@remaining_in_context = todos_in_container.deferred_or_blocked.count
@target_context_count = todos_in_target_container.deferred_or_blocked.count
}
from.todo {
end
from.todo do
todos_in_container, todos_in_target_container = find_todos_in_container_and_target_container(todo, @todo)
@remaining_in_context = todos_in_container.active.not_hidden.count
@target_context_count = todos_in_target_container.active.not_hidden.count
}
from.tag {
end
from.tag do
tag = Tag.where(:name => params['_tag_name']).first
tag = Tag.new(:name => params['tag']) if tag.nil?
@ -1006,8 +998,8 @@ end
@target_context_count = todos_in_target_container.active.not_hidden.with_tag(tag.id).count
@remaining_hidden_count = current_user.todos.hidden.with_tag(tag.id).count
@remaining_deferred_or_pending_count = current_user.todos.with_tag(tag.id).deferred_or_blocked.count
}
from.project {
end
from.project do
project_id = @project_changed ? @original_item.project_id : @todo.project_id
@remaining_deferred_or_pending_count = current_user.projects.find(project_id).todos.deferred_or_blocked.count
@ -1018,11 +1010,11 @@ end
end
@target_context_count = current_user.projects.find(project_id).todos.active.count
}
from.calendar {
end
from.calendar do
@target_context_count = @new_due_id.blank? ? 0 : count_old_due_empty(@new_due_id)
}
from.context {
end
from.context do
context = current_user.contexts.find(todo.context_id)
@remaining_deferred_or_pending_count = context.todos.deferred_or_blocked.count
@ -1037,13 +1029,11 @@ end
actions_in_target = @todo.context.todos.deferred_or_blocked
end
@target_context_count = actions_in_target.count
}
from.done {
end
from.done do
@remaining_in_context = DoneTodos.remaining_in_container(current_user.todos, @original_completed_period)
}
from.all_done {
@remaining_in_context = current_user.todos.completed.count
}
end
from.all_done { @remaining_in_context = current_user.todos.completed.count }
end
end

View file

@ -97,7 +97,7 @@ class UsersController < ApplicationController
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)

View file

@ -3,12 +3,12 @@ class RichMessageExtractor
include ActionView::Helpers::SanitizeHelper
extend ActionView::Helpers::SanitizeHelper::ClassMethods
PROJECT_MARKER = '~'
CONTEXT_MARKER = '@'
TICKLER_MARKER = '>'
DUE_MARKER = '<'
TAG_MARKER = '#'
STAR_MARKER = '*'
PROJECT_MARKER = '~'.freeze
CONTEXT_MARKER = '@'.freeze
TICKLER_MARKER = '>'.freeze
DUE_MARKER = '<'.freeze
TAG_MARKER = '#'.freeze
STAR_MARKER = '*'.freeze
ALL_MARKERS = [
PROJECT_MARKER,