fix admins portal image setting

dev_ec
p31729568 6 years ago
parent 15a1eb805c
commit 761e6c473f

@ -22,12 +22,19 @@ module Util::FileManage
File.exist?(disk_filename(source.class, source.id)) File.exist?(disk_filename(source.class, source.id))
end end
def disk_file_url(source_type, source_id) def disk_file_url(source_type, source_id, suffix = nil)
File.join('/images', relative_path, "#{source_type}", "#{source_id}") t = ctime(source_type, source_id)
File.join('/images', relative_path, "#{source_type}", "#{source_id}#{suffix}") + "?t=#{t}"
end end
def source_disk_file_url(source) def source_disk_file_url(source)
File.join('/images', relative_path, "#{source.class}", "#{source.id}") disk_file_url(source.class, source.id)
end
def ctime(source_type, source_id)
return nil unless exist?(source_type, source_id)
File.ctime(disk_filename(source_type, source_id)).to_i
end end
def disk_auth_filename(source_type, source_id, type) def disk_auth_filename(source_type, source_id, type)
@ -39,7 +46,7 @@ module Util::FileManage
end end
def auth_file_url(source_type, source_id, type) def auth_file_url(source_type, source_id, type)
File.join('/images', relative_path, source_type, "#{source_id}#{type}") disk_file_url(source_type, source_id, type)
end end
def real_name_auth_file_url(source_id) def real_name_auth_file_url(source_id)

@ -14,7 +14,7 @@ class Admins::DragPortalImageService < ApplicationService
images = PortalImage.all images = PortalImage.all
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
if after.blank? # 移动至末尾 if after.blank? || move.id == after.id # 移动至末尾
total = images.count total = images.count
images.where('position > ?', move.position).update_all('position = position - 1') images.where('position > ?', move.position).update_all('position = position - 1')
@ -26,8 +26,8 @@ class Admins::DragPortalImageService < ApplicationService
images.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1') images.where('position >= ? AND position < ?', after.position, move.position).update_all('position = position + 1')
move.update!(position: after.position) move.update!(position: after.position)
else # 后移 else # 后移
images.where('position > ? AND position <= ?', move.position, after.position).update_all('position = position - 1') images.where('position > ? AND position < ?', move.position, after.position).update_all('position = position - 1')
move.update!(position: after.position) move.update!(position: after.position - 1)
end end
end end
end end

Loading…
Cancel
Save