start on card editing

This commit is contained in:
Torsten 2022-11-30 11:22:45 +02:00
parent 5ade5c6c19
commit 277d4dce36
26 changed files with 187 additions and 19 deletions

View File

@ -0,0 +1,17 @@
module Merged
class CardsController < MergedController
before_action :set_page
def index
end
private
def set_page
@page = Page.find(params[:page_id])
section_id = params[:id] || params[:section_id]
@section = @page.find_section( section_id )
end
end
end

View File

@ -0,0 +1,4 @@
module Merged
module CardsHelper
end
end

16
app/models/merged/card.rb Normal file
View File

@ -0,0 +1,16 @@
module Merged
class Card
include ActiveModel::API
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_reader :content , :section
def initialize(section , card_data)
@section = section
raise "No data #{card_data}" unless card_data.is_a?(Hash)
@content = card_data
end
end
end

View File

@ -13,7 +13,7 @@ module Merged
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)
raise "No hash #{section_data}" unless section_data.is_a?(Hash)
@index = index
@content = section_data
end
@ -28,6 +28,12 @@ module Merged
@content[key] = value
end
def cards
element = @content["cards"]
return [] if element.nil?
element.collect{|card_content| Card.new(self , card_content)}
end
def template
@content["template"]
end

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,11 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
%p= value
%p #{section.content['cards'].length} cards
%p view cards (index)
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "View and Edit Cards" , page_section_card_url(@page.name,@section.id)
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "Change Card Template" , page_section_select_card_template_url(@page.name,@section.id)
.relative.block.border.border-gray-100
=image_tag("merged/card_preview/#{value}" , class: "w-full object-contain")

View File

@ -0,0 +1,6 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
= section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do
= text_field_tag( :header , @section.content["header"], class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-sm.font-medium.text-white{:type => "submit"}
Update

View File

View File

@ -0,0 +1,13 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "Change Image" , page_section_select_image_url(@page.name,@section.id)
%button.ml-3.inline-block.rounded-lg.bg-red-500.px-5.py-3.text-md.font-medium.text-white
= link_to( "Remove image" , page_section_set_image_path( @page.name, @section.id , image: ""))
.relative.block.border.border-gray-100
-if( value.blank? )
No image
-else
= image_tag( "cms/" + value)

View File

@ -0,0 +1,6 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase + " : " + value
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "Change Template" , page_section_select_template_url(@page.name,@section.id)
.relative.block.border.border-gray-100
=image_tag("merged/section_preview/#{section.template}" , class: "w-full object-contain")

View File

@ -0,0 +1,7 @@
.relative.block.border.border-gray-100
%h3.mt-4.text-lg.font-bold= key.upcase
.relative.block.border.border-gray-100
= section_form( class: "mx-auto mt-8 mb-0 max-w space-y-4") do
= text_area_tag( :text , @section.content["text"], class: "w-full rounded-lg border-gray-200 p-4 pr-12 text-sm shadow-sm")
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-sm.font-medium.text-white{:type => "submit"}
Update

View File

@ -0,0 +1,29 @@
%p#notice= notice
.flex.flex-col.bg-white
.flex.items-center.justify-center.flex-1
.max-w-xl.px-4.py-8.mx-auto.text-center
%h1.text-2xl.font-bold.tracking-tight.text-gray-900
Page #{@page.name}
.flex.items-center.justify-center.flex-1
%h3.text-xl.font-bold.tracking-tight.text-gray-900
Cards for Section #{@section.id}
.grid.grid-cols-4.gap-2.m-8
- @section.cards.each_with_index do |card , index|
.relative.block.border.border-gray-100
.p-4
%h3.mt-4.text-lg.font-bold Card #{index + 1}
%button.mt-4.rounded-lg.bg-yellow-500.p-4
=link_to( "Up" , "/index")
%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" , 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"
- card.content.each do |key , value|
= render "merged/cards/view/#{key}", card: card , key: key , value: value

View File

@ -0,0 +1,8 @@
.p-6
%h3.mt-4.text-lg.font-bold= key.upcase
%p
.font-bold Text
= value["text"]
%p
.font-bold Link
= value["link"]

View File

View File

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

View File

View File

@ -0,0 +1,3 @@
.p-6
%h3.mt-4.text-lg.font-bold= key.upcase
%p= value

View File

View File

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

View File

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

View File

@ -0,0 +1,3 @@
.p-6
%h3.mt-4.text-lg.font-bold= key.upcase
%p= value

View File

@ -3,6 +3,8 @@
%p= value
%p #{section.content['cards'].length} cards
%p view cards (index)
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "View and Edit Cards" , page_section_card_url(@page.name,@section.id)
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
=link_to "Change Card Template" , page_section_select_card_template_url(@page.name,@section.id)
.relative.block.border.border-gray-100

View File

@ -1,19 +1,24 @@
%h1 Listing merged_sections
%p#notice= notice
.flex.flex-col.bg-white
.flex.items-center.justify-center.flex-1
.max-w-xl.px-4.py-8.mx-auto.text-center
%h1.text-2xl.font-bold.tracking-tight.text-gray-900.sm:text-4xl
Page #{@page.name}
%table
%thead
%tr
%th
%th
%th
%tbody
- @merged_sections.each do |merged_section|
%tr
%td= link_to 'Show', section
%td= link_to 'Edit', edit_section_path(merged_section)
%td= link_to 'Destroy', section, method: :delete, data: { confirm: 'Are you sure?' }
%br
= link_to 'New Section', new_section_path
-@page.sections.each_with_index do |section , index|
.grid.grid-cols-6.gap-2.m-8{class: (index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' }
.relative.block.border.border-gray-100
.p-4
%h3.mt-4.text-lg.font-bold Section #{index + 1}
%button.mt-4.rounded-lg.bg-yellow-500.p-4
=link_to( "Up" , "/index")
%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" , 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 "merged/sections/overview/#{key}", section: section , key: key , value: value

View File

@ -9,6 +9,7 @@ Merged::Engine.routes.draw do
get :set_template
get :select_card_template
get :set_card_template
resources :cards
end
end
resources :images

View File

@ -0,0 +1,7 @@
require 'rails_helper'
module Merged
RSpec.describe Card, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
end