Class: Georgia::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Georgia::PagesController
- Includes:
- Concerns::Helpers
- Defined in:
- app/controllers/georgia/pages_controller.rb
Instance Method Summary collapse
-
#copy ⇒ Object
Creates a copy of a page and redirects to its revisions#edit.
-
#create ⇒ Object
Create page, load first current revision and js redirect to revisions#edit.
-
#destroy ⇒ Object
Destroys page and its revisions from page Also used to destroy multiple pages from table checkboxes.
-
#edit ⇒ Object
Edit current revision.
- #index ⇒ Object
-
#publish ⇒ Object
Publishes multiple pages from table checkboxes.
- #search ⇒ Object
-
#settings ⇒ Object
Edit current page.
- #show ⇒ Object
-
#sort ⇒ Object
Sorts subpages/children from pages#settings FIXME: This should be taken care of in pages#update.
-
#unpublish ⇒ Object
Unpublishes multiple pages from table checkboxes.
-
#update ⇒ Object
Update page settings.
Methods included from Concerns::Helpers
Methods inherited from ApplicationController
#current_ability, #current_locale
Instance Method Details
#copy ⇒ Object
Creates a copy of a page and redirects to its revisions#edit
79 80 81 82 83 84 85 86 87 |
# File 'app/controllers/georgia/pages_controller.rb', line 79 def copy @page if @copy = CopyPage.new(@page.model).call CreateActivity.new(@page, :copy, owner: current_user).call redirect_to edit_page_revision_path(@copy, @copy.current_revision), notice: "#{instance_name.humanize} successfully copied. Do not forget to change your url" else render_error("Oups. Something went wrong.") end end |
#create ⇒ Object
Create page, load first current revision and js redirect to revisions#edit
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/georgia/pages_controller.rb', line 39 def create @page = model.new(slug: params[:title].try(:parameterize)) @page if @page.save @page.revisions.create(template: Georgia.templates.first, revised_by_id: current_user.id, status: :published) do |rev| rev.contents << Georgia::Content.new(locale: I18n.default_locale, title: params[:title]) end @page.update_attribute(:current_revision, @page.revisions.first) CreateActivity.new(@page, :create, owner: current_user).call respond_to do |format| format.html { redirect_to edit_page_revision_path(@page, @page.current_revision), notice: "#{@page.title} was successfully created." } format.js { render layout: false } end else respond_to do |format| format.html { redirect_to :back, alert: "Oups. Something went wrong." } format.js { render layout: false } end end end |
#destroy ⇒ Object
Destroys page and its revisions from page Also used to destroy multiple pages from table checkboxes
91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/controllers/georgia/pages_controller.rb', line 91 def destroy back_url = url_for(controller: controller_name, action: :search) @pages = model.where(id: params[:id]) @pages = @pages.length > 1 ? "#{instance_name.humanize.pluralize(@pages.length)} successfully deleted." : "#{@pages.first.title} successfully deleted." if @pages.destroy_all render_success(, redirect_url: [:search, model]) else render_error("Oups. Something went wrong.") end end |
#edit ⇒ Object
Edit current revision
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/georgia/pages_controller.rb', line 20 def edit if @page and @page.current_revision @page redirect_to edit_page_revision_path(@page, @page.current_revision) else Georgia::Page redirect_to [:search, model], alert: "This #{instance_name} has been deleted." end end |
#index ⇒ Object
143 144 145 146 |
# File 'app/controllers/georgia/pages_controller.rb', line 143 def index model redirect_to [:search, model] end |
#publish ⇒ Object
Publishes multiple pages from table checkboxes
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/georgia/pages_controller.rb', line 104 def publish set_pages @pages unless @pages.map(&:publish).include?(false) @pages.each do |page| CreateActivity.new(page, :publish, owner: current_user).call end render_success("Successfully published.") else render_error("Oups. Something went wrong.") end end |
#search ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/controllers/georgia/pages_controller.rb', line 148 def search model session[:search_params] = params if model.count > 0 search_conditions = model.search_conditions(params) @search = model.search(search_conditions).page(params[:page]) @pages = Georgia::PageDecorator.decorate_collection(@search.records) else @pages = [] end end |
#settings ⇒ Object
Edit current page
31 32 33 34 35 36 |
# File 'app/controllers/georgia/pages_controller.rb', line 31 def settings @page @revision = @page.current_revision @activities = @page.activities.order(created_at: :desc) @awaiting_revisions = @page.revisions.where(status: Georgia::Revision.statuses[:review]) end |
#show ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/georgia/pages_controller.rb', line 9 def show if @page @page redirect_to edit_page_revision_path(@page, @page.current_revision) else Georgia::Page redirect_to [:search, model], alert: "This #{instance_name} has been deleted." end end |
#sort ⇒ Object
Sorts subpages/children from pages#settings FIXME: This should be taken care of in pages#update
134 135 136 137 138 139 140 141 |
# File 'app/controllers/georgia/pages_controller.rb', line 134 def sort if params[:page] params[:page].each_with_index do |id, index| model.update_all({position: index+1}, {id: id}) end end render nothing: true end |
#unpublish ⇒ Object
Unpublishes multiple pages from table checkboxes
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/controllers/georgia/pages_controller.rb', line 118 def unpublish set_pages @pages unless @pages.map(&:unpublish).include?(false) @pages.each do |page| CreateActivity.new(page, :unpublish, owner: current_user).call end render_success("Successfully unpublished.") else render_error("Oups. Something went wrong.") end end |
#update ⇒ Object
Update page settings
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/georgia/pages_controller.rb', line 61 def update @page model.update_tree(params[:page_tree]) if params[:page_tree] if @page.update(sanitized_params) CreateActivity.new(@page, :update, owner: current_user).call respond_to do |format| format.html { redirect_to [:settings, @page], notice: "#{@page.title} was successfully updated." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to [:settings, @page], alert: "Oups. Something went wrong." } format.js { head :internal_server_error } end end end |