fix all news

This commit is contained in:
Torsten 2022-12-12 18:17:48 +02:00
parent 0d1adab3f3
commit 7966437324
10 changed files with 47 additions and 33 deletions

View File

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

View File

@ -11,7 +11,8 @@ module Merged
message = Page.check_name(name)
message = "Must enter name" if name.blank?
if( message.nil?)
@page = Page.build_new(name)
@page = Page.new_page(name)
@page.save
redirect_to new_page_section_url(@page.id) , notice: "Page was successfully created."
else
@pages = Page.all.values

View File

@ -23,7 +23,7 @@ module Merged
page = Page.find(params[:page_id])
template = params[:template]
new_section = page.new_section(template)
page.save
new_section.save
if(template.blank?) # new
redirect_to section_select_template_url(new_section.id), notice: "New section created"
else # copy

View File

@ -9,10 +9,6 @@ module Merged
fields :index , :section_id, :id , :text , :header, :image
def template_style
section.card_template
end
def move_up
swap_index_with(next_card)
end
@ -60,11 +56,12 @@ module Merged
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|
template = CardStyle.find_by_template( card_template )
template.fields.each do |key|
data[key] = "NEW"
end
card = Card.new(data)
card.add_default_options
card.add_default_options(template.options_definitions)
card
end

View File

@ -23,12 +23,12 @@ module Merged
end
def set_option( option , value)
puts "#{template_style} setting option #{option}=#{value.class}"
options[option] = value
end
def add_default_options
option_definitions.each do |option|
def add_default_options( definitions = nil )
definitions = option_definitions if definitions.nil?
definitions.each do |option|
next unless option.default
set_option( option.name , option.default)
end

View File

@ -15,7 +15,7 @@ module Merged
def new_section(section_template)
section_template = "section_spacer" if section_template.blank?
section = Section.new_section(section_template, self.id , sections.length)
section = Section.new_section(section_template, self.id , sections.length + 1)
section
end

View File

@ -19,10 +19,8 @@ module Merged
new_style = template_style
if(new_style.has_cards?)
unless card_template
self.card_template = CardStyle.first.name
self.card_template = CardStyle.first.template
end
else
cards.delete_all
end
end
@ -43,7 +41,6 @@ module Merged
end
end
def move_up
swap_index_with(next_section)
end
@ -60,19 +57,9 @@ module Merged
page.sections.where(index: index + 1).first
end
def self.new_section(template , page_id , index)
data = { template: template , index: index , page_id: page_id}
style = SectionStyle.find_by_template( template)
style.fields.each do |key|
data[key] = key.upcase
end unless style.fields.blank?
if(style.has_cards?)
data["cards"] = []
data["card_template"] = CardStyle.first.name
end
s = Section.new(data)
s.add_default_options
s
def new_card
card = Card.new_card(card_template, self.id , cards.length + 1)
card
end
def reset_index
@ -98,6 +85,21 @@ module Merged
Section.save_all
end
def self.new_section(template , page_id , index)
data = { template: template , index: index , page_id: page_id}
style = SectionStyle.find_by_template( template)
style.fields.each do |key|
data[key] = key.upcase
end unless style.fields.blank?
if(style.has_cards?)
data["cards"] = []
data["card_template"] = CardStyle.first.name
end
s = Section.new(data)
s.add_default_options
s
end
def self.save_all
data = Section.the_private_records.collect {|obj| obj.attributes}
File.write( Section.full_path , data.to_yaml)

View File

@ -23,6 +23,11 @@ module Merged
expect(first.next_card.index).to be 2
end
it "create a new" do
card = Card.new_card("card_normal_square" , 1 , 1)
expect(card.index).to eq 1
end
it "deletes " do
card = Card.find(20)
expect(card).not_to be nil

View File

@ -21,32 +21,33 @@ module Merged
expect(section.index).to be index + 1 # because we have human index
end
end
it "deletes " do
id = index.id
index.delete
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys " do
id = index.id
index.destroy
Section.reload
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys sections" do
id = index.sections.first.id
index.destroy
Section.reload
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "creates simple section" do
s = index.new_section("section_spacer")
expect(s).not_to be nil
expect(s.template).to eq "section_spacer"
end
it "creates section with right index" do
should_be = index.sections.last.index + 1
s = index.new_section("section_spacer")
expect(s.index).to eq should_be
end
it "creates page" do
name = "randomname"
page = Page.new_page( name)

View File

@ -50,6 +50,13 @@ module Merged
expect(s.template).to eq "section_spacer"
end
it "creates card with right index" do
s = Section.find_by_template("section_cards")
length = s.cards.length
c = s.new_card
expect(c.index).to eq length + 1
end
it "deletes " do
last_id = last.id
last.delete