summaryrefslogtreecommitdiff
path: root/app/controllers/nodes_controller.rb
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-08 17:32:17 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-08 17:32:17 +0200
commitbc03601ee5c7acd4ef012ec4a404bd7b76bceaa0 (patch)
tree9b160ea6194ffe27b6d8471b92a84bd0bdad4e2b /app/controllers/nodes_controller.rb
parent6ad96c44d04df01e6abde097c681e824dd5fe745 (diff)
Add revert!/discard and rebuild nodes#edit around the new hierarchy
revert! discards exactly the topmost non-empty layer -- autosave if present, else draft -- and reveals whatever's beneath it, releasing the lock only once nothing is left to protect. Guards against destroying a brand-new, never-published node's only draft, which would violate the (head | draft) invariant every other method here assumes holds; the view's Destroy/Discard button is gated the same way. nodes#edit now calls lock_for_editing! instead of find_or_create_draft, and always displays autosave || draft || head, resurrecting an abandoned session's unsaved content by default with an explicit flash explaining what's shown and how to get back to the last saved version. The view drops content_for :subnavigation entirely: Show becomes "Unlock + Back", Preview stays a plain link, metadata's own <details> already replaced the old toggle, and Publish moves off this page for good, per the earlier decision to manage the publish lifecycle entirely from nodes#show. Save Draft and Save + Unlock + Exit appear both above and below the form, given the body field alone runs 600px on desktop.
Diffstat (limited to 'app/controllers/nodes_controller.rb')
-rw-r--r--app/controllers/nodes_controller.rb34
1 files changed, 24 insertions, 10 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index 042963b..6fd000b 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -12,7 +12,8 @@ class NodesController < ApplicationController
12 :destroy, 12 :destroy,
13 :publish, 13 :publish,
14 :unlock, 14 :unlock,
15 :autosave 15 :autosave,
16 :revert
16 ] 17 ]
17 18
18 def index 19 def index
@@ -59,16 +60,17 @@ class NodesController < ApplicationController
59 end 60 end
60 61
61 def edit 62 def edit
62 begin 63 @node.lock_for_editing!( current_user )
63 @draft = @node.find_or_create_draft( current_user ) 64 @page = @node.autosave || @node.draft || @node.head
64 rescue LockedByAnotherUser => e 65
65 flash[:error] = e.message 66 if @node.autosave
66 if request.referer 67 flash.now[:notice] =
67 redirect_to request.referer || node_path(@node) 68 "This page has unsaved changes from a previous session, shown below. " \
68 else 69 "Save to keep them, or use \"Discard changes\" below to go back to the last saved version."
69 redirect_to node_path(@node)
70 end
71 end 70 end
71 rescue LockedByAnotherUser => e
72 flash[:error] = e.message
73 redirect_to(request.referer || node_path(@node))
72 end 74 end
73 75
74 def update 76 def update
@@ -104,6 +106,18 @@ class NodesController < ApplicationController
104 render plain: "Autosave failed", status: :internal_server_error 106 render plain: "Autosave failed", status: :internal_server_error
105 end 107 end
106 108
109 def revert
110 @node.revert!(current_user)
111 if @node.draft
112 redirect_to edit_node_path(@node)
113 else
114 redirect_to node_path(@node)
115 end
116 rescue LockedByAnotherUser => e
117 flash[:error] = e.message
118 redirect_to node_path(@node)
119 end
120
107 def destroy 121 def destroy
108 @node.destroy 122 @node.destroy
109 end 123 end