Add new Accordion list template with expanded setting feature.

This commit is contained in:
BoHung Chiu 2022-04-08 11:20:21 +08:00
parent 32855e3ff3
commit 2226d59446
9 changed files with 205 additions and 106 deletions

View File

@ -1,4 +1,8 @@
class ArchivesController < ApplicationController class ArchivesController < ApplicationController
def self.custom_widget_data
ac = ActionController::Base.new
ac.render_to_string("archives/custom_widget_data",:locals=>{:@custom_data_field=>@custom_data_field,:@field_name=>@field_name})
end
#avoid the categories to be not in the ArchiveCategory #avoid the categories to be not in the ArchiveCategory
def serve_cmap def serve_cmap
serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__) serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__)
@ -9,8 +13,17 @@ class ArchivesController < ApplicationController
end end
end end
def index def index
page = OrbitHelper.page rescue nil
unless page
page = Page.where(url:params['url']).first
end
params = OrbitHelper.params params = OrbitHelper.params
@@total_pages = 1 @@total_pages = 1
in_class = ""
custom_data_field = page.custom_data_field rescue nil
if custom_data_field && custom_data_field["expanded"] == "yes"
in_class = "in"
end
cats_last = [] cats_last = []
sort_order = (ArchiveSortOrder.first['sort_order'] rescue false) ? 1 : -1 #Order with ascending sort_order = (ArchiveSortOrder.first['sort_order'] rescue false) ? 1 : -1 #Order with ascending
if !params['title'].nil? if !params['title'].nil?
@ -313,7 +326,8 @@ class ArchivesController < ApplicationController
"date-head" => I18n.t("archive.updated_at"), "date-head" => I18n.t("archive.updated_at"),
"title-head" => I18n.t(:name), "title-head" => I18n.t(:name),
"description-head"=>I18n.t("archive.description"), "description-head"=>I18n.t("archive.description"),
"file-head" =>I18n.t("archive.download_file") "file-head" =>I18n.t("archive.download_file"),
"in_class" => in_class
} }
} }
end end

View File

@ -0,0 +1,20 @@
<% active_expanded = @custom_data_field[:expanded] rescue nil %>
<div class="control-group input-content hide archive_expanded">
<label class="control-label muted" for="custom_expanded"><%=t("archive.expanded")%> :</label>
<div class="controls">
<%= select_tag("#{@field_name}[custom_data_field][expanded]", options_for_select(["yes","no"].map{|opt| [t("archive.#{opt}"),opt]},active_expanded),{:id=>"custom_expanded"})%>
</div>
</div>
<script type="text/javascript">
if($("#page_layout").val() == "archive_index12"){
$(".archive_expanded").addClass("show").removeClass("hide");
}
$("#page_layout").change(function(){
var value = $(this).val();
if(value == "archive_index12"){
$(".archive_expanded").addClass("show").removeClass("hide");
}else{
$(".archive_expanded").removeClass("show").addClass("hide");
}
})
</script>

View File

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

View File

