diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-06-29 04:28:55 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-06-29 04:30:22 +0200 |
| commit | 191a77b2f7c280e00f7348507c13a173c704fcf9 (patch) | |
| tree | 56bd250c1b135f149c85ddb3be322c3f3139c9eb | |
| parent | c96fbbb701ec97f9f6c69ca0d51ed3cd895b260e (diff) | |
Restore and improve admin node search
- Admin search broke when routing-filter was removed: hardcoded /admin/search
and /admin/menu_search URLs in admin_search.js no longer matched the
locale-scoped routes. Fix by emitting locale-aware URLs from the layout
as JS variables.
- Also fixes form submission (POST -> GET, missing = on form_tag), jQuery
.attr("value") -> .val() for typeahead input reading, and template name
for Rails 8 compatibility.
- Adds a visible "search" link to the admin menu so editors can discover
the feature without knowing the Alt+F shortcut. Search results now show
node path alongside title and link directly to the edit view.
Named route admin_menu_search added to routes.rb.
| -rw-r--r-- | app/controllers/admin_controller.rb | 4 | ||||
| -rw-r--r-- | app/views/admin/_menu.html.erb | 1 | ||||
| -rw-r--r-- | app/views/admin/search_results.html.erb | 2 | ||||
| -rw-r--r-- | app/views/layouts/admin.html.erb | 6 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | public/javascripts/admin_search.js | 17 |
6 files changed, 21 insertions, 10 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 9e8564e..1a94a77 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -35,12 +35,12 @@ class AdminController < ApplicationController | |||
| 35 | 35 | ||
| 36 | respond_to do |format| | 36 | respond_to do |format| |
| 37 | format.html do | 37 | format.html do |
| 38 | render :template => 'admin/search_results.html' | 38 | render :template => 'admin/search_results' |
| 39 | end | 39 | end |
| 40 | format.js do | 40 | format.js do |
| 41 | render( :json => @results.map do |node| | 41 | render( :json => @results.map do |node| |
| 42 | if node | 42 | if node |
| 43 | {:id => node.id, :title => node.title, :edit_path => node_path(node)} | 43 | {:id => node.id, :title => " #{node.title} (#{node.unique_name})", :edit_path => edit_node_path(node)} |
| 44 | end | 44 | end |
| 45 | end | 45 | end |
| 46 | ) | 46 | ) |
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 6f217eb..6dba085 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | <%= language_selector %> | 1 | <%= language_selector %> |
| 2 | <%= button_to 'Logout', logout_path, method: :delete %> | 2 | <%= button_to 'Logout', logout_path, method: :delete %> |
| 3 | <%= link_to 'Overview', admin_path %> | 3 | <%= link_to 'Overview', admin_path %> |
| 4 | <a href="#" onclick="admin_search.display_toggle(); return false;">search</a> | ||
| 4 | <%= link_to 'Nodes', nodes_path, selected?('nodes') %> | 5 | <%= link_to 'Nodes', nodes_path, selected?('nodes') %> |
| 5 | <%= link_to 'Assets', assets_path, selected?('assets') %> | 6 | <%= link_to 'Assets', assets_path, selected?('assets') %> |
| 6 | <%= link_to 'User', users_path, selected?('users') %> | 7 | <%= link_to 'User', users_path, selected?('users') %> |
diff --git a/app/views/admin/search_results.html.erb b/app/views/admin/search_results.html.erb index 671b665..f8aece0 100644 --- a/app/views/admin/search_results.html.erb +++ b/app/views/admin/search_results.html.erb | |||
| @@ -2,6 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | <ul> | 3 | <ul> |
| 4 | <%- @results.each do |result| %> | 4 | <%- @results.each do |result| %> |
| 5 | <li><a href="<%= node_path(result) %>"><%= result.title %></a></li> | 5 | <li><%= link_to "#{result.title} (#{result.unique_name})", edit_node_path(result) %></li> |
| 6 | <% end %> | 6 | <% end %> |
| 7 | </ul> | 7 | </ul> |
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 890aeaa..c1cada3 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb | |||
| @@ -13,6 +13,10 @@ | |||
| 13 | <link rel="stylesheet" href="/stylesheets/admin.css"> | 13 | <link rel="stylesheet" href="/stylesheets/admin.css"> |
| 14 | <script src="/javascripts/admin_search.js"></script> | 14 | <script src="/javascripts/admin_search.js"></script> |
| 15 | <script src="/javascripts/admin_interface.js"></script> | 15 | <script src="/javascripts/admin_interface.js"></script> |
| 16 | <script> | ||
| 17 | var ADMIN_SEARCH_URL = "<%= admin_search_path %>"; | ||
| 18 | var ADMIN_MENU_SEARCH_URL = "<%= admin_menu_search_path %>"; | ||
| 19 | </script> | ||
| 16 | </head> | 20 | </head> |
| 17 | 21 | ||
| 18 | <body> | 22 | <body> |
| @@ -41,7 +45,7 @@ | |||
| 41 | 45 | ||
| 42 | <div id="search_widget" style="display: none;"> | 46 | <div id="search_widget" style="display: none;"> |
| 43 | <div> | 47 | <div> |
| 44 | <% form_tag admin_search_path do %> | 48 | <%= form_tag admin_search_path, method: :get do %> |
| 45 | <span>Search: </span><%= text_field_tag :search_term %> | 49 | <span>Search: </span><%= text_field_tag :search_term %> |
| 46 | <% end %> | 50 | <% end %> |
| 47 | </div> | 51 | </div> |
diff --git a/config/routes.rb b/config/routes.rb index 92f2452..88f49a2 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
| @@ -54,6 +54,7 @@ Cccms::Application.routes.draw do | |||
| 54 | match '/login' => 'sessions#new', :as => :login, :via => :get | 54 | match '/login' => 'sessions#new', :as => :login, :via => :get |
| 55 | match 'admin' => 'admin#index', :as => :admin, :via => :get | 55 | match 'admin' => 'admin#index', :as => :admin, :via => :get |
| 56 | match 'admin/search' => 'admin#search', :as => :admin_search, :via => :get | 56 | match 'admin/search' => 'admin#search', :as => :admin_search, :via => :get |
| 57 | match 'admin/menu_search' => 'admin#menu_search', :as => :admin_menu_search, :via => :get | ||
| 57 | match 'search' => 'search#index', :as => :search, :via => :get | 58 | match 'search' => 'search#index', :as => :search, :via => :get |
| 58 | 59 | ||
| 59 | resources :users | 60 | resources :users |
diff --git a/public/javascripts/admin_search.js b/public/javascripts/admin_search.js index 78577e7..8ff0db1 100644 --- a/public/javascripts/admin_search.js +++ b/public/javascripts/admin_search.js | |||
| @@ -18,14 +18,19 @@ admin_search = { | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | $("#search_term").bind("keyup", function() { | 20 | $("#search_term").bind("keyup", function() { |
| 21 | if ($(this).attr("value")) { | 21 | console.log("keyup fired, value:", $(this).val()); |
| 22 | if ($(this).val()) { | ||
| 23 | console.log("sending ajax to", ADMIN_SEARCH_URL); | ||
| 22 | $.ajax({ | 24 | $.ajax({ |
| 23 | type: "GET", | 25 | type: "GET", |
| 24 | url: "/admin/search", | 26 | url: ADMIN_SEARCH_URL, |
| 25 | data: "search_term=" + $(this).attr("value"), | 27 | data: "search_term=" + $(this).val(), |
| 26 | dataType: "json", | 28 | dataType: "json", |
| 27 | success : function(results) { | 29 | success : function(results) { |
| 28 | admin_search.show_results(results); | 30 | admin_search.show_results(results); |
| 31 | }, | ||
| 32 | error: function(xhr, status, error) { | ||
| 33 | console.log("Ajax error:", status, error, xhr.status, xhr.responseText); | ||
| 29 | } | 34 | } |
| 30 | }); | 35 | }); |
| 31 | } | 36 | } |
| @@ -52,7 +57,7 @@ menu_items = { | |||
| 52 | if ($(this).attr("value")) { | 57 | if ($(this).attr("value")) { |
| 53 | $.ajax({ | 58 | $.ajax({ |
| 54 | type: "GET", | 59 | type: "GET", |
| 55 | url: "/admin/menu_search", | 60 | url: ADMIN_MENU_SEARCH_URL, |
| 56 | data: "search_term=" + $(this).attr("value"), | 61 | data: "search_term=" + $(this).attr("value"), |
| 57 | dataType: "json", | 62 | dataType: "json", |
| 58 | success : function(results) { | 63 | success : function(results) { |
| @@ -104,7 +109,7 @@ parent_search = { | |||
| 104 | if ($(this).attr("value")) { | 109 | if ($(this).attr("value")) { |
| 105 | $.ajax({ | 110 | $.ajax({ |
| 106 | type: "GET", | 111 | type: "GET", |
| 107 | url: "/admin/menu_search", | 112 | url: ADMIN_MENU_SEARCH_URL, |
| 108 | data: "search_term=" + $(this).attr("value"), | 113 | data: "search_term=" + $(this).attr("value"), |
| 109 | dataType: "json", | 114 | dataType: "json", |
| 110 | success : function(results) { | 115 | success : function(results) { |
| @@ -184,7 +189,7 @@ move_to_search = { | |||
| 184 | if (_this.attr("value")) { | 189 | if (_this.attr("value")) { |
| 185 | $.ajax({ | 190 | $.ajax({ |
| 186 | type: "GET", | 191 | type: "GET", |
| 187 | url: "/admin/menu_search", | 192 | url: ADMIN_MENU_SEARCH_URL, |
| 188 | data: "search_term=" + _this.attr("value"), | 193 | data: "search_term=" + _this.attr("value"), |
| 189 | dataType: "json", | 194 | dataType: "json", |
| 190 | success : function(results) { | 195 | success : function(results) { |
