delete code, untested
This commit is contained in:
@ -23,7 +23,7 @@ module Merged
|
||||
@card.move_down
|
||||
end
|
||||
@card.save
|
||||
redirect_to section_cards_url(@card.section.id),notice: "Card moved"
|
||||
redirect_to section_cards_url(@card.section.id),notice: "#{@card.header} moved"
|
||||
end
|
||||
|
||||
def new
|
||||
@ -34,8 +34,7 @@ module Merged
|
||||
|
||||
def destroy
|
||||
@card.destroy
|
||||
@card.section.save
|
||||
redirect_to section_cards_url(@card.section.id) , notice: "Card #{@card.index} removed"
|
||||
redirect_to section_cards_url(@card.section.id) , notice: "#{@card.header} removed"
|
||||
end
|
||||
|
||||
def update
|
||||
@ -50,7 +49,7 @@ module Merged
|
||||
@card.set_option(option.name, options[option.name])
|
||||
end if options
|
||||
@card.save
|
||||
redirect_to section_cards_url(@card.section.id) , notice: "Update ok"
|
||||
redirect_to section_cards_url(@card.section.id) , notice: "Updated #{@card.header}"
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -21,7 +21,7 @@ module Merged
|
||||
end
|
||||
|
||||
def destroy
|
||||
Page.destroy(@page)
|
||||
@page.destroy()
|
||||
redirect_to pages_url, notice: "Page #{@page.name} was removed."
|
||||
end
|
||||
|
||||
|
@ -33,8 +33,7 @@ module Merged
|
||||
|
||||
def destroy
|
||||
@section.destroy()
|
||||
@section.page.save
|
||||
redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.index} removed"
|
||||
redirect_to page_sections_url(@section.page.id) , notice: "Section #{@section.header} removed"
|
||||
end
|
||||
|
||||
def set_image
|
||||
|
@ -3,7 +3,7 @@ module Merged
|
||||
include MergedHelper
|
||||
|
||||
def view
|
||||
@page = Page.find(params[:id])
|
||||
@page = Page.find_by_name(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -10,11 +10,7 @@ module Merged
|
||||
fields :index , :section_id, :id , :text , :header, :image
|
||||
|
||||
def template_style
|
||||
@section.card_template
|
||||
end
|
||||
|
||||
def destroy
|
||||
@section.remove_card( self)
|
||||
section.card_template
|
||||
end
|
||||
|
||||
def move_up
|
||||
@ -33,12 +29,6 @@ module Merged
|
||||
section.cards.where(index: index + 1).first
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
data = Card.all.collect {|obj| obj.attributes}
|
||||
File.write( Card.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@index = index
|
||||
end
|
||||
@ -47,6 +37,27 @@ module Merged
|
||||
CardStyle.find_by_template( section.card_template)
|
||||
end
|
||||
|
||||
def destroy
|
||||
delete
|
||||
Card.save_all
|
||||
end
|
||||
|
||||
def delete(reindex = true)
|
||||
Card.delete( self.id )
|
||||
section.reset_index if reindex
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Card.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Card.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Card.full_path , data.to_yaml)
|
||||
Card.reload
|
||||
end
|
||||
|
||||
def self.new_card(card_template , section_id , index)
|
||||
data = { section_id: section_id , index: index}
|
||||
CardStyle.find_by_template( card_template ).fields.each do |key|
|
||||
|
@ -25,11 +25,6 @@ module Merged
|
||||
Page.new(name)
|
||||
end
|
||||
|
||||
def self.destroy( page )
|
||||
@@all.delete(page.name)
|
||||
File.delete(Rails.root.join(Page.cms_root , page.name + ".yaml"))
|
||||
end
|
||||
|
||||
def new_section(section_template)
|
||||
section_template = "section_spacer" if section_template.blank?
|
||||
section_data = Section.build_data(section_template)
|
||||
@ -54,11 +49,36 @@ module Merged
|
||||
@content[0]["template"]
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
data = Page.all.collect {|obj| obj.attributes}
|
||||
File.write( Page.full_path , data.to_yaml)
|
||||
def reset_index
|
||||
sections.each_with_index{|section, index| section.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_sections , has_cards = delete()
|
||||
Page.save_all
|
||||
if has_sections > 0
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
has_sections = sections.length
|
||||
has_cards = 0
|
||||
sections.each {|section| has_cards += section.delete(false) }
|
||||
Page.delete( self.id )
|
||||
[has_sections , has_cards]
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Page.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Page.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Page.full_path , data.to_yaml)
|
||||
Page.reload
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -66,13 +66,6 @@ module Merged
|
||||
page.sections.where(index: index + 1).first
|
||||
end
|
||||
|
||||
|
||||
def save
|
||||
super
|
||||
data = Section.all.collect {|obj| obj.attributes}
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
end
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
style = SectionStyle.sections[ template ]
|
||||
@ -86,5 +79,34 @@ module Merged
|
||||
data
|
||||
end
|
||||
|
||||
def reset_index
|
||||
cards.each_with_index{|card, index| card.index = index + 1}
|
||||
end
|
||||
|
||||
def destroy
|
||||
has_cards = delete()
|
||||
Section.save_all
|
||||
Card.save_all if has_cards > 0
|
||||
end
|
||||
|
||||
def delete( reindex = true )
|
||||
has_cards = cards.length
|
||||
cards.each {|card| card.delete(false) }
|
||||
Section.delete( self.id )
|
||||
page.reset_index if reindex
|
||||
has_cards
|
||||
end
|
||||
|
||||
def save
|
||||
super
|
||||
Section.save_all
|
||||
end
|
||||
|
||||
def self.save_all
|
||||
data = Section.the_private_records.collect {|obj| obj.attributes}
|
||||
File.write( Section.full_path , data.to_yaml)
|
||||
Section.reload
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Merged
|
||||
fields :template , :text , :header, :fields , :cards
|
||||
|
||||
def has_cards?
|
||||
cards == true
|
||||
cards
|
||||
end
|
||||
|
||||
def section_preview
|
||||
|
@ -2,7 +2,7 @@
|
||||
.flex.items-center.justify-center.flex-1
|
||||
.max-w-xl.px-4.py-8.mx-auto.text-center
|
||||
%h1.text-3xl.font-bold.tracking-tight.text-gray-900
|
||||
Page #{link_to @section.page.name, page_sections_url(@section.page.name), class: "underline"}
|
||||
Page #{link_to @section.page.name, page_sections_url(@section.page.id), class: "underline"}
|
||||
.flex.items-center.justify-center.flex-1
|
||||
.max-w-xl.px-4.py-8.mx-auto.text-center
|
||||
%h1.text-3xl.font-bold.tracking-tight.text-gray-900
|
||||
|
@ -5,7 +5,7 @@
|
||||
.flex.items-center.justify-center.flex-1
|
||||
.max-w-xl.px-4.py-8.mx-auto.text-center
|
||||
%h1.text-3xl.font-bold.tracking-tight.text-gray-900
|
||||
Page #{link_to @section.page.name, page_sections_url(@section.page.name), class: "underline"}
|
||||
Page #{link_to @section.page.name, page_sections_url(@section.page.id), class: "underline"}
|
||||
.flex.items-center.justify-center.flex-1
|
||||
%h3.text-xl.font-bold.tracking-tight.text-gray-900
|
||||
Section #{@section.index} / #{@section.page.sections.length}
|
||||
|
Reference in New Issue
Block a user