new cards
This commit is contained in:
parent
6287373dae
commit
1e452ca62a
@ -1,6 +1,6 @@
|
||||
module Merged
|
||||
class CardsController < MergedController
|
||||
before_action :set_card , except: :index
|
||||
before_action :set_card , except: [:index , :new]
|
||||
|
||||
def index
|
||||
@section = Section.find(params[:section_id])
|
||||
@ -26,6 +26,12 @@ module Merged
|
||||
redirect_to section_cards_url(@card.section.id)
|
||||
end
|
||||
|
||||
def new
|
||||
@section = Section.find(params[:section_id])
|
||||
new_card = @section.new_card
|
||||
redirect_to section_cards_url(@section.id)
|
||||
end
|
||||
|
||||
def remove
|
||||
section = @card.section
|
||||
section.remove_card( @card )
|
||||
@ -34,9 +40,9 @@ module Merged
|
||||
end
|
||||
|
||||
def update
|
||||
@card.content.each do |key , value|
|
||||
next if key == "id"
|
||||
if(!params[key].nil?)
|
||||
@card.allowed_fields.each do |key|
|
||||
puts "Update Card #{key}"
|
||||
if( params.has_key?(key) )
|
||||
@card.update(key, params[key])
|
||||
puts "updating:#{key}=#{params[key]}"
|
||||
end
|
||||
|
@ -64,7 +64,7 @@ module Merged
|
||||
|
||||
def update
|
||||
@section.allowed_fields.each do |key|
|
||||
puts "Update #{key}"
|
||||
puts "Update Section #{key}"
|
||||
if( params.has_key?(key) )
|
||||
@section.update(key, params[key])
|
||||
puts "updating:#{key}=#{params[key]}"
|
||||
|
@ -6,17 +6,19 @@ module Merged
|
||||
"merged/view/" + section.template
|
||||
end
|
||||
|
||||
# background image as inline style
|
||||
def bg(section)
|
||||
return "" if section.image.blank?
|
||||
puts "--#{Image.image_root}/#{section.image}--"
|
||||
img = asset_url( "#{Image.image_root}/#{section.image}" )
|
||||
"background-image: url('#{img}');"
|
||||
end
|
||||
def image_for(section , classes)
|
||||
image_tag("#{Image.image_root}/#{section.image}" , class: classes)
|
||||
end
|
||||
def has_button(section)
|
||||
section.content['button']
|
||||
|
||||
# works for with sections and cards that respond to .image
|
||||
def image_for(element , classes)
|
||||
return "" if element.image.blank?
|
||||
image_tag("#{Image.image_root}/#{element.image}" , class: classes)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -46,15 +46,30 @@ module Merged
|
||||
section.save
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@index = index
|
||||
end
|
||||
|
||||
def template_style
|
||||
Style.cards[ section.card_template ]
|
||||
end
|
||||
def allowed_fields
|
||||
template_style.fields
|
||||
end
|
||||
|
||||
def self.build_data(card_template)
|
||||
data = { "id" => SecureRandom.hex(10) }
|
||||
Style.cards[ card_template ].fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
def self.find_card(id)
|
||||
raise "nil given" if id.blank?
|
||||
card = @@all[id]
|
||||
raise "Section not found #{id}" unless card
|
||||
return card
|
||||
end
|
||||
|
||||
def set_index(index)
|
||||
@index = index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -35,7 +35,8 @@ module Merged
|
||||
end
|
||||
|
||||
def new_section
|
||||
section_data = Section.build_data
|
||||
section_template = params[:template] || "section_spacer"
|
||||
section_data = Section.build_data(section_template)
|
||||
index = sections.length
|
||||
section = Section.new(self , index, section_data)
|
||||
@sections << section
|
||||
|
@ -25,12 +25,6 @@ module Merged
|
||||
end
|
||||
end
|
||||
|
||||
def self.build_data
|
||||
data = { "template" => "spacer"}
|
||||
data["id"] = SecureRandom.hex(10)
|
||||
data
|
||||
end
|
||||
|
||||
[:template , :card_template , :id , :text , :header, :image].each do |meth|
|
||||
define_method(meth) do
|
||||
@content[meth.to_s]
|
||||
@ -67,6 +61,15 @@ module Merged
|
||||
! cards.empty?
|
||||
end
|
||||
|
||||
def new_card
|
||||
card_data = Card.build_data(card_template)
|
||||
index = cards.length
|
||||
card = Card.new(self , index, card_data)
|
||||
@cards << card
|
||||
@content["cards"] << card_data
|
||||
card
|
||||
end
|
||||
|
||||
def remove_card(card)
|
||||
from_index = card.index
|
||||
@cards.delete_at(from_index)
|
||||
@ -128,6 +131,15 @@ module Merged
|
||||
@index = index
|
||||
end
|
||||
|
||||
def self.build_data(template)
|
||||
data = { "template" => template , "id" => SecureRandom.hex(10) }
|
||||
Style.sections[ template ].fields.each do |key|
|
||||
data[key] = key.upcase
|
||||
end
|
||||
data
|
||||
|
||||
end
|
||||
|
||||
def self.find(section_id)
|
||||
raise "nil given" if section_id.blank?
|
||||
section = @@all[section_id]
|
||||
|
@ -13,6 +13,7 @@
|
||||
Cards for
|
||||
= link_to "Section #{@section.index + 1}", section_url( @section.id) , class: "underline"
|
||||
|
||||
|
||||
.grid.grid-cols-4.gap-2.m-8
|
||||
- @section.cards.each_with_index do |card , index|
|
||||
.relative.block.border.border-gray-100
|
||||
@ -20,7 +21,6 @@
|
||||
%h3.mt-4.text-lg.font-bold Card #{index + 1}
|
||||
= blue_button( "Up" , card_move_url(card.id , dir: :up) )
|
||||
= blue_button( "Down" , card_move_url(card.id , dir: :down) )
|
||||
= green_button( "New" , "/index" )
|
||||
= red_button( "Delete" , card_remove_path(card.id) )
|
||||
.p-4
|
||||
%h3.mt-4.text-lg.font-bold Image
|
||||
@ -47,3 +47,5 @@
|
||||
.relative.block.border.border-gray-100
|
||||
%h3.mt-4.text-lg.font-bold Options
|
||||
To be done
|
||||
%p
|
||||
= green_button( "New Card" , new_section_card_url(@section.id) )
|
||||
|
@ -52,6 +52,8 @@
|
||||
.text-sm "#{card.text[0..70]} ....."
|
||||
%p.p-3
|
||||
= yellow_button( "View and Edit Cards" , section_cards_url(@section.id))
|
||||
= green_button( "New Card" , new_section_card_url(@section.id) )
|
||||
|
||||
.relative.block.border.border-gray-100
|
||||
%h3.mt-4.text-lg.font-bold Options
|
||||
To be done
|
||||
|
Loading…
Reference in New Issue
Block a user