diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-05 21:49:21 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-05 21:49:21 +0200 |
| commit | 1fa2f3821497d5529a6753cee84cf5ca679e8bcc (patch) | |
| tree | 7c6e98cfc9fc0b452e055c6201fb8aefa3c71965 /app/controllers | |
| parent | 9c630d186003a47563be2e3547485060dac7dd98 (diff) | |
Fix admin search results colliding with other search widgets
layouts/admin.html.erb's top-bar search results div shared id
"search_results" with nodes#new/nodes#edit's parent-search widget -
since the layout renders on every admin page, whichever widget's JS
ran last silently won the shared ID, putting top-bar results into the
parent-search box on affected pages. Renamed to "menu_search_results"
and updated admin_search.js to match.
Also modernizes admin_search.js's event bindings from keyup/keydown/
keypress/paste/cut + .attr("value") to input + .val() throughout
(menu_items, parent_search, move_to_search) - the multi-event binding
was working around old IE compatibility that .val() + "input" already
handles correctly. parent_search's result rendering now matches
menu_search's convention (real <p>/<a> markup with a .result_path
span) instead of a bare <a> in a throwaway wrapper div, so the same
CSS rule now correctly applies to both.
menu_search's JSON response gains node_path per result, matching what
admin_search's own results already provide - not yet consumed by
parent_search/move_to_search, which still render click-to-select links
rather than navigable ones (correct for their purpose - selecting a
value, not leaving the page).
Known remaining gap, not fixed here: menu_items, parent_search, and
move_to_search still all target the literal id "search_results"
between themselves. No live collision today since none of the three
currently share a page, but it's the same fragility as the bug above -
tracked alongside the existing menu_items/parent_search/move_to_search
consolidation backlog item rather than treated as resolved.
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin_controller.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d671384..e0098b0 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -29,46 +29,49 @@ class AdminController < ApplicationController | |||
| 29 | .order("updated_at desc") | 29 | .order("updated_at desc") |
| 30 | .uniq.first(50) | 30 | .uniq.first(50) |
| 31 | end | 31 | end |
| 32 | 32 | ||
| 33 | def conventions | ||
| 34 | @node_kinds = CccConventions::NODE_KINDS | ||
| 35 | end | ||
| 36 | |||
| 33 | def search | 37 | def search |
| 34 | @results = Node.search params[:search_term], :per_page => 1000 | 38 | @results = Node.search params[:search_term], :per_page => 1000 |
| 35 | 39 | ||
| 36 | respond_to do |format| | 40 | respond_to do |format| |
| 37 | format.html do | 41 | format.html do |
| 38 | render :template => 'admin/search_results' | 42 | render :template => 'admin/search_results' |
| 39 | end | 43 | end |
| 40 | format.js do | 44 | format.js do |
| 41 | render( :json => @results.map do |node| | 45 | render( :json => @results.map do |node| |
| 42 | if node | 46 | if node |
| 43 | { :id => node.id, :title => node.title, :unique_name => node.unique_name, :node_path => node_path(node) } | 47 | { :id => node.id, :title => node.title, :unique_name => node.unique_name, :node_path => node_path(node) } |
| 44 | end | 48 | end |
| 45 | end | 49 | end |
| 46 | ) | 50 | ) |
| 47 | 51 | ||
| 48 | end | 52 | end |
| 49 | end | 53 | end |
| 50 | end | 54 | end |
| 51 | 55 | ||
| 52 | def menu_search | 56 | def menu_search |
| 53 | if params[:search_term] == "Root" | 57 | if params[:search_term] == "Root" |
| 54 | @results = [Node.root] | 58 | @results = [Node.root] |
| 55 | else | 59 | else |
| 56 | @results = Node.search params[:search_term] | 60 | @results = Node.search params[:search_term] |
| 57 | end | 61 | end |
| 58 | 62 | ||
| 59 | respond_to do |format| | 63 | respond_to do |format| |
| 60 | format.html do | 64 | format.html do |
| 61 | render :partial => 'admin/menu_search_results' | 65 | render :partial => 'admin/menu_search_results' |
| 62 | end | 66 | end |
| 63 | 67 | ||
| 64 | format.js do | 68 | format.js do |
| 65 | render( :json => @results.map do |node| | 69 | render( :json => @results.map do |node| |
| 66 | {:node_id => node.id, :title => node.title, :unique_name => node.unique_name} | 70 | {:node_id => node.id, :title => node.title, :unique_name => node.unique_name, :node_path => node_path(node)} |
| 67 | end | 71 | end |
| 68 | ) | 72 | ) |
| 69 | 73 | ||
| 70 | end | 74 | end |
| 71 | end | 75 | end |
| 72 | end | 76 | end |
| 73 | |||
| 74 | end | 77 | end |
