From 576b763046e085b2daee0b7b0270a1b032e76e77 Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 4 Feb 2020 16:18:36 +0800 Subject: [PATCH] fix timeout error for too many album --- app/assets/javascripts/gallery.js | 10 ++ app/controllers/admin/galleries_controller.rb | 56 +++++++---- app/views/admin/galleries/index.html.erb | 96 +++++++++++++------ app/views/galleries/index.html.erb | 3 +- config/locales/en.yml | 2 + config/locales/zh_tw.yml | 2 + 6 files changed, 121 insertions(+), 48 deletions(-) diff --git a/app/assets/javascripts/gallery.js b/app/assets/javascripts/gallery.js index c5b7912..97e6281 100644 --- a/app/assets/javascripts/gallery.js +++ b/app/assets/javascripts/gallery.js @@ -111,6 +111,14 @@ $(function () { }); } }); +Array.prototype.uniq = function(){ + var attr = this + attr = $.grep(attr, function(v, k){ + return $.inArray(v ,attr) === k; + }); + return attr; +} + function batch_crop(){ var check_li = $('#imgholder').find("input[type='checkbox']:checked").parents('li'); var image_ids =[]; @@ -372,11 +380,13 @@ $(function() { $container.sortable("enable"); $(".order-edit-notification").slideDown(); images_order = $container.sortable( "toArray", { attribute: "data-image-id" }); + images_order = images_order.uniq(); $container.data("order-edit","1"); translate(el,'','gallery.save_order',false) }else{ var temp = $container.sortable( "toArray", { attribute: "data-image-id" }), type = $container.attr("id"); + temp = temp.uniq() if(images_order.toString() != temp.toString()){ $.ajax({ url : "/admin/galleries/order", diff --git a/app/controllers/admin/galleries_controller.rb b/app/controllers/admin/galleries_controller.rb index 34e404b..01705c1 100644 --- a/app/controllers/admin/galleries_controller.rb +++ b/app/controllers/admin/galleries_controller.rb @@ -4,6 +4,7 @@ class Admin::GalleriesController < OrbitAdminController before_filter :setup_vars before_action :authenticate_user, :except => "imgs" before_action :log_user_action + layout :compute_layout find_tag = Tag.all.select{|value| value.name==I18n.t('gallery.not_show_desc')} if find_tag.length==0 module_app_id = ModuleApp.where(:key=>"gallery").first[:_id] @@ -38,7 +39,13 @@ class Admin::GalleriesController < OrbitAdminController end end end - + def compute_layout + if action_name== 'index' && !params['page_no'].nil? + false + else + 'back_end' + end + end def rotate_images begin image_ids = params['image_ids'].split(',') @@ -250,27 +257,42 @@ class Admin::GalleriesController < OrbitAdminController 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| - if album.album_colors.first.nil? - album.album_colors.create('color' => 'transparent') - end - end + def filter_album @tags = @module_app.tags categories = @module_app.categories.enabled @filter_fields = filter_fields(categories, @tags) @filter_fields.delete(:status) - @albums = Album.where(:order => -1).desc(:created_at).with_categories(filters("category")).with_tags(filters("tag")) - @albums = search_data(@albums,[:name]) - albums = Album.where(:order.gt => -1).asc(:order).with_categories(filters("category")).with_tags(filters("tag")) - albums = search_data(albums,[:name]) - @albums = @albums.concat(albums) - if AlbumColor.count!=0 - if AlbumColor.all.desc('updated_at').first[:color] == 'transparent' - @color_save = '' - else - @color_save = AlbumColor.desc('updated_at').first[:color] + albums1 = Album.where(:order => -1).desc(:created_at).with_categories(filters("category")).with_tags(filters("tag")) + albums1 = search_data(albums1,[:name]) + albums2 = Album.where(:order.gt => -1).asc(:order).with_categories(filters("category")).with_tags(filters("tag")) + albums2 = search_data(albums2,[:name]) + @fiter_albums = albums1.concat(albums2) + end + def index + album_length = Album.all.count + album_sort = Album.all.asc(:created_at) + if album_sort.first.album_colors.first.nil? + album_sort.each_with_index do |album| + if album.album_colors.first.nil? + album.album_colors.create('color' => 'transparent') end + end + end + @url = request.original_fullpath + if params['page_no'].nil? + @show_script = true + @albums = filter_album.take 50 + else + @show_script = false + start = (params['page_no'].to_i - 1)*50 + @albums = filter_album[start...start+50] + end + if AlbumColor.count!=0 + if AlbumColor.all.desc('updated_at').first[:color] == 'transparent' + @color_save = '' + else + @color_save = AlbumColor.desc('updated_at').first[:color] + end else @color_save = 'transparent' end diff --git a/app/views/admin/galleries/index.html.erb b/app/views/admin/galleries/index.html.erb index 09a54a5..4d351c8 100644 --- a/app/views/admin/galleries/index.html.erb +++ b/app/views/admin/galleries/index.html.erb @@ -1,31 +1,67 @@ -<%= stylesheet_link_tag "gallery" %> -<%= stylesheet_link_tag "lib/tags-groups" %> -<% content_for :page_specific_javascript do %> - <%= javascript_include_tag "lib/jquery-ui-1.10.0.custom.min" %> - <%= javascript_include_tag "jquery.masonry.min.js" %> - <%= javascript_include_tag "jquery.lite.image.resize.js" %> - <%= javascript_include_tag "gallery" %> -<% end %> -<%= render_filter @filter_fields, "orbit_gallery" %> -
Albums re-ordering enabled.
-<%= render 'recreate_thumb' %> -
- -
-
-
- <% if can_edit_or_delete?(nil) %> - <%= t('gallery.edit_order') %> - <% end %> +<% if @show_script %> + <%= stylesheet_link_tag "gallery" %> + <%= stylesheet_link_tag "lib/tags-groups" %> + <% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/jquery-ui-1.10.0.custom.min" %> + <%= javascript_include_tag "jquery.masonry.min.js" %> + <%= javascript_include_tag "jquery.lite.image.resize.js" %> + <%= javascript_include_tag "gallery" %> + + <% end %> + + <%= render_filter @filter_fields, "orbit_gallery" %> +
Albums re-ordering enabled.
+ <%= render 'recreate_thumb' %> +
+
-
- - - - - - - +
+
+ <% if can_edit_or_delete?(nil) %> + <%= t('gallery.edit_order') %> + <% end %> + <% if @fiter_albums.length > 50 %> + + <% end %> +
+
+<% else %> + <%= render :partial => "album", :collection => @albums %> +<% end %> \ No newline at end of file diff --git a/app/views/galleries/index.html.erb b/app/views/galleries/index.html.erb index 648b75c..d2897fd 100644 --- a/app/views/galleries/index.html.erb +++ b/app/views/galleries/index.html.erb @@ -1 +1,2 @@ -<%= render_view %> \ No newline at end of file +<%= render_view %> + diff --git a/config/locales/en.yml b/config/locales/en.yml index 96e75b9..96055db 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,8 @@ en: gallery: + load_html: Load next 50 data + wait_time: please wait a minute show_desc: Show the album description not_show_desc: Don't show the album description show_original_image: Show the original picture diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index e9615c9..b307dec 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -1,6 +1,8 @@ zh_tw: gallery: + load_html: 存取下50筆 + wait_time: 請稍等 show_desc: 顯示相簿描述 not_show_desc: 不顯示相簿描述 show_original_image: 顯示原始圖片