Class: Sibu::PagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Sibu::PagesController
- Defined in:
- app/controllers/sibu/pages_controller.rb
Instance Method Summary collapse
- #child_element ⇒ Object
- #clone_element ⇒ Object
- #create ⇒ Object
- #create_section ⇒ Object
- #delete_element ⇒ Object
- #delete_section ⇒ Object
- #destroy ⇒ Object
- #duplicate ⇒ Object
- #edit ⇒ Object
- #edit_content ⇒ Object
- #edit_element ⇒ Object
- #edit_section ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #new_section ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #update_element ⇒ Object
- #update_section ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#child_element ⇒ Object
121 122 123 |
# File 'app/controllers/sibu/pages_controller.rb', line 121 def child_element @added = @entity.child_element(*@section_id.split('|'), *@element_id.split('|')) end |
#clone_element ⇒ Object
113 114 115 |
# File 'app/controllers/sibu/pages_controller.rb', line 113 def clone_element @cloned = @entity.clone_element(*@section_id.split('|'), *@element_id.split('|')) end |
#create ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/sibu/pages_controller.rb', line 48 def create @page = Sibu::Page.new(page_params) if @page.save_and_init redirect_to site_pages_url(@page.site_id), notice: "La page a bien été créée." else flash.now[:alert] = "Une erreur s'est produite lors de la création de la page." render :new end end |
#create_section ⇒ Object
138 139 140 |
# File 'app/controllers/sibu/pages_controller.rb', line 138 def create_section @created = @entity.create_section(*@section_id.split('|'), params[:after], section_params) end |
#delete_element ⇒ Object
117 118 119 |
# File 'app/controllers/sibu/pages_controller.rb', line 117 def delete_element @deleted = @entity.delete_element(*@section_id.split('|'), *@element_id.split('|')) end |
#delete_section ⇒ Object
153 154 155 |
# File 'app/controllers/sibu/pages_controller.rb', line 153 def delete_section @deleted = @entity.delete_section(*@section_id.split('|')) end |
#destroy ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/controllers/sibu/pages_controller.rb', line 70 def destroy site_id = @page.site_id if @page.destroy redirect_to site_pages_url(site_id), notice: "La page a bien été supprimée." else flash.now[:alert] = "Une erreur s'est produite lors de la suppression de la page." render :index end end |
#duplicate ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'app/controllers/sibu/pages_controller.rb', line 80 def duplicate new_page = @page.deep_copy if new_page.save redirect_to site_pages_url(@page.site_id), notice: "La page a bien été copiée." else flash.now[:alert] = "Une erreur s'est produite lors de la copie de la page." render :index end end |
#edit ⇒ Object
58 59 |
# File 'app/controllers/sibu/pages_controller.rb', line 58 def edit end |
#edit_content ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/controllers/sibu/pages_controller.rb', line 90 def edit_content @page = Sibu::Page.find(params[:page_id]) @site = Sibu::Site.includes(:pages).find(@page.site_id) if @page @links = @site.pages_path_by_id if @site @edit_section = params[:edit_section] render :edit_content, layout: 'sibu/edit_content' end |
#edit_element ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/controllers/sibu/pages_controller.rb', line 98 def edit_element @content_type = params[:content_type] @links = @site.pages_path_by_id if @site @element = @entity.element(*@section_id.split('|'), *@element_id.split('|')) @repeat = params[:repeat] @size = params[:size].blank? ? :medium : params[:size].to_sym @children = params[:children] end |
#edit_section ⇒ Object
142 143 144 |
# File 'app/controllers/sibu/pages_controller.rb', line 142 def edit_section @section = @entity.section(params[:section_id]) end |
#index ⇒ Object
15 16 17 |
# File 'app/controllers/sibu/pages_controller.rb', line 15 def index @pages = @site.pages.order(:created_at) end |
#new ⇒ Object
44 45 46 |
# File 'app/controllers/sibu/pages_controller.rb', line 44 def new @page = Sibu::Page.new(site_id: @site.id) end |
#new_section ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/controllers/sibu/pages_controller.rb', line 125 def new_section page = Sibu::Page.find(params[:id]) @page = Page.new(id: page.id, sections: []) @site = Sibu::Site.includes(:pages).find(page.site_id) @after = params[:after] @links = @site.pages_path_by_id @site.site_template.available_templates.each do |t| template_defaults = @site.site_template.templates ? (@site.site_template.templates[t["template"]] || {}) : {} @page.sections << template_defaults.merge(t).to_h end end |
#show ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/sibu/pages_controller.rb', line 19 def show return_code = :ok if params[:site_id].blank? @page = Sibu::Page.lookup(request.host, params[:path]) if @page @query_path = params[:path][@page.path.length + 1..-1] unless @page.path.blank? @query_params = show_params.except(:controller, :action, :path).to_h @site = @page.site @links = @site.pages_path_by_id view_template = 'show' else view_template = Rails.application.config.sibu[:not_found] return_code = :not_found end else @site = Sibu::Site.find(params[:site_id]) @page = Sibu::Page.find(params[:id]) @links = @site.pages_path_by_id @query_path = params[:path] view_template = 'show' end render view_template, layout: 'sibu/site', status: return_code end |
#update ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'app/controllers/sibu/pages_controller.rb', line 61 def update if @page.update(page_params) redirect_to site_pages_url(@page.site_id), notice: "La page a bien été mise à jour." else flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de la page." render :edit end end |
#update_element ⇒ Object
107 108 109 110 111 |
# File 'app/controllers/sibu/pages_controller.rb', line 107 def update_element ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1] @updated = @entity.update_element(*ids, element_params) @refresh = params[:refresh] end |
#update_section ⇒ Object
146 147 148 149 150 151 |
# File 'app/controllers/sibu/pages_controller.rb', line 146 def update_section # {"utf8"=>"✓", "section"=>{"color"=>"#AFCA0B", "filters"=>"school_camps"}, "section_id"=>"cs1536301729", "refresh"=>"true", "commit"=>"Valider", "site_id"=>"3", "id"=>"1392"} @entity.section(params[:section_id]).merge!(section_params) logger.debug @entity.section(params[:section_id]) @updated = @entity.save end |