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.
-
#flush_cache ⇒ Object
Flush cache from multiple pages.
- #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 the page.
-
#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
61 62 63 64 |
# File 'app/controllers/georgia/pages_controller.rb', line 61 def copy @copy = @page.copy redirect_to edit_page_revision_path(@copy, @copy.current_revision), notice: "Do not forget to change your url" end |
#create ⇒ Object
Create page, load first current revision and js redirect to revisions#edit
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/georgia/pages_controller.rb', line 25 def create @page = model.new(slug: params[:title].try(:parameterize)) if @page.save @page.revisions.create(template: Georgia.templates.first) do |rev| rev.contents << Georgia::Content.new(locale: I18n.default_locale, title: params[:title]) end @page.update_attribute(:current_revision, @page.revisions.first) 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/georgia/pages_controller.rb', line 68 def destroy back_url = url_for(controller: controller_name, action: :search) @pages = model.where(id: params[:id]) if @pages.destroy_all respond_to do |format| format.html { redirect_to back_url, notice: "#{instance_name.humanize} successfully deleted." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to back_url, alert: "Oups. Something went wrong." } format.js { head :internal_server_error } end end end |
#edit ⇒ Object
Edit current revision
16 17 18 |
# File 'app/controllers/georgia/pages_controller.rb', line 16 def edit redirect_to [:edit, @page, @page.current_revision] end |
#flush_cache ⇒ Object
Flush cache from multiple pages
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/controllers/georgia/pages_controller.rb', line 85 def flush_cache @pages = model.where(id: params[:id]) @cache_keys = @pages.map(&:cache_key) unless @cache_keys.map{|k| expire_action(k)}.include?(false) respond_to do |format| format.html { redirect_to :back, notice: "Cache was successfully cleared." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to :back, alert: "Oups. Either there wasn't any cache to start with or something went wrong." } format.js { head :internal_server_error } end end end |
#index ⇒ Object
146 147 148 |
# File 'app/controllers/georgia/pages_controller.rb', line 146 def index redirect_to search_pages_path end |
#publish ⇒ Object
Publishes multiple pages from table checkboxes
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/georgia/pages_controller.rb', line 102 def publish @pages = model.where(id: params[:id]) unless @pages.map(&:publish).include?(false) respond_to do |format| format.html { redirect_to :back, notice: "Successfully published." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to :back, alert: "Oups. Something went wrong." } format.js { head :internal_server_error } end end end |
#search ⇒ Object
150 151 152 153 154 |
# File 'app/controllers/georgia/pages_controller.rb', line 150 def search session[:search_params] = params @search = Georgia::Indexer.adapter.search(model, params) @pages = Georgia::PageDecorator.decorate_collection(@search.results) end |
#settings ⇒ Object
Edit current page
21 22 |
# File 'app/controllers/georgia/pages_controller.rb', line 21 def settings end |
#show ⇒ Object
11 12 13 |
# File 'app/controllers/georgia/pages_controller.rb', line 11 def show redirect_to [:edit, @page] end |
#sort ⇒ Object
Sorts subpages/children from pages#settings FIXME: This should be taken care of in pages#update
137 138 139 140 141 142 143 144 |
# File 'app/controllers/georgia/pages_controller.rb', line 137 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 the page
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/georgia/pages_controller.rb', line 119 def unpublish @pages = model.where(id: params[:id]) unless @pages.map(&:unpublish).include?(false) respond_to do |format| format.html { redirect_to :back, notice: "Successfully unpublished." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to :back, alert: "Oups. Something went wrong." } format.js { head :internal_server_error } end end end |
#update ⇒ Object
Update page settings
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/georgia/pages_controller.rb', line 45 def update Georgia::Page.update_tree(params[:page_tree]) if params[:page_tree] if @page.update_attributes(params[:page]) respond_to do |format| format.html { render :settings, notice: "#{@page.title} was successfully updated." } format.js { head :ok } end else respond_to do |format| format.html { redirect_to [:settings, @page], notice: "Oups. Something went wrong." } format.js { head :internal_server_error } end end end |