mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-01 02:20:16 +01:00
Merged tracks-mu-import branch changes r113:130 into the trunk
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@131 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
2d2f9fcca8
commit
91641500a7
75 changed files with 4054 additions and 1375 deletions
|
|
@ -1,9 +1,9 @@
|
|||
class ContextController < ApplicationController
|
||||
|
||||
|
||||
helper :context
|
||||
model :project
|
||||
model :todo
|
||||
|
||||
|
||||
before_filter :login_required
|
||||
layout "standard"
|
||||
|
||||
|
|
@ -16,160 +16,124 @@ class ContextController < ApplicationController
|
|||
# Set page title, and collect existing contexts in @contexts
|
||||
#
|
||||
def list
|
||||
self.init
|
||||
@page_title = "TRACKS::List Contexts"
|
||||
@contexts = Context.find(:all, :conditions => nil, :order => "position ASC", :limit => nil )
|
||||
end
|
||||
|
||||
# Filter the projects to show just the one passed in the URL
|
||||
# e.g. <home>/project/show/<project_name> shows just <project_name>.
|
||||
#
|
||||
def show
|
||||
@context = Context.find_by_name(deurlize(@params["name"]))
|
||||
@places = Context.find(:all, :order => "position ASC")
|
||||
@projects = Project.find( :all, :conditions => "done=0", :order => "position ASC" )
|
||||
self.init
|
||||
self.init_todos
|
||||
self.check_user_set_context
|
||||
@page_title = "TRACKS::Context: #{@context.name}"
|
||||
@not_done = Todo.find(:all, :conditions => "done=0 AND context_id=#{@context.id}",
|
||||
:order => "due IS NULL, due ASC, created ASC")
|
||||
@done = Todo.find(:all, :conditions => "done=1 AND context_id=#{@context.id}",
|
||||
:order => "completed DESC")
|
||||
@count = Todo.count( "context_id=#{@context.id} AND done=0" )
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# Creates a new context via Ajax helpers
|
||||
#
|
||||
def new_context
|
||||
@context = Context.new(@params['context'])
|
||||
if @context.save
|
||||
render_partial( 'context_listing', @context )
|
||||
context = @session['user'].contexts.build
|
||||
context.attributes = @params['context']
|
||||
context.name = deurlize(context.name)
|
||||
|
||||
if context.save
|
||||
render :partial => 'context_listing', :locals => { :context_listing => context }
|
||||
else
|
||||
flash["warning"] = "Couldn't add new context"
|
||||
render_text "#{flash["warning"]}"
|
||||
render :text => "#{flash["warning"]}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Edit the details of the context
|
||||
#
|
||||
#
|
||||
def update
|
||||
context = Context.find(params[:id])
|
||||
context.attributes = @params["context"]
|
||||
if context.save
|
||||
render_partial 'context_listing', context
|
||||
check_user_set_context
|
||||
@context.attributes = @params["context"]
|
||||
@context.name = deurlize(@context.name)
|
||||
if @context.save
|
||||
render_partial 'context_listing', @context
|
||||
else
|
||||
flash["warning"] = "Couldn't update new context"
|
||||
render_text ""
|
||||
render :text => ""
|
||||
end
|
||||
end
|
||||
|
||||
# Edit the details of the action in this context
|
||||
#
|
||||
def update_action
|
||||
@places = Context.find(:all, :order => "position ASC")
|
||||
@projects = Project.find( :all, :conditions => "done=0", :order => "position ASC" )
|
||||
action = Todo.find(params[:id])
|
||||
action.attributes = @params["item"]
|
||||
if action.due?
|
||||
action.due = Date.strptime(@params["item"]["due"], DATE_FORMAT)
|
||||
else
|
||||
action.due = ""
|
||||
end
|
||||
|
||||
if action.save
|
||||
render_partial 'show_items', action
|
||||
else
|
||||
flash["warning"] = "Couldn't update the action"
|
||||
render_text ""
|
||||
end
|
||||
end
|
||||
|
||||
# Called by a form button
|
||||
# Parameters from form fields are passed to create new action
|
||||
#
|
||||
def add_item
|
||||
@projects = Project.find( :all, :conditions => "done=0", :order => "position ASC" )
|
||||
@places = Context.find( :all, :order => "position ASC" )
|
||||
|
||||
item = Todo.new
|
||||
item.attributes = @params["new_item"]
|
||||
|
||||
if item.due?
|
||||
item.due = Date.strptime(@params["new_item"]["due"], DATE_FORMAT)
|
||||
else
|
||||
item.due = ""
|
||||
end
|
||||
|
||||
if item.save
|
||||
render_partial 'show_items', item
|
||||
else
|
||||
flash["warning"] = "Couldn't add next action \"#{item.description}\""
|
||||
render_text ""
|
||||
end
|
||||
end
|
||||
|
||||
# Fairly self-explanatory; deletes the context
|
||||
# If the context contains actions, you'll get a warning dialogue.
|
||||
# If you choose to go ahead, any actions in the context will also be deleted.
|
||||
def destroy
|
||||
this_context = Context.find(params[:id])
|
||||
if this_context.destroy
|
||||
def destroy
|
||||
check_user_set_context
|
||||
if @context.destroy
|
||||
render_text ""
|
||||
else
|
||||
flash["warning"] = "Couldn't delete context \"#{context.name}\""
|
||||
flash["warning"] = "Couldn't delete context \"#{@context.name}\""
|
||||
redirect_to( :controller => "context", :action => "list" )
|
||||
end
|
||||
end
|
||||
|
||||
# Delete a next action in a context
|
||||
#
|
||||
def destroy_action
|
||||
item = Todo.find(params[:id])
|
||||
if item.destroy
|
||||
render_text ""
|
||||
else
|
||||
flash["warning"] = "Couldn't delete next action \"#{item.description}\""
|
||||
redirect_to :action => "list"
|
||||
end
|
||||
end
|
||||
|
||||
# Toggles the 'done' status of the action
|
||||
#
|
||||
def toggle_check
|
||||
@places = Context.find(:all, :order => "position ASC")
|
||||
@projects = Project.find( :all, :conditions => "done=0", :order => "position ASC" )
|
||||
|
||||
item = Todo.find(params[:id])
|
||||
|
||||
item.toggle!('done')
|
||||
render_partial 'show_items', item
|
||||
end
|
||||
|
||||
# Methods for changing the sort order of the contexts in the list
|
||||
#
|
||||
def move_up
|
||||
line = Context.find(params[:id])
|
||||
line.move_higher
|
||||
line.save
|
||||
check_user_set_context
|
||||
@context.move_higher
|
||||
@context.save
|
||||
redirect_to(:controller => "context", :action => "list")
|
||||
end
|
||||
|
||||
|
||||
def move_down
|
||||
line = Context.find(params[:id])
|
||||
line.move_lower
|
||||
line.save
|
||||
check_user_set_context
|
||||
@context.move_lower
|
||||
@context.save
|
||||
redirect_to(:controller => "context", :action => "list")
|
||||
end
|
||||
|
||||
|
||||
def move_top
|
||||
line = Context.find(params[:id])
|
||||
line.move_to_top
|
||||
line.save
|
||||
check_user_set_context
|
||||
@context.move_to_top
|
||||
@context.save
|
||||
redirect_to(:controller => "context", :action => "list")
|
||||
end
|
||||
|
||||
|
||||
def move_bottom
|
||||
line = Context.find(params[:id])
|
||||
line.move_to_bottom
|
||||
line.save
|
||||
check_user_set_context
|
||||
@context.move_to_bottom
|
||||
@context.save
|
||||
redirect_to(:controller => "context", :action => "list" )
|
||||
end
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def check_user_set_context
|
||||
@user = @session['user']
|
||||
if @params["name"]
|
||||
@context = Context.find_by_name_and_user_id(deurlize(@params["name"]), @user.id)
|
||||
elsif @params['id']
|
||||
@context = Context.find_by_id_and_user_id(@params["id"], @user.id)
|
||||
else
|
||||
redirect_to(:controller => "context", :action => "list" )
|
||||
end
|
||||
if @user == @context.user
|
||||
return @context
|
||||
else
|
||||
@context = nil # Should be nil anyway.
|
||||
flash["warning"] = "Item and session user mis-match: #{@context.user_id} and #{@session['user'].id}!"
|
||||
render_text ""
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def init
|
||||
@user = @session['user']
|
||||
@projects = @user.projects.collect { |x| x.done? ? nil:x }.compact
|
||||
@contexts = @user.contexts
|
||||
end
|
||||
|
||||
def init_todos
|
||||
check_user_set_context
|
||||
@done = @context.find_done_todos
|
||||
@not_done = @context.find_not_done_todos
|
||||
@count = @not_done.size
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue