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 def new
@section = Section.find(params[:section_id]) @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" redirect_to section_cards_url(@section.id) , notice: "Card created"
end end

View File

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

View File

@ -27,6 +27,13 @@ module Merged
options[option] = value options[option] = value
end 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) def update(key , value)
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key) raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
if(! attributes[key].nil? ) # first setting ok, types not (yet?) specified 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 fields :name , :content , :size , :updated_at
alias :id :name
def sections def sections
Section.where(page_id: name).order(index: :asc) Section.where(page_id: name).order(index: :asc)
end end

View File

@ -35,11 +35,8 @@ module Merged
end end
def new_card def new_card
card_data = Card.build_data(card_template) card = Card.new_card( card_template , self.id , cards.length)
index = cards.length card.save
card = Card.new(self , index, card_data)
@cards << card
@content["cards"] << card_data
card card
end end