diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index 79389d2..55009ae 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -9,6 +9,9 @@ module Merged def select_template @sections = Style.sections end + def select_card_template + @cards = Style.cards + end def set_image @section.content["image"] = params[:image] @@ -17,7 +20,17 @@ module Merged end def set_template - @section.content["template"] = params[:template] + template = params[:template] + raise "no template given" if template.blank? + @section.content["template"] = template + @page.save + redirect_to page_section_url(@page.id,@section.id) + end + + def set_card_template + card_template = params[:card_template] + raise "no card template given" if card_template.blank? + @section.content["card_template"] = card_template @page.save redirect_to page_section_url(@page.id,@section.id) end diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index bfda48d..d799cf7 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -31,6 +31,9 @@ module Merged def template @content["template"] end + def card_template + @content["card_template"] + end def id @content["id"] diff --git a/app/models/merged/style.rb b/app/models/merged/style.rb index ac20d19..84ffc17 100644 --- a/app/models/merged/style.rb +++ b/app/models/merged/style.rb @@ -11,7 +11,6 @@ module Merged def initialize content @content = content end - def template @content["template"] end diff --git a/app/views/merged/sections/edit.html.haml b/app/views/merged/sections/edit.html.haml deleted file mode 100644 index f0337b1..0000000 --- a/app/views/merged/sections/edit.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 Editing merged_section - -= render 'form' - -= link_to 'Show', @merged_section -\| -= link_to 'Back', merged_sections_path diff --git a/app/views/merged/sections/editors/_card_template.haml b/app/views/merged/sections/editors/_card_template.haml index 7c4483a..ff7435f 100644 --- a/app/views/merged/sections/editors/_card_template.haml +++ b/app/views/merged/sections/editors/_card_template.haml @@ -3,5 +3,7 @@ %p= value %p #{section.content['cards'].length} cards %p view cards (index) + %button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white + =link_to "Change Card Template" , page_section_select_card_template_url(@page.name,@section.id) .relative.block.border.border-gray-100 =image_tag("merged/card_preview/#{value}" , class: "w-full object-contain") diff --git a/app/views/merged/sections/select_card_template.haml b/app/views/merged/sections/select_card_template.haml new file mode 100644 index 0000000..3e5b60e --- /dev/null +++ b/app/views/merged/sections/select_card_template.haml @@ -0,0 +1,6 @@ +.grid.grid-cols-4.gap-2.m-8 + - @cards.each do |style| + .relative.block.border.border-gray-100 + = link_to( page_section_set_card_template_path( card_template: style.template )) do + =image_tag(style.card_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 4ee36ea..e79df53 100644 --- a/app/views/merged/sections/show.html.haml +++ b/app/views/merged/sections/show.html.haml @@ -12,7 +12,3 @@ .grid.grid-cols-2.gap-2.m-8 - @section.content.each do |key , value| = render "merged/sections/editors/#{key}", section: @section , key: key , value: value - -= #link_to 'Edit', edit_section_path(@merged_section) -\| -= #link_to 'Back', sections_path diff --git a/config/routes.rb b/config/routes.rb index 00d6dec..5cb6bc9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,8 @@ Merged::Engine.routes.draw do get :set_image get :select_template get :set_template + get :select_card_template + get :set_card_template end end resources :images