diff --git a/app/assets/javascripts/gallery.js b/app/assets/javascripts/gallery.js index 26f7ca5..8135aa8 100644 --- a/app/assets/javascripts/gallery.js +++ b/app/assets/javascripts/gallery.js @@ -16,29 +16,31 @@ function form_submit() { var length_upload var count_upload var send_start - $( 'form#fileupload' ).ajaxSuccess(function() { - if (typeof length_upload == "undefined"){ - count_upload = 1 - length_upload = $('#file-list').find('li.template-upload').length - } - else{ - count_upload ++ - } - if (count_upload === length_upload){ - send_start = undefined - $.ajax({ - url : "/admin/galleries/start_upload_process", - dataType : "json", - type : "post", - error: function(){ - alert('init upload process failed, please try again later.') - }, - success: function(){ - window.location.href = '/admin/galleries/upload_process' - } - }) - } - }); + if (temp_length>1){ + $( 'form#fileupload' ).ajaxSuccess(function() { + if (typeof length_upload == "undefined"){ + count_upload = 1 + length_upload = $('#file-list').find('li.template-upload').length + } + else{ + count_upload ++ + } + if (count_upload === length_upload){ + send_start = undefined + $.ajax({ + url : "/admin/galleries/start_upload_process", + dataType : "json", + type : "post", + error: function(){ + alert('init upload process failed, please try again later.') + }, + success: function(){ + window.location.href = '/admin/galleries/upload_process' + } + }) + } + }); + } } function form_only_one_submit() { var temp_length = 1 diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index 0f70ba9..2211f36 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -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]) end end - @@finish = false - @@start = false + variable = AlbumVariable.first + if variable.nil? + variable = AlbumVariable.new + end + variable.finish = false + variable.save! Thread.new do - @@start = true + variable = AlbumVariable.first 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} begin #org_fname = image.file.path #org_extname = File.extname(org_fname) #org_fname.slice! 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| if !(version.to_s == 'resized' && crop_but_no_backup(image)) image.file.recreate_versions! version @@ -60,11 +64,13 @@ class Admin::GalleriesController < OrbitAdminController end end rescue => e - @@progress_filename = e.inspect.to_s + variable.progress_filename = e.inspect.to_s puts e.inspect end + variable.save! end - @@finish = true + variable.finish = true + variable.save! end rescue => e puts e.inspect @@ -77,9 +83,15 @@ class Admin::GalleriesController < OrbitAdminController render :json => {'translate' => "#{t(text.to_s)}" }.to_json end def recreate_image - notalive = @@progress_percent.nil? rescue true + notalive = ((AlbumVariable.first.notalive.nil? ? true : AlbumVariable.first.notalive) rescue true) if notalive 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(',') albums = Album.all.select { |value| (choice_ids.include? value.id.to_s)} if !(params['use_default']=='true') @@ -92,12 +104,9 @@ class Admin::GalleriesController < OrbitAdminController end end end - @@start = false count = 0 albums.each{|album| count+=album.album_images.count } - @@finish = false Thread.new do - @@start = true i = 0 albums.each do |album| album.album_images.each do |image| @@ -112,42 +121,44 @@ class Admin::GalleriesController < OrbitAdminController end rescue => error 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? - @@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) else - @@progress_filename = image[:file].to_s + variable.progress_filename = image[:file].to_s end + variable.save! i+=1 end end - @@finish = true + variable = AlbumVariable.first + variable.finish = true + variable.save! end else - @@start = true - @@progress_filename = '' - @@finish = true - @@progress_percent = '100%' + variable = AlbumVariable.first + variable.finish = true + variable.progress_filename = '' + variable.progress_percent = '100%' + variable.save! end end end def finish_recreate - @@progress_percent = nil - @@progress_filename = nil - @@start = false + variable = AlbumVariable.first + variable.progress_percent = '0%' + variable.progress_filename = '' + variable.notalive = true + variable.save! render :text => '' end def recreate_progress - if self.class.class_variable_defined? :@@start - if @@start - render :json => {'percent' => (@@progress_percent rescue '0%'), 'filename' => (@@progress_filename rescue ''), 'finish' => (@@finish rescue false) }.to_json - else - render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json - end - else - render :json => {'percent' => '0%', 'filename' => '', 'finish' => false }.to_json - end + progress_percent = AlbumVariable.first.progress_percent rescue '0%' + progress_filename = AlbumVariable.first.progress_filename rescue '' + finish = AlbumVariable.first.finish rescue false + render :json => {'percent' => progress_percent, 'filename' => progress_filename, 'finish' => finish }.to_json end def index Album.each do |album| @@ -353,8 +364,7 @@ class Admin::GalleriesController < OrbitAdminController album_unprocess = AlbumUnprocess.all count = album_unprocess.count Thread.new do - begin - @@start = true + begin 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.file = un_image.save_var @@ -363,13 +373,17 @@ class Admin::GalleriesController < OrbitAdminController file.close File.delete file.path un_image.delete - @@progress_filename = album[:file] - @@progress_percent = ((i+1)*100.0/count).floor.to_s + '%' + variable = AlbumVariable.first + variable.progress_filename = album[:file] + variable.progress_percent = ((i+1)*100.0/count).floor.to_s + '%' + variable.save! end rescue => e puts ['err',e.inspect] end - @@finish = true + variable = AlbumVariable.first + variable.finish = true + variable.save! end album_temp = AlbumUnprocess.first album_temp.upload_success = false @@ -383,11 +397,16 @@ class Admin::GalleriesController < OrbitAdminController render :json => {}.to_json end def init_upload - Thread.current['count'] = params['all_length'].to_i - @@start = false - @@finish = false - @@progress_percent = '0%' - @@progress_filename = 'processing!!' + variable = AlbumVariable.first + if variable.nil? + variable = AlbumVariable.new + end + 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 end def upload_image @@ -397,7 +416,7 @@ class Admin::GalleriesController < OrbitAdminController files.each do |file| image = album.album_images.new image.tags = (album.tags rescue []) - if Thread.current['count']==1 + if AlbumVariable.first.count==1 image.file = file else album_unprocess.image_id = image.id diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 6da5fc0..e485cb0 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -37,7 +37,6 @@ class GalleriesController < ApplicationController "total_pages" => albums.total_pages } end - def show params = OrbitHelper.params album = Album.find_by_param(params[:uid]) @@ -57,7 +56,6 @@ class GalleriesController < ApplicationController "album-description" => (flag ? "

