fixing the updates

This commit is contained in:
Torsten 2022-12-11 14:31:04 +02:00
parent 912400b852
commit aa20013121
4 changed files with 20 additions and 40 deletions

View File

@ -56,7 +56,7 @@ module Merged
private private
def set_card def set_card
card_id = params[:id] || params[:card_id] card_id = params[:id] || params[:card_id]
@card = Card.find_card( card_id ) @card = Card.find( card_id )
end end
end end

View File

@ -17,16 +17,6 @@ module Merged
@section.remove_card( self) @section.remove_card( self)
end end
def update(key , value)
return if key == "id" #not updating that
if(! @content[key].nil? )
if( @content[key].class != value.class )
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
end
end
@content[key] = value
end
def move_up def move_up
swap_index_with(next_card) swap_index_with(next_card)
end end
@ -57,10 +47,6 @@ module Merged
CardStyle.find_by_template( section.card_template) CardStyle.find_by_template( section.card_template)
end end
def allowed_fields
template_style.fields
end
def self.build_data(card_template) def self.build_data(card_template)
data = { "id" => SecureRandom.hex(10) } data = { "id" => SecureRandom.hex(10) }
CardStyle.find_by_template( card_template ).fields.each do |key| CardStyle.find_by_template( card_template ).fields.each do |key|
@ -69,11 +55,5 @@ module Merged
data data
end 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
end end
end end

View File

@ -1,6 +1,9 @@
module Merged module Merged
#relies only on @content["options"] #relies only on @content["options"]
#and a method template_style #and a method template_style
# and index
# and is due for a rename
module Optioned module Optioned
def has_option?(option) def has_option?(option)
options.has_key?(option) and !options[option].blank? options.has_key?(option) and !options[option].blank?
@ -15,15 +18,25 @@ module Merged
end end
def options def options
attributes[:options] || {} return attributes[:options] unless attributes[:options].blank?
attributes[:options] = {}
end end
def set_option( option , value) def set_option( option , value)
puts "#{template_style} setting option #{option}=#{value.class}" puts "#{template_style} setting option #{option}=#{value.class}"
@content["options"] = {} if @content["options"].nil?
options[option] = value options[option] = value
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
if( @attributes[key].class != value.class )
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
end
end
attributes[key] = value
end
#other may be nil #other may be nil
def swap_index_with(other) def swap_index_with(other)
return unless other return unless other
@ -32,5 +45,9 @@ module Merged
other.index = old_index other.index = old_index
end end
def allowed_fields
template_style.fields.collect{|f| f.to_sym}
end
end end
end end

View File

@ -30,10 +30,6 @@ module Merged
SectionStyle.find_by_template( template ) SectionStyle.find_by_template( template )
end end
def allowed_fields
template_style.fields
end
def has_cards? def has_cards?
! card_template.blank? ! card_template.blank?
end end
@ -73,15 +69,6 @@ module Merged
page.sections.where(index: index + 1).first page.sections.where(index: index + 1).first
end end
def update(key , value)
raise "unsuported field #{key} for #{template}" unless allowed_fields.include?(key)
if(! @content[key].nil? ) # first setting ok, types not (yet?) specified
if( @content[key].class != value.class )
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
end
end
@content[key] = value
end
def save def save
super super
@ -89,10 +76,6 @@ module Merged
File.write( Section.full_path , data.to_yaml) File.write( Section.full_path , data.to_yaml)
end end
def set_index(index)
@index = index
end
def self.build_data(template) def self.build_data(template)
data = { "template" => template , "id" => SecureRandom.hex(10) } data = { "template" => template , "id" => SecureRandom.hex(10) }
style = SectionStyle.sections[ template ] style = SectionStyle.sections[ template ]