unused image finder

This commit is contained in:
Torsten 2023-01-23 14:53:04 +02:00
parent dd0a0d0ced
commit 1570e34d35
2 changed files with 22 additions and 7 deletions

View File

@ -5,7 +5,7 @@ module Merged
before_action :set_image, only: %i[ update destroy show scale crop copy ]
def index
@images = Image.all
@images = get_images
@image_data = @images.collect{|i|
data = i.attributes.dup
data[:url] = view_context.asset_path(i.asset_name)
@ -65,6 +65,18 @@ module Merged
private
def get_images
images = Image.all
puts "Images #{images.length}"
return images unless params[:unused]
hash = images.collect{|i| [i.id , i ] }.to_h
puts "Images1 #{hash.length}"
Section.all.each{ |s| hash.delete(s.image&.id)}
puts "Images2 #{hash.length}"
Card.all.each{ |s| hash.delete(s.image&.id)}
puts "Images3 #{hash.length}"
hash.values
end
def set_image
@image = Image.find(params[:id] || params[:image_id])
end

View File

@ -1,11 +1,14 @@
%script{:src => "https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"}
.mx-20.flex.h-16.items-center.gap-16
.mx-20.flex.h-16.items-center.gap-16.justify-between
.flex.gap-20
.text-xl.font-bold.text-gray-900
= text_for_index
= link_to(merged.new_image_path(new_link_params) ) do
.button.action New Image
= link_to(merged.images_path(unused: true) ) do
.button.action Show unused Images
.images
.flex.justify-center.gap-4
@ -27,7 +30,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"}
%path{:d => "M15.75 17.25L12 21m0 0l-3.75-3.75M12 21V3", "stroke-linecap" => "round", "stroke-linejoin" => "round"}
.grid.grid-cols-6.gap-4.m-8
.grid.grid-cols-2.lg:grid-cols-4.xl:grid-cols-6.gap-4.m-8
.flex.flex-col.border.border-gray-100.rounded.image_box{"v-for": "image in filter_and_sort"}
.flex.align-center.justify-between.mb-4
.text-lg.font-bold.mt-2.mx-2