Merge branch 'master' into 'master'

Update gallery.js

fix js problem

See merge request !7
This commit is contained in:
wmcheng 2019-11-06 17:21:28 +08:00
commit 915bf860a8
6 changed files with 97 additions and 73 deletions

View File

@ -16,6 +16,7 @@ function form_submit() {
var length_upload var length_upload
var count_upload var count_upload
var send_start var send_start
if (temp_length>1){
$( 'form#fileupload' ).ajaxSuccess(function() { $( 'form#fileupload' ).ajaxSuccess(function() {
if (typeof length_upload == "undefined"){ if (typeof length_upload == "undefined"){
count_upload = 1 count_upload = 1
@ -39,6 +40,7 @@ function form_submit() {
}) })
} }
}); });
}
} }
function form_only_one_submit() { function form_only_one_submit() {
var temp_length = 1 var temp_length = 1

View File

@ -40,19 +40,23 @@ class Admin::GalleriesController < OrbitAdminController
image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3]) image.album_crops.first.update_attributes(crop_x: cord[0],crop_y: cord[1],crop_w: cord[2],crop_h: cord[3])
end end
end end
@@finish = false variable = AlbumVariable.first
@@start = false if variable.nil?
variable = AlbumVariable.new
end
variable.finish = false
variable.save!
Thread.new do Thread.new do
@@start = true variable = AlbumVariable.first
images.each_with_index do |image,index| images.each_with_index do |image,index|
@@progress_percent = (index*100.0/count).floor.to_s+'%' variable.progress_percent = (index*100.0/count).floor.to_s+'%'
all_version = image.file.versions.map{|k,v| k} all_version = image.file.versions.map{|k,v| k}
begin begin
#org_fname = image.file.path #org_fname = image.file.path
#org_extname = File.extname(org_fname) #org_extname = File.extname(org_fname)
#org_fname.slice! org_extname #org_fname.slice! org_extname
#FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname) #FileUtils.cp(org_fname + org_extname, org_fname + '_resized' + org_extname)
@@progress_filename = image[:file].to_s variable.progress_filename = image[:file].to_s
all_version.each do |version| all_version.each do |version|
if !(version.to_s == 'resized' && crop_but_no_backup(image)) if !(version.to_s == 'resized' && crop_but_no_backup(image))
image.file.recreate_versions! version image.file.recreate_versions! version
@ -60,11 +64,13 @@ class Admin::GalleriesController < OrbitAdminController
end end
end end
rescue => e rescue => e
@@progress_filename = e.inspect.to_s variable.progress_filename = e.inspect.to_s
puts e.inspect puts e.inspect
end end
variable.save!
end end
@@finish = true variable.finish = true
variable.save!
end end
rescue => e rescue => e
puts e.inspect puts e.inspect
@ -77,9 +83,15 @@ class Admin::GalleriesController < OrbitAdminController
render :json => {'translate' => "#{t(text.to_s)}" }.to_json render :json => {'translate' => "#{t(text.to_s)}" }.to_json
end end
def recreate_image def recreate_image
notalive = @@progress_percent.nil? rescue true notalive = ((AlbumVariable.first.notalive.nil? ? true : AlbumVariable.first.notalive) rescue true)
if notalive if notalive
if !params['album_id'].to_s.empty? if !params['album_id'].to_s.empty?
variable = AlbumVariable.first
if variable.nil?
variable = AlbumVariable.new
end
variable.finish = false
variable.save!
choice_ids = params['album_id'].split(',') choice_ids = params['album_id'].split(',')
albums = Album.all.select { |value| (choice_ids.include? value.id.to_s)} albums = Album.all.select { |value| (choice_ids.include? value.id.to_s)}
if !(params['use_default']=='true') if !(params['use_default']=='true')
@ -92,12 +104,9 @@ class Admin::GalleriesController < OrbitAdminController
end end
end end
end end
@@start = false
count = 0 count = 0
albums.each{|album| count+=album.album_images.count } albums.each{|album| count+=album.album_images.count }
@@finish = false
Thread.new do Thread.new do
@@start = true
i = 0 i = 0
albums.each do |album| albums.each do |album|
album.album_images.each do |image| album.album_images.each do |image|
@ -112,42 +121,44 @@ class Admin::GalleriesController < OrbitAdminController
end end
rescue => error rescue => error
end end
@@progress_percent = (i*100.0/count).floor.to_s+'%' variable = AlbumVariable.first
variable.progress_percent = (i*100.0/count).floor.to_s+'%'
if !error.nil? if !error.nil?
@@progress_filename = error.inspect.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') variable.progress_filename = error.inspect.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
sleep(1) sleep(1)
else else
@@progress_filename = image[:file].to_s variable.progress_filename = image[:file].to_s
end end
variable.save!
i+=1 i+=1
end end
end end
@@finish = true variable = AlbumVariable.first
variable.finish = true
variable.save!
end end
else else
@@start = true variable = AlbumVariable.first
@@progress_filename = '' variable.finish = true
@@finish = true variable.progress_filename = ''
@@progress_percent = '100%' variable.progress_percent = '100%'
variable.save!
end end
end end
end end
def finish_recreate def finish_recreate
@@progress_percent = nil variable = AlbumVariable.first
@@progress_filename = nil variable.progress_percent = '0%'
@@start = false variable.progress_filename = ''
variable.notalive = true
variable.save!
render :text => '' render :text => ''
end end
def recreate_progress def recreate_progress
if self.class.class_variable_defined? :@@start progress_percent = AlbumVariable.first.progress_percent rescue '0%'
if @@start progress_filename = AlbumVariable.first.progress_filename rescue ''
render :json => {'percent' => (@@progress_percent rescue '0%'), 'filename' => (@@progress_filename rescue ''), 'finish' => (@@finish rescue false) }.to_json finish = AlbumVariable.first.finish rescue false
else render :json => {'percent' => progress_percent, 'filename' => progress_filename, 'finish' => finish }.to_json
render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json
end
else
render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json
end
end end
def index def index
Album.each do |album| Album.each do |album|
@ -354,7 +365,6 @@ class Admin::GalleriesController < OrbitAdminController
count = album_unprocess.count count = album_unprocess.count
Thread.new do Thread.new do
begin begin
@@start = true
album_unprocess.each_with_index do |un_image,i| album_unprocess.each_with_index do |un_image,i|
album = AlbumImage.all.select{|value| value.id.to_s == un_image.image_id.to_s}[0] album = AlbumImage.all.select{|value| value.id.to_s == un_image.image_id.to_s}[0]
album.file = un_image.save_var album.file = un_image.save_var
@ -363,13 +373,17 @@ class Admin::GalleriesController < OrbitAdminController
file.close file.close
File.delete file.path File.delete file.path
un_image.delete un_image.delete
@@progress_filename = album[:file] variable = AlbumVariable.first
@@progress_percent = ((i+1)*100.0/count).floor.to_s + '%' variable.progress_filename = album[:file]
variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%'
variable.save!
end end
rescue => e rescue => e
puts ['err',e.inspect] puts ['err',e.inspect]
end end
@@finish = true variable = AlbumVariable.first
variable.finish = true
variable.save!
end end
album_temp = AlbumUnprocess.first album_temp = AlbumUnprocess.first
album_temp.upload_success = false album_temp.upload_success = false
@ -383,11 +397,16 @@ class Admin::GalleriesController < OrbitAdminController
render :json => {}.to_json render :json => {}.to_json
end end
def init_upload def init_upload
Thread.current['count'] = params['all_length'].to_i variable = AlbumVariable.first
@@start = false if variable.nil?
@@finish = false variable = AlbumVariable.new
@@progress_percent = '0%' end
@@progress_filename = 'processing!!' variable.count = params['all_length'].to_i
variable.finish = false
variable.progress_percent = '0%'
variable.progress_filename = 'processing!!'
variable.notalive = true
variable.save!
render :json => {}.to_json render :json => {}.to_json
end end
def upload_image def upload_image
@ -397,7 +416,7 @@ class Admin::GalleriesController < OrbitAdminController
files.each do |file| files.each do |file|
image = album.album_images.new image = album.album_images.new
image.tags = (album.tags rescue []) image.tags = (album.tags rescue [])
if Thread.current['count']==1 if AlbumVariable.first.count==1
image.file = file image.file = file
else else
album_unprocess.image_id = image.id album_unprocess.image_id = image.id

View File

@ -37,7 +37,6 @@ class GalleriesController < ApplicationController
"total_pages" => albums.total_pages "total_pages" => albums.total_pages
} }
end end
def show def show
params = OrbitHelper.params params = OrbitHelper.params
album = Album.find_by_param(params[:uid]) album = Album.find_by_param(params[:uid])
@ -57,7 +56,6 @@ class GalleriesController < ApplicationController
"album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")} "album-description" => (flag ? "<p><span>#{album.description}</span></p>" : "")}
} }
end end
def widget def widget
tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags
albums = Album.filter_by_widget_categories.filter_by_tags(tags) albums = Album.filter_by_widget_categories.filter_by_tags(tags)
@ -84,7 +82,6 @@ class GalleriesController < ApplicationController
end end
images = images.collect do |a| images = images.collect do |a|
alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description) alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description)
{ {
"link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s, "link_to_show" => OrbitHelper.widget_more_url + "/" + a.album.to_param + "#" + a.id.to_s,
"alt_title" => alt_text, "alt_title" => alt_text,
@ -102,7 +99,6 @@ class GalleriesController < ApplicationController
"extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url} "extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url}
} }
end end
def imgs(album_id) def imgs(album_id)
album = Album.find(album_id) album = Album.find(album_id)
tag_names = Array.new tag_names = Array.new
@ -121,7 +117,6 @@ class GalleriesController < ApplicationController
end end
return output return output
end end
def theater def theater
image = AlbumImage.find(params[:id]) image = AlbumImage.find(params[:id])
albumid = image.album_id albumid = image.album_id

View File

@ -0,0 +1,8 @@
class AlbumVariable
include Mongoid::Document
field :count, type: Integer
field :progress_percent, type: String
field :progress_filename, type: String
field :finish, type: Boolean
field :notalive, type: Boolean
end

View File

@ -35,5 +35,5 @@ function get_data(){
} }
}) })
} }
var id = setInterval(get_data,200) var id = setInterval(get_data,1000)
</SCRIPT> </SCRIPT>

View File

@ -35,5 +35,5 @@ function get_data(){
} }
}) })
} }
var id = setInterval(get_data,200) var id = setInterval(get_data,1000)
</SCRIPT> </SCRIPT>