From 82457c4951779fddd90b1361f225f558ef332244 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Fri, 20 Mar 2020 15:20:16 +0800 Subject: [PATCH] Add rss2_id and rich_title to let custom add style to title in admin page(it will show in frontend show index). Add frontend show page link to admin index page. --- app/controllers/admin/faqs_controller.rb | 17 +++++++++++++++-- app/models/qa.rb | 9 +++++++-- app/views/admin/faqs/_form.html.erb | 6 +++--- app/views/admin/faqs/_index.html.erb | 6 +++++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/faqs_controller.rb b/app/controllers/admin/faqs_controller.rb index 72733fa..71f5f10 100644 --- a/app/controllers/admin/faqs_controller.rb +++ b/app/controllers/admin/faqs_controller.rb @@ -14,7 +14,7 @@ class Admin::FaqsController < OrbitAdminController .with_status(filters("status")) @qas = search_data(@qas,[:title]).page(params[:page]).per(10) - + @faq_page_url = Page.where(:module=>'faq').first.url rescue '#' render :partial => "index" if request.xhr? end @@ -87,10 +87,23 @@ class Admin::FaqsController < OrbitAdminController private def setup_vars + if ModuleApp.where(:key => "faq").count > 1 + module_apps = ModuleApp.where(:key => "faq").to_a + categories_count = module_apps.map{|m| m.categories.count} + module_apps = module_apps.map.with_index{|m,i| {'id'=>m.id,'count'=>categories_count[i]}}.sort_by{|m| -m['count']} + module_apps[1..-1].each do |m| + module_app = ModuleApp.find(m['id']) + module_app.categories.each{|c| c.update(:module_app_id=>module_apps.first['id'])} + module_app.destroy + end + end @module_app = ModuleApp.where(:key => "faq").first end def create_params - params.require(:qa).permit! + qa_params = params.require(:qa).permit! + qa_params['title_translations'] = {} + qa_params['rich_title_translations'].each{|locale,value| temp_title = Nokogiri::HTML(value);qa_params['title_translations'][locale] = temp_title.inner_text;} + return qa_params end end diff --git a/app/models/qa.rb b/app/models/qa.rb index c40cc01..d5cc8bb 100644 --- a/app/models/qa.rb +++ b/app/models/qa.rb @@ -11,13 +11,14 @@ class Qa include Slug field :title,as: :slug_title, localize: true + field :rich_title, localize: true field :answer, localize: true field :create_user_id field :update_user_id field :uid, type: String field :order_position, type: Integer, default: -1 - + field :rss2_id, type: String has_many :qa_links, :autosave => true, :dependent => :destroy has_many :qa_files, :autosave => true, :dependent => :destroy @@ -32,7 +33,11 @@ class Qa before_save :clean_values # validates :title, :at_least_one => true - + after_initialize do |record| + if record.rich_title.blank? && !record.title.blank? + record.update(:rich_title_translations => record.title_translations) + end + end def self.search( category_id = nil ) diff --git a/app/views/admin/faqs/_form.html.erb b/app/views/admin/faqs/_form.html.erb index 3f3e6c2..5b3409e 100644 --- a/app/views/admin/faqs/_form.html.erb +++ b/app/views/admin/faqs/_form.html.erb @@ -92,10 +92,10 @@ <% @site_in_use_locales.each_with_index do |locale, i| %>
">
- <%= f.label :title , t('faq.question'), :class=>"control-label muted" %> + <%= f.label :rich_title , t('faq.question'), :class=>"control-label muted" %>
- <%= f.fields_for :title_translations do |f| %> - <%= f.text_field locale, :class=>'post-title', :value => (@qa.title_translations[locale] rescue nil) %> + <%= f.fields_for :rich_title_translations do |f| %> + <%= f.text_area locale, :class=>'post-title ckeditor input-block-level', :value => (@qa.rich_title_translations[locale] rescue nil) %> <% end %>
diff --git a/app/views/admin/faqs/_index.html.erb b/app/views/admin/faqs/_index.html.erb index 4c8dc9d..1ac871f 100644 --- a/app/views/admin/faqs/_index.html.erb +++ b/app/views/admin/faqs/_index.html.erb @@ -17,7 +17,11 @@ <% end %> - <%= qa.title %> + <% if @faq_page_url != '#'%> + <%= qa.title %> + <% else %> + <%= qa.title %> + <% end %>