From 2226d5944644889116a041d6e95e9cf4e2321771 Mon Sep 17 00:00:00 2001 From: Bohung Date: Fri, 8 Apr 2022 11:20:21 +0800 Subject: [PATCH] Add new Accordion list template with expanded setting feature. --- app/controllers/archives_controller.rb | 16 +- .../archives/custom_widget_data.html.erb | 20 ++ app/views/archives/index.html.erb | 6 + archive.gemspec | 219 +++++++++--------- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + lib/archive/engine.rb | 2 +- modules/archive/archive_index12.html.erb | 38 +++ modules/archive/info.json | 8 + 9 files changed, 205 insertions(+), 106 deletions(-) create mode 100644 app/views/archives/custom_widget_data.html.erb create mode 100644 modules/archive/archive_index12.html.erb diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index 2ecce79..518b293 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -1,4 +1,8 @@ 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 def serve_cmap 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 def index + page = OrbitHelper.page rescue nil + unless page + page = Page.where(url:params['url']).first + end params = OrbitHelper.params @@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 = [] sort_order = (ArchiveSortOrder.first['sort_order'] rescue false) ? 1 : -1 #Order with ascending if !params['title'].nil? @@ -313,7 +326,8 @@ class ArchivesController < ApplicationController "date-head" => I18n.t("archive.updated_at"), "title-head" => I18n.t(:name), "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 diff --git a/app/views/archives/custom_widget_data.html.erb b/app/views/archives/custom_widget_data.html.erb new file mode 100644 index 0000000..7139d29 --- /dev/null +++ b/app/views/archives/custom_widget_data.html.erb @@ -0,0 +1,20 @@ +<% active_expanded = @custom_data_field[:expanded] rescue nil %> +
+ +
+ <%= select_tag("#{@field_name}[custom_data_field][expanded]", options_for_select(["yes","no"].map{|opt| [t("archive.#{opt}"),opt]},active_expanded),{:id=>"custom_expanded"})%> +
+
+ \ No newline at end of file diff --git a/app/views/archives/index.html.erb b/app/views/archives/index.html.erb index d9e27a1..7d90b28 100644 --- a/app/views/archives/index.html.erb +++ b/app/views/archives/index.html.erb @@ -1,2 +1,8 @@ <%= render_view %> +<% data = action_data %> +<% if data["categories"].length == 1 %> + +<% end %> <%= create_pagination(ArchivesController.get_total_pages).html_safe %> \ No newline at end of file diff --git a/archive.gemspec b/archive.gemspec index 626f175..1e6b2ae 100644 --- a/archive.gemspec +++ b/archive.gemspec @@ -3,117 +3,128 @@ $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "archive/version" require 'json' -env_pwd = ENV['PWD'] -app_path = File.expand_path(__dir__) -template_path = env_pwd + '/app/templates' -all_template = Dir.glob(template_path+'/*/') -all_template.each do |folder| - if !folder.include?('mobile') - begin - next unless File.exist?("#{folder}modules/archive/info.json") - info_json_file = "#{folder}modules/archive/info.json" - 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"] - old_file_infos = [ - { - "filename" => "archive_index7", - "name" => { - "zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )", - "en" => "7. Table list (widget-title, category, filename, download link)" - }, - "thumbnail" => "ar5.png" - }, - { - "filename" => "archive_index8", - "name" => { - "zh_tw" => "8. 表格列表 ( 模組標題, 檔案名稱, 檔案簡介, 下載連結 )", - "en" => "8. Table list (widget-title, filename, download link)" - }, - "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" - }, - { - "filename" => "archive_index10", - "name" => { - "zh_tw" => "10. 表格列表 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", - "en" => "10. Table list (widget-title, category, Serial Number, filename, download link)" - }, - "thumbnail" => "ar5.png" - }, - { - "filename" => "archive_index11", - "name" => { - "zh_tw" => "11. 表格列表 - 簡約 - 展開檔案 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", - "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| - 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 +bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' +if bundle_update_flag + env_pwd = ENV['PWD'] + app_path = File.expand_path(__dir__) + template_path = env_pwd + '/app/templates' + all_template = Dir.glob(template_path+'/*/') + all_template.each do |folder| + if !folder.include?('mobile') + begin + next unless File.exist?("#{folder}modules/archive/info.json") + info_json_file = "#{folder}modules/archive/info.json" + 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"] + old_file_infos = [ + { + "filename" => "archive_index7", + "name" => { + "zh_tw" => "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )", + "en" => "7. Table list (widget-title, category, filename, download link)" + }, + "thumbnail" => "ar5.png" + }, + { + "filename" => "archive_index8", + "name" => { + "zh_tw" => "8. 表格列表 ( 模組標題, 檔案名稱, 檔案簡介, 下載連結 )", + "en" => "8. Table list (widget-title, filename, download link)" + }, + "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" + }, + { + "filename" => "archive_index10", + "name" => { + "zh_tw" => "10. 表格列表 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", + "en" => "10. Table list (widget-title, category, Serial Number, filename, download link)" + }, + "thumbnail" => "ar5.png" + }, + { + "filename" => "archive_index11", + "name" => { + "zh_tw" => "11. 表格列表 - 簡約 - 展開檔案 ( 模組標題, 類別標題, 編號, 檔案名稱, 下載連結 )", + "en" => "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)" + }, + "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" + } + ] + flags = [] + all_frontend_names = info_json["frontend"].map{|h| h["name"]} + 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) + 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 + flags << flag end - flags << flag - end - force_update_files = ["archive_index1.html.erb","archive_index3.html.erb"] - puts "updating archive index page" - if flags.select{|flag| flag }.count != 0 - flags.each_with_index do |flag,i| - if flag - Bundler.with_clean_env{%x[cp -f #{app_path}/modules/archive/#{check_files[i]} #{folder}modules/archive/#{check_files[i]}]} + force_update_files = ["archive_index1.html.erb","archive_index3.html.erb","archive_index12.html.erb"] + puts "updating archive index page" + if flags.select{|flag| flag }.count != 0 + flags.each_with_index do |flag,i| + if flag + 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 - begin - info_json = JSON.pretty_generate(info_json).gsub(":[",":[\n").gsub(":{",":{\n") - rescue - info_json = info_json.to_s.gsub("=>",": \n") + 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 - 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 - 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index dd6a711..c46d698 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,7 @@ en: restful_actions: categories_order: Categories Order archive: + expanded: Expanded other: Other serial_number: "Serial Number" url_text: "URL Text" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 5ffc7d3..bc33ad7 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,7 @@ zh_tw: restful_actions: categories_order: 類別排序 archive: + expanded: 展開的 other: 其他 serial_number: "編號" url_text: "連結文字" diff --git a/lib/archive/engine.rb b/lib/archive/engine.rb index 2ac93af..fff6813 100644 --- a/lib/archive/engine.rb +++ b/lib/archive/engine.rb @@ -16,7 +16,7 @@ module Archive module_label "archive.archive" base_url File.expand_path File.dirname(__FILE__) 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] taggable "ArchiveFile" categorizable diff --git a/modules/archive/archive_index12.html.erb b/modules/archive/archive_index12.html.erb new file mode 100644 index 0000000..7f1f618 --- /dev/null +++ b/modules/archive/archive_index12.html.erb @@ -0,0 +1,38 @@ +
+

+ {{page-title}} +

+
+
+ +
+
+
+
+ {{archive-title}} + + {{status}} + +
+
+
+ {{file-name}} + {{file-type}} +
+
+
+
+
+
+ {{link_to_edit}} +
+
\ No newline at end of file diff --git a/modules/archive/info.json b/modules/archive/info.json index daf5caf..0971445 100644 --- a/modules/archive/info.json +++ b/modules/archive/info.json @@ -87,6 +87,14 @@ "en" : "11. Table list - Simple - Unfold Files (widget-title, category, Serial Number, filename, download link)" }, "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" : [