Implement undoing
This commit is contained in:
parent
dc55fc10f1
commit
dfa4ffeaea
5 changed files with 31 additions and 7 deletions
|
@ -1,3 +1,11 @@
|
||||||
class Admin::BaseController < ApplicationController
|
class Admin::BaseController < ApplicationController
|
||||||
layout 'admin'
|
layout 'admin'
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def undo_link(item)
|
||||||
|
view_context.link_to('Undo this change',
|
||||||
|
admin_revert_version_path(id: item.version.last),
|
||||||
|
method: :post)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,8 @@ class Admin::CardsController < Admin::BaseController
|
||||||
authorize @card
|
authorize @card
|
||||||
|
|
||||||
if @card.save
|
if @card.save
|
||||||
redirect_to admin_cards_path, notice: 'Card was created'
|
redirect_to admin_cards_path,
|
||||||
|
notice: "Card was created. #{undo_link(@card)}"
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
|
@ -40,7 +41,8 @@ class Admin::CardsController < Admin::BaseController
|
||||||
authorize @card
|
authorize @card
|
||||||
|
|
||||||
if @card.update(card_params)
|
if @card.update(card_params)
|
||||||
redirect_to admin_cards_path, notice: 'Card was updated'
|
redirect_to admin_cards_path,
|
||||||
|
notice: "Card was updated. #{undo_link(@card)}"
|
||||||
else
|
else
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
|
@ -51,7 +53,8 @@ class Admin::CardsController < Admin::BaseController
|
||||||
|
|
||||||
@card.destroy
|
@card.destroy
|
||||||
|
|
||||||
redirect_to admin_cards_path, notice: 'Card was deleted'
|
redirect_to admin_cards_path,
|
||||||
|
notice: "Card was deleted. #{undo_link(@card)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -1,16 +1,27 @@
|
||||||
class Admin::VersionsController < Admin::BaseController
|
class Admin::VersionsController < Admin::BaseController
|
||||||
before_action :set_version, only: [:show]
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@version = PaperTrail::Version.find(params[:id]).reify(has_one: true)
|
||||||
|
|
||||||
type = @version.class.to_s.underscore
|
type = @version.class.to_s.underscore
|
||||||
instance_variable_set('@' + type, @version)
|
instance_variable_set('@' + type, @version)
|
||||||
|
|
||||||
render "admin/#{type.pluralize}/show"
|
render "admin/#{type.pluralize}/show"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def revert
|
||||||
|
@version = PaperTrail::Version.find(params[:id])
|
||||||
|
|
||||||
|
if @version.reify(has_one: true)
|
||||||
|
@version.reify(has_one: true).save!
|
||||||
|
else
|
||||||
|
@version.item.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to :back, notice: "Undid #{@version.event}!"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_version
|
def set_version
|
||||||
@version = PaperTrail::Version.find(params[:id]).reify(has_one: true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
button.close type='button' data-dismiss='alert'
|
button.close type='button' data-dismiss='alert'
|
||||||
span aria-hidden='true' ×
|
span aria-hidden='true' ×
|
||||||
span.sr-only Close
|
span.sr-only Close
|
||||||
= message
|
= raw(message)
|
||||||
|
|
|
@ -12,6 +12,8 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
get '/dashboard', to: 'dashboard#index'
|
get '/dashboard', to: 'dashboard#index'
|
||||||
|
|
||||||
|
post '/versions/revert', to: 'versions#revert', as: 'revert_version'
|
||||||
|
|
||||||
resources :awaken_types
|
resources :awaken_types
|
||||||
resources :cards
|
resources :cards
|
||||||
resources :characters
|
resources :characters
|
||||||
|
|
Loading…
Reference in a new issue