mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Introduce current_user and prefs accessors that replace the @user and @prefs variables that were being used in most places.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@575 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
ad5fbc7147
commit
30c23fc560
18 changed files with 233 additions and 207 deletions
|
|
@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
helper :application
|
||||
include LoginSystem
|
||||
helper_method :current_user, :prefs
|
||||
|
||||
layout proc{ |controller| controller.mobile? ? "mobile" : "standard" }
|
||||
|
||||
|
|
@ -94,12 +95,12 @@ class ApplicationController < ActionController::Base
|
|||
count || 0
|
||||
end
|
||||
|
||||
# Convert a date object to the format specified
|
||||
# Convert a date object to the format specified in the user's preferences
|
||||
# in config/settings.yml
|
||||
#
|
||||
def format_date(date)
|
||||
if date
|
||||
date_format = @user.prefs.date_format
|
||||
date_format = prefs.date_format
|
||||
formatted_date = date.strftime("#{date_format}")
|
||||
else
|
||||
formatted_date = ''
|
||||
|
|
@ -178,27 +179,27 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def parse_date_per_user_prefs( s )
|
||||
return nil if s.blank?
|
||||
Date.strptime(s, @user.prefs.date_format)
|
||||
Date.strptime(s, prefs.date_format)
|
||||
end
|
||||
|
||||
def init_data_for_sidebar
|
||||
@projects = @projects || @user.projects
|
||||
@contexts = @contexts || @user.contexts
|
||||
@projects = @projects || current_user.projects
|
||||
@contexts = @contexts || current_user.contexts
|
||||
init_not_done_counts
|
||||
if @prefs.show_hidden_projects_in_sidebar
|
||||
if prefs.show_hidden_projects_in_sidebar
|
||||
init_project_hidden_todo_counts(['project'])
|
||||
end
|
||||
end
|
||||
|
||||
def init_not_done_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'active'], :group => :#{parent}_id)")
|
||||
eval("@#{parent}_not_done_counts = @#{parent}_not_done_counts || Todo.count(:conditions => ['user_id = ? and state = ?', current_user.id, 'active'], :group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
def init_project_hidden_todo_counts(parents = ['project','context'])
|
||||
parents.each do |parent|
|
||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and state = ?', @user.id, 'project_hidden'], :group => :#{parent}_id)")
|
||||
eval("@#{parent}_project_hidden_todo_counts = @#{parent}_project_hidden_todo_counts || Todo.count(:conditions => ['user_id = ? and state = ?', current_user.id, 'project_hidden'], :group => :#{parent}_id)")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ContextsController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
|
||||
|
||||
def index
|
||||
@contexts = @user.contexts
|
||||
@contexts = current_user.contexts
|
||||
init_not_done_counts(['context'])
|
||||
respond_to do |format|
|
||||
format.html &render_contexts_html
|
||||
|
|
@ -46,7 +46,7 @@ class ContextsController < ApplicationController
|
|||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
return
|
||||
end
|
||||
@context = @user.contexts.build
|
||||
@context = current_user.contexts.build
|
||||
params_are_invalid = true
|
||||
if (params['context'] || (params['request'] && params['request']['context']))
|
||||
@context.attributes = params['context'] || params['request']['context']
|
||||
|
|
@ -104,7 +104,7 @@ class ContextsController < ApplicationController
|
|||
#
|
||||
def order
|
||||
params["list-contexts"].each_with_index do |id, position|
|
||||
@user.contexts.update(id, :position => position + 1)
|
||||
current_user.contexts.update(id, :position => position + 1)
|
||||
end
|
||||
render :nothing => true
|
||||
end
|
||||
|
|
@ -121,30 +121,31 @@ class ContextsController < ApplicationController
|
|||
|
||||
def render_contexts_rss_feed
|
||||
lambda do
|
||||
render_rss_feed_for @contexts, :feed => Context.feed_options(@user),
|
||||
render_rss_feed_for @contexts, :feed => feed_options,
|
||||
:item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) } }
|
||||
end
|
||||
end
|
||||
|
||||
def render_contexts_atom_feed
|
||||
lambda do
|
||||
render_atom_feed_for @contexts, :feed => Context.feed_options(@user),
|
||||
render_atom_feed_for @contexts, :feed => feed_options,
|
||||
:item => { :description => lambda { |c| c.summary(count_undone_todos_phrase(c)) },
|
||||
:author => lambda { |c| nil } }
|
||||
end
|
||||
end
|
||||
|
||||
def feed_options
|
||||
Context.feed_options(current_user)
|
||||
end
|
||||
|
||||
def set_context_from_params
|
||||
@context = @user.contexts.find_by_params(params)
|
||||
@context = current_user.contexts.find_by_params(params)
|
||||
rescue
|
||||
@context = nil
|
||||
end
|
||||
|
||||
def init
|
||||
@source_view = params['_source_view'] || 'context'
|
||||
# If we exclude completed projects, then we can't display them in the sidebar
|
||||
# if the user sets the preference for them to be shown
|
||||
# @projects = @user.projects.reject { |x| x.completed? }
|
||||
init_data_for_sidebar
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ class DataController < ApplicationController
|
|||
def yaml_export
|
||||
all_tables = {}
|
||||
|
||||
all_tables['todos'] = @user.todos.find(:all)
|
||||
all_tables['contexts'] = @user.contexts.find(:all)
|
||||
all_tables['projects'] = @user.projects.find(:all)
|
||||
all_tables['notes'] = @user.notes.find(:all)
|
||||
all_tables['todos'] = current_user.todos.find(:all)
|
||||
all_tables['contexts'] = current_user.contexts.find(:all)
|
||||
all_tables['projects'] = current_user.projects.find(:all)
|
||||
all_tables['notes'] = current_user.notes.find(:all)
|
||||
|
||||
result = all_tables.to_yaml
|
||||
result.gsub!(/\n/, "\r\n") # TODO: general functionality for line endings
|
||||
|
|
@ -33,7 +33,7 @@ class DataController < ApplicationController
|
|||
csv << ["ID", "Context", "Project", "Description", "Notes",
|
||||
"Created at", "Due", "Completed at", "User ID", "Show from",
|
||||
"state"]
|
||||
@user.todos.find(:all, :include => [:context, :project]).each do |todo|
|
||||
current_user.todos.find(:all, :include => [:context, :project]).each do |todo|
|
||||
# Format dates in ISO format for easy sorting in spreadsheet
|
||||
# Print context and project names for easy viewing
|
||||
csv << [todo.id, todo.context.name,
|
||||
|
|
@ -57,7 +57,7 @@ class DataController < ApplicationController
|
|||
"Created at", "Updated at"]
|
||||
# had to remove project include because it's association order is leaking through
|
||||
# and causing an ambiguous column ref even with_exclusive_scope didn't seem to help -JamesKebinger
|
||||
@user.notes.find(:all,:order=>"notes.created_at").each do |note|
|
||||
current_user.notes.find(:all,:order=>"notes.created_at").each do |note|
|
||||
# Format dates in ISO format for easy sorting in spreadsheet
|
||||
# Print context and project names for easy viewing
|
||||
csv << [note.id, note.user_id,
|
||||
|
|
@ -71,10 +71,10 @@ class DataController < ApplicationController
|
|||
|
||||
def xml_export
|
||||
result = ""
|
||||
result << @user.todos.find(:all).to_xml
|
||||
result << @user.contexts.find(:all).to_xml(:skip_instruct => true)
|
||||
result << @user.projects.find(:all).to_xml(:skip_instruct => true)
|
||||
result << @user.notes.find(:all).to_xml(:skip_instruct => true)
|
||||
result << current_user.todos.find(:all).to_xml
|
||||
result << current_user.contexts.find(:all).to_xml(:skip_instruct => true)
|
||||
result << current_user.projects.find(:all).to_xml(:skip_instruct => true)
|
||||
result << current_user.notes.find(:all).to_xml(:skip_instruct => true)
|
||||
send_data(result, :filename => "tracks_backup.xml", :type => 'text/xml')
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class NotesController < ApplicationController
|
||||
|
||||
def index
|
||||
@all_notes = @user.notes
|
||||
@all_notes = current_user.notes
|
||||
@page_title = "TRACKS::All notes"
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
|
@ -10,14 +10,12 @@ class NotesController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@note = check_user_return_note
|
||||
@note = current_user.notes.find(params['id'])
|
||||
@page_title = "TRACKS::Note " + @note.id.to_s
|
||||
end
|
||||
|
||||
# Add a new note to this project
|
||||
#
|
||||
def create
|
||||
note = @user.notes.build
|
||||
note = current_user.notes.build
|
||||
note.attributes = params["new_note"]
|
||||
|
||||
if note.save
|
||||
|
|
@ -28,34 +26,24 @@ class NotesController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
note = check_user_return_note
|
||||
note = current_user.notes.find(params['id'])
|
||||
if note.destroy
|
||||
render :text => ''
|
||||
else
|
||||
notify :warning, "Couldn't delete note \"#{note.id.to_s}\""
|
||||
notify :warning, "Couldn't delete note \"#{note.id}\""
|
||||
render :text => ''
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
note = check_user_return_note
|
||||
note = current_user.notes.find(params['id'])
|
||||
note.attributes = params["note"]
|
||||
if note.save
|
||||
render :partial => 'notes', :object => note
|
||||
else
|
||||
notify :warning, "Couldn't update note \"#{note.id.to_s}\""
|
||||
render :text => ''
|
||||
end
|
||||
if note.save
|
||||
render :partial => 'notes', :object => note
|
||||
else
|
||||
notify :warning, "Couldn't update note \"#{note.id}\""
|
||||
render :text => ''
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def check_user_return_note
|
||||
note = Note.find_by_id( params['id'] )
|
||||
if @user == note.user
|
||||
return note
|
||||
else
|
||||
render :text => ''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,20 +2,18 @@ class PreferencesController < ApplicationController
|
|||
|
||||
def index
|
||||
@page_title = "TRACKS::Preferences"
|
||||
@prefs = @user.preference
|
||||
@prefs = prefs
|
||||
end
|
||||
|
||||
def edit
|
||||
@page_title = "TRACKS::Edit Preferences"
|
||||
@prefs = @user.preference
|
||||
|
||||
render :object => @prefs
|
||||
render :object => prefs
|
||||
end
|
||||
|
||||
def update
|
||||
user_success = @user.update_attributes(params['user'])
|
||||
prefs_success = @user.preference.update_attributes(params['prefs'])
|
||||
if user_success && prefs_success
|
||||
user_updated = current_user.update_attributes(params['user'])
|
||||
prefs_updated = current_user.preference.update_attributes(params['prefs'])
|
||||
if user_updated && prefs_updated
|
||||
redirect_to :action => 'index'
|
||||
else
|
||||
render :action => 'edit'
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ class ProjectsController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
|
||||
|
||||
def index
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
@projects = current_user.projects
|
||||
@contexts = current_user.contexts
|
||||
init_not_done_counts(['project'])
|
||||
if params[:only_active_with_no_next_actions]
|
||||
@projects = @projects.select { |p| p.active? && count_undone_todos(p) == 0 }
|
||||
|
|
@ -26,15 +26,15 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def show
|
||||
init_data_for_sidebar
|
||||
@projects = @user.projects
|
||||
@contexts = @user.contexts
|
||||
@projects = current_user.projects
|
||||
@contexts = current_user.contexts
|
||||
@page_title = "TRACKS::Project: #{@project.name}"
|
||||
@not_done = @project.not_done_todos(:include_project_hidden_todos => true)
|
||||
@deferred = @project.deferred_todos
|
||||
@done = @project.done_todos
|
||||
@count = @not_done.size
|
||||
@next_project = @user.projects.next_from(@project)
|
||||
@previous_project = @user.projects.previous_from(@project)
|
||||
@next_project = current_user.projects.next_from(@project)
|
||||
@previous_project = current_user.projects.previous_from(@project)
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
|
@ -52,7 +52,7 @@ class ProjectsController < ApplicationController
|
|||
render_failure "Expected post format is valid xml like so: <request><project><name>project name</name></project></request>."
|
||||
return
|
||||
end
|
||||
@project = @user.projects.build
|
||||
@project = current_user.projects.build
|
||||
params_are_invalid = true
|
||||
if (params['project'] || (params['request'] && params['request']['project']))
|
||||
@project.attributes = params['project'] || params['request']['project']
|
||||
|
|
@ -61,8 +61,8 @@ class ProjectsController < ApplicationController
|
|||
@go_to_project = params['go_to_project']
|
||||
@saved = @project.save
|
||||
@project_not_done_counts = { @project.id => 0 }
|
||||
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")
|
||||
@contexts = @user.contexts
|
||||
@active_projects_count = current_user.projects.count(:conditions => "state = 'active'")
|
||||
@contexts = current_user.contexts
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.xml do
|
||||
|
|
@ -101,10 +101,10 @@ class ProjectsController < ApplicationController
|
|||
@project_not_done_counts = Hash.new
|
||||
@project_not_done_counts[@project.id] = @project.reload().not_done_todo_count(:include_project_hidden_todos => true)
|
||||
end
|
||||
@contexts = @user.contexts
|
||||
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")
|
||||
@hidden_projects_count = @user.projects.count(:conditions => "state = 'hidden'")
|
||||
@completed_projects_count = @user.projects.count(:conditions => "state = 'completed'")
|
||||
@contexts = current_user.contexts
|
||||
@active_projects_count = current_user.projects.count(:conditions => "state = 'active'")
|
||||
@hidden_projects_count = current_user.projects.count(:conditions => "state = 'hidden'")
|
||||
@completed_projects_count = current_user.projects.count(:conditions => "state = 'completed'")
|
||||
render
|
||||
elsif boolean_param('update_status')
|
||||
render :action => 'update_status'
|
||||
|
|
@ -121,9 +121,9 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
@project.destroy
|
||||
@active_projects_count = @user.projects.count(:conditions => "state = 'active'")
|
||||
@hidden_projects_count = @user.projects.count(:conditions => "state = 'hidden'")
|
||||
@completed_projects_count = @user.projects.count(:conditions => "state = 'completed'")
|
||||
@active_projects_count = current_user.projects.count(:conditions => "state = 'active'")
|
||||
@hidden_projects_count = current_user.projects.count(:conditions => "state = 'hidden'")
|
||||
@completed_projects_count = current_user.projects.count(:conditions => "state = 'completed'")
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.xml { render :text => "Deleted project #{@project.name}" }
|
||||
|
|
@ -132,7 +132,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def order
|
||||
project_ids = params["list-active-projects"] || params["list-hidden-projects"] || params["list-completed-projects"]
|
||||
projects = @user.projects.update_positions( project_ids )
|
||||
projects = current_user.projects.update_positions( project_ids )
|
||||
render :nothing => true
|
||||
rescue
|
||||
notify :error, $!
|
||||
|
|
@ -141,8 +141,8 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def alphabetize
|
||||
@state = params['state']
|
||||
@projects = @user.projects.alphabetize(:state => @state) if @state
|
||||
@contexts = @user.contexts
|
||||
@projects = current_user.projects.alphabetize(:state => @state) if @state
|
||||
@contexts = current_user.contexts
|
||||
init_not_done_counts(['project'])
|
||||
end
|
||||
|
||||
|
|
@ -157,26 +157,30 @@ class ProjectsController < ApplicationController
|
|||
@completed_projects = @projects.select{ |p| p.completed? }
|
||||
@no_projects = @projects.empty?
|
||||
@projects.cache_note_counts
|
||||
@new_project = @user.projects.build
|
||||
@new_project = current_user.projects.build
|
||||
render
|
||||
end
|
||||
end
|
||||
|
||||
def render_rss_feed
|
||||
lambda do
|
||||
render_rss_feed_for @projects, :feed => Project.feed_options(@user),
|
||||
render_rss_feed_for @projects, :feed => feed_options,
|
||||
:item => { :title => :name, :description => lambda { |p| summary(p) } }
|
||||
end
|
||||
end
|
||||
|
||||
def render_atom_feed
|
||||
lambda do
|
||||
render_atom_feed_for @projects, :feed => Project.feed_options(@user),
|
||||
render_atom_feed_for @projects, :feed => feed_options,
|
||||
:item => { :description => lambda { |p| summary(p) },
|
||||
:title => :name,
|
||||
:author => lambda { |p| nil } }
|
||||
end
|
||||
end
|
||||
|
||||
def feed_options
|
||||
Project.feed_options(current_user)
|
||||
end
|
||||
|
||||
def render_text_feed
|
||||
lambda do
|
||||
|
|
@ -186,7 +190,7 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def set_project_from_params
|
||||
@project = @user.projects.find_by_params(params)
|
||||
@project = current_user.projects.find_by_params(params)
|
||||
end
|
||||
|
||||
def set_source_view
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ class TodosController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| is_feed_request(req) }
|
||||
|
||||
def index
|
||||
@projects = @user.projects.find(:all, :include => [ :todos ])
|
||||
@contexts = @user.contexts.find(:all, :include => [ :todos ])
|
||||
@projects = current_user.projects.find(:all, :include => [ :todos ])
|
||||
@contexts = current_user.contexts.find(:all, :include => [ :todos ])
|
||||
|
||||
@contexts_to_show = @contexts.reject {|x| x.hide? }
|
||||
|
||||
|
|
@ -27,15 +27,15 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@projects = @user.projects.find(:all)
|
||||
@contexts = @user.contexts.find(:all)
|
||||
@projects = current_user.projects.find(:all)
|
||||
@contexts = current_user.contexts.find(:all)
|
||||
respond_to do |format|
|
||||
format.m { render :action => "new_mobile" }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@todo = @user.todos.build
|
||||
@todo = current_user.todos.build
|
||||
p = params['request'] || params
|
||||
|
||||
if p['todo']['show_from'] && !mobile?
|
||||
|
|
@ -45,9 +45,9 @@ class TodosController < ApplicationController
|
|||
@todo.attributes = p['todo']
|
||||
|
||||
if p['todo']['project_id'].blank? && !p['project_name'].blank? && p['project_name'] != 'None'
|
||||
project = @user.projects.find_by_name(p['project_name'].strip)
|
||||
project = current_user.projects.find_by_name(p['project_name'].strip)
|
||||
unless project
|
||||
project = @user.projects.build
|
||||
project = current_user.projects.build
|
||||
project.name = p['project_name'].strip
|
||||
project.save
|
||||
@new_project_created = true
|
||||
|
|
@ -56,9 +56,9 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
if p['todo']['context_id'].blank? && !p['context_name'].blank?
|
||||
context = @user.contexts.find_by_name(p['context_name'].strip)
|
||||
context = current_user.contexts.find_by_name(p['context_name'].strip)
|
||||
unless context
|
||||
context = @user.contexts.build
|
||||
context = current_user.contexts.build
|
||||
context.name = p['context_name'].strip
|
||||
context.save
|
||||
@new_context_created = true
|
||||
|
|
@ -75,7 +75,7 @@ class TodosController < ApplicationController
|
|||
|
||||
@saved = @todo.save
|
||||
if @saved
|
||||
@todo.tag_with(params[:tag_list],@user) if params[:tag_list]
|
||||
@todo.tag_with(params[:tag_list], current_user) if params[:tag_list]
|
||||
@todo.reload
|
||||
end
|
||||
|
||||
|
|
@ -97,15 +97,15 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def edit
|
||||
@projects = @user.projects.find(:all)
|
||||
@contexts = @user.contexts.find(:all)
|
||||
@projects = current_user.projects.find(:all)
|
||||
@contexts = current_user.contexts.find(:all)
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.m do
|
||||
@projects = @user.projects.find(:all)
|
||||
@contexts = @user.contexts.find(:all)
|
||||
@projects = current_user.projects.find(:all)
|
||||
@contexts = current_user.contexts.find(:all)
|
||||
render :action => 'show_mobile'
|
||||
end
|
||||
format.xml { render :xml => @todo.to_xml( :root => 'todo', :except => :user_id ) }
|
||||
|
|
@ -120,7 +120,7 @@ class TodosController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.js do
|
||||
if @saved
|
||||
@remaining_undone_in_context = @user.contexts.find(@todo.context_id).not_done_todo_count
|
||||
@remaining_undone_in_context = current_user.contexts.find(@todo.context_id).not_done_todo_count
|
||||
determine_down_count
|
||||
determine_completed_count
|
||||
end
|
||||
|
|
@ -145,7 +145,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@todo.tag_with(params[:tag_list],@user) if params[:tag_list]
|
||||
@todo.tag_with(params[:tag_list], current_user) if params[:tag_list]
|
||||
@original_item_context_id = @todo.context_id
|
||||
@original_item_project_id = @todo.project_id
|
||||
@original_item_was_deferred = @todo.deferred?
|
||||
|
|
@ -153,9 +153,9 @@ class TodosController < ApplicationController
|
|||
if params['project_name'] == 'None'
|
||||
project = Project.null_object
|
||||
else
|
||||
project = @user.projects.find_by_name(params['project_name'].strip)
|
||||
project = current_user.projects.find_by_name(params['project_name'].strip)
|
||||
unless project
|
||||
project = @user.projects.build
|
||||
project = current_user.projects.build
|
||||
project.name = params['project_name'].strip
|
||||
project.save
|
||||
@new_project_created = true
|
||||
|
|
@ -165,9 +165,9 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
if params['todo']['context_id'].blank? && !params['context_name'].blank?
|
||||
context = @user.contexts.find_by_name(params['context_name'].strip)
|
||||
context = current_user.contexts.find_by_name(params['context_name'].strip)
|
||||
unless context
|
||||
context = @user.contexts.build
|
||||
context = current_user.contexts.build
|
||||
context.name = params['context_name'].strip
|
||||
context.save
|
||||
@new_context_created = true
|
||||
|
|
@ -192,9 +192,9 @@ class TodosController < ApplicationController
|
|||
@saved = @todo.update_attributes params["todo"]
|
||||
@context_changed = @original_item_context_id != @todo.context_id
|
||||
@todo_was_activated_from_deferred_state = @original_item_was_deferred && @todo.active?
|
||||
if @context_changed then @remaining_undone_in_context = @user.contexts.find(@original_item_context_id).not_done_todo_count; end
|
||||
if @context_changed then @remaining_undone_in_context = current_user.contexts.find(@original_item_context_id).not_done_todo_count; end
|
||||
@project_changed = @original_item_project_id != @todo.project_id
|
||||
if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = @user.projects.find(@original_item_project_id).not_done_todo_count; end
|
||||
if (@project_changed && !@original_item_project_id.nil?) then @remaining_undone_in_project = current_user.projects.find(@original_item_project_id).not_done_todo_count; end
|
||||
determine_down_count
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
@ -231,7 +231,7 @@ class TodosController < ApplicationController
|
|||
determine_down_count
|
||||
source_view do |from|
|
||||
from.todo do
|
||||
@remaining_undone_in_context = @user.contexts.find(@context_id).not_done_todo_count
|
||||
@remaining_undone_in_context = current_user.contexts.find(@context_id).not_done_todo_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -245,27 +245,27 @@ class TodosController < ApplicationController
|
|||
|
||||
def completed
|
||||
@page_title = "TRACKS::Completed tasks"
|
||||
@done = @user.completed_todos
|
||||
@done_today = @done.completed_within @user.time - 1.day
|
||||
@done_this_week = @done.completed_within @user.time - 1.week
|
||||
@done_this_month = @done.completed_within @user.time - 4.week
|
||||
@done = current_user.completed_todos
|
||||
@done_today = @done.completed_within current_user.time - 1.day
|
||||
@done_this_week = @done.completed_within current_user.time - 1.week
|
||||
@done_this_month = @done.completed_within current_user.time - 4.week
|
||||
end
|
||||
|
||||
def completed_archive
|
||||
@page_title = "TRACKS::Archived completed tasks"
|
||||
@done = @user.completed_todos
|
||||
@done_archive = @done.completed_more_than @user.time - 28.days
|
||||
@done = current_user.completed_todos
|
||||
@done_archive = @done.completed_more_than current_user.time - 28.days
|
||||
end
|
||||
|
||||
def list_deferred
|
||||
@source_view = 'deferred'
|
||||
@page_title = "TRACKS::Tickler"
|
||||
|
||||
@projects = @user.projects.find(:all, :include => [ :todos ])
|
||||
@contexts_to_show = @contexts = @user.contexts.find(:all, :include => [ :todos ])
|
||||
@projects = current_user.projects.find(:all, :include => [ :todos ])
|
||||
@contexts_to_show = @contexts = current_user.contexts.find(:all, :include => [ :todos ])
|
||||
|
||||
@user.deferred_todos.find_and_activate_ready
|
||||
@not_done_todos = @user.deferred_todos
|
||||
current_user.deferred_todos.find_and_activate_ready
|
||||
@not_done_todos = current_user.deferred_todos
|
||||
@count = @not_done_todos.size
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
end
|
||||
|
|
@ -273,7 +273,7 @@ class TodosController < ApplicationController
|
|||
# Check for any due tickler items, activate them
|
||||
# Called by periodically_call_remote
|
||||
def check_deferred
|
||||
@due_tickles = @user.deferred_todos.find_and_activate_ready
|
||||
@due_tickles = current_user.deferred_todos.find_and_activate_ready
|
||||
respond_to do |format|
|
||||
format.html { redirect_to home_path }
|
||||
format.js
|
||||
|
|
@ -281,12 +281,12 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def filter_to_context
|
||||
context = @user.contexts.find(params['context']['id'])
|
||||
context = current_user.contexts.find(params['context']['id'])
|
||||
redirect_to formatted_context_todos_path(context, :m)
|
||||
end
|
||||
|
||||
def filter_to_project
|
||||
project = @user.projects.find(params['project']['id'])
|
||||
project = current_user.projects.find(params['project']['id'])
|
||||
redirect_to formatted_project_todos_path(project, :m)
|
||||
end
|
||||
|
||||
|
|
@ -303,19 +303,19 @@ class TodosController < ApplicationController
|
|||
@not_done_todos = []
|
||||
else
|
||||
tag_collection = Tag.find_by_name(tag_name).todos
|
||||
@not_done_todos = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'active'])
|
||||
@not_done_todos = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'active'])
|
||||
end
|
||||
|
||||
@contexts = @user.contexts.find(:all, :include => [ :todos ])
|
||||
@contexts = current_user.contexts.find(:all, :include => [ :todos ])
|
||||
@contexts_to_show = @contexts.reject {|x| x.hide? }
|
||||
|
||||
@deferred = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'deferred'])
|
||||
@deferred = tag_collection.find(:all, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'deferred'])
|
||||
|
||||
@page_title = "TRACKS::Tagged with \'#{@tag}\'"
|
||||
# If you've set no_completed to zero, the completed items box
|
||||
# isn't shown on the home page
|
||||
max_completed = @user.prefs.show_number_completed
|
||||
@done = tag_collection.find(:all, :limit => max_completed, :conditions => ['taggings.user_id = ? and state = ?', @user.id, 'completed'])
|
||||
max_completed = current_user.prefs.show_number_completed
|
||||
@done = tag_collection.find(:all, :limit => max_completed, :conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'completed'])
|
||||
# Set count badge to number of items with this tag
|
||||
@not_done_todos.empty? ? @count = 0 : @count = @not_done_todos.size
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
|
||||
|
|
@ -325,7 +325,7 @@ class TodosController < ApplicationController
|
|||
private
|
||||
|
||||
def get_todo_from_params
|
||||
@todo = @user.todos.find(params['id'])
|
||||
@todo = current_user.todos.find(params['id'])
|
||||
end
|
||||
|
||||
def init
|
||||
|
|
@ -353,7 +353,7 @@ class TodosController < ApplicationController
|
|||
|
||||
if params.key?('due')
|
||||
due_within = params['due'].to_i
|
||||
due_within_when = @user.time + due_within.days
|
||||
due_within_when = current_user.time + due_within.days
|
||||
condition_builder.add('todos.due <= ?', due_within_when)
|
||||
due_within_date_s = due_within_when.strftime("%Y-%m-%d")
|
||||
@title << " due today" if (due_within == 0)
|
||||
|
|
@ -363,7 +363,7 @@ class TodosController < ApplicationController
|
|||
|
||||
if params.key?('done')
|
||||
done_in_last = params['done'].to_i
|
||||
condition_builder.add('todos.completed_at >= ?', @user.time - done_in_last.days)
|
||||
condition_builder.add('todos.completed_at >= ?', current_user.time - done_in_last.days)
|
||||
@title << " actions completed"
|
||||
@description << " in the last #{done_in_last.to_s} days"
|
||||
end
|
||||
|
|
@ -376,12 +376,12 @@ class TodosController < ApplicationController
|
|||
|
||||
def with_parent_resource_scope(&block)
|
||||
if (params[:context_id])
|
||||
@context = @user.contexts.find_by_params(params)
|
||||
@context = current_user.contexts.find_by_params(params)
|
||||
Todo.with_scope :find => {:conditions => ['todos.context_id = ?', @context.id]} do
|
||||
yield
|
||||
end
|
||||
elsif (params[:project_id])
|
||||
@project = @user.projects.find_by_params(params)
|
||||
@project = current_user.projects.find_by_params(params)
|
||||
Todo.with_scope :find => {:conditions => ['todos.project_id = ?', @project.id]} do
|
||||
yield
|
||||
end
|
||||
|
|
@ -414,23 +414,23 @@ class TodosController < ApplicationController
|
|||
|
||||
if mobile?
|
||||
|
||||
@todos, @page = @user.todos.paginate(:all,
|
||||
@todos, @page = current_user.todos.paginate(:all,
|
||||
:conditions => ['state = ?', 'active' ], :include => [:context],
|
||||
:order => 'due IS NULL, due ASC, todos.created_at ASC',
|
||||
:page => params[:page], :per_page => @prefs.mobile_todos_per_page)
|
||||
:page => params[:page], :per_page => prefs.mobile_todos_per_page)
|
||||
@pagination_params = { :format => :m }
|
||||
@pagination_params[:context_id] = @context.to_param if @context
|
||||
@pagination_params[:project_id] = @project.to_param if @project
|
||||
|
||||
else
|
||||
|
||||
# Note: these next two finds were previously using @users.todos.find but that broke with_scope for :limit
|
||||
# Note: these next two finds were previously using current_users.todos.find but that broke with_scope for :limit
|
||||
|
||||
# Exclude hidden projects from count on home page
|
||||
@todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', @user.id, 'active', 'completed'], :include => [ :project, :context, :tags ])
|
||||
@todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ? or todos.state = ?', current_user.id, 'active', 'completed'], :include => [ :project, :context, :tags ])
|
||||
|
||||
# Exclude hidden projects from the home page
|
||||
@not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ?', @user.id, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ])
|
||||
@not_done_todos = Todo.find(:all, :conditions => ['todos.user_id = ? and todos.state = ?', current_user.id, 'active'], :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC", :include => [ :project, :context, :tags ])
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -442,19 +442,19 @@ class TodosController < ApplicationController
|
|||
def determine_down_count
|
||||
source_view do |from|
|
||||
from.todo do
|
||||
@down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'active', false])
|
||||
@down_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', current_user.id, 'active', false])
|
||||
end
|
||||
from.context do
|
||||
@down_count = @user.contexts.find(@todo.context_id).not_done_todo_count
|
||||
@down_count = current_user.contexts.find(@todo.context_id).not_done_todo_count
|
||||
end
|
||||
from.project do
|
||||
unless @todo.project_id == nil
|
||||
@down_count = @user.projects.find(@todo.project_id).not_done_todo_count
|
||||
@deferred_count = @user.projects.find(@todo.project_id).deferred_todo_count
|
||||
@down_count = current_user.projects.find(@todo.project_id).not_done_todo_count
|
||||
@deferred_count = current_user.projects.find(@todo.project_id).deferred_todo_count
|
||||
end
|
||||
end
|
||||
from.deferred do
|
||||
@down_count = @user.todos.count_in_state(:deferred)
|
||||
@down_count = current_user.todos.count_in_state(:deferred)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -462,14 +462,14 @@ class TodosController < ApplicationController
|
|||
def determine_completed_count
|
||||
source_view do |from|
|
||||
from.todo do
|
||||
@completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', @user.id, 'completed', false])
|
||||
@completed_count = Todo.count_by_sql(['SELECT COUNT(*) FROM todos, contexts WHERE todos.context_id = contexts.id and todos.user_id = ? and todos.state = ? and contexts.hide = ?', current_user.id, 'completed', false])
|
||||
end
|
||||
from.context do
|
||||
@completed_count = @user.contexts.find(@todo.context_id).done_todo_count
|
||||
@completed_count = current_user.contexts.find(@todo.context_id).done_todo_count
|
||||
end
|
||||
from.project do
|
||||
unless @todo.project_id == nil
|
||||
@completed_count = @user.projects.find(@todo.project_id).done_todo_count
|
||||
@completed_count = current_user.projects.find(@todo.project_id).done_todo_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -481,8 +481,8 @@ class TodosController < ApplicationController
|
|||
|
||||
# If you've set no_completed to zero, the completed items box
|
||||
# isn't shown on the home page
|
||||
max_completed = @user.prefs.show_number_completed
|
||||
@done = @user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0
|
||||
max_completed = current_user.prefs.show_number_completed
|
||||
@done = current_user.completed_todos.find(:all, :limit => max_completed, :include => [ :context, :project, :tags ]) unless max_completed == 0
|
||||
|
||||
# Set count badge to number of not-done, not hidden context items
|
||||
@count = @todos.reject { |x| !x.active? || x.context.hide? }.size
|
||||
|
|
@ -512,7 +512,7 @@ class TodosController < ApplicationController
|
|||
|
||||
def render_rss_feed
|
||||
lambda do
|
||||
render_rss_feed_for @todos, :feed => Todo.feed_options(@user),
|
||||
render_rss_feed_for @todos, :feed => todo_feed_options,
|
||||
:item => {
|
||||
:title => :description,
|
||||
:link => lambda { |t| context_url(t.context) },
|
||||
|
|
@ -520,6 +520,10 @@ class TodosController < ApplicationController
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
def todo_feed_options
|
||||
Todo.feed_options(current_user)
|
||||
end
|
||||
|
||||
def todo_feed_content
|
||||
lambda do |i|
|
||||
|
|
@ -538,7 +542,7 @@ class TodosController < ApplicationController
|
|||
|
||||
def render_atom_feed
|
||||
lambda do
|
||||
render_atom_feed_for @todos, :feed => Todo.feed_options(@user),
|
||||
render_atom_feed_for @todos, :feed => todo_feed_options,
|
||||
:item => {
|
||||
:title => :description,
|
||||
:link => lambda { |t| context_url(t.context) },
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
module ApplicationHelper
|
||||
|
||||
def user_time
|
||||
@user.time
|
||||
current_user.time
|
||||
end
|
||||
|
||||
# Replicates the link_to method but also checks request.request_uri to find
|
||||
|
|
@ -47,7 +47,7 @@ module ApplicationHelper
|
|||
"<a title='#{format_date(due)}'><span class=\"amber\">Due Tomorrow</span></a> "
|
||||
# due 2-7 days away
|
||||
when 2..7
|
||||
if @user.prefs.due_style == Preference::DUE_ON_DUE_STYLE
|
||||
if prefs.due_style == Preference::DUE_ON_DUE_STYLE
|
||||
"<a title='#{format_date(due)}'><span class=\"orange\">Due on #{due.strftime("%A")}</span></a> "
|
||||
else
|
||||
"<a title='#{format_date(due)}'><span class=\"orange\">Due in #{pluralize(days, 'day')}</span></a> "
|
||||
|
|
@ -114,13 +114,13 @@ module ApplicationHelper
|
|||
|
||||
def item_link_to_context(item)
|
||||
descriptor = "[C]"
|
||||
descriptor = "[#{item.context.name}]" if (@user.prefs.verbose_action_descriptors)
|
||||
descriptor = "[#{item.context.name}]" if prefs.verbose_action_descriptors
|
||||
link_to_context( item.context, descriptor )
|
||||
end
|
||||
|
||||
def item_link_to_project(item)
|
||||
descriptor = "[P]"
|
||||
descriptor = "[#{item.project.name}]" if (@user.prefs.verbose_action_descriptors)
|
||||
descriptor = "[#{item.project.name}]" if prefs.verbose_action_descriptors
|
||||
link_to_project( item.project, descriptor )
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,28 @@ module FeedlistHelper
|
|||
|
||||
def rss_formatted_link(options = {})
|
||||
image_tag = image_tag("feed-icon.png", :size => "16X16", :border => 0, :class => "rss-icon")
|
||||
linkoptions = { :token => @user.token, :format => 'rss' }
|
||||
linkoptions.merge!(options)
|
||||
linkoptions = merge_hashes( { :format => 'rss'}, user_token_hash, options)
|
||||
link_to(image_tag, linkoptions, :title => "RSS feed")
|
||||
end
|
||||
|
||||
def text_formatted_link(options = {})
|
||||
linkoptions = { :token => @user.token, :format => 'txt' }
|
||||
linkoptions.merge!(options)
|
||||
linkoptions = merge_hashes( { :format => 'txt'}, user_token_hash, options)
|
||||
link_to('<span class="feed">TXT</span>', linkoptions, :title => "Plain text feed" )
|
||||
end
|
||||
|
||||
def ical_formatted_link(options = {})
|
||||
linkoptions = { :token => @user.token, :format => 'ics' }
|
||||
linkoptions.merge!(options)
|
||||
linkoptions = merge_hashes ( { :format => 'ics'}, user_token_hash, options)
|
||||
link_to('<span class="feed">iCal</span>', linkoptions, :title => "iCal feed" )
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def merge_hashes(*hashes)
|
||||
hashes.inject(Hash.new){ |result, h| result.merge(h) }
|
||||
end
|
||||
|
||||
def user_token_hash
|
||||
{ :token => current_user.token }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -107,11 +107,11 @@ module TodosHelper
|
|||
def staleness_class(item)
|
||||
if item.due || item.completed?
|
||||
return ""
|
||||
elsif item.created_at < user_time - (@user.prefs.staleness_starts * 3).days
|
||||
elsif item.created_at < user_time - (prefs.staleness_starts * 3).days
|
||||
return " stale_l3"
|
||||
elsif item.created_at < user_time - (@user.prefs.staleness_starts * 2).days
|
||||
elsif item.created_at < user_time - (prefs.staleness_starts * 2).days
|
||||
return " stale_l2"
|
||||
elsif item.created_at < user_time - (@user.prefs.staleness_starts).days
|
||||
elsif item.created_at < user_time - (prefs.staleness_starts).days
|
||||
return " stale_l1"
|
||||
else
|
||||
return ""
|
||||
|
|
@ -138,7 +138,7 @@ module TodosHelper
|
|||
"<a title='" + format_date(due) + "'><span class=\"amber\">Show Tomorrow</span></a> "
|
||||
# due 2-7 days away
|
||||
when 2..7
|
||||
if @user.prefs.due_style == Preference::DUE_ON_DUE_STYLE
|
||||
if prefs.due_style == Preference::DUE_ON_DUE_STYLE
|
||||
"<a title='" + format_date(due) + "'><span class=\"orange\">Show on " + due.strftime("%A") + "</span></a> "
|
||||
else
|
||||
"<a title='" + format_date(due) + "'><span class=\"orange\">Show in " + days.to_s + " days</span></a> "
|
||||
|
|
@ -150,10 +150,8 @@ module TodosHelper
|
|||
end
|
||||
|
||||
def calendar_setup( input_field )
|
||||
date_format = @user.prefs.date_format
|
||||
week_starts = @user.prefs.week_starts
|
||||
str = "Calendar.setup({ ifFormat:\"#{date_format}\""
|
||||
str << ",firstDay:#{week_starts},showOthers:true,range:[2004, 2010]"
|
||||
str = "Calendar.setup({ ifFormat:\"#{prefs.date_format}\""
|
||||
str << ",firstDay:#{prefs.week_starts},showOthers:true,range:[2004, 2010]"
|
||||
str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"
|
||||
javascript_tag str
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<div id="display_box">
|
||||
<%= render :partial => "contexts/context", :locals => { :context => @context, :collapsible => false } %>
|
||||
<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{@user.prefs.show_number_completed})" } %>
|
||||
<%= render :partial => "todos/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this context (last #{prefs.show_number_completed})" } %>
|
||||
|
||||
</div><!-- [end:display_box] -->
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
<%= javascript_include_tag "protoload" %>
|
||||
|
||||
<link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" />
|
||||
<%= auto_discovery_link_tag(:rss,{:controller => "todos", :action => "index", :format => 'rss', :token => "#{@user.token}"}, {:title => "RSS feed of next actions"}) %>
|
||||
<%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.onload=function(){
|
||||
|
|
@ -44,7 +44,7 @@ window.onload=function(){
|
|||
page.select('.notes').each { |e| e.toggle }
|
||||
end
|
||||
-%> |
|
||||
<%= link_to "Logout (#{@user.display_name}) »", logout_path %>
|
||||
<%= link_to "Logout (#{current_user.display_name}) »", logout_path %>
|
||||
</div>
|
||||
|
||||
<div id="navcontainer">
|
||||
|
|
@ -57,7 +57,7 @@ window.onload=function(){
|
|||
<li><%= navigation_link( "Notes", notes_path, {:accesskey => "o", :title => "Show all notes"} ) %></li>
|
||||
<li><%= navigation_link( "Preferences", preferences_path, {:accesskey => "u", :title => "Show my preferences"} ) %></li>
|
||||
<li><%= navigation_link( "Import/Export", {:controller => "data", :action => "index"}, {:accesskey => "i", :title => "Import and export data"} ) %></li>
|
||||
<% if @user.is_admin? -%>
|
||||
<% if current_user.is_admin? -%>
|
||||
<li><%= navigation_link("Admin", users_path, {:accesskey => "a", :title => "Add or delete users"} ) %></li>
|
||||
<% end -%>
|
||||
<li><%= navigation_link(image_tag("feed-icon.png", :size => "16X16", :border => 0), {:controller => "feedlist", :action => "index"}, :title => "See a list of available feeds" ) %></li>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
<li><strong>show completed projects in sidebar:</strong> whether or not projects marked as complete are shown in the sidebar on the home page and elsewhere</li>
|
||||
<li><strong>show hidden contexts in sidebar:</strong> whether or not contexts marked as hidden are shown in the sidebar on the home page and elsewhere</li>
|
||||
<li><strong>show project on todo done:</strong> whether or not to redirect to the project page when an action associated with a project is marked complete</li>
|
||||
<% if @user.is_admin? %>
|
||||
<% if current_user.is_admin? %>
|
||||
<li><strong>admin email:</strong> email address for the admin user of Tracks (displayed on the signup page for users to contact to obtain an account)</li>
|
||||
<% end %>
|
||||
<li><strong>staleness starts:</strong> the number of days before items with no due date get marked as stale (with a yellow highlight)</li>
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
<%= row_with_select_field("show_hidden_contexts_in_sidebar") %>
|
||||
<%= row_with_select_field("show_project_on_todo_done") %>
|
||||
|
||||
<% if @user.is_admin? %> <%= row_with_text_field('admin_email') %> <% end %>
|
||||
<% if current_user.is_admin? %> <%= row_with_text_field('admin_email') %> <% end %>
|
||||
<%= row_with_text_field('staleness_starts', true) %>
|
||||
<%= row_with_text_field('show_number_completed') %>
|
||||
<%= row_with_text_field('refresh') %>
|
||||
|
|
|
|||
|
|
@ -3,31 +3,31 @@
|
|||
<h2>Your preferences</h2>
|
||||
|
||||
<ul id="prefs">
|
||||
<li>First name: <span class="highlight"><%= @user.first_name %></span></li>
|
||||
<li>Last name: <span class="highlight"><%= @user.last_name %></span></li>
|
||||
<li>Date format: <span class="highlight"><%= @prefs.date_format %></span> Your current date: <%= format_date(user_time) %></li>
|
||||
<li>Title date format: <span class="highlight"><%= @prefs.title_date_format %></span> Your current title date: <%= user_time.strftime(@prefs.title_date_format) %></li>
|
||||
<li>Time zone: <span class="highlight"><%= @prefs.tz %></span> Your current time: <%= user_time.strftime('%I:%M %p') %></li>
|
||||
<li>Week starts on: <span class="highlight"><%= Preference.day_number_to_name_map[@prefs.week_starts] %></span></li>
|
||||
<li>Show the last <span class="highlight"><%= @prefs.show_number_completed %></span> completed items on the home page</li>
|
||||
<li>Show completed projects in sidebar: <span class="highlight"><%= @prefs.show_completed_projects_in_sidebar %></span></li>
|
||||
<li>Show hidden projects in sidebar: <span class="highlight"><%= @prefs.show_hidden_projects_in_sidebar %></span></li>
|
||||
<li>Show hidden contexts in sidebar: <span class="highlight"><%= @prefs.show_hidden_contexts_in_sidebar %></span></li>
|
||||
<li>Go to project page on todo complete: <span class="highlight"><%= @prefs.show_project_on_todo_done %></span></li>
|
||||
<li>Staleness starts after <span class="highlight"><%= @prefs.staleness_starts %></span> days</li>
|
||||
<li>First name: <span class="highlight"><%= current_user.first_name %></span></li>
|
||||
<li>Last name: <span class="highlight"><%= current_user.last_name %></span></li>
|
||||
<li>Date format: <span class="highlight"><%= prefs.date_format %></span> Your current date: <%= format_date(user_time) %></li>
|
||||
<li>Title date format: <span class="highlight"><%= prefs.title_date_format %></span> Your current title date: <%= user_time.strftime(prefs.title_date_format) %></li>
|
||||
<li>Time zone: <span class="highlight"><%= prefs.tz %></span> Your current time: <%= user_time.strftime('%I:%M %p') %></li>
|
||||
<li>Week starts on: <span class="highlight"><%= Preference.day_number_to_name_map[prefs.week_starts] %></span></li>
|
||||
<li>Show the last <span class="highlight"><%= prefs.show_number_completed %></span> completed items on the home page</li>
|
||||
<li>Show completed projects in sidebar: <span class="highlight"><%= prefs.show_completed_projects_in_sidebar %></span></li>
|
||||
<li>Show hidden projects in sidebar: <span class="highlight"><%= prefs.show_hidden_projects_in_sidebar %></span></li>
|
||||
<li>Show hidden contexts in sidebar: <span class="highlight"><%= prefs.show_hidden_contexts_in_sidebar %></span></li>
|
||||
<li>Go to project page on todo complete: <span class="highlight"><%= prefs.show_project_on_todo_done %></span></li>
|
||||
<li>Staleness starts after <span class="highlight"><%= prefs.staleness_starts %></span> days</li>
|
||||
<li>Due style: <span class="highlight">
|
||||
<% if @prefs.due_style == Preference::DUE_IN_N_DAYS_DUE_STYLE %>
|
||||
<% if prefs.due_style == Preference::DUE_IN_N_DAYS_DUE_STYLE %>
|
||||
Due in ___ days
|
||||
<% else %>
|
||||
Due on ________
|
||||
<% end %>
|
||||
</span></li>
|
||||
<% if @user.is_admin? %>
|
||||
<li>Admin email: <span class="highlight"><%= @prefs.admin_email %></span></li>
|
||||
<% if current_user.is_admin? %>
|
||||
<li>Admin email: <span class="highlight"><%= prefs.admin_email %></span></li>
|
||||
<% end %>
|
||||
<li>Refresh interval (in minutes): <span class="highlight"><%= @prefs.refresh %></span></li>
|
||||
<li>Verbose action descriptors: <span class="highlight"><%= @prefs.verbose_action_descriptors %></span></li>
|
||||
<li>Actions per page (Mobile View): <span class="highlight"><%= @prefs.mobile_todos_per_page %></span></li>
|
||||
<li>Refresh interval (in minutes): <span class="highlight"><%= prefs.refresh %></span></li>
|
||||
<li>Verbose action descriptors: <span class="highlight"><%= prefs.verbose_action_descriptors %></span></li>
|
||||
<li>Actions per page (Mobile View): <span class="highlight"><%= prefs.mobile_todos_per_page %></span></li>
|
||||
</ul>
|
||||
<div class="actions">
|
||||
<%= link_to "Edit preferences »", { :controller => 'preferences', :action => 'edit'}, :class => 'edit_link' %>
|
||||
|
|
@ -36,29 +36,29 @@
|
|||
<h2>Your token</h2>
|
||||
<div id="token_area">
|
||||
<div class="description">Token (for feeds and API use):</div>
|
||||
<div id="token><span class="highlight"><%= @user.token %></span></div>
|
||||
<div id="token><span class="highlight"><%= current_user.token %></span></div>
|
||||
<div class="token_regenerate">
|
||||
<%= button_to "Generate a new token", refresh_token_user_path(@user),
|
||||
<%= button_to "Generate a new token", refresh_token_user_path(current_user),
|
||||
:confirm => "Are you sure? Generating a new token will replace the existing one and break any external usages of this token." %>
|
||||
</div>
|
||||
</div>
|
||||
<h2>Your authentication</h2>
|
||||
<div id="authentication_area">
|
||||
<% if Tracks::Config.auth_schemes.length > 1 %>
|
||||
<p>Your authentication type is <span class="highlight"><%= @user.auth_type %></span>.
|
||||
<p>Your authentication type is <span class="highlight"><%= current_user.auth_type %></span>.
|
||||
<div class="actions">
|
||||
<%= link_to "Change your authentication type »", change_auth_type_user_path(@user), :class => 'edit_link' %>
|
||||
<%= link_to "Change your authentication type »", change_auth_type_user_path(current_user), :class => 'edit_link' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @user.auth_type == 'database' %>
|
||||
<% if current_user.auth_type == 'database' %>
|
||||
<div class="actions">
|
||||
<%= link_to 'Change your password »', change_password_user_path(@user) %>
|
||||
<%= link_to 'Change your password »', change_password_user_path(current_user) %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if @user.auth_type == 'open_id' %>
|
||||
<p>Your Open ID URL is <span class="highlight"><%= @user.open_id_url %></span>.
|
||||
<% if current_user.auth_type == 'open_id' %>
|
||||
<p>Your Open ID URL is <span class="highlight"><%= current_user.open_id_url %></span>.
|
||||
<div class="actions">
|
||||
<%= link_to 'Change Your Identity URL »', change_auth_type_user_path(@user) %></p>
|
||||
<%= link_to 'Change Your Identity URL »', change_auth_type_user_path(current_user) %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
:locals => { :list_name => 'Active Projects',
|
||||
:projects => @projects.select{|p| p.active? } } -%>
|
||||
|
||||
<% if @user.prefs.show_hidden_projects_in_sidebar -%>
|
||||
<% if prefs.show_hidden_projects_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/project_list",
|
||||
:locals => { :list_name => 'Hidden Projects',
|
||||
:projects => @projects.select{|p| p.hidden? } } -%>
|
||||
<% end -%>
|
||||
|
||||
<% if @user.prefs.show_completed_projects_in_sidebar -%>
|
||||
<% if prefs.show_completed_projects_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/project_list",
|
||||
:locals => { :list_name => 'Completed Projects',
|
||||
:projects => @projects.select{|p| p.completed? } } -%>
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
:locals => { :list_name => 'Active Contexts',
|
||||
:contexts => @contexts.reject{|c| c.hide? } } -%>
|
||||
|
||||
<% if @user.prefs.show_hidden_contexts_in_sidebar -%>
|
||||
<% if prefs.show_hidden_contexts_in_sidebar -%>
|
||||
<%= render :partial => "sidebar/context_list",
|
||||
:locals => { :list_name => 'Hidden Contexts',
|
||||
:contexts => @contexts.select{|c| c.hide? } } -%>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<% form_tag :action => 'update_auth_type' do %>
|
||||
<div><label for="user_auth_type">Authentication type:</label> <%= select('user', 'auth_type', Tracks::Config.auth_schemes.collect {|p| [ p, p ] }) %></div>
|
||||
<div id="open_id" style="display:<%= @user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="user_open_id_url">Identity URL:</label> <input type="text" name="openid_url" value="<%= @user.open_id_url %>" class="open_id" /></div>
|
||||
<div id="open_id" style="display:<%= current_user.auth_type == 'open_id' ? 'block' : 'none' %>"><label for="user_open_id_url">Identity URL:</label> <input type="text" name="openid_url" value="<%= current_user.open_id_url %>" class="open_id" /></div>
|
||||
<div class="actions"><%= submit_tag 'Change Authentication Type' %> <%= link_to 'Cancel', preferences_path %></div>
|
||||
|
||||
<%= observe_field( :user_auth_type, :function => "$('open_id').style.display = value == 'open_id' ? 'block' : 'none'") %>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
require_dependency "user"
|
||||
|
||||
module LoginSystem
|
||||
|
||||
|
||||
def current_user
|
||||
get_current_user
|
||||
end
|
||||
|
||||
def prefs
|
||||
current_user.prefs unless current_user.nil?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# overwrite this if you want to restrict access to only a few actions
|
||||
|
|
@ -38,9 +46,9 @@ module LoginSystem
|
|||
user = User.find_by_remember_token(cookies[:auth_token])
|
||||
if user && user.remember_token?
|
||||
session['user_id'] = user.id
|
||||
@user = user
|
||||
@user.remember_me
|
||||
cookies[:auth_token] = { :value => @user.remember_token , :expires => @user.remember_token_expires_at }
|
||||
set_current_user(user)
|
||||
current_user.remember_me
|
||||
cookies[:auth_token] = { :value => current_user.remember_token , :expires => current_user.remember_token_expires_at }
|
||||
flash[:notice] = "Logged in successfully. Welcome back!"
|
||||
end
|
||||
end
|
||||
|
|
@ -111,8 +119,7 @@ module LoginSystem
|
|||
end
|
||||
|
||||
def logged_in?
|
||||
get_current_user
|
||||
@user != nil
|
||||
current_user != nil
|
||||
end
|
||||
|
||||
def get_current_user
|
||||
|
|
@ -125,8 +132,6 @@ module LoginSystem
|
|||
|
||||
def set_current_user(user)
|
||||
@user = user
|
||||
@prefs = @user.prefs unless @user.nil?
|
||||
@user
|
||||
end
|
||||
|
||||
# overwrite if you want to have special behavior in case the user is not authorized
|
||||
|
|
|
|||
|
|
@ -114,6 +114,26 @@ class LoginControllerTest < Test::Rails::TestCase
|
|||
assert !@controller.send(:logged_in?)
|
||||
end
|
||||
|
||||
def test_current_user_nil
|
||||
get :login
|
||||
assert_nil @controller.current_user
|
||||
end
|
||||
|
||||
def test_current_user_correct
|
||||
user = login('jane','sesame', 'off')
|
||||
assert_equal user, @controller.current_user
|
||||
end
|
||||
|
||||
def test_prefs_nil
|
||||
get :login
|
||||
assert_nil @controller.prefs
|
||||
end
|
||||
|
||||
def test_prefs_correct
|
||||
user = login('jane','sesame', 'off')
|
||||
assert_equal user.prefs, @controller.prefs
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Logs in a user and returns the user object found in the session object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue