Add template: index 9.

Fix bug.
Add tags filter blocks.
This commit is contained in:
BoHung Chiu 2021-09-22 12:27:02 +08:00
parent 5758a91865
commit d401049a92
9 changed files with 194 additions and 45 deletions

View File

@ -11,11 +11,11 @@ class ArchivesController < ApplicationController
def index def index
params = OrbitHelper.params params = OrbitHelper.params
@@total_pages = 1 @@total_pages = 1
cats_last = []
if !params['title'].nil? if !params['title'].nil?
files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category) files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category)
categories = files_by_category.keys categories = files_by_category.keys
categories_sort = get_sorted_cat_with_filter(categories,'orm') categories_sort = get_sorted_cat_with_filter(categories,'orm')
cats_last = []
categories_sort.each do |category| categories_sort.each do |category|
url_to_edit = "" url_to_edit = ""
flag = false flag = false
@ -78,7 +78,88 @@ class ArchivesController < ApplicationController
page.save page.save
end end
end end
files_by_category = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.order_by(:created_at => "desc").group_by(&:category) categories = OrbitHelper.page_categories
tags = OrbitHelper.page_tags
module_app = ModuleApp.where(:key=>'archive').first
if categories == ["all"]
categories = module_app.categories.pluck(:id).map(&:to_s)
end
if tags == ["all"]
tags = module_app.tags.pluck(:id).map(&:to_s)
end
if params[:data_count].to_i <=0
page_data_count = 0
else
page_data_count = params[:data_count].to_i
end
if params[:page_no].nil?
page_no = 1
else
page_no = params[:page_no].to_i
end
if (tags.count > 1 && categories.count <= 1 rescue false)
archive_files = ArchiveFile.where(is_hidden: false,:title.nin=>["",nil]).filter_by_categories.order_by(:created_at => "desc")
group_archive_files = {}
cats = []
each_data_count = []
tags.each do |tag_id|
tag = Tag.find(tag_id) rescue nil
next if tag.nil?
url_to_edit = OrbitHelper.current_user ? "/admin/archive_files?filters[tags][]=#{tag_id}" : ""
taggings = Tagging.where(:tag_id=>tag_id).pluck(:taggable_id)
archives = archive_files.where(:id.in=>taggings).to_a
if archives.count != 0
archives = archives.map do |archive|
statuses = archive.statuses_with_classname.collect do |status|
{
"status" => status["name"] || "",
"status-class" => "status-#{status['classname']}"
}
end
files = []
archive.archive_file_multiples.order_by(:sort_number=>'desc').each do |file|
if file.choose_lang.include?(I18n.locale.to_s)
title = (file.file_title.blank? ? File.basename(file.file.path) : file.file_title) rescue ""
extension = file.file.file.extension.downcase rescue ""
files << {
"file-name" => title,
"file-type" => extension,
"file-url" => "/xhr/archive/download?file=#{file.id}"
}
end
if archive.url.present?
files << {
"file-name" => archive.title,
"file-type" => "link",
"file-url" => archive.url
}
end
end
{
"archive-title" => archive.title,
"description" => archive.description,
"created_at" => archive.created_at.strftime('%Y%m%d').to_i,
"archive-url" => archive.url,
"url" => archive.url,
"statuses" => statuses,
"sort_number" => archive.sort_number,
"is_top" => (archive.is_top ? 1 : 0),
"files" => files
}
end
each_data_count.push(archives.length)
sorted = archives.sort_by{|k,v| -k["sort_number"].to_i}
sorted = sorted.sort{|k,v| v["is_top"] <=> k["is_top"]}
cats << {
"category-title" => Tag.find(tag_id).name,
"archives" => sorted,
"url_to_edit" => url_to_edit
}
end
end
cats_last = cats
else
files_by_category = ArchiveFile.where(is_hidden: false,:title.nin=>["",nil]).filter_by_categories.filter_by_tags.order_by(:created_at => "desc").group_by(&:category)
each_data_count = [] each_data_count = []
categories = files_by_category.keys categories = files_by_category.keys
categories_sort = get_sorted_cat_with_filter(categories,'orm') categories_sort = get_sorted_cat_with_filter(categories,'orm')
@ -140,16 +221,6 @@ class ArchivesController < ApplicationController
Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : -tp['sort_number'].to_i),-tp['created_at']]}) : v] }] Hash[cat.map{|k,v| [k,k=='archives' ? (v.sort_by{|tp| [(tp['sort_number'].nil? ? Float::INFINITY : -tp['sort_number'].to_i),-tp['created_at']]}) : v] }]
end end
end end
if params[:data_count].to_i <=0
page_data_count = 0
else
page_data_count = params[:data_count].to_i
end
if params[:page_no].nil?
page_no = 1
else
page_no = params[:page_no].to_i
end
if page_data_count != 0 if page_data_count != 0
all_data_count = 0 all_data_count = 0
data_start = -1 data_start = -1
@ -198,10 +269,16 @@ class ArchivesController < ApplicationController
@@total_pages = 1 @@total_pages = 1
end end
end end
end
end end
{ {
"categories" => cats_last, "categories" => cats_last,
"extras" =>{"description-head"=>I18n.t("archive.description")} "extras" =>{
"date-head" => I18n.t("archive.updated_at"),
"title-head" => I18n.t("archive.Title"),
"description-head"=>I18n.t("archive.description"),
"file-head" =>I18n.t("archive.download_file")
}
} }
end end

