fic new cards

This commit is contained in:
Torsten 2022-12-11 16:27:08 +02:00
parent 76f5e4e6e1
commit dc4124a03d
5 changed files with 17 additions and 13 deletions

View File

@ -28,7 +28,7 @@ module Merged
def new
@section = Section.find(params[:section_id])
new_card = @section.new_card
new_card = @section.new_card
redirect_to section_cards_url(@section.id) , notice: "Card created"
end

View File

@ -36,7 +36,7 @@ module Merged
def save
super
data = Card.all.collect {|obj| obj.attributes}
File.write( OptionDefinition.full_path , data.to_yaml)
File.write( Card.full_path , data.to_yaml)
end
def set_index(index)
@ -47,12 +47,14 @@ module Merged
CardStyle.find_by_template( section.card_template)
end
def self.build_data(card_template)
data = { "id" => SecureRandom.hex(10) }
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|
data[key] = key.upcase
data[key] = "NEW"
end
data
card = Card.new(data)
card.add_default_options
card
end
end

View File

@ -27,6 +27,13 @@ module Merged
options[option] = value
end
def add_default_options
option_definitions.each do |option|
next unless option.default
set_option( option.name , option.default)
end
end
def update(key , value)
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
if(! attributes[key].nil? ) # first setting ok, types not (yet?) specified

View File

@ -9,8 +9,6 @@ module Merged
fields :name , :content , :size , :updated_at
alias :id :name
def sections
Section.where(page_id: name).order(index: :asc)
end

View File

@ -35,11 +35,8 @@ module Merged
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 = Card.new_card( card_template , self.id , cards.length)
card.save
card
end