This commit is contained in:
BoHung Chiu 2023-01-03 12:07:58 +08:00
parent e4888e1421
commit 4601c1faff
23 changed files with 80 additions and 114 deletions

View File

@ -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
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
end
end
if ( data_end == -1 && data_start != -1)
data_end = i
data_end_last = -1
end
if data_start!=-1 && page_no>=1
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 = []
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]
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
else
cats_last << Hash[cats[i].map{|k,v| [k,(k=='archives' ? v[data_start_first..data_end_last] : v)]}]
archives = archives[start_idx...end_idx]
if archives && archives.count > 0
cat_data['archives'] = archives
cats_last << cat_data
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'

View File

@ -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

View File

@ -1,8 +1,13 @@
<%= render_view %>
<% data = action_data %>
<%
data = action_data
total_pages = ArchivesController.get_total_pages
%>
<% if data["categories"].length == 1 %>
<script>
$("#main-content .panel-collapse").addClass("in");
</script>
<% end %>
<%= create_pagination(ArchivesController.get_total_pages).html_safe %>
<% if total_pages > 1 %>
<%= create_pagination(total_pages).html_safe %>
<% end %>

View File

@ -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

View File

@ -6,7 +6,7 @@
<li class="w-archive__item level-2">
<ul class="w-archive__list level-3" data-list="archives" data-level="1">
<li class="w-archive__item level-3">
<a class="w-archive__link" href="{{archive_url}}">{{archive-title}}</a>
<a class="w-archive__link" href="{{archive_url}}" target="{{target}}" title="{{archive-title}}">{{archive-title}}</a>
</li>
</ul>
</li>

View File

@ -15,7 +15,7 @@
<div class="panel-body">
<ul class="widget-archive-item-group" data-list="archives" data-level="1">
<li class="widget-archive-item-list">
<a href="{{archive_url}}">{{archive-title}}</a>
<a class="w-archive__link" href="{{archive_url}}" target="{{target}}" title="{{archive-title}}">{{archive-title}}</a>
</li>
</ul>
</div>

View File

@ -9,7 +9,7 @@
<span class="w-archive__title" href="{{archive_url}}">{{archive-title}}</span>
<ul class="w-archive__list level-4" data-list="files" data-level="2">
<li class="w-archive__item level-4">
<a href="{{file-url}}" class="widget-archive-files-item w-archive__link" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="widget-archive-files-item w-archive__link" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</li>
</ul>

View File

@ -25,7 +25,7 @@
</dt>
<dl class="widget-archive-files-list" data-list="files" data-level="2">
<dd>
<a href="{{file-url}}" class="widget-archive-files-item" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="widget-archive-files-item" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>

View File

@ -13,7 +13,7 @@
</dt>
<dl class="i-archive__file-list" data-list="files" data-level="2">
<dd class="i-archive__file-wrap">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a class="i-archive__file-name" href="{{file-url}}" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="i-archive__file-type label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>

View File

@ -22,7 +22,7 @@
</span>
</td>
<td class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</td>
</tr>
</tbody>

View File

@ -20,10 +20,10 @@
<span class="i-archive__serial_number">{{serial_number}}</span>
</td>
<td class="col-sm-7">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a class="i-archive__file-name" href="{{file-url}}" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
</td>
<td class="col-sm-3">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</td>
</tr>
</span>

View File

@ -25,7 +25,7 @@
</dt>
<dl class="i-archive-files-list" data-list="files" data-level="2">
<dd>
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>
@ -41,18 +41,4 @@
width: auto;
}
</style>
<script>
$('.index-archive-12 .panel-heading').each(function(i, v){
var $v = $(v);
if($v.text().trim() == ''){
$v.css('display', 'none');
}
})
$(document).ready(function(){
var location_id = window.location.hash;
if(location_id && location_id != '' && location_id.length > 1){
$(location_id).addClass('in');
}
})
</script>
</div>

View File

@ -15,11 +15,11 @@
<span data-list="statuses" data-level="2">
<span class="label status {{status-class}}">{{status}}</span>
</span>
<a href="{{archive-file-url}}" target="_blank" title="{{archive-title}}">
<a href="{{archive-file-url}}" target="{{target}}" title="{{archive-title}}">
{{archive-title}}
</a>
<span class="i-archive-files-list" data-list="files" data-level="2">
<a href="{{file-url}}" class="i-archive-files-item" title="{{file-name}}" data-toggle="tooltip" data-placement="bottom">
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" title="{{file-name}}" data-toggle="tooltip" data-placement="bottom">
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</a>
</span>