View File

@ -13,8 +13,8 @@ all_template.each do |folder|
next unless File.exist?("#{folder}modules/archive/info.json") next unless File.exist?("#{folder}modules/archive/info.json")
info_json_file = "#{folder}modules/archive/info.json" info_json_file = "#{folder}modules/archive/info.json"
info_json = JSON.parse(File.read(info_json_file)) info_json = JSON.parse(File.read(info_json_file))
check_files = ["archive_index7.html.erb","archive_index8.html.erb"] check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb"]
file_infos = [ old_file_infos = [
{ {
"filename" => "archive_index7", "filename" => "archive_index7",
"name" => { "name" => {
@ -32,11 +32,48 @@ all_template.each do |folder|
"thumbnail" => "ar5.png" "thumbnail" => "ar5.png"
} }
] ]
new_file_infos = [
{
"filename" => "archive_index7",
"name" => {
"zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"en" => "7. Table list (widget-title, category, Updated At, filename, download link)"
},
"thumbnail" => "ar5.png"
},
{
"filename" => "archive_index8",
"name" => {
"zh_tw" => "8. 表格列表 ( 模組標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"en" => "8. Table list (widget-title, Updated At, filename, download link)"
},
"thumbnail" => "ar5.png"
},
{
"filename" => "archive_index9",
"name" => {
"zh_tw" => "9. 表格列表 - 簡約 ( 模組標題, 檔案名稱, 下載連結 )",
"en" => "9. Table list - Simple (widget-title, download link)"
},
"thumbnail" => "ar9.png"
}
]
flags = [] flags = []
all_frontend_names = info_json["frontend"].map{|h| h["name"]}
check_files.each_with_index do |check_file,i| check_files.each_with_index do |check_file,i|
flag = (info_json["frontend"].select{|h| h["filename"] == check_file.split(".").first}.count == 0 rescue false) flag = (info_json["frontend"].select{|h| h["filename"] == check_file.split(".").first}.count == 0 rescue false)
if flag if flag
info_json["frontend"].push(file_infos[i]) info_json["frontend"].push(new_file_infos[i])
end
if !flag
old_file_info = old_file_infos[i]
if old_file_info
idx = all_frontend_names.index(old_file_info["name"])
if idx && idx != -1
info_json["frontend"][idx] = new_file_infos[i]
flag = true
end
end
end end
flags << flag flags << flag
end end
@ -47,8 +84,14 @@ all_template.each do |folder|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{check_files[i]} #{folder}modules/archive/#{check_files[i]}]} Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{check_files[i]} #{folder}modules/archive/#{check_files[i]}]}
end end
end end
File.open(info_json_file,"w+"){|f| f.write(info_json.to_json)} begin
info_json = JSON.pretty_generate(info_json).gsub(":[",":[\n").gsub(":{",":{\n")
rescue
info_json = info_json.to_s.gsub("=>",": \n")
end
File.open(info_json_file,"w+"){|f| f.write(info_json)}
end end
Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/archive/thumbs/* #{folder}modules/archive/thumbs/.]}
rescue rescue
puts "There has some error when updating archive index page." puts "There has some error when updating archive index page."
end end

View File

@ -2,6 +2,8 @@ en:
restful_actions: restful_actions:
categories_order: Categories Order categories_order: Categories Order
archive: archive:
updated_at: Updated At
download_file: Download file
drag_file_to_here: Drag file to here drag_file_to_here: Drag file to here
description: File description description: File description
category: Category category: Category

View File

@ -2,6 +2,8 @@ zh_tw:
restful_actions: restful_actions:
categories_order: 類別排序 categories_order: 類別排序
archive: archive:
updated_at: 上傳日期
download_file: 檔案下載
drag_file_to_here: 拖移檔案到此 drag_file_to_here: 拖移檔案到此
description: 檔案簡介 description: 檔案簡介
category: 類別 category: 類別

View File

@ -6,23 +6,23 @@
<h4 class="i-archive__category-title">{{category-title}}</h4> <h4 class="i-archive__category-title">{{category-title}}</h4>
<div class="i-items"> <div class="i-items">
<div class="thead row"> <div class="thead row">
<div class="col-sm-2 date-thead">上傳日期</div> <div class="col-sm-2 date-thead">{{date-head}}</div>
<div class="col-sm-3 title-thead">標題</div> <div class="col-sm-4 title-thead">{{title-head}}</div>
<div class="col-sm-3 description-thead">{{description-head}}</div> <div class="col-sm-3 description-thead">{{description-head}}</div>
<div class="col-sm-2 file-thead">檔案下載</div> <div class="col-sm-3 file-thead">{{file-head}}</div>
</div> </div>
<div class="tbody"> <div class="tbody">
<div class="i-archive__category-list list-unstyled" data-list="archives" data-level="1"> <div class="i-archive__category-list list-unstyled" data-list="archives" data-level="1">
<div class="archive-items clearfix"> <div class="archive-items clearfix">
<div class="date col-sm-2">{{created_at}}</div> <div class="date col-sm-2">{{created_at}}</div>
<div class="head col-sm-3"> <div class="head col-sm-4">
{{archive-title}} {{archive-title}}
<span class="i-archive__status-wrap" data-list="statuses" data-level="2"> <span class="i-archive__status-wrap" data-list="statuses" data-level="2">
<span class="i-archive__status label status {{status-class}}">{{status}}</span> <span class="i-archive__status label status {{status-class}}">{{status}}</span>
</span> </span>
</div> </div>
<div class="description col-sm-3" style="border-right: 0.05em solid #333;">{{description}}</div> <div class="description col-sm-3" style="border-right: 0.05em solid #333;">{{description}}</div>
<div class="i-archive__file-list col-sm-2" data-list="files" data-level="2"> <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}}</span></a> <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}}</span></a>
</div> </div>
</div> </div>
@ -34,11 +34,6 @@
</div> </div>
<script> <script>
if( window.location.href.indexOf('/en/') > -1 ) {
$('.date-thead').replaceWith('<div class="col-sm-2 date-thead-en">Updated At</div>')
$('.title-thead').replaceWith('<div class="col-sm-7 title-thead-en">Title</div>')
$('.file-thead').replaceWith('<div class="col-sm-3 file-thead-en">Download file</div>')
}
$(document).ready(function(){ $(document).ready(function(){
if(window.innerWidth >= 768){ if(window.innerWidth >= 768){
$(".archive-items .date").each(function(i,d){ $(".archive-items .date").each(function(i,d){

View File

@ -6,16 +6,16 @@
<h4 class="i-archive__category-title">{{category-title}}</h4> <h4 class="i-archive__category-title">{{category-title}}</h4>
<div class="i-items"> <div class="i-items">
<div class="thead row"> <div class="thead row">
<div class="col-sm-2 date-thead">上傳日期</div> <div class="col-sm-2 date-thead">{{date-head}}</div>
<div class="col-sm-3 title-thead">標題</div> <div class="col-sm-4 title-thead">{{title-head}}</div>
<div class="col-sm-3 description-thead">{{description-head}}</div> <div class="col-sm-3 description-thead">{{description-head}}</div>
<div class="col-sm-2 file-thead">檔案下載</div> <div class="col-sm-3 file-thead">{{file-head}}</div>
</div> </div>
<div class="tbody"> <div class="tbody">
<div class="i-archive__category-list list-unstyled" data-list="archives" data-level="1"> <div class="i-archive__category-list list-unstyled" data-list="archives" data-level="1">
<div class="archive-items clearfix"> <div class="archive-items clearfix">
<div class="date col-sm-2">{{created_at}}</div> <div class="date col-sm-2">{{created_at}}</div>
<div class="head col-sm-3"> <div class="head col-sm-4">
<dl class="i-archive__file" data-list="files" data-level="2"> <dl class="i-archive__file" data-list="files" data-level="2">
<div class="file-name"> <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="_blank" title="{{file-name}}">{{file-name}}</a>
@ -26,7 +26,7 @@
</dl> </dl>
</div> </div>
<div class="description col-sm-3">{{description}}</div> <div class="description col-sm-3">{{description}}</div>
<div class="i-archive__file-list col-sm-2" data-list="files" data-level="2"> <div class="i-archive__file-list col-sm-3" data-list="files" data-level="2">
<div class="file-item"> <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}}</span></a> <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}}</span></a>
</div> </div>
@ -37,12 +37,4 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<script>
if( window.location.href.indexOf('/en/') > -1 ) {
$('.date-thead').replaceWith('<div class="col-sm-2 date-thead-en">Updated At</div>')
$('.title-thead').replaceWith('<div class="col-sm-7 title-thead-en">Title</div>')
$('.file-thead').replaceWith('<div class="col-sm-3 file-thead-en">Download file</div>')
}
</script>

View File

@ -0,0 +1,30 @@
<div class="i-archive index-archive-9">
<h3 class="i-archive-title">
<span>{{page-title}}</span>
</h3>
<div class="i-archive__list list-unstyled" id="index-archive-group" data-list="categories" data-level="0">
<h4 class="i-archive__category-title">{{category-title}}</h4>
<table class="i-items table table-bordered">
<thead class="thead">
<tr>
<th class="col-sm-8 title-thead">{{title-head}}</th>
<th class="col-sm-4 file-thead">{{file-head}}</th>
</th>
</thead>
<tbody class="tbody" >
<span data-list="archives" data-level="1">
<span data-list="files" data-level="2">
<tr class="archive-items">
<td class="col-sm-8">
<a class="i-archive__file-name" href="{{file-url}}" target="_blank" title="{{file-name}}">{{file-name}}</a>
</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}}</span></a>
</td>
</tr>
</span>
</span>
</tbody>
</table>
</div>
</div>

View File

@ -51,18 +51,26 @@
{ {
"filename" : "archive_index7", "filename" : "archive_index7",
"name" : { "name" : {
"zh_tw" : "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )", "zh_tw" : "7. 表格列表 ( 模組標題, 類別標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"en" : "7. Table list (widget-title, category, filename, download link)" "en" : "7. Table list (widget-title, category, Updated At, filename, download link)"
}, },
"thumbnail" : "ar5.png" "thumbnail" : "ar5.png"
}, },
{ {
"filename" : "archive_index8", "filename" : "archive_index8",
"name" : { "name" : {
"zh_tw" : "8. 表格列表 ( 模組標題, 檔案名稱, 檔案簡介, 下載連結 )", "zh_tw" : "8. 表格列表 ( 模組標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"en" : "8. Table list (widget-title, filename, download link)" "en" : "8. Table list (widget-title, Updated At, filename, download link)"
}, },
"thumbnail" : "ar5.png" "thumbnail" : "ar5.png"
},
{
"filename" : "archive_index9",
"name" : {
"zh_tw" : "9. 表格列表 - 簡約 ( 模組標題, 檔案名稱, 下載連結 )",
"en" : "9. Table list - Simple (widget-title, download link)"
},
"thumbnail" : "ar9.png"
} }
], ],
"widgets" : [ "widgets" : [

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB