diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index c30099f..3951a24 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -23,6 +23,13 @@ module Merged redirect_to section_select_template_url(new_section.id) end + def remove + page = @section.page + page.remove_section( @section ) + page.save + redirect_to page_sections_url(page.name) + end + def set_image @section.content["image"] = params[:image] @section.save diff --git a/app/helpers/merged/merged_helper.rb b/app/helpers/merged/merged_helper.rb index 0ebc3ba..b1327e7 100644 --- a/app/helpers/merged/merged_helper.rb +++ b/app/helpers/merged/merged_helper.rb @@ -12,8 +12,8 @@ module Merged def green_button( text, url) button( text , url , "bg-green-500" ) end - def submit_button(text) - clazz = "bg-blue-500 " + button_classes + def submit_button(text , danger = false ) + clazz = danger ? "bg-blue-500 " : "bg-blue-500 " + button_classes content_tag(:button , class: clazz , type: :submit) do text end diff --git a/app/models/merged/page.rb b/app/models/merged/page.rb index 7d7144c..d8bef8b 100644 --- a/app/models/merged/page.rb +++ b/app/models/merged/page.rb @@ -43,6 +43,15 @@ module Merged section end + def remove_section(section) + from_index = section.index + @sections.delete_at(from_index) + @content.delete_at(from_index) + @sections.each_with_index do |section, index| + section.set_index(index) + end + end + def first_template @content[0]["template"] end diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 90dd857..ec249e3 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -13,7 +13,7 @@ = blue_button( "Up" , section_move_url(section.id , dir: :up) ) = blue_button( "Down" , section_move_url(section.id , dir: :down) ) = yellow_button("Edit" , section_path(section.id) ) - = red_button( "Delete" , "/index" ) + = red_button( "Delete" , section_remove_path(section.id) ) .relative.block.border.border-gray-100.p-4 %h3.mt-4.text-lg.font-bold Template %p= section.template diff --git a/config/routes.rb b/config/routes.rb index a900caa..c099332 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,12 +10,17 @@ Merged::Engine.routes.draw do get :select_card_template get :set_card_template get :move + get :remove resources :cards do get :select_image get :set_image get :move + get :remove end end + get :remove + end + resources :images do + get :remove end - resources :images end