fix image add and delete

This commit is contained in:
Torsten 2022-12-27 17:04:53 +02:00
parent d6b238ba94
commit e671447931
5 changed files with 27 additions and 21 deletions

View File

@ -8,8 +8,8 @@ module Merged
data = i.attributes.dup
data[:url] = view_context.asset_path(i.asset_name)
data[:link] = build_link_for(i)
data[:created_at] = i.created_at.to_date
data[:created] = i.created_at.to_i
data[:updated_at] = i.updated_at.to_date if i.updated_at
data[:created] = i.updated_at.to_i
data[:aspect_ratio] = i.aspect_ratio.join("/")
data[:ratio] = i.aspect_ratio
data
@ -30,7 +30,8 @@ module Merged
end
def create
image = Image.create_new!(params['filename'] ,params['tags'], params['image_file'])
image = Image.create_new(params['filename'] ,params['tags'], params['image_file'])
image.add_save current_member.email
where_to = determine_redirect(image)
redirect_to where_to , notice: "New image created: #{image.name}"
end

View File

@ -1,5 +1,12 @@
module Merged
class ActiveBase < ActiveYaml::Base
fields :updated_at , :updated_by
def edit_save( editor )
self.updated_at = Time.now
self.updated_by = editor
edit_save!
end
def edit_save!
ChangeSet.current.edit(self.class.name , self.change_name)
@ -7,6 +14,12 @@ module Merged
self.class.save_all
end
def add_save( editor )
self.updated_at = Time.now
self.updated_by = editor
add_save!
end
def add_save!
ChangeSet.current.add(self.class.name , self.change_name)
save!()

View File

@ -5,7 +5,11 @@ module Merged
set_root_path Rails.root
fields :name , :tags , :type , :size , :created_at , :height , :width
fields :name , :tags , :type , :size , :height , :width
def change_name
name
end
def aspect_ratio
ratio = self.ratio
@ -19,7 +23,7 @@ module Merged
end
#save an io as new image. The filename is the id, type taken from io
def self.create_new!(name , tags, io)
def self.create_new(name , tags, io)
original , ending = io.original_filename.split("/").last.split(".")
name = original if( name.blank? )
image = Image.new name: name , type: ending , tags: (tags || "")
@ -29,7 +33,6 @@ module Merged
file.write( io.read )
end
image.init_file_data
image.save
image
end
@ -38,13 +41,13 @@ module Merged
self.width = image.width
self.height = image.height
file = File.open( full_filename )
self.created_at = file.birthtime
self.updated_at = file.birthtime
self.size = (file.size/1024).to_i
end
def destroy
File.delete self.full_filename
super
delete_save!
end
def asset_name

View File

@ -10,7 +10,7 @@ module Merged
belongs_to :image , class_name: "Merged::Image"
fields :options , :updated_at , :updated_by
fields :options
def last_update_for(elements)
last = Time.now
@ -24,17 +24,6 @@ module Merged
last_section
end
def edit_save( editor )
self.updated_at = Time.now
self.updated_by = editor
edit_save!
end
def add_save( editor )
self.updated_at = Time.now
self.updated_by = editor
add_save!
end
def has_option?(option)
options.has_key?(option) and !options[option].blank?

View File

@ -57,7 +57,7 @@
%strong.inline-block.rounded.bg-orange-50.px-3.py-1.text-md.font-medium
{{image.size}}k
%strong.inline-block.rounded.bg-orange-50.px-3.py-1.text-md.font-medium
{{image.created_at}}
{{image.updated_at}}
%strong.rounded.h-10.bg-orange-50.px-5.py-2.font-medium
{{image.tags}}