card editing version one
This commit is contained in:
parent
df5713e6fe
commit
204ab1abcc
@ -6,11 +6,32 @@ module Merged
|
||||
@section = Section.find(params[:section_id])
|
||||
end
|
||||
|
||||
def select_image
|
||||
@images = Image.all
|
||||
end
|
||||
|
||||
def set_image
|
||||
@card.content["image"] = params[:image]
|
||||
@card.save
|
||||
redirect_to section_cards_url(@card.section.id)
|
||||
end
|
||||
|
||||
def update
|
||||
@card.content.each do |key , value|
|
||||
next if key == "id"
|
||||
if(!params[key].nil?)
|
||||
@card.update(key, params[key])
|
||||
puts "updating:#{key}=#{params[key]}"
|
||||
end
|
||||
end
|
||||
@card.save
|
||||
redirect_to section_cards_url(@card.section.id)
|
||||
end
|
||||
|
||||
private
|
||||
def set_page
|
||||
@page = Page.find(params[:page_id])
|
||||
section_id = params[:id] || params[:section_id]
|
||||
@section = @page.find_section( section_id )
|
||||
def set_card
|
||||
card_id = params[:id] || params[:card_id]
|
||||
@card = Card.find_card( card_id )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -3,7 +3,6 @@ module Merged
|
||||
|
||||
def section_form(options)
|
||||
url = section_url( @section.id)
|
||||
puts "URL #{url}"
|
||||
form_tag( url , {method: :patch}) do
|
||||
yield
|
||||
end
|
||||
|
@ -22,11 +22,21 @@ module Merged
|
||||
@content['id']
|
||||
end
|
||||
|
||||
def update(key , value)
|
||||
return if key == "id" #not updating that
|
||||
if(! @content[key].nil? )
|
||||
if( @content[key].class != value.class )
|
||||
raise "Type mismatch #{key} #{key.class}!=#{value.class}"
|
||||
end
|
||||
end
|
||||
@content[key] = value
|
||||
end
|
||||
|
||||
def save
|
||||
section.save
|
||||
end
|
||||
|
||||
def self.find(id)
|
||||
def self.find_card(id)
|
||||
raise "nil given" if id.blank?
|
||||
card = @@all[id]
|
||||
raise "Section not found #{id}" unless card
|
||||
|
@ -1,11 +0,0 @@
|
||||
.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" , 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" , 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")
|
@ -1,6 +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
|
||||
%h3.mt-4.text-lg.font-bold Header
|
||||
= form_tag( card_url(card.id) , {method: :patch } ) do
|
||||
= text_field_tag( :header , card.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
|
||||
|
@ -1,11 +1,3 @@
|
||||
.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" , 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" , section_set_image_path( @page.name, @section.id , image: ""))
|
||||
|
||||
|
||||
.relative.block.border.border-gray-100
|
||||
-if( value.blank? )
|
||||
No image
|
||||
|
@ -1,7 +1,6 @@
|
||||
.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")
|
||||
%h3.mt-4.text-lg.font-bold Text
|
||||
= form_tag( card_url(card.id) , {method: :patch } ) do
|
||||
= text_area_tag( :text , card.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
|
||||
|
@ -24,6 +24,12 @@
|
||||
=link_to "New" , "/index"
|
||||
%button.mt-4.rounded-lg.bg-red-400.p-4
|
||||
=link_to "Delete" , "/index"
|
||||
.p-4
|
||||
%h3.mt-4.text-lg.font-bold Image
|
||||
%button.ml-3.inline-block.rounded-lg.bg-blue-500.px-5.py-3.text-md.font-medium.text-white
|
||||
=link_to "Change Image" , card_select_image_url(card.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" , card_set_image_path( card.id , image: ""))
|
||||
|
||||
- card.content.each do |key , value|
|
||||
= render "merged/cards/view/#{key}", card: card , key: key , value: value
|
||||
= render "merged/cards/editors/#{key}", card: card , key: key , value: value
|
||||
|
15
app/views/merged/cards/select_image.haml
Normal file
15
app/views/merged/cards/select_image.haml
Normal file
@ -0,0 +1,15 @@
|
||||
.grid.grid-cols-6.gap-2.m-8
|
||||
.relative.block.border.border-gray-100
|
||||
%h3.mt-4.text-lg.font-bold Add new image or select (click)
|
||||
= form_tag(merged.images_path, multipart: true) do
|
||||
= text_field_tag 'filename'
|
||||
%h5.mt-4.text-lg.font-bold Name is optional
|
||||
%p will be taken from uploaded file
|
||||
= hidden_field_tag :redirect , card_set_image_url(@card.id,image: "NEW")
|
||||
= file_field_tag 'image_file'
|
||||
.inline-block.rounded.border.border-indigo-600.bg-indigo-600.px-12.py-3.text-sm.font-medium.text-white.hover:bg-transparent.hover:text-indigo-600.focus:outline-none.focus:ring.active:text-indigo-500{:href => merged.new_image_path}
|
||||
= submit_tag 'Submit'
|
||||
-@images.each do |name , image|
|
||||
.relative.block.border.border-gray-100
|
||||
= link_to( card_set_image_path( image: name)) do
|
||||
=image_tag("#{image_root}/#{name}" , class: "h-56 w-full object-contain lg:h-72")
|
@ -4,7 +4,7 @@
|
||||
.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 #{@section.page.name}
|
||||
Page #{link_to @section.page.name, page_url(@section.page.name)}
|
||||
.flex.items-center.justify-center.flex-1
|
||||
%h3.text-xl.font-bold.tracking-tight.text-gray-900
|
||||
Section #{@section.id}
|
||||
|
@ -9,7 +9,10 @@ Merged::Engine.routes.draw do
|
||||
get :set_template
|
||||
get :select_card_template
|
||||
get :set_card_template
|
||||
resources :cards
|
||||
resources :cards do
|
||||
get :select_image
|
||||
get :set_image
|
||||
end
|
||||
end
|
||||
end
|
||||
resources :images
|
||||
|
Loading…
Reference in New Issue
Block a user