From 86aacba3b6b0d126761a6b57a2a0091add5a3061 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 30 Oct 2019 22:34:41 +0800 Subject: [PATCH 1/4] Update gallery.js --- app/assets/javascripts/gallery.js | 48 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 23 deletions(-) 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 From 8577c7e8adae604adf3ccd1566c5ad0906f03e54 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 21:14:34 +0800 Subject: [PATCH 2/4] fix recreate thumb problem --- app/controllers/admin/galleries_controller.rb | 94 ++++++++++--------- app/models/album_variable.rb | 8 ++ .../admin/galleries/recreate_image.html.erb | 2 +- .../admin/galleries/upload_process.html.erb | 2 +- 4 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 app/models/album_variable.rb diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index 0f70ba9..e340568 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -40,19 +40,20 @@ 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 + 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 +61,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 +80,12 @@ 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 + 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 +98,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 +115,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 +358,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 +367,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 +391,13 @@ 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 + 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 +407,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/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 From bf0f561c2efb45c97112c16a03af84630c79943b Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 21:21:00 +0800 Subject: [PATCH 3/4] fix error --- app/controllers/admin/galleries_controller.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index e340568..2211f36 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -41,6 +41,9 @@ class Admin::GalleriesController < OrbitAdminController end end variable = AlbumVariable.first + if variable.nil? + variable = AlbumVariable.new + end variable.finish = false variable.save! Thread.new do @@ -84,6 +87,9 @@ class Admin::GalleriesController < OrbitAdminController 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(',') @@ -392,6 +398,9 @@ class Admin::GalleriesController < OrbitAdminController end def init_upload variable = AlbumVariable.first + if variable.nil? + variable = AlbumVariable.new + end variable.count = params['all_length'].to_i variable.finish = false variable.progress_percent = '0%' From 3925c22408d86a2600d7c08c707531539c6fdb89 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 5 Nov 2019 21:31:11 +0800 Subject: [PATCH 4/4] Update galleries_controller.rb merge change with eric's --- app/controllers/galleries_controller.rb | 115 +++++++++++------------- 1 file changed, 54 insertions(+), 61 deletions(-) diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index c6bf45f..cacd566 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -17,53 +17,49 @@ class GalleriesController < ApplicationController tags << tag0 tags << tag1 end - def index - albums = Album.filter_by_categories.filter_by_tags.asc(:order) - galleries = albums.collect do |a| - doc = Nokogiri::HTML(a.description.to_s) - alt_text = doc.text.empty? ? 'gallery image' : doc.text - { - "album-name" => a.name, - "album-description" => a.description, - "alt_title" => alt_text, - "link_to_show" => OrbitHelper.url_to_show(a.to_param), - "thumb-src" => a.cover_path || "/assets/gallery/default.jpg" - } - end + def index + albums = Album.filter_by_categories.filter_by_tags.asc(:order) + galleries = albums.collect do |a| + doc = Nokogiri::HTML(a.description.to_s) + alt_text = doc.text.empty? ? 'gallery image' : doc.text + { + "album-name" => a.name, + "album-description" => a.description, + "alt_title" => alt_text, + "link_to_show" => OrbitHelper.url_to_show(a.to_param), + "thumb-src" => a.cover_path || "/assets/gallery/default.jpg" + } + end { "albums" => galleries, "extras" => {"widget-title"=>"Gallery"}, "total_pages" => albums.total_pages - } - + } end - def show params = OrbitHelper.params album = Album.find_by_param(params[:uid]) flag = show_desc? - images = album.album_images.asc(:order).collect do |a| + images = album.album_images.asc(:order).collect do |a| alt_text = (a.description.nil? || a.description == "" ? "gallery image" : a.description) - { + { "image-description" => a.description, "alt_title" => alt_text, - "link_to_show" => "/xhr/galleries/theater/" + a.id.to_s, - "thumb-src" => a.file.thumb.url - } - end - { - "images" => images, - "data" => {"album-title"=>album.name, - "album-description" => (flag ? "

#{album.description}

" : "")} - } + "link_to_show" => "/xhr/galleries/theater/" + a.id.to_s, + "thumb-src" => a.file.thumb.url + } + end + { + "images" => images, + "data" => {"album-title"=>album.name, + "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) params = OrbitHelper.params counts = OrbitHelper.widget_data_count - images = [] total_images = 0 if !albums.blank? @@ -76,7 +72,7 @@ class GalleriesController < ApplicationController while images.count < counts albums.each do |album| img = album.album_images.sample - if !images.include?(img) && img != nil + if !images.include?(img) && img != nil images << img end end @@ -84,7 +80,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, @@ -93,61 +88,59 @@ class GalleriesController < ApplicationController "thumb-large-src" => a.file.thumb_large.url, "image_description" => a.description, "mobile-src" => a.file.mobile.url, - "theater-src" => a.file.theater.url + "theater-src" => a.file.theater.url, + "album-name" => a.album.name_translations[I18n.locale] } end { "images" => images, "extras" => {"widget-title"=>"Gallery","more_url" => OrbitHelper.widget_more_url} - } + } end - def imgs(album_id) album = Album.find(album_id) tag_names = Array.new images = album.album_images.asc(:order) output = Array.new images.each do |values| - alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description) - output << { _id: values.id.to_s, - description: values.description, - title: values.title, - alt_title: alt_text, - url: values.file.url, - file: values.file.as_json[:file], - gallery_album_id: values.album_id, - tags: values.tags} + alt_text = (values.description.nil? || values.description == "" ? "gallery image" : values.description) + output << { _id: values.id.to_s, + description: values.description, + title: values.title, + alt_title: alt_text, + url: values.file.url, + file: values.file.as_json[:file], + gallery_album_id: values.album_id, + tags: values.tags} end return output end - def theater image = AlbumImage.find(params[:id]) albumid = image.album_id album = Album.find(albumid) images = album.album_images.asc(:order) - data = { + data = { "album" => album, "image" => image.id.to_s, "images" => imgs(albumid) - } - - render :json => {"data" => data}.to_json + } + render :json => {"data" => data}.to_json end private - def show_desc? - tags = OrbitHelper.page_tags if tags.blank? - tags = [tags].flatten.uniq + def show_desc? + tags = OrbitHelper.page_tags if tags.blank? + tags = [tags].flatten.uniq + flag = true + tag_temp = Tag.all.select{|value| tags.include? value.id.to_s} + tag_temp_length = 0 + tag_temp.each do |value| + if value.name==I18n.t('gallery.show_desc') flag = true - tag_temp = Tag.all.select{|value| tags.include? value.id.to_s} - tag_temp_length = 0 - tag_temp.each do |value| - if value.name==I18n.t('gallery.show_desc') - flag = true - elsif value.name==I18n.t('gallery.not_show_desc') - flag = false - end - end - flag + elsif value.name==I18n.t('gallery.not_show_desc') + flag = false + end end + flag + end end \ No newline at end of file