From d1ecda07c408d60cd7d5c405b7e3a44537094ae3 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 29 Nov 2022 20:03:48 +0200 Subject: [PATCH] section template selection --- app/controllers/merged/sections_controller.rb | 14 ++++++++++++-- app/views/merged/pages/edit.haml | 4 ++-- app/views/merged/sections/index.html.haml | 8 ++++---- app/views/merged/sections/new.html.haml | 2 +- app/views/merged/sections/select_template.haml | 6 ++++++ app/views/merged/sections/show.html.haml | 4 ++-- 6 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 app/views/merged/sections/select_template.haml diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index 2099950..79389d2 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -1,10 +1,14 @@ module Merged class SectionsController < MergedController - before_action :set_page, only: %i[ show edit update destroy set_image select_image] + before_action :set_page + #, only: %i[ show edit update destroy set_image select_image] def select_image @images = Image.all end + def select_template + @sections = Style.sections + end def set_image @section.content["image"] = params[:image] @@ -12,6 +16,12 @@ module Merged redirect_to page_section_url(@page.id,@section.id) end + def set_template + @section.content["template"] = params[:template] + @page.save + redirect_to page_section_url(@page.id,@section.id) + end + def update @section.content.each do |key , value| next if key == "id" @@ -21,7 +31,7 @@ module Merged end end @page.save - redirect_to :merged_page_section + redirect_to :page_section end private diff --git a/app/views/merged/pages/edit.haml b/app/views/merged/pages/edit.haml index c1fc387..6cf9333 100644 --- a/app/views/merged/pages/edit.haml +++ b/app/views/merged/pages/edit.haml @@ -2,6 +2,6 @@ = render 'form' -= link_to 'Show', merged_page_url(@merged_page.name) += link_to 'Show', page_url(@merged_page.name) \| -= link_to 'Back', merged_pages_path += link_to 'Back', pages_path diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 9d2286f..3395fb6 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -10,10 +10,10 @@ %tbody - @merged_sections.each do |merged_section| %tr - %td= link_to 'Show', merged_section - %td= link_to 'Edit', edit_merged_section_path(merged_section) - %td= link_to 'Destroy', merged_section, method: :delete, data: { confirm: 'Are you sure?' } + %td= link_to 'Show', section + %td= link_to 'Edit', edit_section_path(merged_section) + %td= link_to 'Destroy', section, method: :delete, data: { confirm: 'Are you sure?' } %br -= link_to 'New Section', new_merged_section_path += link_to 'New Section', new_section_path diff --git a/app/views/merged/sections/new.html.haml b/app/views/merged/sections/new.html.haml index 4b64e04..92ce9f7 100644 --- a/app/views/merged/sections/new.html.haml +++ b/app/views/merged/sections/new.html.haml @@ -2,4 +2,4 @@ = render 'form' -= link_to 'Back', merged_sections_path += link_to 'Back', sections_path diff --git a/app/views/merged/sections/select_template.haml b/app/views/merged/sections/select_template.haml new file mode 100644 index 0000000..2c44234 --- /dev/null +++ b/app/views/merged/sections/select_template.haml @@ -0,0 +1,6 @@ +.grid.grid-cols-4.gap-2.m-8 + - @sections.each do |style| + .relative.block.border.border-gray-100 + = link_to( page_section_set_template_path( template: style.template )) do + =image_tag(style.section_preview , class: "h-56 w-full object-contain lg:h-72") + = style.header diff --git a/app/views/merged/sections/show.html.haml b/app/views/merged/sections/show.html.haml index d3814e5..4ee36ea 100644 --- a/app/views/merged/sections/show.html.haml +++ b/app/views/merged/sections/show.html.haml @@ -13,6 +13,6 @@ - @section.content.each do |key , value| = render "merged/sections/editors/#{key}", section: @section , key: key , value: value -= #link_to 'Edit', edit_merged_section_path(@merged_section) += #link_to 'Edit', edit_section_path(@merged_section) \| -= #link_to 'Back', merged_sections_path += #link_to 'Back', sections_path