diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index ba56e20..8055ea0 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -16,12 +16,12 @@ class ArchivesController < ApplicationController end def show params = OrbitHelper.params - archive_file = ArchiveFile.find_by(:uid=>params[:uid].to_s) - locale = I18n.locale.to_s - data, serial_number, idx = archive_file.get_frontend_data(locale, 0, 0, true, OrbitHelper.url_to_show("")) - { - "data" => data - } + archive_file = ArchiveFile.find_by(:uid=>params[:uid].to_s) + locale = I18n.locale.to_s + data, serial_number, idx = archive_file.get_frontend_data(locale, 0, 0, true, OrbitHelper.url_to_show("")) + { + "data" => data + } end def index ArchiveFile.check_sort_number @@ -30,6 +30,8 @@ class ArchivesController < ApplicationController page = Page.where(url:params['url']).first end params = OrbitHelper.params + OrbitHelper.render_css_in_head(['archive/archive_frontend.css']) + OrbitHelper.render_js_in_head(['archive/archive_frontend.js']) @@total_pages = 1 in_class = "" custom_data_field = page.custom_data_field rescue nil @@ -64,14 +66,7 @@ class ArchivesController < ApplicationController end end else - if OrbitHelper.page_data_count > 0 - OrbitHelper.set_page_data_count 0 - page = Page.where(:page_id => params["page_id"]).first rescue nil - if !page.nil? - page.data_count = 0 - page.save - end - end + page_data_count = OrbitHelper.page_data_count categories = params["categories"].blank? ? OrbitHelper.page_categories : params["categories"] tags = params["tags"].blank? ? OrbitHelper.page_tags : params["tags"] module_app = ModuleApp.where(:key=>'archive').first @@ -82,9 +77,7 @@ class ArchivesController < ApplicationController tags = module_app.tags.sort_by{|tag| ((module_app.asc rescue true) ? tag.sort_number.to_i : -tag.sort_number.to_i)}.map{|tag| tag.id.to_s} tags << nil end - if params[:data_count].to_i <=0 - page_data_count = 0 - else + if params[:data_count].to_i > 0 page_data_count = params[:data_count].to_i end if params[:page_no].nil? @@ -93,7 +86,7 @@ class ArchivesController < ApplicationController page_no = params[:page_no].to_i end if (tags.count > 1 && categories.count <= 1 rescue false) - archive_files = ArchiveFile.can_display.filter_by_categories(categories).sorted + archive_files = ArchiveFile.can_display.filter_by_categories(categories, false).sorted group_archive_files = {} cats = [] each_data_count = [] @@ -141,7 +134,7 @@ class ArchivesController < ApplicationController end cats_last = cats else - files_by_category = ArchiveFile.can_display.filter_by_categories(categories).filter_by_tags(tags).sorted.group_by(&:category) + files_by_category = ArchiveFile.can_display.filter_by_categories(categories, false).filter_by_tags(tags).sorted.group_by(&:category) each_data_count = [] categories = files_by_category.keys categories_sort = get_sorted_cat_with_filter(categories, :orm) @@ -162,44 +155,32 @@ class ArchivesController < ApplicationController } end if page_data_count != 0 - all_data_count = 0 + # all_data_count = 0 data_start = -1 data_end = -1 - for i in 0...each_data_count.length - all_data_count_before = all_data_count - all_data_count += each_data_count[i] - if ( data_start == -1 && (all_data_count > (page_no - 1) * page_data_count) ) - data_start = i - data_start_first = (page_no - 1) * page_data_count - all_data_count_before + page_data_end = page_no * page_data_count #Not include end + page_data_start = page_data_end - page_data_count + # all_data_count = each_data_count.sum + cats_last = [] + counter = 0 + cats.each do |cat_data| + start_idx = page_data_start - counter + end_idx = page_data_end - counter + archives = cat_data['archives'] + archives_count = archives.count + counter += archives_count + if start_idx >= archives_count + next + elsif start_idx < 0 + start_idx = 0 end - if ( data_end == -1 && (all_data_count > (page_no * page_data_count - 1)) ) - data_end = i - data_end_last = (page_no * page_data_count - 1) - all_data_count_before + archives = archives[start_idx...end_idx] + if archives && archives.count > 0 + cat_data['archives'] = archives + cats_last << cat_data end end - if ( data_end == -1 && data_start != -1) - data_end = i - data_end_last = -1 - end - if data_start!=-1 && page_no>=1 - cats_last = [] - for i in data_start..data_end - if data_start != data_end - if i==data_start - cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[data_start_first..-1] : v)]}] - elsif i==data_end - cats_last << Hash[cats[i].map{|k,v| [k , (k=='archives' ? v[0..data_end_last] : v)]}] - else - cats_last << cats[i] - end - else - cats_last << Hash[cats[i].map{|k,v| [k,(k=='archives' ? v[data_start_first..data_end_last] : v)]}] - end - end - else - cats_last = [Hash[cats[0].map{|k,v| [k,'']}]] - end - @@total_pages = (all_data_count.to_f / page_data_count).ceil + @@total_pages = (counter.to_f / page_data_count).ceil else if page_no!=1 cats_last = [Hash[cats[0].map{|k,v| [k,'']}]] @@ -232,7 +213,7 @@ class ArchivesController < ApplicationController def download_file file_id = params[:file] file = ArchiveFileMultiple.find(file_id) rescue nil - if !file.nil? + if !file.nil? && file.file.present? file.download_count = file.download_count + 1 file.save @url = file.file.url @@ -259,6 +240,7 @@ class ArchivesController < ApplicationController def group_by_category cat_id = OrbitHelper.widget_categories.map {|cat_id| cat_id.to_s} + page_data_count = OrbitHelper.widget_data_count if OrbitHelper.widget_tags.first == "all" files_by_category = ArchiveFile.where(:category_id.in => OrbitHelper.widget_categories).with_tags(OrbitHelper.widget_module_app.tags.collect{|tag| tag.id.to_s}).asc(:sort_number).group_by(&:category) else @@ -284,15 +266,15 @@ class ArchivesController < ApplicationController t.each do |inner_tag| idx = ts.index{|tot| tot["tag-name"] == inner_tag.name} if !idx.nil? - break if ts[idx]["archives"].count >= OrbitHelper.widget_data_count + break if ts[idx]["archives"].count >= page_data_count ts[idx]["archives"] << a else - break if archives.count >= OrbitHelper.widget_data_count + break if archives.count >= page_data_count archives << a end end else - break if archives.count >= OrbitHelper.widget_data_count + break if archives.count >=page_data_count archives << a end @@ -300,7 +282,7 @@ class ArchivesController < ApplicationController ts << { "tag-name" => (t[0].name rescue ""), "archives" => archives - } if !archives.blank? && archive_counts < OrbitHelper.widget_data_count + } if !archives.blank? && archive_counts < page_data_count end { "category-id" => cat.id, @@ -374,6 +356,8 @@ class ArchivesController < ApplicationController cats_with_archives end def widget + OrbitHelper.render_css_in_head(['archive/archive_frontend.css']) + OrbitHelper.render_js_in_head(['archive/archive_frontend.js']) ArchiveFile.check_sort_number page_data_count = OrbitHelper.widget_data_count categories = OrbitHelper.widget_categories #data are categories' ids or 'all' diff --git a/app/models/archive_file.rb b/app/models/archive_file.rb index aa8aaaf..5daba82 100644 --- a/app/models/archive_file.rb +++ b/app/models/archive_file.rb @@ -221,7 +221,7 @@ class ArchiveFile a["files"] << { "file-name_translations" => title_translations, "file-type" => extension, - "file-url" => "#{base_url}/xhr/archive/download?file=#{file.id}" + "file-url" => (file.file.present? ? "#{base_url}/xhr/archive/download?file=#{file.id}" : "javascript:void(0)") } end end @@ -295,7 +295,8 @@ class ArchiveFile files << { "file-name" => title, "file-type" => extension, - "file-url" => "/xhr/archive/download?file=#{file.id}", + "file-url" => (file.file.present? ? "/xhr/archive/download?file=#{file.id}" : 'javascript:void(0)'), + "target" => "_blank", "serial_number" => serial_number } end @@ -303,10 +304,12 @@ class ArchiveFile if self.urls.present? self.urls.each_with_index do |url,i| serial_number += 1 + target = (url.match(/\/[^\/]/) ? '_self' : '_blank') files << { "file-name" => self.get_url_text(i), "file-type" => 'link', - "file-url" => url, + "file-url" => url + "\" data-target=\"#{target}", + "target" => target, "serial_number" => serial_number } end diff --git a/app/views/archives/index.html.erb b/app/views/archives/index.html.erb index 7d90b28..283fea7 100644 --- a/app/views/archives/index.html.erb +++ b/app/views/archives/index.html.erb @@ -1,8 +1,13 @@ <%= render_view %> -<% data = action_data %> +<% + data = action_data + total_pages = ArchivesController.get_total_pages +%> <% if data["categories"].length == 1 %> <% end %> -<%= create_pagination(ArchivesController.get_total_pages).html_safe %> \ No newline at end of file +<% if total_pages > 1 %> + <%= create_pagination(total_pages).html_safe %> +<% end %> \ No newline at end of file diff --git a/lib/archive/engine.rb b/lib/archive/engine.rb index 5b934ee..fdcf8d1 100644 --- a/lib/archive/engine.rb +++ b/lib/archive/engine.rb @@ -28,6 +28,7 @@ module Archive end widget_methods ["widget","group_by_category"] widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}] + data_count 0..30 models_to_cache [:archive_file] begin avoid_page_cache ArchiveCache diff --git a/modules/archive/_archive_widget1.html.erb b/modules/archive/_archive_widget1.html.erb index 2761be5..333e186 100644 --- a/modules/archive/_archive_widget1.html.erb +++ b/modules/archive/_archive_widget1.html.erb @@ -6,7 +6,7 @@
  • diff --git a/modules/archive/_archive_widget2.html.erb b/modules/archive/_archive_widget2.html.erb index 3bdcf62..c22491b 100644 --- a/modules/archive/_archive_widget2.html.erb +++ b/modules/archive/_archive_widget2.html.erb @@ -15,7 +15,7 @@
    diff --git a/modules/archive/_archive_widget3.html.erb b/modules/archive/_archive_widget3.html.erb index 1978557..45ffc79 100644 --- a/modules/archive/_archive_widget3.html.erb +++ b/modules/archive/_archive_widget3.html.erb @@ -9,7 +9,7 @@ {{archive-title}} diff --git a/modules/archive/_archive_widget4.html.erb b/modules/archive/_archive_widget4.html.erb index 903a726..7791aee 100644 --- a/modules/archive/_archive_widget4.html.erb +++ b/modules/archive/_archive_widget4.html.erb @@ -25,7 +25,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    diff --git a/modules/archive/archive_index1.html.erb b/modules/archive/archive_index1.html.erb index 6efc360..af52014 100644 --- a/modules/archive/archive_index1.html.erb +++ b/modules/archive/archive_index1.html.erb @@ -13,7 +13,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    diff --git a/modules/archive/archive_index10.html.erb b/modules/archive/archive_index10.html.erb index f56f01b..1e2cdcd 100644 --- a/modules/archive/archive_index10.html.erb +++ b/modules/archive/archive_index10.html.erb @@ -22,7 +22,7 @@ - {{file-type}} + {{file-type}} diff --git a/modules/archive/archive_index11.html.erb b/modules/archive/archive_index11.html.erb index b4efc6a..30ac34c 100644 --- a/modules/archive/archive_index11.html.erb +++ b/modules/archive/archive_index11.html.erb @@ -20,10 +20,10 @@ {{serial_number}} - {{file-name}} + {{file-name}} - {{file-type}} + {{file-type}} diff --git a/modules/archive/archive_index12.html.erb b/modules/archive/archive_index12.html.erb index e2e0da5..32aaf84 100644 --- a/modules/archive/archive_index12.html.erb +++ b/modules/archive/archive_index12.html.erb @@ -25,7 +25,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    @@ -41,18 +41,4 @@ width: auto; } - \ No newline at end of file diff --git a/modules/archive/archive_index13.html.erb b/modules/archive/archive_index13.html.erb index 9339ea5..ca352e7 100644 --- a/modules/archive/archive_index13.html.erb +++ b/modules/archive/archive_index13.html.erb @@ -15,11 +15,11 @@ {{status}} - + {{archive-title}} - + {{file-type}} diff --git a/modules/archive/archive_index14.html.erb b/modules/archive/archive_index14.html.erb index 49064ad..d1c7762 100644 --- a/modules/archive/archive_index14.html.erb +++ b/modules/archive/archive_index14.html.erb @@ -18,7 +18,7 @@
    @@ -33,18 +33,4 @@ width: auto; } -
    \ No newline at end of file diff --git a/modules/archive/archive_index2.html.erb b/modules/archive/archive_index2.html.erb index c779d9b..454f049 100644 --- a/modules/archive/archive_index2.html.erb +++ b/modules/archive/archive_index2.html.erb @@ -12,7 +12,7 @@ -
    +
    @@ -23,7 +23,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    diff --git a/modules/archive/archive_index3.html.erb b/modules/archive/archive_index3.html.erb index 21fb229..bbd7caf 100644 --- a/modules/archive/archive_index3.html.erb +++ b/modules/archive/archive_index3.html.erb @@ -12,7 +12,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    diff --git a/modules/archive/archive_index4.html.erb b/modules/archive/archive_index4.html.erb index f8dab84..e4c39a4 100644 --- a/modules/archive/archive_index4.html.erb +++ b/modules/archive/archive_index4.html.erb @@ -11,7 +11,7 @@
    -
    +
    @@ -21,7 +21,7 @@
    - {{file-name}} + {{file-name}} {{file-type}}
    diff --git a/modules/archive/archive_index5.html.erb b/modules/archive/archive_index5.html.erb index 01fb3bc..1325e3f 100644 --- a/modules/archive/archive_index5.html.erb +++ b/modules/archive/archive_index5.html.erb @@ -21,7 +21,7 @@
    diff --git a/modules/archive/archive_index6.html.erb b/modules/archive/archive_index6.html.erb index b2b343d..ae83f3e 100644 --- a/modules/archive/archive_index6.html.erb +++ b/modules/archive/archive_index6.html.erb @@ -17,7 +17,7 @@
    - {{file-name}} + {{file-name}} {{status}} @@ -26,7 +26,7 @@
    diff --git a/modules/archive/archive_index7.html.erb b/modules/archive/archive_index7.html.erb index 4ccc941..5739b88 100644 --- a/modules/archive/archive_index7.html.erb +++ b/modules/archive/archive_index7.html.erb @@ -23,7 +23,7 @@
    {{description}}
    diff --git a/modules/archive/archive_index8.html.erb b/modules/archive/archive_index8.html.erb index 48a14a3..f6e3cc6 100644 --- a/modules/archive/archive_index8.html.erb +++ b/modules/archive/archive_index8.html.erb @@ -18,7 +18,7 @@
    - {{file-name}} + {{file-name}} {{status}} @@ -28,7 +28,7 @@
    {{description}}
    diff --git a/modules/archive/archive_index9.html.erb b/modules/archive/archive_index9.html.erb index 4dacf0e..02056ec 100644 --- a/modules/archive/archive_index9.html.erb +++ b/modules/archive/archive_index9.html.erb @@ -19,7 +19,7 @@ {{file-name}} - {{file-type}} + {{file-type}} diff --git a/modules/archive/info.json b/modules/archive/info.json index e3350cd..1ffc7b5 100644 --- a/modules/archive/info.json +++ b/modules/archive/info.json @@ -33,6 +33,7 @@ "zh_tw" : "4. 手風琴式列表( 無檔案名稱 ( 模組標題, 類別標題, 下載連結 )", "en" : "4. Accordion list(no filename) (widget-title, category, download link)" }, + "force_cover": "true", "thumbnail" : "ar4.png" }, {