From 1570e34d35c7ff5f54093a53f5a594a5c945a8ac Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 23 Jan 2023 14:53:04 +0200 Subject: [PATCH] unused image finder --- app/controllers/merged/images_controller.rb | 14 +++++++++++++- app/views/merged/images/index.haml | 15 +++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/controllers/merged/images_controller.rb b/app/controllers/merged/images_controller.rb index bb7b856..052ef01 100644 --- a/app/controllers/merged/images_controller.rb +++ b/app/controllers/merged/images_controller.rb @@ -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 diff --git a/app/views/merged/images/index.haml b/app/views/merged/images/index.haml index b926478..7b04d60 100644 --- a/app/views/merged/images/index.haml +++ b/app/views/merged/images/index.haml @@ -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 - .text-xl.font-bold.text-gray-900 - = text_for_index +.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.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