From 66c6b08d7600a9c3439c89079a40713f5b918022 Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Fri, 21 Jul 2023 10:10:22 +0800 Subject: [PATCH] Fix bug. --- .../admin/publications_controller.rb | 5 ++-- app/controllers/publications_controller.rb | 2 +- app/helpers/admin/publications_helper.rb | 27 +++++++++++++++++++ app/models/chapter.rb | 2 +- app/models/publication.rb | 2 +- app/views/admin/publications/_index.html.erb | 2 +- .../admin/publications/_module_tag.html.erb | 2 +- app/views/admin/publications/show.html.erb | 2 +- config/locales/en.yml | 2 +- config/locales/zh_tw.yml | 2 +- lib/publications/engine.rb | 4 +-- .../publication/publications_index1.html.erb | 2 +- .../publication/show_chapter_table.html.erb | 8 +++--- 13 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 app/helpers/admin/publications_helper.rb diff --git a/app/controllers/admin/publications_controller.rb b/app/controllers/admin/publications_controller.rb index e524573..fb2a546 100644 --- a/app/controllers/admin/publications_controller.rb +++ b/app/controllers/admin/publications_controller.rb @@ -1,8 +1,9 @@ class Admin::PublicationsController < OrbitAdminController - before_action :categories, only: [:index, :new, :edit] + include Admin::PublicationsHelper + before_action :categories, only: [:index, :new, :edit] def index - @table_fields = [:title, 'publications.chapter', :pub_date, :category] + @table_fields = [:title, 'publications_.chapter', :pub_date, :category] @filter_fields = filter_fields(@categories, @tags) @publications = Publication.order_by(sort) .with_categories(filters("category")) diff --git a/app/controllers/publications_controller.rb b/app/controllers/publications_controller.rb index 4b5fecd..4558ed3 100644 --- a/app/controllers/publications_controller.rb +++ b/app/controllers/publications_controller.rb @@ -219,7 +219,7 @@ class PublicationsController < ApplicationController "widget-title" => t("module_name.publication"), "th_keywords" => t('chapter.keywords'), "th_tags" => t('tags'), - "th_title" => t('publications.chapter'), + "th_title" => t('publications_.chapter'), "th_pub_date" => t('publication.pub_date'), "th_chapter_title" => t('chapter.title'), "th_author" => t('chapter.author'), diff --git a/app/helpers/admin/publications_helper.rb b/app/helpers/admin/publications_helper.rb new file mode 100644 index 0000000..0ea97b7 --- /dev/null +++ b/app/helpers/admin/publications_helper.rb @@ -0,0 +1,27 @@ +module Admin::PublicationsHelper + def page_for_publication(publication) + pub_page = nil + pages = Page.where(:module=>'publication').select{|page| page.enabled_for.include?(I18n.locale.to_s)} + + pages.each do |page| + if page.categories.count ==1 + if (page.categories.include?(publication.category.id.to_s) rescue false) + pub_page = page + end + end + break if !pub_page.nil? + end + + if pub_page.nil? + pages.each do |page| + if (page.categories.include?(publication.category.id.to_s) rescue false) + pub_page = page + end + break if !pub_page.nil? + end + end + + pub_page = pages.first if pub_page.nil? + request.protocol+(request.host_with_port+pub_page.url+'/'+publication.to_param).gsub('//','/') rescue "#" + end +end \ No newline at end of file diff --git a/app/models/chapter.rb b/app/models/chapter.rb index 6913131..256922c 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -3,7 +3,7 @@ class Chapter include Slug include OrbitTag::Taggable - field :title, type: String, localize: true + field :title, as: :slug_title, type: String, localize: true field :author, type: String, localize: true field :author_description, type: String, localize: true field :author_url, type: String diff --git a/app/models/publication.rb b/app/models/publication.rb index e41e881..245bef2 100644 --- a/app/models/publication.rb +++ b/app/models/publication.rb @@ -6,7 +6,7 @@ class Publication include OrbitCategory::Categorizable include Slug - field :title, type: String, localize: true + field :title, as: :slug_title, type: String, localize: true field :pub_date, type: DateTime field :author, type: String, localize: true field :author_description, type: String, localize: true diff --git a/app/views/admin/publications/_index.html.erb b/app/views/admin/publications/_index.html.erb index d31dc9a..f613907 100644 --- a/app/views/admin/publications/_index.html.erb +++ b/app/views/admin/publications/_index.html.erb @@ -14,7 +14,7 @@ <% @publications.each do |node| %> - <%= link_to node.title, publication_path(node.id) %> + <%= link_to node.title, page_for_publication(node) %>
- <%= t('publications.select_cover') %> + <%= t('publications_.select_cover') %> <%= t(:change) %> <%= f.file_field :cover %> diff --git a/app/views/admin/publications/show.html.erb b/app/views/admin/publications/show.html.erb index b5afe49..75078a0 100644 --- a/app/views/admin/publications/show.html.erb +++ b/app/views/admin/publications/show.html.erb @@ -74,7 +74,7 @@ <% if can_edit_or_delete?(@publication) %>
- <%= link_to t("publications.add_chapter"), new_admin_chapter_path(page: params[:page], publication_id: @publication.id), class: "btn btn-primary" %> + <%= link_to t("publications_.add_chapter"), new_admin_chapter_path(page: params[:page], publication_id: @publication.id), class: "btn btn-primary" %>
<%= content_tag :div, paginate(@chapters), class: "pagination pagination-centered" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 77a9cd7..f3a21c5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -35,7 +35,7 @@ en: search_placeholder: Please Input Keywords search: Search - publications: + publications_: publication: Publication select_cover: Select cover add_chapter: Add chapter diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 5195e50..7596889 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -35,7 +35,7 @@ zh_tw: search_placeholder: 請輸入關鍵字 search: 搜尋 - publications: + publications_: publication: 出版品 select_cover: 選擇封面 add_chapter: 新增章節 diff --git a/lib/publications/engine.rb b/lib/publications/engine.rb index 79c2d8f..f6779eb 100644 --- a/lib/publications/engine.rb +++ b/lib/publications/engine.rb @@ -26,7 +26,7 @@ module Publications puts ['error in publications',e] end OrbitApp.registration "Publications", :type => "ModuleApp" do - module_label "publications.publication" + module_label "publications_.publication" base_url File.expand_path File.dirname(__FILE__) # widget_methods ['widget'] # widget_settings [{"data_count"=>30}] @@ -44,7 +44,7 @@ module Publications end side_bar do - head_label_i18n 'publications.publication', icon_class: "icon-book" + head_label_i18n 'publications_.publication', icon_class: "icon-book" available_for "users" active_for_controllers (['admin/publications']) head_link_path "admin_publications_path" diff --git a/modules/publication/publications_index1.html.erb b/modules/publication/publications_index1.html.erb index 7ce82f0..9b28be0 100644 --- a/modules/publication/publications_index1.html.erb +++ b/modules/publication/publications_index1.html.erb @@ -14,7 +14,7 @@ {{status}} - {{title}} + {{title}} diff --git a/modules/publication/show_chapter_table.html.erb b/modules/publication/show_chapter_table.html.erb index 71fb468..fba41eb 100644 --- a/modules/publication/show_chapter_table.html.erb +++ b/modules/publication/show_chapter_table.html.erb @@ -1,5 +1,5 @@ -
- +
+
@@ -12,10 +12,10 @@ - +
- {{tag}} + {{tag}} {{title}}{{title}} {{author}} {{page}}