View File

@ -18,7 +18,7 @@
<div class="panel-body">
<ul class="i-archive-files-list" data-list="files" data-level="2">
<li>
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</li>
</ul>
@ -33,18 +33,4 @@
width: auto;
}
</style>
<script>
$('.index-archive-12 .panel-heading').each(function(i, v){
var $v = $(v);
if($v.text().trim() == ''){
$v.css('display', 'none');
}
})
$(document).ready(function(){
var location_id = window.location.hash;
if(location_id && location_id != '' && location_id.length > 1){
$(location_id).addClass('in');
}
})
</script>
</div>

View File

@ -12,7 +12,7 @@
</a>
</h4>
</div>
<div id="collapse" class="panel-collapse collapse">
<div id="collapse" class="panel-collapse collapse {{in_class}}">
<div class="panel-body">
<dl class="dl-horizontal i-archive-item-group" data-list="archives" data-level="1">
<dt class="i-archive-item-list col-sm-3">
@ -23,7 +23,7 @@
</dt>
<dl class="i-archive-files-list col-sm-9" data-list="files" data-level="2">
<dd>
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>

View File

@ -12,7 +12,7 @@
</dt>
<dl class="i-archive__file-list" data-list="files" data-level="2">
<dd class="i-archive__file-wrap">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a class="i-archive__file-name" href="{{file-url}}" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="i-archive__file-type label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>

View File

@ -11,7 +11,7 @@
</a>
</h4>
</div>
<div id="collapse" class="panel-collapse collapse">
<div id="collapse" class="panel-collapse collapse {{in_class}}">
<div class="panel-body">
<dl class="dl-horizontal i-archive-item-group" data-list="archives" data-level="1">
<dt class="i-archive-item-list col-sm-5">
@ -21,7 +21,7 @@
</dt>
<dl class="i-archive-files-list col-sm-7" data-list="files" data-level="2">
<dd>
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</dd>
</dl>

View File

@ -21,7 +21,7 @@
</span>
</div>
<div class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}">
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}">
<span class="label label-primary {{file-type}}">{{file-type}}</span>
</a>
</div>

View File

@ -17,7 +17,7 @@
<div class="head col-sm-7">
<dl class="i-archive__file" data-list="files" data-level="2">
<div class="file-name">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a class="i-archive__file-name" href="{{file-url}}" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="i-archive__status-wrap" data-list="statuses" data-level="2">
<span class="i-archive__status label status {{status-class}}">{{status}}</span>
</span>
@ -26,7 +26,7 @@
</div>
<div class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<div class="file-item">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</div>
</div>
</div>

View File

@ -23,7 +23,7 @@
</div>
<div class="description col-sm-3" style="border-right: 0.05em solid #333;">{{description}}</div>
<div class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</div>
</div>
</div>

View File

@ -18,7 +18,7 @@
<div class="head col-sm-4">
<dl class="i-archive__file" data-list="files" data-level="2">
<div class="file-name">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
<a class="i-archive__file-name" href="{{file-url}}" target="{{target}}" title="{{file-name}}">{{file-name}}</a>
<span class="i-archive__status-wrap" data-list="statuses" data-level="2">
<span class="i-archive__status label status {{status-class}}">{{status}}</span>
</span>
@ -28,7 +28,7 @@
<div class="description col-sm-3">{{description}}</div>
<div class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<div class="file-item">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</div>
</div>
</div>

View File

@ -19,7 +19,7 @@
{{file-name}}
</td>
<td class="col-sm-4">
<a href="{{file-url}}" class="i-archive-files-item" target="_blank" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
<a href="{{file-url}}" class="i-archive-files-item" target="{{target}}" data-toggle="tooltip" data-placement="bottom" title="{{file-name}}"><span class="label label-primary {{file-type}}">{{file-type}}</span></a>
</td>
</tr>
</span>

View File

@ -33,6 +33,7 @@
"zh_tw" : "4. 手風琴式列表( 無檔案名稱 ( 模組標題, 類別標題, 下載連結 )",
"en" : "4. Accordion list(no filename) (widget-title, category, download link)"
},
"force_cover": "true",
"thumbnail" : "ar4.png"
},
{