start on card editing
This commit is contained in:
parent
5ade5c6c19
commit
277d4dce36
17
app/controllers/merged/cards_controller.rb
Normal file
17
app/controllers/merged/cards_controller.rb
Normal 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
|
4
app/helpers/merged/cards_helper.rb
Normal file
4
app/helpers/merged/cards_helper.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
module Merged
|
||||||
|
module CardsHelper
|
||||||
|
end
|
||||||
|
end
|
16
app/models/merged/card.rb
Normal file
16
app/models/merged/card.rb
Normal 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
|
@ -13,7 +13,7 @@ module Merged
|
|||||||
def initialize(page , index , section_data)
|
def initialize(page , index , section_data)
|
||||||
@page = page
|
@page = page
|
||||||
raise "No number #{index}" unless index.is_a?(Integer)
|
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
|
@index = index
|
||||||
@content = section_data
|
@content = section_data
|
||||||
end
|
end
|
||||||
@ -28,6 +28,12 @@ module Merged
|
|||||||
@content[key] = value
|
@content[key] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cards
|
||||||
|
element = @content["cards"]
|
||||||
|
return [] if element.nil?
|
||||||
|
element.collect{|card_content| Card.new(self , card_content)}
|
||||||
|
end
|
||||||
|
|
||||||
def template
|
def template
|
||||||
@content["template"]
|
@content["template"]
|
||||||
end
|
end
|
||||||
|
9
app/views/merged/cards/editors/_button.haml
Normal file
9
app/views/merged/cards/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"]
|
11
app/views/merged/cards/editors/_card_template.haml
Normal file
11
app/views/merged/cards/editors/_card_template.haml
Normal 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")
|
0
app/views/merged/cards/editors/_cards.haml
Normal file
0
app/views/merged/cards/editors/_cards.haml
Normal file
6
app/views/merged/cards/editors/_header.haml
Normal file
6
app/views/merged/cards/editors/_header.haml
Normal 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
|
0
app/views/merged/cards/editors/_id.haml
Normal file
0
app/views/merged/cards/editors/_id.haml
Normal file
13
app/views/merged/cards/editors/_image.haml
Normal file
13
app/views/merged/cards/editors/_image.haml
Normal 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)
|
6
app/views/merged/cards/editors/_template.haml
Normal file
6
app/views/merged/cards/editors/_template.haml
Normal 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")
|
7
app/views/merged/cards/editors/_text.haml
Normal file
7
app/views/merged/cards/editors/_text.haml
Normal 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
|
29
app/views/merged/cards/index.haml
Normal file
29
app/views/merged/cards/index.haml
Normal 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
|
8
app/views/merged/cards/view/_button.haml
Normal file
8
app/views/merged/cards/view/_button.haml
Normal 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"]
|
0
app/views/merged/cards/view/_card
Normal file
0
app/views/merged/cards/view/_card
Normal file
5
app/views/merged/cards/view/_card_template.haml
Normal file
5
app/views/merged/cards/view/_card_template.haml
Normal 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
|
0
app/views/merged/cards/view/_cards.haml
Normal file
0
app/views/merged/cards/view/_cards.haml
Normal file
3
app/views/merged/cards/view/_header.haml
Normal file
3
app/views/merged/cards/view/_header.haml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.p-6
|
||||||
|
%h3.mt-4.text-lg.font-bold= key.upcase
|
||||||
|
%p= value
|
0
app/views/merged/cards/view/_id.haml
Normal file
0
app/views/merged/cards/view/_id.haml
Normal file
6
app/views/merged/cards/view/_image.haml
Normal file
6
app/views/merged/cards/view/_image.haml
Normal 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
|
4
app/views/merged/cards/view/_template.haml
Normal file
4
app/views/merged/cards/view/_template.haml
Normal 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")
|
3
app/views/merged/cards/view/_text.haml
Normal file
3
app/views/merged/cards/view/_text.haml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.p-6
|
||||||
|
%h3.mt-4.text-lg.font-bold= key.upcase
|
||||||
|
%p= value
|
@ -3,6 +3,8 @@
|
|||||||
%p= value
|
%p= value
|
||||||
%p #{section.content['cards'].length} cards
|
%p #{section.content['cards'].length} cards
|
||||||
%p view cards (index)
|
%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
|
%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)
|
=link_to "Change Card Template" , page_section_select_card_template_url(@page.name,@section.id)
|
||||||
.relative.block.border.border-gray-100
|
.relative.block.border.border-gray-100
|
||||||
|
@ -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
|
-@page.sections.each_with_index do |section , index|
|
||||||
%thead
|
.grid.grid-cols-6.gap-2.m-8{class: (index%2)==1 ? 'bg-cyan-50' : 'bg-red-50' }
|
||||||
%tr
|
.relative.block.border.border-gray-100
|
||||||
%th
|
.p-4
|
||||||
%th
|
%h3.mt-4.text-lg.font-bold Section #{index + 1}
|
||||||
%th
|
%button.mt-4.rounded-lg.bg-yellow-500.p-4
|
||||||
|
=link_to( "Up" , "/index")
|
||||||
%tbody
|
%button.mt-4.rounded-lg.bg-yellow-500.p-4
|
||||||
- @merged_sections.each do |merged_section|
|
=link_to "Down" , "/index"
|
||||||
%tr
|
%button.mt-4.rounded-lg.bg-blue-400.p-4
|
||||||
%td= link_to 'Show', section
|
=link_to "Edit" , page_section_path(@page.name , section.id)
|
||||||
%td= link_to 'Edit', edit_section_path(merged_section)
|
%button.mt-4.rounded-lg.bg-cyan-400.p-4
|
||||||
%td= link_to 'Destroy', section, method: :delete, data: { confirm: 'Are you sure?' }
|
=link_to "New" , "/index"
|
||||||
|
%button.mt-4.rounded-lg.bg-red-400.p-4
|
||||||
%br
|
=link_to "Delete" , "/index"
|
||||||
|
-section.content.each do |key , value|
|
||||||
= link_to 'New Section', new_section_path
|
= render "merged/sections/overview/#{key}", section: section , key: key , value: value
|
||||||
|
@ -9,6 +9,7 @@ Merged::Engine.routes.draw do
|
|||||||
get :set_template
|
get :set_template
|
||||||
get :select_card_template
|
get :select_card_template
|
||||||
get :set_card_template
|
get :set_card_template
|
||||||
|
resources :cards
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :images
|
resources :images
|
||||||
|
7
spec/models/merged/card_spec.rb
Normal file
7
spec/models/merged/card_spec.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user