From d401049a922b339d35f0cce7db1063e89daf05d1 Mon Sep 17 00:00:00 2001 From: Bohung Date: Wed, 22 Sep 2021 12:27:02 +0800 Subject: [PATCH] Add template: index 9. Fix bug. Add tags filter blocks. --- app/controllers/archives_controller.rb | 103 +++++++++++++++++++++--- archive.gemspec | 51 +++++++++++- config/locales/en.yml | 2 + config/locales/zh_tw.yml | 2 + modules/archive/archive_index7.html.erb | 15 ++-- modules/archive/archive_index8.html.erb | 20 ++--- modules/archive/archive_index9.html.erb | 30 +++++++ modules/archive/info.json | 16 +++- modules/archive/thumbs/ar9.png | Bin 0 -> 1690 bytes 9 files changed, 194 insertions(+), 45 deletions(-) create mode 100644 modules/archive/archive_index9.html.erb create mode 100644 modules/archive/thumbs/ar9.png diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index e28a0e8..0133d81 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -11,11 +11,11 @@ class ArchivesController < ApplicationController def index params = OrbitHelper.params @@total_pages = 1 + cats_last = [] if !params['title'].nil? files_by_category = ArchiveFile.where(is_hidden: false).order_by(:created_at => "desc").group_by(&:category) categories = files_by_category.keys categories_sort = get_sorted_cat_with_filter(categories,'orm') - cats_last = [] categories_sort.each do |category| url_to_edit = "" flag = false @@ -78,7 +78,88 @@ class ArchivesController < ApplicationController page.save 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 = [] categories = files_by_category.keys 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] }] 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 all_data_count = 0 data_start = -1 @@ -198,10 +269,16 @@ class ArchivesController < ApplicationController @@total_pages = 1 end end + end end { "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 diff --git a/archive.gemspec b/archive.gemspec index 24c866f..be32bc8 100644 --- a/archive.gemspec +++ b/archive.gemspec @@ -13,8 +13,8 @@ all_template.each do |folder| 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"] - file_infos = [ + check_files = ["archive_index7.html.erb","archive_index8.html.erb","archive_index9.html.erb"] + old_file_infos = [ { "filename" => "archive_index7", "name" => { @@ -32,11 +32,48 @@ all_template.each do |folder| "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 = [] + 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(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 flags << flag 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]}]} 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 + 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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 076955c..f3a89d3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,6 +2,8 @@ en: restful_actions: categories_order: Categories Order archive: + updated_at: Updated At + download_file: Download file drag_file_to_here: Drag file to here description: File description category: Category diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index e452edd..c409ac9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -2,6 +2,8 @@ zh_tw: restful_actions: categories_order: 類別排序 archive: + updated_at: 上傳日期 + download_file: 檔案下載 drag_file_to_here: 拖移檔案到此 description: 檔案簡介 category: 類別 diff --git a/modules/archive/archive_index7.html.erb b/modules/archive/archive_index7.html.erb index cd4449f..097115b 100644 --- a/modules/archive/archive_index7.html.erb +++ b/modules/archive/archive_index7.html.erb @@ -6,23 +6,23 @@

{{category-title}}

-
上傳日期
-
標題
+
{{date-head}}
+
{{title-head}}
{{description-head}}
-
檔案下載
+
{{file-head}}
{{created_at}}
-
+
{{archive-title}} {{status}}
{{description}}
- @@ -34,11 +34,6 @@
\ No newline at end of file +
\ No newline at end of file diff --git a/modules/archive/archive_index9.html.erb b/modules/archive/archive_index9.html.erb new file mode 100644 index 0000000..839160f --- /dev/null +++ b/modules/archive/archive_index9.html.erb @@ -0,0 +1,30 @@ +
+

+ {{page-title}} +

+
+

{{category-title}}

+ + + + + + + + + + + + + + + + + +
{{title-head}}{{file-head}}
+ {{file-name}} + + {{file-type}} +
+
+
\ No newline at end of file diff --git a/modules/archive/info.json b/modules/archive/info.json index 3d25987..a1fd1d5 100644 --- a/modules/archive/info.json +++ b/modules/archive/info.json @@ -51,18 +51,26 @@ { "filename" : "archive_index7", "name" : { - "zh_tw" : "7. 表格列表 ( 模組標題, 類別標題, 檔案名稱, 檔案簡介, 下載連結 )", - "en" : "7. Table list (widget-title, category, filename, download link)" + "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, filename, download link)" + "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" } ], "widgets" : [ diff --git a/modules/archive/thumbs/ar9.png b/modules/archive/thumbs/ar9.png new file mode 100644 index 0000000000000000000000000000000000000000..8b11bb77498b603ac9078de8943a2bb1614e8886 GIT binary patch literal 1690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