new cards

This commit is contained in:
2022-12-02 23:22:43 +02:00
parent 6287373dae
commit 1e452ca62a
8 changed files with 62 additions and 22 deletions

View File

@ -46,15 +46,30 @@ module Merged
section.save
end
def set_index(index)
@index = index
end
def template_style
Style.cards[ section.card_template ]
end
def allowed_fields
template_style.fields
end
def self.build_data(card_template)
data = { "id" => SecureRandom.hex(10) }
Style.cards[ card_template ].fields.each do |key|
data[key] = key.upcase
end
data
end
def self.find_card(id)
raise "nil given" if id.blank?
card = @@all[id]
raise "Section not found #{id}" unless card
return card
end
def set_index(index)
@index = index
end
end
end

View File

@ -35,7 +35,8 @@ module Merged
end
def new_section
section_data = Section.build_data
section_template = params[:template] || "section_spacer"
section_data = Section.build_data(section_template)
index = sections.length
section = Section.new(self , index, section_data)
@sections << section

View File

@ -25,12 +25,6 @@ module Merged
end
end
def self.build_data
data = { "template" => "spacer"}
data["id"] = SecureRandom.hex(10)
data
end
[:template , :card_template , :id , :text , :header, :image].each do |meth|
define_method(meth) do
@content[meth.to_s]
@ -67,6 +61,15 @@ module Merged
! cards.empty?
end
def new_card
card_data = Card.build_data(card_template)
index = cards.length
card = Card.new(self , index, card_data)
@cards << card
@content["cards"] << card_data
card
end
def remove_card(card)
from_index = card.index
@cards.delete_at(from_index)
@ -128,6 +131,15 @@ module Merged
@index = index
end
def self.build_data(template)
data = { "template" => template , "id" => SecureRandom.hex(10) }
Style.sections[ template ].fields.each do |key|
data[key] = key.upcase
end
data
end
def self.find(section_id)
raise "nil given" if section_id.blank?
section = @@all[section_id]