start on section edit (without edit)
This commit is contained in:
parent
29183a3394
commit
1823f5cb3e
@ -1,4 +1,13 @@
|
||||
module Cms
|
||||
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
|
||||
|
@ -21,12 +21,25 @@ module Cms
|
||||
@content.collect{|section_data| Section.new(self , section_data)}
|
||||
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"]
|
||||
end
|
||||
|
||||
def new_section
|
||||
section = Hash.new
|
||||
section['id'] = SecureRandom.hex(10)
|
||||
@content << section
|
||||
Section.new(self , section)
|
||||
end
|
||||
|
||||
def save
|
||||
false
|
||||
file_name = Rails.root.join("cms" , name + ".yaml")
|
||||
File.write( file_name , @content.to_yaml)
|
||||
end
|
||||
|
||||
def self.all
|
||||
|
@ -20,6 +20,10 @@ module Cms
|
||||
@content["template"]
|
||||
end
|
||||
|
||||
def id
|
||||
@content["id"]
|
||||
end
|
||||
|
||||
def save
|
||||
false
|
||||
end
|
||||
|
@ -19,7 +19,7 @@
|
||||
%td.whitespace-nowrap.px-4.py-2.text-gray-700
|
||||
= link_to cms_page.name , cms_page_path(cms_page.name)
|
||||
%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
|
||||
= cms_page.content.length
|
||||
%td.whitespace-nowrap.px-4.py-2
|
||||
|
@ -15,10 +15,10 @@
|
||||
%button.mt-4.rounded-lg.bg-yellow-500.p-4
|
||||
=link_to "Down" , "/index"
|
||||
%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
|
||||
=link_to "New" , "/index"
|
||||
%button.mt-4.rounded-lg.bg-red-400.p-4
|
||||
=link_to "Delete" , "/index"
|
||||
-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
|
||||
|
9
app/views/cms/sections/editors/_button.haml
Normal file
9
app/views/cms/sections/editors/_button.haml
Normal 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"]
|
6
app/views/cms/sections/editors/_card_template.haml
Normal file
6
app/views/cms/sections/editors/_card_template.haml
Normal 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")
|
4
app/views/cms/sections/editors/_cards.haml
Normal file
4
app/views/cms/sections/editors/_cards.haml
Normal file
@ -0,0 +1,4 @@
|
||||
.relative.block.border.border-gray-100
|
||||
Cards number
|
||||
.relative.block.border.border-gray-100
|
||||
Card preview
|
4
app/views/cms/sections/editors/_header.haml
Normal file
4
app/views/cms/sections/editors/_header.haml
Normal 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
|
4
app/views/cms/sections/editors/_image.haml
Normal file
4
app/views/cms/sections/editors/_image.haml
Normal 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
|
5
app/views/cms/sections/editors/_template.haml
Normal file
5
app/views/cms/sections/editors/_template.haml
Normal 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")
|
4
app/views/cms/sections/editors/_text.haml
Normal file
4
app/views/cms/sections/editors/_text.haml
Normal 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
|
0
app/views/cms/sections/overview/_card
Normal file
0
app/views/cms/sections/overview/_card
Normal file
0
app/views/cms/sections/overview/_cards.haml
Normal file
0
app/views/cms/sections/overview/_cards.haml
Normal file
0
app/views/cms/sections/overview/_id.haml
Normal file
0
app/views/cms/sections/overview/_id.haml
Normal file
@ -1,5 +1,8 @@
|
||||
%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)
|
||||
\|
|
||||
|
Loading…
Reference in New Issue
Block a user