start on section edit (without edit)

This commit is contained in:
Torsten 2022-11-26 19:07:20 +02:00
parent 29183a3394
commit 1823f5cb3e
23 changed files with 70 additions and 5 deletions

View File

@ -1,4 +1,13 @@
module Cms module Cms
class SectionsController < CmsController class SectionsController < CmsController
before_action :set_page, only: %i[ show edit update destroy ]
private
def set_page
@page = Page.find(params[:page_id])
@section = @page.find_section( params[:id] )
end
end end
end end

View File

@ -21,12 +21,25 @@ module Cms
@content.collect{|section_data| Section.new(self , section_data)} @content.collect{|section_data| Section.new(self , section_data)}
end end
def template def find_section(section_id)
content = @content.find{|section| section["id"] == section_id }
Section.new(self , content)
end
def first_template
@content[0]["template"] @content[0]["template"]
end end
def new_section
section = Hash.new
section['id'] = SecureRandom.hex(10)
@content << section
Section.new(self , section)
end
def save def save
false file_name = Rails.root.join("cms" , name + ".yaml")
File.write( file_name , @content.to_yaml)
end end
def self.all def self.all

View File

@ -20,6 +20,10 @@ module Cms
@content["template"] @content["template"]
end end
def id
@content["id"]
end
def save def save
false false
end end

View File

@ -19,7 +19,7 @@
%td.whitespace-nowrap.px-4.py-2.text-gray-700 %td.whitespace-nowrap.px-4.py-2.text-gray-700
= link_to cms_page.name , cms_page_path(cms_page.name) = link_to cms_page.name , cms_page_path(cms_page.name)
%td.whitespace-nowrap.px-4.py-2.text-gray-700 %td.whitespace-nowrap.px-4.py-2.text-gray-700
= cms_page.template = cms_page.first_template
%td.whitespace-nowrap.px-4.py-2.text-gray-700 %td.whitespace-nowrap.px-4.py-2.text-gray-700
= cms_page.content.length = cms_page.content.length
%td.whitespace-nowrap.px-4.py-2 %td.whitespace-nowrap.px-4.py-2

View File

@ -15,10 +15,10 @@
%button.mt-4.rounded-lg.bg-yellow-500.p-4 %button.mt-4.rounded-lg.bg-yellow-500.p-4
=link_to "Down" , "/index" =link_to "Down" , "/index"
%button.mt-4.rounded-lg.bg-blue-400.p-4 %button.mt-4.rounded-lg.bg-blue-400.p-4
=link_to "Edit" , cms_page_section_path(@page.name , 1234) =link_to "Edit" , cms_page_section_path(@page.name , section.id)
%button.mt-4.rounded-lg.bg-cyan-400.p-4 %button.mt-4.rounded-lg.bg-cyan-400.p-4
=link_to "New" , "/index" =link_to "New" , "/index"
%button.mt-4.rounded-lg.bg-red-400.p-4 %button.mt-4.rounded-lg.bg-red-400.p-4
=link_to "Delete" , "/index" =link_to "Delete" , "/index"
-section.content.each do |key , value| -section.content.each do |key , value|
= render "cms/sections/data/#{key}", section: section , key: key , value: value = render "cms/sections/overview/#{key}", section: section , key: key , value: value

View File

@ -0,0 +1,9 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
%p
.font-bold Text
= value["text"]
.relative.block.border.border-gray-100
%p
.font-bold Link
= value["link"]

View File

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

View File

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

View File

@ -0,0 +1,4 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
.relative.block.border.border-gray-100
%p= value

View File

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

View File

@ -0,0 +1,5 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
%p= value
.relative.block.border.border-gray-100
=image_tag("cms/section_preview/#{section.template}" , class: "w-full object-contain")

View File

@ -0,0 +1,4 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
.relative.block.border.border-gray-100
%p= value

View File

View File

View File

@ -1,5 +1,8 @@
%p#notice= notice %p#notice= notice
.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
= #link_to 'Edit', edit_cms_section_path(@cms_section) = #link_to 'Edit', edit_cms_section_path(@cms_section)
\| \|