diff options
Diffstat (limited to 'app/controllers/nodes_controller.rb')
| -rw-r--r-- | app/controllers/nodes_controller.rb | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb index bff1733..6caa827 100644 --- a/app/controllers/nodes_controller.rb +++ b/app/controllers/nodes_controller.rb | |||
| @@ -13,7 +13,9 @@ class NodesController < ApplicationController | |||
| 13 | :publish, | 13 | :publish, |
| 14 | :unlock, | 14 | :unlock, |
| 15 | :autosave, | 15 | :autosave, |
| 16 | :revert | 16 | :revert, |
| 17 | :trash, | ||
| 18 | :restore_from_trash | ||
| 17 | ] | 19 | ] |
| 18 | 20 | ||
| 19 | around_action :pin_to_default_locale, :only => [:show, :edit, :update, :autosave] | 21 | around_action :pin_to_default_locale, :only => [:show, :edit, :update, :autosave] |
| @@ -27,10 +29,7 @@ class NodesController < ApplicationController | |||
| 27 | def new | 29 | def new |
| 28 | @node = Node.new node_params | 30 | @node = Node.new node_params |
| 29 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 31 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 30 | if params.has_key?(:parent_id) | 32 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 31 | @parent_id = params[:parent_id] | ||
| 32 | @parent_name = Node.find(@parent_id).title | ||
| 33 | end | ||
| 34 | end | 33 | end |
| 35 | 34 | ||
| 36 | def create | 35 | def create |
| @@ -48,14 +47,14 @@ class NodesController < ApplicationController | |||
| 48 | @node.draft.save! | 47 | @node.draft.save! |
| 49 | 48 | ||
| 50 | @node.update!(default_template_name: config[:template]) if config && config[:template] | 49 | @node.update!(default_template_name: config[:template]) if config && config[:template] |
| 50 | NodeAction.record!(:node => @node, :page => @node.draft, :user => current_user, | ||
| 51 | :action => "create", | ||
| 52 | :title => params[:title], :path => @node.unique_name) | ||
| 51 | 53 | ||
| 52 | redirect_to(edit_node_path(@node)) | 54 | redirect_to(edit_node_path(@node)) |
| 53 | else | 55 | else |
| 54 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" | 56 | @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic" |
| 55 | if params[:parent_id].present? | 57 | @parent = Node.find(params[:parent_id]) if params.has_key?(:parent_id) |
| 56 | @parent_id = params[:parent_id] | ||
| 57 | @parent_name = Node.find(@parent_id).title | ||
| 58 | end | ||
| 59 | render :new | 58 | render :new |
| 60 | end | 59 | end |
| 61 | end | 60 | end |
| @@ -63,6 +62,9 @@ class NodesController < ApplicationController | |||
| 63 | def show | 62 | def show |
| 64 | @page = @node.draft || @node.head | 63 | @page = @node.draft || @node.head |
| 65 | @translations = @page.translation_summary | 64 | @translations = @page.translation_summary |
| 65 | @page_actions = NodeAction.where(:page_id => @node.pages.select(:id)) | ||
| 66 | .order(:occurred_at, :id) | ||
| 67 | .group_by(&:page_id) | ||
| 66 | end | 68 | end |
| 67 | 69 | ||
| 68 | def edit | 70 | def edit |
| @@ -142,12 +144,44 @@ class NodesController < ApplicationController | |||
| 142 | redirect_to node_path(@node) | 144 | redirect_to node_path(@node) |
| 143 | end | 145 | end |
| 144 | 146 | ||
| 147 | def trash | ||
| 148 | if @node.trash!(current_user) | ||
| 149 | flash[:notice] = "Page has been moved to the Trash" | ||
| 150 | redirect_to trashed_nodes_path | ||
| 151 | else | ||
| 152 | flash[:notice] = "Page is already in the Trash" | ||
| 153 | redirect_to node_path(@node) | ||
| 154 | end | ||
| 155 | rescue ActiveRecord::RecordInvalid, LockedByAnotherUser => e | ||
| 156 | flash[:error] = e.message | ||
| 157 | redirect_to node_path(@node) | ||
| 158 | end | ||
| 159 | |||
| 160 | def restore_from_trash | ||
| 161 | parent = Node.find(params[:parent_id]) | ||
| 162 | @node.restore_from_trash!(parent, current_user) | ||
| 163 | flash[:notice] = "Page has been restored from the Trash" | ||
| 164 | redirect_to node_path(@node) | ||
| 165 | rescue ActiveRecord::RecordNotFound | ||
| 166 | flash[:error] = "Restore target not found" | ||
| 167 | redirect_to node_path(@node) | ||
| 168 | rescue ActiveRecord::RecordInvalid => e | ||
| 169 | flash[:error] = e.message | ||
| 170 | redirect_to node_path(@node) | ||
| 171 | end | ||
| 172 | |||
| 145 | def destroy | 173 | def destroy |
| 146 | @node.destroy | 174 | @node.destroy_from_trash!(current_user) |
| 175 | flash[:notice] = "Page has been permanently deleted" | ||
| 176 | redirect_to trashed_nodes_path | ||
| 177 | |||
| 178 | rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotDestroyed => e | ||
| 179 | flash[:error] = e.message | ||
| 180 | redirect_to node_path(@node) | ||
| 147 | end | 181 | end |
| 148 | 182 | ||
| 149 | def publish | 183 | def publish |
| 150 | @node.publish_draft! | 184 | @node.publish_draft!(current_user) |
| 151 | flash[:notice] = "Draft has been published" | 185 | flash[:notice] = "Draft has been published" |
| 152 | redirect_to node_path(@node) | 186 | redirect_to node_path(@node) |
| 153 | end | 187 | end |
| @@ -217,6 +251,11 @@ class NodesController < ApplicationController | |||
| 217 | @sitemap_descendant_counts = descendant_counts_for(@sitemap) | 251 | @sitemap_descendant_counts = descendant_counts_for(@sitemap) |
| 218 | end | 252 | end |
| 219 | 253 | ||
| 254 | def trashed | ||
| 255 | @nodes = Node.trash.children.order(:slug) | ||
| 256 | .paginate(:page => params[:page], :per_page => 50) | ||
| 257 | end | ||
| 258 | |||
| 220 | private | 259 | private |
| 221 | 260 | ||
| 222 | def slug_for(title) | 261 | def slug_for(title) |
