add index (synthetic) to sections

This commit is contained in:
Torsten 2022-11-27 14:09:16 +02:00
parent 1823f5cb3e
commit 8d405e44e1
8 changed files with 31 additions and 15 deletions

View File

@ -18,12 +18,19 @@ module Cms
end
def sections
@content.collect{|section_data| Section.new(self , section_data)}
sections = []
@content.each_with_index do |section_data, index|
sections << Section.new(self , index, section_data)
end
sections
end
def find_section(section_id)
content = @content.find{|section| section["id"] == section_id }
Section.new(self , content)
@content.each_with_index do |section , index|
next unless section["id"] == section_id
return Section.new(self , index , section)
end
raise "Page #{name} as no section #{section_id}"
end
def first_template
@ -34,7 +41,7 @@ module Cms
section = Hash.new
section['id'] = SecureRandom.hex(10)
@content << section
Section.new(self , section)
Section.new(self , 0 , section)
end
def save

View File

@ -4,16 +4,18 @@ module Cms
include ActiveModel::Conversion
include ActiveModel::Dirty
attr_reader :name , :content , :page
attr_reader :name , :content , :page , :index
def persisted?
false
end
def initialize(page , section_data)
def initialize(page , index , section_data)
@page = page
raise "No number #{index}" unless index.is_a?(Integer)
raise "No has #{section_data}" unless section_data.is_a?(Hash)
@index = index
@content = section_data
# id = SecureRandom.hex(10) if new or not there
end
def template

View File

@ -2,5 +2,6 @@
%h3.mt-4.text-lg.font-bold= key.upcase
%p= value
%p #{section.content['cards'].length} cards
%p view cards (index)
.relative.block.border.border-gray-100
=image_tag("cms/card_preview/#{value}" , class: "w-full object-contain")

View File

@ -1,4 +0,0 @@
.relative.block.border.border-gray-100
Cards number
.relative.block.border.border-gray-100
Card preview

View File

@ -1,4 +1,7 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
.relative.block.border.border-gray-100
-if value
= image_tag "cms/" + value
-else
No image

View File

@ -1,3 +1,6 @@
.p-6
%h3.mt-4.text-lg.font-bold= key.upcase
-if value
= image_tag "cms/" + value
-else
No image

View File

@ -1,5 +1,9 @@
%p#notice= notice
%h1 Page #{@page.name}
%h4 Section #{@section.id}
.grid.grid-cols-2.gap-2.m-8
- @section.content.each do |key , value|
= render "cms/sections/editors/#{key}", section: @section , key: key , value: value

View File

@ -6,7 +6,8 @@
The rooms are in the old hospital wings, so most are old patient rooms, but there
are plenty of others too. Prices do not include electricity or vat, but do include
the use of common spaces, see below.
image: makerspace.webp
image:
id: b7d16d4da518bafd3d39
card_template: card_full_image
cards:
- header: Standard
@ -19,4 +20,3 @@
are large enough to be shared. The size is about 30m2 and the cost 240e. Like
the small rooms these are south facing, very light.
image: large.webp
id: b7d16d4da518bafd3d39