copy sections (template) and fix cards inclusion
This commit is contained in:
parent
1e452ca62a
commit
ecaf0eb587
@ -19,8 +19,14 @@ module Merged
|
||||
|
||||
def new
|
||||
page = Page.find(params[:page_id])
|
||||
new_section = page.new_section
|
||||
template = params[:template]
|
||||
new_section = page.new_section(template)
|
||||
page.save
|
||||
if(template.blank?) # new
|
||||
redirect_to section_select_template_url(new_section.id)
|
||||
else # copy
|
||||
redirect_to section_url(new_section.id)
|
||||
end
|
||||
end
|
||||
|
||||
def remove
|
||||
@ -39,7 +45,7 @@ module Merged
|
||||
def set_template
|
||||
template = params[:template]
|
||||
raise "no template given" if template.blank?
|
||||
@section.content["template"] = template
|
||||
@section.set_template( template )
|
||||
@section.save
|
||||
redirect_to section_url(@section.id)
|
||||
end
|
||||
|
@ -34,8 +34,8 @@ module Merged
|
||||
@@all[@name] = self
|
||||
end
|
||||
|
||||
def new_section
|
||||
section_template = params[:template] || "section_spacer"
|
||||
def new_section(section_template)
|
||||
section_template = "section_spacer" if section_template.blank?
|
||||
section_data = Section.build_data(section_template)
|
||||
index = sections.length
|
||||
section = Section.new(self , index, section_data)
|
||||
|
@ -50,6 +50,22 @@ module Merged
|
||||
options[option] = value
|
||||
end
|
||||
|
||||
def set_template(new_template)
|
||||
@content["template"] = new_template
|
||||
new_style = template_style
|
||||
if(new_style.cards?)
|
||||
unless card_template
|
||||
@content["card_template"] = Style.cards.keys.first
|
||||
@content["cards"] = []
|
||||
raise "Should not have cards" unless cards.empty?
|
||||
end
|
||||
else
|
||||
@content.delete("cards")
|
||||
@content.delete("card_template")
|
||||
@cards.clear
|
||||
end
|
||||
end
|
||||
|
||||
def template_style
|
||||
Style.sections[ template ]
|
||||
end
|
||||
@ -58,7 +74,7 @@ module Merged
|
||||
end
|
||||
|
||||
def cards?
|
||||
! cards.empty?
|
||||
! card_template.blank?
|
||||
end
|
||||
|
||||
def new_card
|
||||
@ -133,11 +149,15 @@ module Merged
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
Style.sections[ template ].fields.each do |key|
|
||||
style = Style.sections[ template ]
|
||||
style.fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end unless style.fields.blank?
|
||||
if(style.cards?)
|
||||
data["cards"] = []
|
||||
data["card_template"] = Style.cards.keys.first
|
||||
end
|
||||
data
|
||||
|
||||
end
|
||||
|
||||
def self.find(section_id)
|
||||
|
@ -2,7 +2,6 @@ module Merged
|
||||
class Style
|
||||
include ActiveModel::API
|
||||
|
||||
cattr_accessor :sections , :cards
|
||||
@@sections = {}
|
||||
@@cards = {}
|
||||
|
||||
@ -29,16 +28,16 @@ module Merged
|
||||
end
|
||||
|
||||
def self.cards
|
||||
self.all
|
||||
self.load
|
||||
@@cards
|
||||
end
|
||||
|
||||
def self.sections
|
||||
self.all
|
||||
self.load
|
||||
@@sections
|
||||
end
|
||||
|
||||
def self.all
|
||||
def self.load
|
||||
if @@sections.length == 0
|
||||
all = YAML.load_file(Engine.root.join("config/styles.yaml"))
|
||||
all["sections"].each do |content|
|
||||
|
@ -13,6 +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) )
|
||||
= green_button( "Copy" , new_page_section_url(@page.name, template: section.template) )
|
||||
= red_button( "Delete" , section_remove_path(section.id) )
|
||||
.relative.block.border.border-gray-100.p-4
|
||||
%h3.mt-4.text-lg.font-bold Template
|
||||
|
Loading…
Reference in New Issue
Block a user