Bug #300: Actions can be created with dependencies through the add_new_item_form

Still lacks error checking for circular dependencies and other validation.
Also, javascript for displaying the new item is broken.

Conflicts:

	app/views/layouts/standard.html.erb
This commit is contained in:
Eric Allen 2009-11-04 22:45:38 -05:00
parent 6d97bca57f
commit 1f556a4f0a
3 changed files with 53 additions and 19 deletions

View file

@ -54,6 +54,7 @@ class TodosController < ApplicationController
p = TodoCreateParamsHelper.new(params, prefs)
p.parse_dates() unless mobile?
tag_list = p.tag_list
predecessor_list = p.predecessor_list
@todo = current_user.todos.build(p.attributes)
@ -77,6 +78,14 @@ class TodosController < ApplicationController
@todo.tags.reload
end
unless predecessor_list.blank?
@todo.add_predecessor_list(predecessor_list)
unless @todo.uncompleted_predecessors.empty? || @todo.state == 'project_hidden'
@todo.state = 'pending'
end
@saved = @todo.save
end
respond_to do |format|
format.html { redirect_to :action => "index" }
format.m do
@ -559,20 +568,29 @@ class TodosController < ApplicationController
end
def auto_complete_for_predecessor
get_todo_from_params
# Begin matching todos in current project
@items = current_user.todos.find(:all,
:conditions => [ 'NOT (id = ?) AND description LIKE ? AND project_id = ?',
@todo.id,
'%' + params[:predecessor_list] + '%',
@todo.project_id ],
:order => 'description ASC',
:limit => 10
)
if @items.empty? # Match todos in other projects
unless params['id'].nil?
get_todo_from_params
# Begin matching todos in current project
@items = current_user.todos.find(:all,
:conditions => [ 'NOT (id = ?) AND description LIKE ?',
params[:id], '%' + params[:predecessor_list] + '%' ],
:conditions => [ 'NOT (id = ?) AND description LIKE ? AND project_id = ?',
@todo.id,
'%' + params[:predecessor_list] + '%',
@todo.project_id ],
:order => 'description ASC',
:limit => 10
)
if @items.empty? # Match todos in other projects
@items = current_user.todos.find(:all,
:conditions => [ 'NOT (id = ?) AND description LIKE ?',
params[:id], '%' + params[:predecessor_list] + '%' ],
:order => 'description ASC',
:limit => 10
)
end
else
# New todo - TODO: Filter on project
@items = current_user.todos.find(:all,
:conditions => [ 'description LIKE ?', '%' + params[:predecessor_list] + '%' ],
:order => 'description ASC',
:limit => 10
)
@ -1023,6 +1041,10 @@ class TodosController < ApplicationController
def tag_list
@params['tag_list']
end
def predecessor_list
@params['predecessor_list']
end
def parse_dates()
@attributes['show_from'] = @prefs.parse_date(show_from)

View file

@ -74,7 +74,11 @@ class Todo < ActiveRecord::Base
def update_state_from_project
if state == 'project_hidden' and !project.hidden?
self.state = 'active'
if self.uncompleted_predecessors.empty?
self.state = 'pending'
else
self.state = 'active'
end
elsif state == 'active' and project.hidden?
self.state = 'project_hidden'
end
@ -154,10 +158,6 @@ class Todo < ActiveRecord::Base
return self.recurring_todo_id != nil
end
def add_predecessor(predecessor)
logger.debug "add_predecessor #{predecessor.description}"
end
# TODO: DELIMITER
# TODO: Todo::Error
# TODO: Handle todos with the same description
@ -181,7 +181,11 @@ class Todo < ActiveRecord::Base
t = Todo.find_by_description(description)
#raise Todo::Error, "predecessor could not be found: #{description}" if t.nil?
# Create dependency record
self.predecessors << t unless self.predecessors.include?(t)
unless t.nil?
self.predecessors << t unless self.predecessors.include?(t)
else
logger.error "Could not find #{description}"
end
end
# debugger

View file

@ -51,6 +51,14 @@
<%= text_field("todo", "show_from", "size" => 12, "class" => "Date", "tabindex" => 7, "autocomplete" => "off") %>
</div>
<label for="predecessor_list">Depends on</label>
<%= text_field_tag "predecessor_list", nil, :size => 30, :tabindex => 8 %>
<%= content_tag("div", "", :id => "predecessor_list_auto_complete", :class => "auto_complete") %>
<%= auto_complete_field 'predecessor_list', {
:url => {:controller => 'todos', :action => 'auto_complete_for_predecessor', :id => nil},
:tokens => [',']
} %>
<%= source_view_tag( @source_view ) %>
<%= hidden_field_tag :_tag_name, @tag_name.underscore.gsub(/\s+/,'_') if source_view_is :tag %>