diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index f704d86..b86fe63 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -32,11 +32,10 @@ module Merged redirect_to section_cards_url(@section.id) end - def remove - section = @card.section - section.remove_card( @card ) - section.save - redirect_to section_cards_url(section.id) + def destroy + @card.destroy + @card.section.save + redirect_to section_cards_url(@card.section.id) , notice: "Card #{@card.index + 1} removed" end def update diff --git a/app/controllers/merged/pages_controller.rb b/app/controllers/merged/pages_controller.rb index d8d8061..1c54cd0 100644 --- a/app/controllers/merged/pages_controller.rb +++ b/app/controllers/merged/pages_controller.rb @@ -1,24 +1,15 @@ module Merged class PagesController < MergedController - before_action :set_page, only: %i[ show edit update destroy ] + before_action :set_page, only: %i[ update destroy ] - # GET /merged/pages def index @pages = Page.all.values end - # GET /merged/pages/1 - def show - end - - # GET /merged/pages/1/edit - def edit - end - - # POST /merged/pages def create name = params[:name] message = Page.check_name(name) + message = "Must enter name" if name.blank? if( message.nil?) @page = Page.build_new(name) redirect_to new_page_section_url(@page.name) , notice: "Page was successfully created." @@ -29,30 +20,15 @@ module Merged end end - # PATCH/PUT /merged/pages/1 - def update - if @page.update(page_params) - redirect_to @page, notice: "Page was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - # DELETE /merged/pages/1 def destroy Page.destroy(@page) redirect_to pages_url, notice: "Page #{@page.name} was removed." end private - # Use callbacks to share common setup or constraints between actions. - def set_page - @page = Page.find(params[:id]) - end + def set_page + @page = Page.find(params[:id]) + end - # Only allow a list of trusted parameters through. - def page_params - params.fetch(:page, {}) - end end end diff --git a/app/controllers/merged/sections_controller.rb b/app/controllers/merged/sections_controller.rb index ea82f97..dc9654f 100644 --- a/app/controllers/merged/sections_controller.rb +++ b/app/controllers/merged/sections_controller.rb @@ -29,11 +29,10 @@ module Merged end end - def remove - page = @section.page - page.remove_section( @section ) - page.save - redirect_to page_sections_url(page.name) + def destroy + @section.destroy() + @section.page.save + redirect_to page_sections_url(@section.page.name) , notice: "Section #{@section.index + 1} removed" end def set_image diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index ea1ab3c..633837b 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -24,6 +24,9 @@ module Merged @@all[self.id] = self end + def destroy + @section.remove_card( self) + end def update(key , value) return if key == "id" #not updating that diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index c4da345..2b62c95 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -103,9 +103,14 @@ module Merged end end + def destroy + @page.remove_section(self) + end + def move_up @page.move_section_up(self) end + def move_down @page.move_section_down(self) end diff --git a/app/views/layouts/_merged_messages.haml b/app/views/layouts/_merged_messages.haml index feb1283..316c6ed 100644 --- a/app/views/layouts/_merged_messages.haml +++ b/app/views/layouts/_merged_messages.haml @@ -6,7 +6,7 @@ =flash.alert -if flash.notice - .rounded-xl.border.border-gray-100.p-4.shadow-xl{:role => "alert"} + .m-20.rounded-xl.border.border-gray-100.p-4.shadow-xl{:role => "alert"} .flex.items-start.gap-4 %span.text-green-600 %svg.h-6.w-6{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index 5860823..77c898b 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -19,7 +19,8 @@ %h3.mt-4.text-lg.font-bold Card #{index + 1} = blue_button( "Up" , card_move_url(card.id , dir: :up) ) = blue_button( "Down" , card_move_url(card.id , dir: :down) ) - = red_button( "Delete" , card_remove_path(card.id) ) + = form_tag( card_url(card.id) , {method: :delete } ) do + =submit_button( "Delete" , true) .p-4 %h3.mt-4.text-lg.font-bold Image = yellow_button("Change Image" , card_select_image_url(card.id) ) diff --git a/app/views/merged/pages/index.haml b/app/views/merged/pages/index.haml index 9c39aa8..cf4e7da 100644 --- a/app/views/merged/pages/index.haml +++ b/app/views/merged/pages/index.haml @@ -21,7 +21,7 @@ %td.whitespace-nowrap.px-4.py-2.text-gray-700 = merged_page.first_template %td.whitespace-nowrap.px-4.py-2.text-gray-700 - = merged_page.content.length + = merged_page.sections.length %td.whitespace-nowrap.px-4.py-2 %strong.rounded.bg-green-100.px-3.text-xs.font-medium.text-green-700{:class => "py-1.5"} = link_to 'Sections', page_sections_path(merged_page.name) diff --git a/app/views/merged/sections/index.html.haml b/app/views/merged/sections/index.html.haml index 7cd35a5..2e420de 100644 --- a/app/views/merged/sections/index.html.haml +++ b/app/views/merged/sections/index.html.haml @@ -13,7 +13,8 @@ = blue_button( "Down" , section_move_url(section.id , dir: :down) ) = yellow_button("Edit" , section_path(section.id) ) = green_button( "Copy" , new_page_section_url(@page.name, template: section.template) ) - = red_button( "Delete" , section_remove_path(section.id) ) + = form_tag( section_url(section.id) , {method: :delete } ) do + =submit_button( "Delete" , true) .relative.block.border.border-gray-100.p-4 %h3.mt-4.text-lg.font-bold Template = link_to(section_select_template_url(section.id)) do @@ -42,9 +43,11 @@ %p = name = value -.relative.block.border.border-gray-100 - %p - = green_button( "New Section" , new_page_section_url(@page.name) ) - %p - = form_tag( page_url(@page.name) , {method: :delete } ) do - =submit_button( "Delete" , true) +.grid.grid-cols-2.gap-2.m-8 + .relative.block + %p + = green_button( "New Section" , new_page_section_url(@page.name) ) + .relative.block + %p + = form_tag( page_url(@page.name) , {method: :delete } ) do + =submit_button( "Delete Page" , true) diff --git a/config/routes.rb b/config/routes.rb index 87ebec7..cdeef69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,17 +13,12 @@ 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