From a8cf725312d245d8d1f1df0fff22718975ce249e Mon Sep 17 00:00:00 2001 From: erdgeist Date: Thu, 20 Aug 2026 12:50:30 +0200 Subject: Add redirect ui in in nodes#edit and apply some minor cleanup Also give search inputs a magnifier and a clear control: input_group wraps a field with an icon and, where clearing is meaningful, a button that empties it and any hidden companion named by data-clears. Clean up some inconistency between field hints presented as p and as span. Remove stray console.log. --- app/controllers/content_controller.rb | 5 ++++ app/models/page.rb | 26 ++++++++++------- app/views/nodes/edit.html.erb | 53 ++++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 24 deletions(-) (limited to 'app') diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index 8be4bfbd..debb69b9 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -14,6 +14,11 @@ class ContentController < ApplicationController expires_in 20.minutes, :public => true if @page and @page.public? + if (target = @page.redirect_target) + return redirect_to(target.internal? ? content_path(target.node.unique_name) : target.url, + :status => @page.redirect_status) + end + render( :template => @page.valid_template, :layout => true diff --git a/app/models/page.rb b/app/models/page.rb index 9115ccb0..b17708e7 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -124,7 +124,7 @@ class Page < ApplicationRecord end # One row per non-default locale, read from the actual translation - # row -- never through the locale-dependent accessor, so a locale + # row, never through the locale-dependent accessor, so a locale # with no real translation yet reports as absent rather than quietly # showing a fallback value borrowed from another locale. def translation_summary @@ -311,21 +311,27 @@ class Page < ApplicationRecord published_at.nil? ? true : published_at < Time.now end - # The destination this page sends visitors to, or nil. An internal target - # wins over an external one. A target that is restricted or has no head is - # no destination at all, so the page renders itself rather than linking to - # nothing. The banner partial calls this too, so the precedence cannot - # drift between the redirect and the link. + # Where this page sends visitors, or nil. Internal wins over external. A + # node that is restricted or has no head is no destination at all, so the + # page renders itself rather than pointing at nothing. + RedirectTarget = Struct.new(:node, :url) do + def internal? + node.present? + end + end + def redirect_target return nil if redirect.blank? if redirect_node_id.present? - node = Node.find_by(:id => redirect_node_id) - return nil unless node&.head && !node.restricted? - return node.unique_name + target = Node.find_by(:id => redirect_node_id) + return nil unless target&.head && !target.restricted? + return RedirectTarget.new(target, nil) end - external_url.presence + return RedirectTarget.new(nil, external_url) if external_url.present? + + nil end def redirect_status diff --git a/app/views/nodes/edit.html.erb b/app/views/nodes/edit.html.erb index 927cc648..f629985e 100644 --- a/app/views/nodes/edit.html.erb +++ b/app/views/nodes/edit.html.erb @@ -80,7 +80,7 @@ <% end %> -

<%= t(".headline_hint") %>

+ <%= t(".headline_hint") %> <%= text_field_tag nil, nil, id: "related_asset_search_term", placeholder: t(".attach_search_placeholder"), autocomplete: "off" %> @@ -118,7 +118,7 @@
<%= t(".parent") %>
<%= text_field_tag :move_to_search_term, (Node.find_by(:id => @page.parent_node_id) || @node.parent)&.title %> -

<%= t(".parent_hint") %>

+ <%= t(".parent_hint") %>
<%= d.hidden_field( :parent_node_id, @@ -128,6 +128,43 @@
+
+
<%= t(".author") %>
+
+ <%= d.select :user_id, user_list, + :selected => @page.user_id || @node.draft&.user_id || @node.head&.user_id %> +
+
+ +
+
<%= t(".publish_at") %>
+
<%= d.datetime_select :published_at, :value => @page.published_at %>
+
+ +
+
<%= t(".redirect") %>
+
+ + <%= t(".redirect_hint") %> + +
"> +
+ <%= icon("search", library: "tabler", "aria-hidden": true) %> + <%= text_field_tag :redirect_search_term, + Node.find_by(:id => @page.redirect_node_id)&.title, + :placeholder => "—", :class => "clearable_input" %> +
+ + <%= d.hidden_field :redirect_node_id %> +
+
+
+
+
<%= t(".external_url") %>
@@ -143,11 +180,6 @@
-
-
<%= t(".publish_at") %>
-
<%= d.datetime_select :published_at, :value => @page.published_at %>
-
-
<%= t(".template") %>
@@ -156,13 +188,6 @@
-
-
<%= t(".author") %>
-
- <%= d.select :user_id, user_list, - :selected => @page.user_id || @node.draft&.user_id || @node.head&.user_id %> -
-
-- cgit v1.3