diff --git a/app/controllers/merged/images_controller.rb b/app/controllers/merged/images_controller.rb index 5448f94..37a16dc 100644 --- a/app/controllers/merged/images_controller.rb +++ b/app/controllers/merged/images_controller.rb @@ -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 diff --git a/app/models/merged/active_base.rb b/app/models/merged/active_base.rb index 7f47f32..fa413ba 100644 --- a/app/models/merged/active_base.rb +++ b/app/models/merged/active_base.rb @@ -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!() diff --git a/app/models/merged/image.rb b/app/models/merged/image.rb index d8399f5..b2ea286 100644 --- a/app/models/merged/image.rb +++ b/app/models/merged/image.rb @@ -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 diff --git a/app/models/merged/view_base.rb b/app/models/merged/view_base.rb index 525a1c8..67571db 100644 --- a/app/models/merged/view_base.rb +++ b/app/models/merged/view_base.rb @@ -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? diff --git a/app/views/merged/images/index.haml b/app/views/merged/images/index.haml index b2a084d..2aeeef8 100644 --- a/app/views/merged/images/index.haml +++ b/app/views/merged/images/index.haml @@ -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}}