diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index b8858ad8..485db8c8 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -78,6 +78,69 @@ namespace :migrate do end p 'End UnitListForAnc' + p '=====================================================' + p '=====================================================' + + p 'Start NewsBulletin' + news_bulletins = NewsBulletin.admin_manager_all + i = 1 + news_bulletins.each do |news_bulletin| + p "#{i}/#{news_bulletins.size} - #{news_bulletin.id}" + title = I18nVariable.first(:conditions => {:key => 'title', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class}) + news_bulletin.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title + subtitle = I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class}) + news_bulletin.subtitle_translations = {'en' => subtitle['en'], 'zh_tw' => subtitle['zh_tw']} if subtitle + text = I18nVariable.first(:conditions => {:key => 'text', :language_value_id => news_bulletin.id, :language_value_type => news_bulletin.class}) + news_bulletin.text_translations = {'en' => text['en'], 'zh_tw' => text['zh_tw']} if text + news_bulletin.save(:validate => false) + i += 1 + end + p 'End NewsBulletin' + + p '=====================================================' + + p 'Start NewsBulletinCategory' + categories = NewsBulletinCategory.admin_manager_all + i = 1 + categories.each do |category| + p "#{i}/#{categories.size} - #{category.id}" + title = I18nVariable.first(:conditions => {:language_value_id => category.id, :language_value_type => category.class}) + category.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title + category.save(:validate => false) + i += 1 + end + p 'End NewsBulletinCategory' + + p '=====================================================' + + p 'Start NewsBulletinFile' + files = NewsBulletinFile.all + i = 1 + files.each do |file| + p "#{i}/#{files.size} - #{file.id}" + description = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class}) + file.description_translations = {'en' => description['en'], 'zh_tw' => description['zh_tw']} if description + title = I18nVariable.first(:conditions => {:language_value_id => file.id, :language_value_type => file.class}) + file.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title + file.save(:validate => false) + i += 1 + end + p 'End NewsBulletinFile' + + p '=====================================================' + + p 'Start NewsBulletinLink' + links = NewsBulletinLink.all + i = 1 + links.each do |link| + p "#{i}/#{links.size} - #{link.id}" + title = I18nVariable.first(:conditions => {:language_value_id => link.id, :language_value_type => link.class}) + link.title_translations = {'en' => title['en'], 'zh_tw' => title['zh_tw']} if title + link.save(:validate => false) + i += 1 + end + p 'End NewsBulletinLink' + end end diff --git a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb index cc45309a..0c946ca3 100644 --- a/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb +++ b/vendor/built_in_modules/news/app/controllers/panel/news/back_end/news_approvals_controller.rb @@ -26,7 +26,7 @@ class Panel::News::BackEnd::NewsApprovalsController < OrbitBackendController def setting @sys_users = User.all(conditions: {admin: false}).includes(:avatar) @news_bulletin_categorys = NewsBulletinCategory.all - @options_from_collection_for_select_news_bulletin_categorys = @news_bulletin_categorys.collect{|bc| [bc.i18n_variable[I18n.locale],bc.id] } + @options_from_collection_for_select_news_bulletin_categorys = @news_bulletin_categorys.collect{|bc| [bc.title,bc.id] } if params.has_key? :news_category @news_bulletin_categorys = NewsBulletinCategory.find params[:news_category][:id] else diff --git a/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletins_helper.rb b/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletins_helper.rb index d8342f74..bb64dbc7 100644 --- a/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletins_helper.rb +++ b/vendor/built_in_modules/news/app/helpers/panel/news/back_end/news_bulletins_helper.rb @@ -14,9 +14,9 @@ module Panel::News::BackEnd::NewsBulletinsHelper def show_news_bulletin_title_at_index (news_bulletin) if news_bulletin.is_checked? - link_to news_bulletin.title[I18n.locale], panel_news_front_end_news_bulletin_path(news_bulletin, :category_id => news_bulletin.news_bulletin_category.id) rescue '' + link_to news_bulletin.title, panel_news_front_end_news_bulletin_path(news_bulletin, :category_id => news_bulletin.news_bulletin_category.id) rescue '' else - news_bulletin.title[I18n.locale] + news_bulletin.title end end diff --git a/vendor/built_in_modules/news/app/models/news_bulletin.rb b/vendor/built_in_modules/news/app/models/news_bulletin.rb index dbcd215c..a724ba0e 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin.rb @@ -18,9 +18,9 @@ class NewsBulletin is_impressionable :counter_cache => { :column_name => :view_count } - has_one :title, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy - has_one :subtitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy - has_one :text, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + field :title, localize: true + field :subtitle, localize: true + field :text, localize: true has_and_belongs_to_many :tags, :class_name => "NewsTag" field :postdate , :type => DateTime @@ -59,7 +59,7 @@ class NewsBulletin validates_presence_of :title - before_save :set_key, :update_status + before_save :update_status after_save :save_news_bulletin_links after_save :save_news_bulletin_files @@ -182,19 +182,6 @@ class NewsBulletin end end end - - - def title - @title ||= I18nVariable.first(:conditions => {:key => 'title', :language_value_id => self.id, :language_value_type => self.class}) rescue nil - end - - def subtitle - @subtitle ||= I18nVariable.first(:conditions => {:key => 'subtitle', :language_value_id => self.id, :language_value_type => self.class}) rescue nil - end - - def text - @text ||= I18nVariable.first(:conditions => {:key => 'text', :language_value_id => self.id, :language_value_type => self.class}) rescue nil - end def self.filter(news_bulletins) news_bulletins.each do |news_bulletin| @@ -208,18 +195,6 @@ class NewsBulletin end protected - - def set_key - if title && title.new_record? - title.key = 'title' - end - if subtitle && subtitle.new_record? - subtitle.key = 'subtitle' - end - if text && text.new_record? - text.key = 'text' - end - end def update_status if !self.is_pending diff --git a/vendor/built_in_modules/news/app/models/news_bulletin_category.rb b/vendor/built_in_modules/news/app/models/news_bulletin_category.rb index 79443f82..8d433d96 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin_category.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin_category.rb @@ -16,11 +16,11 @@ class NewsBulletinCategory field :key field :display - has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + field :title, localize: true has_many :news_bulletins def pp_object - i18n_variable[I18n.locale] + title end def self.from_id(id) diff --git a/vendor/built_in_modules/news/app/models/news_bulletin_file.rb b/vendor/built_in_modules/news/app/models/news_bulletin_file.rb index 40495cb4..882d96cb 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin_file.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin_file.rb @@ -5,36 +5,13 @@ class NewsBulletinFile mount_uploader :file, AssetUploader - # field :filetitle - # field :description - has_one :filetitle, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy - has_one :description, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy + field :title, localize: true + field :description, localize: true # field :to_save, :type => Boolean field :should_destroy, :type => Boolean belongs_to :news_bulletin # embedded_in :news_bulletin - - before_save :set_key - - def filetitle - @filetitle ||= I18nVariable.first(:conditions => {:key => 'filetitle', :language_value_id => self.id, :language_value_type => self.class}) rescue nil - end - - def description - @description ||= I18nVariable.first(:conditions => {:key => 'description', :language_value_id => self.id, :language_value_type => self.class}) rescue nil - end - - protected - - def set_key - if filetitle && filetitle.new_record? - filetitle.key = 'filetitle' - end - if description && description.new_record? - description.key = 'description' - end - end end diff --git a/vendor/built_in_modules/news/app/models/news_bulletin_link.rb b/vendor/built_in_modules/news/app/models/news_bulletin_link.rb index 2e56c23c..0a793d27 100644 --- a/vendor/built_in_modules/news/app/models/news_bulletin_link.rb +++ b/vendor/built_in_modules/news/app/models/news_bulletin_link.rb @@ -4,12 +4,9 @@ class NewsBulletinLink include Mongoid::Timestamps field :url - # field :name - - has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy + field :title, localize: true field :should_destroy, :type => Boolean - # embedded_in :news_bulletin belongs_to :news_bulletin end diff --git a/vendor/built_in_modules/news/app/models/news_tag.rb b/vendor/built_in_modules/news/app/models/news_tag.rb index 5005f617..005bd438 100644 --- a/vendor/built_in_modules/news/app/models/news_tag.rb +++ b/vendor/built_in_modules/news/app/models/news_tag.rb @@ -3,7 +3,7 @@ class NewsTag < Tag has_and_belongs_to_many :news_bulletins - def get_visible_news_bulletins(sort = :name) + def get_visible_news_bulletins(sort = :title) date_now = Time.now self.news_bulletins.where(:is_hidden => false).any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc(:is_top, sort) end diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/fact_checks/setting.html.erb b/vendor/built_in_modules/news/app/views/panel/news/back_end/fact_checks/setting.html.erb index aa7949f9..53320355 100644 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/fact_checks/setting.html.erb +++ b/vendor/built_in_modules/news/app/views/panel/news/back_end/fact_checks/setting.html.erb @@ -2,14 +2,9 @@ <%= stylesheet_link_tag "inc/permission-checkbox" %> <% end %> <% content_for :page_specific_javascript do %> -<<<<<<< HEAD <%= javascript_include_tag "bootstrap" %> - <%#= javascript_include_tag "inc/permission-checkbox" %> - <%#= javascript_include_tag "inc/search" %> -======= <%= javascript_include_tag "inc/permission-checkbox" %> <%= javascript_include_tag "inc/search" %> ->>>>>>> 291d5e3a03ba7da62ceb5e3b18012f0c9198dfba <% end %> <%#= label_tag :fact_check_setting, t("news.news_bulletin.fact_check_setting") %> <%= form_tag('', :remote => true) %> diff --git a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_list_table.html.erb.can_del b/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_list_table.html.erb.can_del deleted file mode 100644 index 0149988f..00000000 --- a/vendor/built_in_modules/news/app/views/panel/news/back_end/news_approvals/_list_table.html.erb.can_del +++ /dev/null @@ -1,15 +0,0 @@ -
<%= t('news_bulletin.status') %> | -<%= t('news_bulletin.category') %> | -<%= t('news_bulletin.title') %> | -<%= t('news_bulletin.postdate') %> | -<%= t('news_bulletin.deadline') %> | -<%= t('news_bulletin.action') %> | -
---|