take new back out of images into ruby land

This commit is contained in:
Torsten 2023-01-09 20:48:14 +02:00
parent 484fa4f6e7
commit 68179949c8
8 changed files with 59 additions and 60 deletions

View File

@ -1345,6 +1345,10 @@ select {
grid-column: span 2 / span 2; grid-column: span 2 / span 2;
} }
.col-span-3 {
grid-column: span 3 / span 3;
}
.m-0 { .m-0 {
margin: 0px; margin: 0px;
} }
@ -1885,6 +1889,10 @@ select {
gap: 2rem; gap: 2rem;
} }
.gap-20 {
gap: 5rem;
}
.space-y-4 > :not([hidden]) ~ :not([hidden]) { .space-y-4 > :not([hidden]) ~ :not([hidden]) {
--tw-space-y-reverse: 0; --tw-space-y-reverse: 0;
margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse))); margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse)));

View File

@ -9,7 +9,7 @@ module Merged
@image_data = @images.collect{|i| @image_data = @images.collect{|i|
data = i.attributes.dup data = i.attributes.dup
data[:url] = view_context.asset_path(i.asset_name) data[:url] = view_context.asset_path(i.asset_name)
data[:link] = build_link_for(i) data[:link] = build_select_link_for(i)
data[:updated_at] = i.updated_at.to_date if i.updated_at data[:updated_at] = i.updated_at.to_date if i.updated_at
data[:created] = i.updated_at.to_i data[:created] = i.updated_at.to_i
data[:aspect_ratio] = i.aspect_ratio.join("/") data[:aspect_ratio] = i.aspect_ratio.join("/")
@ -19,7 +19,7 @@ module Merged
end end
def destroy def destroy
@image.destroy @image.destroy(current_member.email)
redirect_to :images , notice: "Image #{@image.name} deleted" redirect_to :images , notice: "Image #{@image.name} deleted"
end end
@ -82,7 +82,7 @@ module Merged
end end
end end
def build_link_for(image) def build_select_link_for(image)
if(params[:section_id]) if(params[:section_id])
return view_context.section_set_image_url(params[:section_id] , image_id: image.id) return view_context.section_set_image_url(params[:section_id] , image_id: image.id)
end end

View File

@ -17,16 +17,25 @@ module Merged
def text_for_new def text_for_new
if(section_id) if(section_id)
section = Section.find(section_id) section = Section.find(section_id)
"Add image for Section" "Add image for Section: #{section.header}"
elsif(card_id) elsif(card_id)
card = Card.find(card_id) card = Card.find(card_id)
"Select image for Card" "Select image for Card: #{card.header}"
else else
"New Image" "New Image"
end end
end end
def hidden_for_select def new_link_params
if(params[:section_id])
return {section_id: params[:section_id]}
end
if(params[:card_id])
return {card_id: params[:card_id]}
end
nil
end
def hidden_for_select_image
if(section_id) if(section_id)
hidden_field_tag :section_id , section_id hidden_field_tag :section_id , section_id
elsif(card_id) elsif(card_id)

View File

@ -53,9 +53,9 @@ module Merged
self.size = (image.size/1024).to_i self.size = (image.size/1024).to_i
end end
def destroy def destroy(editor)
File.delete self.full_filename File.delete self.full_filename
delete_save!(current_member.email) delete_save!(editor)
end end
def asset_name def asset_name

View File

@ -1,7 +0,0 @@
.flex.flex-col.border.border-gray-100.rounded.p-4
%h3.my-4.text-xl.font-bold Add new image
= text_field_tag 'filename' ,nil, placeholder: "Optiona name", class: "rounded"
%p.my-4 Name will be taken from uploaded file
= yield :hidden
= file_field_tag 'image_file' , class: "mb-8 w-full px-2 text-xl bg-clip-padding border border-solid border-gray-300 rounded"
= submit_button 'Submit'

View File

@ -2,6 +2,8 @@
.text-xl.font-bold.text-gray-900 .text-xl.font-bold.text-gray-900
= text_for_index = text_for_index
= link_to( "New Image" , merged.new_image_path(new_link_params) , class: "p-2 border border-gray-200 bg-cyan-100 font-bold rounded-lg hover:bg-sky-100")
- if Rails.env.development? - if Rails.env.development?
= javascript_include_tag "merged/vue.js" = javascript_include_tag "merged/vue.js"
-else -else
@ -9,8 +11,6 @@
.images .images
.flex.justify-center.gap-4 .flex.justify-center.gap-4
.rounded.border.mr-20{"@click" => "toggle_new" , ":class" => "{'bg-orange-200': show_new }"}
.mx-4.text-lg.font-bold Add new
%label.block %label.block
.mt-1.text-lg.font-bold Search: .mt-1.text-lg.font-bold Search:
@ -29,21 +29,7 @@
%svg.w-6.h-6.mt-1{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"} %svg.w-6.h-6.mt-1{:fill => "none", :stroke => "currentColor", "stroke-width" => "1.5", :viewbox => "0 0 24 24", :xmlns => "http://www.w3.org/2000/svg"}
%path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"} %path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.grid.grid-cols-3.gap-4.m-8{":class" => "{'hidden': !show_new }"} .grid.grid-cols-6.gap-4.m-8
%div
= form_tag(merged.images_path, multipart: true) do
.flex.flex-col.border.border-gray-100.rounded.p-4
%h3.my-4.text-xl.font-bold= text_for_new
= text_field_tag 'filename' ,nil, placeholder: "Optional name", class: "rounded mt-4"
%p.my-4 Name will be taken from uploaded file if not given
= text_field_tag 'tags' ,nil, placeholder: "Optional tags", class: "rounded mt-4"
%p.my-4 Tags describe the size or format
= hidden_for_select
= file_field_tag 'image_file' , class: "mb-8 w-full px-2 text-xl bg-clip-padding border border-solid border-gray-300 rounded"
= submit_button 'Submit'
%div
.grid.grid-cols-6.gap-4.m-8{":class" => "{'hidden': show_new }"}
.flex.flex-col.border.border-gray-100.rounded.image_box{"v-for": "image in filter_and_sort"} .flex.flex-col.border.border-gray-100.rounded.image_box{"v-for": "image in filter_and_sort"}
.flex.align-center.justify-between.mb-4 .flex.align-center.justify-between.mb-4
.text-lg.font-bold.mt-2.mx-2 .text-lg.font-bold.mt-2.mx-2
@ -69,7 +55,6 @@
@search_tag = "" @search_tag = ""
@sort_by = "created" @sort_by = "created"
@sort_dir = -1 # 1 up @sort_dir = -1 # 1 up
@show_new = false
end end
def filter_and_sort def filter_and_sort
dat = @image_data dat = @image_data
@ -90,11 +75,4 @@
end end
dat dat
end end
def toggle_new()
if @show_new == true
@show_new = false
else
@show_new = true
end
end
end end

View File

@ -0,0 +1,12 @@
.grid.grid-cols-3.gap-4.m-8{":class" => "{'hidden': !show_new }"}
%div
= form_tag(merged.images_path, multipart: true) do
.flex.flex-col.border.border-gray-100.rounded.p-4
%h3.my-4.text-xl.font-bold= text_for_new
= text_field_tag 'filename' ,nil, placeholder: "Optional name", class: "rounded mt-4"
%p.my-4 Name will be taken from uploaded file if not given
= text_field_tag 'tags' ,nil, placeholder: "Optional tags", class: "rounded mt-4"
%p.my-4 Tags describe the size or format
= hidden_for_select_image
= file_field_tag 'image_file' , class: "mb-8 w-full px-2 text-xl bg-clip-padding border border-solid border-gray-300 rounded"
= submit_button 'Submit'

View File

@ -17,7 +17,7 @@
= @image.type = @image.type
%p %p
.font-bold Size .font-bold Size
= @image.size = "#{@image.size}k"
%p %p
.font-bold Ratio .font-bold Ratio
= @image.ratio.round(2) = @image.ratio.round(2)
@ -32,33 +32,32 @@
=render "editor" , image: @image =render "editor" , image: @image
.flex.gap-2.m-20 .flex.gap-10.m-20
-if @used -if @used
.grid.grid-cols-2 .grid.grid-cols-2.gap-10
%p .grid.grid-cols-3.gap-10
Sections %p.col-span-3.font-bold
=@sections.length Sections using the image
%p
Cards
=@cards.length
%div
-@sections.each do |section| -@sections.each do |section|
%p %p
= link_to section.header , merged.section_path(section) = link_to section.header , merged.section_path(section)
on Page %p
%em on Page
%p
= link_to section.page.name , merged.page_sections_path(section.page) = link_to section.page.name , merged.page_sections_path(section.page)
%div .grid.grid-cols-3.gap-10
%p.col-span-3.font-bold
Cards using the image
-@cards.each do |card| -@cards.each do |card|
%p %p
= link_to card.header , merged.section_cards_path(card.section) = link_to card.header , merged.section_cards_path(card.section)
on Page %p
%em on Page
%p
= link_to card.section.page.name , merged.page_sections_path(card.section.page) = link_to card.section.page.name , merged.page_sections_path(card.section.page)
-else -else
.grid.grid-cols-2 %p.align-center Not used, you may delete
%div %p
%p Not used, you may delete = form_tag( merged.image_path(@image.id) , {method: :delete } ) do
%div =submit_button( "Delete" , true)
%p
= form_tag( merged.image_path(@image.id) , {method: :delete } ) do
=submit_button( "Delete" , true)