fixes from transition, tests pass, just because there are too little

This commit is contained in:
2022-12-11 12:20:53 +02:00
parent c615a77af3
commit 829d653b44
12 changed files with 54 additions and 32 deletions

View File

@ -3,7 +3,7 @@ module Merged
before_action :set_page, only: %i[ update destroy ]
def index
@pages = Page.all.values
@pages = Page.all
end
def create

View File

@ -12,7 +12,6 @@ module Merged
attributes["style"] = "background-image: url('#{img}');"
if(section.option("fixed") == "on")
attributes[:class] = attributes[:class] + " bg-fixed"
puts "Adding fixed"
end
attributes
end

View File

@ -15,7 +15,7 @@ module Merged
end
def options
@content["options"] || {}
attributes[:options] || {}
end
def set_option( option , value)

View File

@ -2,8 +2,7 @@ module Merged
class Page < ActiveYaml::Base
set_root_path Rails.root #ouside engines not necessary
include ActiveHash::Associations
has_many :sections , class_name: "Merged::Section"
has_many :sections , class_name: "Merged::Section" , scope: -> { order(index: :desc) }
# could be config options
def self.cms_root
"cms"

View File

@ -4,11 +4,12 @@ module Merged
include ActiveHash::Associations
belongs_to :page , class_name: "Merged::Page"
has_many :cards , class_name: "Merged::Card"
has_many :cards , class_name: "Merged::Card" , scope: -> { order(index: :desc) }
include Optioned
fields :name , :page_id , :index , :cards
fields :name , :page_id , :index , :cards , :options
fields :template , :card_template , :id , :text , :header, :image
def set_template(new_template)
@ -66,13 +67,11 @@ module Merged
end
def previous_section
return nil if index == 0
page.sections[index - 1]
page.sections.where(index: index - 1).first
end
def next_section
return nil if index == (page.sections.length - 1)
page.sections[index + 1]
page.sections.where(index: index + 1).first
end
def move_card_up(card)
@ -135,12 +134,5 @@ module Merged
data
end
def self.find(section_id)
raise "nil given" if section_id.blank?
section = @@all[section_id]
raise "Section not found #{section_id}" unless section
return section
end
end
end

View File

@ -9,7 +9,7 @@
=link_to "View live" , "/#{@page.name}" , target: @page.name
-@page.sections.each do |section |
.grid.grid-cols-5.gap-2.m-8{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' }
.grid.grid-cols-5.gap-2.m-8{class: (section.index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' , id: "section_#{section.id}"}
.relative.block.border.border-gray-100.p-4
%h3.mt-4.text-lg.font-bold Section #{section.index + 1} : #{section.header}
= blue_button( "Up" , section_move_url(section.id , dir: :up) )
@ -30,7 +30,7 @@
%p= section.text[0..100] + " ..." if section.text
.relative.block.border.border-gray-100.p-4
- if section.has_cards?
%h3.mt-4.text-lg.font-bold #{section.content['cards'].length} Cards
%h3.mt-4.text-lg.font-bold #{section.cards.length} Cards
=link_to section_cards_url(section.id) do
=card_preview(section , class: "w-full object-contain")
- else

View File

@ -9,9 +9,9 @@
.flex.items-center.justify-center.flex-1
%h3.text-xl.font-bold.tracking-tight.text-gray-900
Section #{@section.index + 1} / #{@section.page.sections.length}
- unless @section.index == 0
- if @section.previous_section
=link_to "(prev)" , section_url(@section.previous_section.id)
- unless @section.index == (@section.page.sections.length - 1)
- if @section.next_section
=link_to "(next)" , section_url(@section.next_section.id)
.grid.grid-cols-3.gap-2.m-8
.relative.block.border.border-gray-100