mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 16:20:12 +01:00
let autocomplete fail gracefully when param is not set
This commit is contained in:
parent
05ba6060fc
commit
1a821a228f
3 changed files with 13 additions and 10 deletions
|
|
@ -128,9 +128,13 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_autocomplete(coll, substr)
|
def for_autocomplete(coll, substr)
|
||||||
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
|
if substr # protect agains empty request
|
||||||
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
|
filtered = coll.find_all{|item| item.name.downcase.include? substr.downcase}
|
||||||
return json_elems == "[{}]" ? "" : json_elems
|
json_elems = "[{" + filtered.map {|item| "\"value\" : \"#{item.name}\", \"id\" : \"#{item.id}\""}.join("},{") + "}]"
|
||||||
|
return json_elems == "[{}]" ? "" : json_elems
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Uses RedCloth to transform text using either Textile or Markdown Need to
|
# Uses RedCloth to transform text using either Textile or Markdown Need to
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@source_view = params['_source_view'] || 'project_list'
|
@source_view = params['_source_view'] || 'project_list'
|
||||||
@projects = current_user.projects.all
|
|
||||||
@new_project = current_user.projects.build
|
@new_project = current_user.projects.build
|
||||||
if params[:projects_and_actions]
|
if params[:projects_and_actions]
|
||||||
projects_and_actions
|
projects_and_actions
|
||||||
|
|
@ -18,6 +17,8 @@ class ProjectsController < ApplicationController
|
||||||
init_not_done_counts(['project'])
|
init_not_done_counts(['project'])
|
||||||
if params[:only_active_with_no_next_actions]
|
if params[:only_active_with_no_next_actions]
|
||||||
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
|
@projects = current_user.projects.active.select { |p| count_undone_todos(p) == 0 }
|
||||||
|
else
|
||||||
|
@projects = current_user.projects.all
|
||||||
end
|
end
|
||||||
init_project_hidden_todo_counts(['project'])
|
init_project_hidden_todo_counts(['project'])
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
@ -27,9 +28,7 @@ class ProjectsController < ApplicationController
|
||||||
format.rss &render_rss_feed
|
format.rss &render_rss_feed
|
||||||
format.atom &render_atom_feed
|
format.atom &render_atom_feed
|
||||||
format.text &render_text_feed
|
format.text &render_text_feed
|
||||||
format.autocomplete {
|
format.autocomplete { render :text => for_autocomplete(current_user.projects.uncompleted, params[:term]) }
|
||||||
uncompleted_projects = current_user.projects.uncompleted(true)
|
|
||||||
render :text => for_autocomplete(uncompleted_projects, params[:term]) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -139,7 +138,7 @@ class ProjectsController < ApplicationController
|
||||||
render :template => 'projects/update.js.erb'
|
render :template => 'projects/update.js.erb'
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO: are these params ever set? or is this dead code?
|
# TODO: are these params ever set? or is this dead code?
|
||||||
|
|
||||||
elsif boolean_param('update_status')
|
elsif boolean_param('update_status')
|
||||||
render :template => 'projects/update_status.js.rjs'
|
render :template => 'projects/update_status.js.rjs'
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ Feature: Edit a next action from every page
|
||||||
Scenario: I can delete a todo
|
Scenario: I can delete a todo
|
||||||
Given this is a pending scenario
|
Given this is a pending scenario
|
||||||
|
|
||||||
Scenario: Deleting the last todo in context will hide context
|
Scenario: Removing the last todo in context will hide context # delete, edit
|
||||||
Given this is a pending scenario
|
Given this is a pending scenario
|
||||||
|
|
||||||
Scenario: Deleting the last todo in container will show empty message
|
Scenario: Deleting the last todo in container will show empty message # only project, context, tag, not todo
|
||||||
Given this is a pending scenario
|
Given this is a pending scenario
|
||||||
|
|
||||||
Scenario: I can mark a todo complete
|
Scenario: I can mark a todo complete
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue