From aa2001312189e4591fdccd9d8e729012a34eec46 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 11 Dec 2022 14:31:04 +0200 Subject: [PATCH] fixing the updates --- app/controllers/merged/cards_controller.rb | 2 +- app/models/merged/card.rb | 20 -------------------- app/models/merged/optioned.rb | 21 +++++++++++++++++++-- app/models/merged/section.rb | 17 ----------------- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/app/controllers/merged/cards_controller.rb b/app/controllers/merged/cards_controller.rb index 602aef2..bffaf91 100644 --- a/app/controllers/merged/cards_controller.rb +++ b/app/controllers/merged/cards_controller.rb @@ -56,7 +56,7 @@ module Merged private def set_card card_id = params[:id] || params[:card_id] - @card = Card.find_card( card_id ) + @card = Card.find( card_id ) end end diff --git a/app/models/merged/card.rb b/app/models/merged/card.rb index 532e95f..6d70da5 100644 --- a/app/models/merged/card.rb +++ b/app/models/merged/card.rb @@ -17,16 +17,6 @@ module Merged @section.remove_card( self) 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 swap_index_with(next_card) end @@ -57,10 +47,6 @@ module Merged CardStyle.find_by_template( section.card_template) end - def allowed_fields - template_style.fields - end - def self.build_data(card_template) data = { "id" => SecureRandom.hex(10) } CardStyle.find_by_template( card_template ).fields.each do |key| @@ -69,11 +55,5 @@ module Merged 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 end end diff --git a/app/models/merged/optioned.rb b/app/models/merged/optioned.rb index b7d0e25..f6f5a80 100644 --- a/app/models/merged/optioned.rb +++ b/app/models/merged/optioned.rb @@ -1,6 +1,9 @@ module Merged #relies only on @content["options"] #and a method template_style + # and index + # and is due for a rename + module Optioned def has_option?(option) options.has_key?(option) and !options[option].blank? @@ -15,15 +18,25 @@ module Merged end def options - attributes[:options] || {} + return attributes[:options] unless attributes[:options].blank? + attributes[:options] = {} end def set_option( option , value) puts "#{template_style} setting option #{option}=#{value.class}" - @content["options"] = {} if @content["options"].nil? options[option] = value 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 def swap_index_with(other) return unless other @@ -32,5 +45,9 @@ module Merged other.index = old_index end + def allowed_fields + template_style.fields.collect{|f| f.to_sym} + end + end end diff --git a/app/models/merged/section.rb b/app/models/merged/section.rb index 57b8aa4..0499a19 100644 --- a/app/models/merged/section.rb +++ b/app/models/merged/section.rb @@ -30,10 +30,6 @@ module Merged SectionStyle.find_by_template( template ) end - def allowed_fields - template_style.fields - end - def has_cards? ! card_template.blank? end @@ -73,15 +69,6 @@ module Merged page.sections.where(index: index + 1).first 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 super @@ -89,10 +76,6 @@ module Merged File.write( Section.full_path , data.to_yaml) end - def set_index(index) - @index = index - end - def self.build_data(template) data = { "template" => template , "id" => SecureRandom.hex(10) } style = SectionStyle.sections[ template ]