@ -3,117 +3,128 @@ $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version: # Maintain your gem's version:
require "archive/version" require "archive/version"
require 'json' require 'json'
env_pwd = ENV['PWD'] bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
app_path = File.expand_path(__dir__) if bundle_update_flag
template_path = env_pwd + '/app/templates' env_pwd = ENV['PWD']
all_template = Dir.glob(template_path+'/*/') app_path = File.expand_path(__dir__)
all_template.each do |folder| template_path = env_pwd + '/app/templates'
if !folder.include?('mobile') all_template = Dir.glob(template_path+'/*/')
begin all_template.each do |folder|
next unless File.exist?("#{folder}modules/archive/info.json") if !folder.include?('mobile')
info_json_file = "#{folder}modules/archive/info.json" begin
info_json = JSON.parse(File.read(info_json_file)) next unless File.exist?("#{folder}modules/archive/info.json")
check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb","archive_index10.html.erb","archive_index11.html.erb"] info_json_file = "#{folder}modules/archive/info.json"
old_file_infos = [ info_json = JSON.parse(File.read(info_json_file))
{ check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb","archive_index10.html.erb","archive_index11.html.erb","archive_index12.html.erb"]
"filename" => "archive_index7", old_file_infos = [
"name" => { {
"zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )", "filename" => "archive_index7",
"en" => "7. Table list (widget-title, category, filename, download link)" "name" => {
}, "zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )",
"thumbnail" => "ar5.png" "en" => "7. Table list (widget-title, category, filename, download link)"
}, },
{ "thumbnail" => "ar5.png"
"filename" => "archive_index8", },
"name" => { {
"zh_tw" => "8. 表格列表 ( 模組標題, 檔案名稱, 檔案簡介, 下載連結 )", "filename" => "archive_index8",
"en" => "8. Table list (widget-title, filename, download link)" "name" => {
}, "zh_tw" => "8. 表格列表 ( 模組標題, 檔案名稱, 檔案簡介, 下載連結 )",
"thumbnail" => "ar5.png" "en" => "8. Table list (widget-title, filename, download link)"
} },
] "thumbnail" => "ar5.png"
new_file_infos = [ }
{ ]
"filename" => "archive_index7", new_file_infos = [
"name" => { {
"zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )", "filename" => "archive_index7",
"en" => "7. Table list (widget-title, category, Updated At, filename, download link)" "name" => {
}, "zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"thumbnail" => "ar5.png" "en" => "7. Table list (widget-title, category, Updated At, filename, download link)"
}, },
{ "thumbnail" => "ar5.png"
"filename" => "archive_index8", },
"name" => { {
"zh_tw" => "8. 表格列表 ( 模組標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )", "filename" => "archive_index8",
"en" => "8. Table list (widget-title, Updated At, filename, download link)" "name" => {
}, "zh_tw" => "8. 表格列表 ( 模組標題, 上傳日期, 檔案名稱, 檔案簡介, 下載連結 )",
"thumbnail" => "ar5.png" "en" => "8. Table list (widget-title, Updated At, filename, download link)"
}, },
{ "thumbnail" => "ar5.png"
"filename" => "archive_index9", },
"name" => { {
"zh_tw" => "9. 表格列表 - 簡約 ( 模組標題, 檔案名稱, 下載連結 )", "filename" => "archive_index9",
"en" => "9. Table list - Simple (widget-title, download link)" "name" => {
}, "zh_tw" => "9. 表格列表 - 簡約 ( 模組標題, 檔案名稱, 下載連結 )",
"thumbnail" => "ar9.png" "en" => "9. Table list - Simple (widget-title, download link)"
}, },
{ "thumbnail" => "ar9.png"
"filename" => "archive_index10", },
"name" => { {
"zh_tw" => "10. 表格列表 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", "filename" => "archive_index10",
"en" => "10. Table list (widget-title, category, Serial Number, filename, download link)" "name" => {
}, "zh_tw" => "10. 表格列表 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )",
"thumbnail" => "ar5.png" "en" => "10. Table list (widget-title, category, Serial Number, filename, download link)"
}, },
{ "thumbnail" => "ar5.png"
"filename" => "archive_index11", },
"name" => { {
"zh_tw" => "11. 表格列表 - 簡約 - 展開檔案 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", "filename" => "archive_index11",
"en" => "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)" "name" => {
}, "zh_tw" => "11. 表格列表 - 簡約 - 展開檔案 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )",
"thumbnail" => "ar9.png" "en" => "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)"
} },
] "thumbnail" => "ar9.png"
flags = [] },
all_frontend_names = info_json["frontend"].map{|h| h["name"]} {
check_files.each_with_index do |check_file,i| "filename" => "archive_index12",
flag = (info_json["frontend"].select{|h| h["filename"] == check_file.split(".").first}.count == 0 rescue false) "name" => {
if flag "zh_tw" => "12. 手風琴式列表 - 有下拉 ( 模組標題, 類別標題, 檔案名稱, 下載連結 )",
info_json["frontend"].push(new_file_infos[i]) "en" => "12. Accordion list - with drop down (widget-title, category, filename, download link)"
end },
if !flag "thumbnail" => "ar2.png"
old_file_info = old_file_infos[i] }
if old_file_info ]
idx = all_frontend_names.index(old_file_info["name"]) flags = []
if idx && idx != -1 all_frontend_names = info_json["frontend"].map{|h| h["name"]}
info_json["frontend"][idx] = new_file_infos[i] check_files.each_with_index do |check_file,i|
flag = true flag = (info_json["frontend"].select{|h| h["filename"] == check_file.split(".").first}.count == 0 rescue false)
if flag
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 end
flags << flag
end end
flags << flag force_update_files = ["archive_index1.html.erb","archive_index3.html.erb","archive_index12.html.erb"]
end puts "updating archive index page"
force_update_files = ["archive_index1.html.erb","archive_index3.html.erb"] if flags.select{|flag| flag }.count != 0
puts "updating archive index page" flags.each_with_index do |flag,i|
if flags.select{|flag| flag }.count != 0 if flag
flags.each_with_index do |flag,i| Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{check_files[i]} #{folder}modules/archive/#{check_files[i]}]}
if flag end
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{check_files[i]} #{folder}modules/archive/#{check_files[i]}]}
end end
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
begin force_update_files.each do |update_file|
info_json = JSON.pretty_generate(info_json).gsub(":[",":[\n").gsub(":{",":{\n") Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{update_file} #{folder}modules/archive/#{update_file}]}
rescue
info_json = info_json.to_s.gsub("=>",": \n")
end end
File.open(info_json_file,"w+"){|f| f.write(info_json)} Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/archive/thumbs/* #{folder}modules/archive/thumbs/.]}
rescue
puts "There has some error when updating archive index page."
end end
force_update_files.each do |update_file|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{update_file} #{folder}modules/archive/#{update_file}]}
end
Bundler.with_clean_env{%x[cp -rn #{app_path}/modules/archive/thumbs/* #{folder}modules/archive/thumbs/.]}
rescue
puts "There has some error when updating archive index page."
end end
end end
end end

View File

@ -2,6 +2,7 @@ en:
restful_actions: restful_actions:
categories_order: Categories Order categories_order: Categories Order
archive: archive:
expanded: Expanded
other: Other other: Other
serial_number: "Serial Number" serial_number: "Serial Number"
url_text: "URL Text" url_text: "URL Text"

View File

@ -2,6 +2,7 @@ zh_tw:
restful_actions: restful_actions:
categories_order: 類別排序 categories_order: 類別排序
archive: archive:
expanded: 展開的
other: 其他 other: 其他
serial_number: "編號" serial_number: "編號"
url_text: "連結文字" url_text: "連結文字"

View File

@ -16,7 +16,7 @@ module Archive
module_label "archive.archive" module_label "archive.archive"
base_url File.expand_path File.dirname(__FILE__) base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","group_by_category"] widget_methods ["widget","group_by_category"]
widget_settings [{"data_count"=>30}] widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}]
models_to_cache [:archive_file] models_to_cache [:archive_file]
taggable "ArchiveFile" taggable "ArchiveFile"
categorizable categorizable

View File

@ -0,0 +1,38 @@
<div class="i-archive index-archive-2">
<h3 class="i-archive-title">
<span>{{page-title}}</span>
</h3>
<div class="panel-group" id="index-archive-group" data-list="categories" data-level="0">
<div class="panel panel-default">
<div class="panel-heading" style="padding: 0.625em 0.9375em;">
<h4 class="panel-title">
<i class="fa fa-file-text" aria-hidden="true"></i>
<a data-toggle="collapse" data-parent="#index-archive-group" href="#collapse" class="collapsed" style="padding: 0;display: inline-block;">
{{category-title}}
<i class="fa fa-chevron-down" aria-hidden="true"></i>
</a>
</h4>
</div>
<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">
<sapn class="i-archive-item-title">{{archive-title}}</span>
<span data-list="statuses" data-level="2">
<span class="label status {{status-class}}">{{status}}</span>
</span>
</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">{{file-name}}</a>
<span class="label label-primary">{{file-type}}</span>
</dd>
</dl>
</dl>
</div>
</div>
</div>
{{link_to_edit}}
</div>
</div>

View File

@ -87,6 +87,14 @@
"en" : "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)" "en" : "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)"
}, },
"thumbnail" : "ar9.png" "thumbnail" : "ar9.png"
},
{
"filename" : "archive_index12",
"name" : {
"zh_tw" : "12. 手風琴式列表 - 有下拉 ( 模組標題, 類別標題, 檔案名稱, 下載連結 )",
"en" : "12. Accordion list - with drop down (widget-title, category, filename, download link)"
},
"thumbnail" : "ar2.png"
} }
], ],
"widgets" : [ "widgets" : [