#{album.description}

" : "")} } end - def widget tags = OrbitHelper.widget_tags.empty? ? ["all"] : OrbitHelper.widget_tags albums = Album.filter_by_widget_categories.filter_by_tags(tags) @@ -84,7 +82,6 @@ class GalleriesController < ApplicationController end images = images.collect do |a| 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, "alt_title" => alt_text, @@ -102,7 +99,6 @@ class GalleriesController < ApplicationController "extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url} } end - def imgs(album_id) album = Album.find(album_id) tag_names = Array.new @@ -121,7 +117,6 @@ class GalleriesController < ApplicationController end return output end - def theater image = AlbumImage.find(params[:id]) albumid = image.album_id @@ -152,4 +147,4 @@ class GalleriesController < ApplicationController end flag end -end +end \ No newline at end of file diff --git a/app/models/album_variable.rb b/app/models/album_variable.rb new file mode 100644 index 0000000..2715780 --- /dev/null +++ b/app/models/album_variable.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/galleries/recreate_image.html.erb b/app/views/admin/galleries/recreate_image.html.erb index c6e12cd..7cced8f 100644 --- a/app/views/admin/galleries/recreate_image.html.erb +++ b/app/views/admin/galleries/recreate_image.html.erb @@ -35,5 +35,5 @@ function get_data(){ } }) } -var id = setInterval(get_data,200) +var id = setInterval(get_data,1000) \ No newline at end of file diff --git a/app/views/admin/galleries/upload_process.html.erb b/app/views/admin/galleries/upload_process.html.erb index c6e12cd..7cced8f 100644 --- a/app/views/admin/galleries/upload_process.html.erb +++ b/app/views/admin/galleries/upload_process.html.erb @@ -35,5 +35,5 @@ function get_data(){ } }) } -var id = setInterval(get_data,200) +var id = setInterval(get_data,1000) \ No newline at end of file