Refactor common code for models (approval, language restriction, status, time frame)
This commit is contained in:
parent
36da89f93e
commit
5de39dd0a6
|
@ -0,0 +1,4 @@
|
|||
require "orbit_model/approval"
|
||||
require "orbit_model/language_restrict"
|
||||
require "orbit_model/status"
|
||||
require "orbit_model/time_frame"
|
|
@ -0,0 +1,64 @@
|
|||
module OrbitModel
|
||||
|
||||
module Approval
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
field :is_checked, :type => Boolean, :default => false
|
||||
field :is_pending, :type => Boolean, :default => true
|
||||
field :is_rejected, :type => Boolean, :default => false
|
||||
field :not_checked_reason
|
||||
class_variable_defined?(:@@can_display) ? \
|
||||
class_variable_set(:@@can_display, class_variable_get(:@@can_display).merge({is_checked: true, is_rejected: false, is_pending: false})) : \
|
||||
class_variable_set(:@@can_display, {is_checked: true, is_rejected: false, is_pending: false})
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def de_pending
|
||||
self.is_pending = false
|
||||
end
|
||||
|
||||
def de_pending!
|
||||
de_pending
|
||||
self.save!
|
||||
end
|
||||
|
||||
def is_checked?
|
||||
!self.is_pending && self.is_checked && (self.is_rejected == false)
|
||||
end
|
||||
|
||||
def is_pending?
|
||||
self.is_pending
|
||||
end
|
||||
|
||||
def is_rejected?
|
||||
!self.is_pending && self.is_rejected && (self.is_rejected == true)
|
||||
end
|
||||
|
||||
def proc_check(check,not_pass_info = "")
|
||||
self.is_checked = true
|
||||
if check == "true"
|
||||
self.is_rejected = false
|
||||
elsif check == "false"
|
||||
self.is_rejected = true
|
||||
self.not_checked_reason = not_pass_info
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
module OrbitModel
|
||||
|
||||
module LanguageRestrict
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
before_save :update_available_language
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
private
|
||||
|
||||
def update_available_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
module OrbitModel
|
||||
|
||||
module Status
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
# scope :can_display, where(is_hidden: false)
|
||||
self.class_variable_defined?(:@@can_display) ? \
|
||||
self.class_variable_set(:@@can_display, self.class_variable_get(:@@can_display).merge({is_hidden: false})) : \
|
||||
self.class_variable_set(:@@can_display, {is_hidden: false})
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def is_hot?
|
||||
self.is_hot
|
||||
end
|
||||
|
||||
def is_hidden?
|
||||
self.is_hidden
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
define_method(:can_display) do
|
||||
where(class_variable_get(:@@can_display))
|
||||
end unless method_defined? :can_display
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
module OrbitModel
|
||||
|
||||
module TimeFrame
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
field :postdate , :type => DateTime
|
||||
field :deadline , :type => DateTime
|
||||
before_save :check_deadline
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def is_expired?
|
||||
Date.today > self.deadline ? true : false rescue false
|
||||
#some dates might sat as nil so rescue false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_deadline
|
||||
if(!self.deadline.nil? and (self.deadline < self.postdate ))
|
||||
self.deadline = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1 +1,3 @@
|
|||
require "orbit_tag/merging"
|
||||
require "orbit_tag/taggable"
|
||||
require "orbit_tag/tagging"
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
module OrbitTag
|
||||
|
||||
module Merging
|
||||
|
||||
protected
|
||||
|
||||
def clone_tag(module_tag, parent_id=nil, set_parent=nil)
|
||||
new_tag = module_tag.clone
|
||||
new_tag['_id'] = BSON::ObjectId.new
|
||||
new_tag['module_app_id'] = @module_app.id
|
||||
new_tag['parent_id'] = parent_id
|
||||
new_tag.save
|
||||
module_tag.update_attribute(:parent_id, new_tag.id) if set_parent
|
||||
end
|
||||
|
||||
def clone_tag_from_default(default_tag)
|
||||
clone_tag(default_tag, default_tag.id)
|
||||
end
|
||||
|
||||
def clone_tag_to_default(default_tag)
|
||||
clone_tag(default_tag, nil, true)
|
||||
end
|
||||
|
||||
def merge_default_tags(name, tag_leases)
|
||||
parent = @module_app.module_tags.create(name_translations: name, is_default: true)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, parent|
|
||||
sorted = parent.children.inject(sorted) do |children, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if children[module_app_id]
|
||||
children[module_app_id] += [lease]
|
||||
else
|
||||
children[module_app_id] = [lease]
|
||||
end
|
||||
children
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
tag_leases.each(&:destroy)
|
||||
parent
|
||||
end
|
||||
|
||||
def merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
lease_by_module_app_id.each do |module_app_id, leases|
|
||||
if leases.count > 0
|
||||
taggings = leases.map { |l| l.tag.taggings }.flatten
|
||||
module_tag = merge_tags(parent.name_translations, taggings, module_app_id, true)
|
||||
module_tag.update_attribute(:parent_id, parent.id)
|
||||
leases.each(&:destroy)
|
||||
else
|
||||
leases[0].update_attributes(name_translations: parent.name_translations, is_default: true, parent_id: parent.id) unless leases[0].is_default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_tags(name, taggings, module_app_id, default=nil)
|
||||
module_app = ModuleApp.find(module_app_id)
|
||||
new_tag = module_app.module_tags.create(name_translations: name, module_app_id: module_app.id, is_default: default)
|
||||
taggings.each do |tagging|
|
||||
tagging.taggable.taggings.create(tag_id: new_tag.tag.id) unless tagging.taggable.taggings.detect{|t| t.tag_id.eql?(new_tag.tag.id)}
|
||||
end
|
||||
new_tag
|
||||
end
|
||||
|
||||
def merge_with_default_tags(name, tag_leases)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, lease|
|
||||
module_app_id = lease.is_default ? 'default' : lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
if lease_by_module_app_id['default'].count > 1
|
||||
parent = merge_default_tags(name, lease_by_module_app_id['default'])
|
||||
else
|
||||
parent = lease_by_module_app_id['default'][0]
|
||||
parent.update_attributes(name_translations: name)
|
||||
end
|
||||
lease_by_module_app_id.delete('default')
|
||||
lease_by_module_app_id = parent.children.inject(lease_by_module_app_id) do |sorted, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,16 +1,14 @@
|
|||
module OrbitTag
|
||||
module Taggable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval 'taggable'
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def taggable
|
||||
init_tag
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def init_tag
|
||||
class_eval do
|
||||
field :tags_to_destroy, type: Array, default: []
|
||||
field :tagged_ids, type: Array, default: []
|
||||
|
@ -18,59 +16,63 @@ module OrbitTag
|
|||
has_many :taggings, as: :taggable, autosave: true, dependent: :destroy
|
||||
accepts_nested_attributes_for :taggings, allow_destroy: true
|
||||
after_save :remove_taggings, unless: Proc.new{self.tags_to_destroy.blank?}
|
||||
end
|
||||
send :include, InstanceMethods
|
||||
end
|
||||
end
|
||||
|
||||
def remove_id(id)
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tagged_ids, self.tagged_ids - [id.to_s])
|
||||
end
|
||||
module InstanceMethods
|
||||
|
||||
def remove_id(id)
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tagged_ids, self.tagged_ids - [id.to_s])
|
||||
end
|
||||
end
|
||||
|
||||
def sorted_tags
|
||||
if tags.blank?
|
||||
[]
|
||||
else
|
||||
tag_array = tags.inject([]){ |result, value|
|
||||
result << [value.name, value]
|
||||
}
|
||||
tag_array.sort.map{|x| x[1] }
|
||||
end
|
||||
end
|
||||
|
||||
def tags
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag}.compact
|
||||
end
|
||||
|
||||
def tags=(tag_ids)
|
||||
ids = [tag_ids].flatten
|
||||
tag_ids.delete('')
|
||||
ids = self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
tag_ids.each do |tag_id|
|
||||
unless ids.include? tag_id
|
||||
self.taggings.build(tag_id: tag_id)
|
||||
end
|
||||
end
|
||||
self.tags_to_destroy = self.taggings.where(:tag_id.in => (ids - tag_ids)).map{|t| t.id}
|
||||
end
|
||||
|
||||
def sorted_tags
|
||||
if tags.blank?
|
||||
[]
|
||||
else
|
||||
tag_array = tags.inject([]){ |result, value|
|
||||
result << [value.name, value]
|
||||
}
|
||||
tag_array.sort.map{|x| x[1] }
|
||||
end
|
||||
end
|
||||
def tag_ids
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
end
|
||||
|
||||
def tags
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag}.compact
|
||||
end
|
||||
def tag_ids=(ids)
|
||||
self.tags = ids
|
||||
ids = [ids].flatten
|
||||
ids.delete('')
|
||||
self.tagged_ids = ids
|
||||
end
|
||||
|
||||
def tags=(tag_ids)
|
||||
ids = [tag_ids].flatten
|
||||
tag_ids.delete('')
|
||||
ids = self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
tag_ids.each do |tag_id|
|
||||
unless ids.include? tag_id
|
||||
self.taggings.build(tag_id: tag_id)
|
||||
end
|
||||
end
|
||||
self.tags_to_destroy = self.taggings.where(:tag_id.in => (ids - tag_ids)).map{|t| t.id}
|
||||
end
|
||||
private
|
||||
|
||||
def tag_ids
|
||||
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag.id}
|
||||
end
|
||||
|
||||
def tag_ids=(ids)
|
||||
self.tags = ids
|
||||
ids = [ids].flatten
|
||||
ids.delete('')
|
||||
self.tagged_ids = ids
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def remove_taggings
|
||||
self.taggings.where(:_id.in => self.tags_to_destroy).destroy
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tags_to_destroy, [])
|
||||
end
|
||||
end
|
||||
def remove_taggings
|
||||
self.taggings.where(:_id.in => self.tags_to_destroy).destroy
|
||||
self.class.without_callback(:save, :after, :remove_taggings) do
|
||||
self.update_attribute(:tags_to_destroy, [])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -78,104 +80,4 @@ module OrbitTag
|
|||
|
||||
end
|
||||
|
||||
module Tagging
|
||||
def get_tags
|
||||
@module_app.tags
|
||||
end
|
||||
|
||||
def get_default_tags
|
||||
Tag.where(is_default: true)
|
||||
end
|
||||
end
|
||||
|
||||
module Merging
|
||||
protected
|
||||
|
||||
def clone_tag(module_tag, parent_id=nil, set_parent=nil)
|
||||
new_tag = module_tag.clone
|
||||
new_tag['_id'] = BSON::ObjectId.new
|
||||
new_tag['module_app_id'] = @module_app.id
|
||||
new_tag['parent_id'] = parent_id
|
||||
new_tag.save
|
||||
module_tag.update_attribute(:parent_id, new_tag.id) if set_parent
|
||||
end
|
||||
|
||||
def clone_tag_from_default(default_tag)
|
||||
clone_tag(default_tag, default_tag.id)
|
||||
end
|
||||
|
||||
def clone_tag_to_default(default_tag)
|
||||
clone_tag(default_tag, nil, true)
|
||||
end
|
||||
|
||||
def merge_default_tags(name, tag_leases)
|
||||
parent = @module_app.module_tags.create(name_translations: name, is_default: true)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, parent|
|
||||
sorted = parent.children.inject(sorted) do |children, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if children[module_app_id]
|
||||
children[module_app_id] += [lease]
|
||||
else
|
||||
children[module_app_id] = [lease]
|
||||
end
|
||||
children
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
tag_leases.each(&:destroy)
|
||||
parent
|
||||
end
|
||||
|
||||
def merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
lease_by_module_app_id.each do |module_app_id, leases|
|
||||
if leases.count > 0
|
||||
taggings = leases.map { |l| l.tag.taggings }.flatten
|
||||
module_tag = merge_tags(parent.name_translations, taggings, module_app_id, true)
|
||||
module_tag.update_attribute(:parent_id, parent.id)
|
||||
leases.each(&:destroy)
|
||||
else
|
||||
leases[0].update_attributes(name_translations: parent.name_translations, is_default: true, parent_id: parent.id) unless leases[0].is_default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def merge_tags(name, taggings, module_app_id, default=nil)
|
||||
module_app = ModuleApp.find(module_app_id)
|
||||
new_tag = module_app.module_tags.create(name_translations: name, module_app_id: module_app.id, is_default: default)
|
||||
taggings.each do |tagging|
|
||||
tagging.taggable.taggings.create(tag_id: new_tag.tag.id) unless tagging.taggable.taggings.detect{|t| t.tag_id.eql?(new_tag.tag.id)}
|
||||
end
|
||||
new_tag
|
||||
end
|
||||
|
||||
def merge_with_default_tags(name, tag_leases)
|
||||
lease_by_module_app_id = tag_leases.inject({}) do |sorted, lease|
|
||||
module_app_id = lease.is_default ? 'default' : lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
if lease_by_module_app_id['default'].count > 1
|
||||
parent = merge_default_tags(name, lease_by_module_app_id['default'])
|
||||
else
|
||||
parent = lease_by_module_app_id['default'][0]
|
||||
parent.update_attributes(name_translations: name)
|
||||
end
|
||||
lease_by_module_app_id.delete('default')
|
||||
lease_by_module_app_id = parent.children.inject(lease_by_module_app_id) do |sorted, lease|
|
||||
module_app_id = lease.module_app_id.to_s
|
||||
if sorted[module_app_id]
|
||||
sorted[module_app_id] += [lease]
|
||||
else
|
||||
sorted[module_app_id] = [lease]
|
||||
end
|
||||
sorted
|
||||
end
|
||||
merge_duplicates_in_module(parent, lease_by_module_app_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
module OrbitTag
|
||||
|
||||
module Tagging
|
||||
|
||||
def get_tags
|
||||
@module_app.tags
|
||||
end
|
||||
|
||||
def get_default_tags
|
||||
Tag.where(is_default: true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -10,9 +10,11 @@ class Bulletin
|
|||
BelongsToCategory = :bulletin_category
|
||||
include OrbitCoreLib::BelongsToCategoryMayDisable
|
||||
include OrbitCoreLib::Preview
|
||||
|
||||
include OrbitModel::Approval
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitModel::TimeFrame
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
|
@ -20,29 +22,12 @@ class Bulletin
|
|||
field :subtitle, localize: true
|
||||
field :text, localize: true
|
||||
|
||||
# has_and_belongs_to_many :tags, :class_name => "AnnouncementTag"
|
||||
|
||||
field :postdate , :type => DateTime
|
||||
field :deadline , :type => DateTime
|
||||
# field :url
|
||||
|
||||
field :create_user_id
|
||||
field :update_user_id, :class_name => "User"
|
||||
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
field :is_checked, :type => Boolean, :default => false
|
||||
field :is_pending, :type => Boolean, :default => true
|
||||
field :is_rejected, :type => Boolean, :default => false
|
||||
field :view_count, :type => Integer, :default => 0
|
||||
|
||||
field :not_checked_reason
|
||||
|
||||
field :public, :type => Boolean, :default => true
|
||||
|
||||
scope :can_display, where(is_checked: true, is_rejected: false, is_pending: false)
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
|
@ -54,7 +39,7 @@ class Bulletin
|
|||
|
||||
validates :title, :at_least_one => true
|
||||
|
||||
before_save :check_deadline, :update_avliable_language#, :clean_values#, :save_bulletin_links, :save_bulletin_files
|
||||
#before_save :clean_values, :save_bulletin_links, :save_bulletin_files
|
||||
|
||||
searchable do
|
||||
text :titles do
|
||||
|
@ -88,25 +73,6 @@ class Bulletin
|
|||
Item.first(conditions:{name: 'announcement'})
|
||||
end
|
||||
|
||||
def proc_check(check,not_pass_info = "")
|
||||
self.is_checked = true
|
||||
if check =="true"
|
||||
self.is_rejected = false
|
||||
elsif check == "false"
|
||||
self.is_rejected = true
|
||||
self.not_checked_reason = not_pass_info
|
||||
end
|
||||
end
|
||||
|
||||
def de_pending
|
||||
self.is_pending = false
|
||||
end
|
||||
|
||||
def de_pending!
|
||||
de_pending
|
||||
self.save!
|
||||
end
|
||||
|
||||
def enabled_for_lang(lang)
|
||||
eval("self.available_for_#{lang}")
|
||||
end
|
||||
|
@ -146,35 +112,6 @@ class Bulletin
|
|||
|
||||
end
|
||||
|
||||
def is_expired?
|
||||
Date.today > self.deadline ? true : false rescue false
|
||||
#some dates might sat as nil so rescue false
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def is_hot?
|
||||
self.is_hot
|
||||
end
|
||||
|
||||
def is_hidden?
|
||||
self.is_hidden
|
||||
end
|
||||
|
||||
def is_checked?
|
||||
!self.is_pending && self.is_checked && (self.is_rejected == false)
|
||||
end
|
||||
|
||||
def is_pending?
|
||||
self.is_pending
|
||||
end
|
||||
|
||||
def is_rejected?
|
||||
!self.is_pending && self.is_rejected && (self.is_rejected == true)
|
||||
end
|
||||
|
||||
|
||||
def save_bulletin_links
|
||||
self.bulletin_links.each do |t|
|
||||
|
@ -217,22 +154,6 @@ class Bulletin
|
|||
|
||||
|
||||
protected
|
||||
|
||||
def check_deadline
|
||||
if(!self.deadline.nil? and (self.deadline < self.postdate ))
|
||||
self.deadline = nil
|
||||
end
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# def clean_values
|
||||
# self.bulletin_links.each do |link|
|
||||
|
|
|
@ -5,8 +5,9 @@ class Qa
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
|
@ -18,12 +19,6 @@ class Qa
|
|||
|
||||
field :create_user_id
|
||||
field :update_user_id
|
||||
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
scope :can_display,where(is_hidden: false)
|
||||
|
||||
has_many :qa_links, :autosave => true, :dependent => :destroy
|
||||
has_many :qa_files, :autosave => true, :dependent => :destroy
|
||||
|
@ -33,7 +28,7 @@ class Qa
|
|||
|
||||
belongs_to :qa_category
|
||||
|
||||
before_save :update_avliable_language, :clean_values
|
||||
before_save :clean_values
|
||||
|
||||
validates :question, :at_least_one => true
|
||||
|
||||
|
@ -59,20 +54,6 @@ class Qa
|
|||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (question_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def qa_category_with_title
|
||||
|
|
|
@ -4,10 +4,10 @@ class WritingBook
|
|||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -37,15 +37,11 @@ class WritingBook
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :writing_book_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :writing_book_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :paper_title, :at_least_one => true
|
||||
|
||||
|
@ -75,20 +71,6 @@ class WritingBook
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_writing_book_files
|
||||
self.writing_book_files.each do |t|
|
||||
|
|
|
@ -3,10 +3,9 @@ class WritingConference
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -33,14 +32,10 @@ class WritingConference
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :writing_conference_files, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :writing_conference_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :paper_title, :at_least_one => true
|
||||
before_validation :add_http
|
||||
|
@ -78,20 +73,6 @@ class WritingConference
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_writing_conference_files
|
||||
self.writing_conference_files.each do |t|
|
||||
if t.should_destroy
|
||||
|
|
|
@ -5,10 +5,9 @@ class Diploma
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -18,8 +17,6 @@ class Diploma
|
|||
field :department, localize: true
|
||||
field :degree, localize: true
|
||||
|
||||
# has_and_belongs_to_many :tags, :class_name => "PersonalDiplomaTag"
|
||||
|
||||
field :year
|
||||
field :language
|
||||
field :keywords
|
||||
|
@ -30,12 +27,8 @@ class Diploma
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :school_name, :at_least_one => true
|
||||
|
||||
|
@ -50,20 +43,6 @@ class Diploma
|
|||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
|
|
|
@ -5,10 +5,9 @@ class Experience
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -30,12 +29,8 @@ class Experience
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :organizationt_title, :at_least_one => true
|
||||
|
||||
|
@ -64,20 +59,6 @@ class Experience
|
|||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
|
|
|
@ -5,10 +5,9 @@ class Honor
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -28,11 +27,7 @@ class Honor
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates_presence_of :award_name
|
||||
|
||||
|
@ -61,20 +56,6 @@ class Honor
|
|||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
|
|
|
@ -3,8 +3,9 @@ class WritingJournal
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -79,20 +80,6 @@ class WritingJournal
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_writing_journal_files
|
||||
self.writing_journal_files.each do |t|
|
||||
if t.should_destroy
|
||||
|
|
|
@ -5,10 +5,9 @@ class Lab
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -31,15 +30,11 @@ class Lab
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :lab_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :lab_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :lab_title, :at_least_one => true
|
||||
|
||||
|
@ -69,20 +64,6 @@ class Lab
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_lab_files
|
||||
self.lab_files.each do |t|
|
||||
|
|
|
@ -5,10 +5,9 @@ class WritingPatent
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -31,15 +30,11 @@ class WritingPatent
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :writing_patent_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :writing_patent_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :patent_title, :at_least_one => true
|
||||
|
||||
|
@ -69,20 +64,6 @@ class WritingPatent
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_writing_patent_files
|
||||
self.writing_patent_files.each do |t|
|
||||
|
|
|
@ -5,10 +5,9 @@ class Project
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -33,15 +32,11 @@ class Project
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :project_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :project_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :project_title, :at_least_one => true
|
||||
|
||||
|
@ -71,20 +66,6 @@ class Project
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_project_files
|
||||
self.project_files.each do |t|
|
||||
|
|
|
@ -5,10 +5,9 @@ class Research
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
# scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
LANGUAGE_TYPES = [ "English", "Chinese" ]
|
||||
|
||||
|
@ -28,15 +27,11 @@ class Research
|
|||
field :create_user_id, :type => BSON::ObjectId
|
||||
field :update_user_id, :type => BSON::ObjectId
|
||||
|
||||
# field :is_top, :type => Boolean, :default => false
|
||||
# field :is_hot, :type => Boolean, :default => false
|
||||
# field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
has_many :research_files, :autosave => true, :dependent => :destroy
|
||||
|
||||
accepts_nested_attributes_for :research_files, :allow_destroy => true
|
||||
|
||||
# before_save :update_avliable_language, :clean_checkboxs
|
||||
# before_save :clean_checkboxs
|
||||
|
||||
validates :research_title, :at_least_one => true
|
||||
|
||||
|
@ -66,20 +61,6 @@ class Research
|
|||
where( :is_hidden => false ).desc(:is_top, :created_at)
|
||||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def save_research_files
|
||||
self.research_files.each do |t|
|
||||
|
|
|
@ -5,10 +5,9 @@ class WebLink
|
|||
include Mongoid::Timestamps
|
||||
include Mongoid::MultiParameterAttributes
|
||||
|
||||
include OrbitModel::LanguageRestrict
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
taggable
|
||||
|
||||
scope :available_for_lang, ->(locale){ where("available_for_#{locale}".to_sym => true) }
|
||||
|
||||
field :title, localize: true
|
||||
field :context, localize: true
|
||||
|
@ -19,13 +18,9 @@ class WebLink
|
|||
field :create_user_id
|
||||
field :update_user_id
|
||||
|
||||
field :is_top, :type => Boolean, :default => false
|
||||
field :is_hot, :type => Boolean, :default => false
|
||||
field :is_hidden, :type => Boolean, :default => false
|
||||
|
||||
belongs_to :web_link_category
|
||||
|
||||
before_save :update_avliable_language, :clean_tags
|
||||
before_save :clean_tags
|
||||
|
||||
validates :title, :at_least_one => true
|
||||
|
||||
|
@ -53,20 +48,6 @@ class WebLink
|
|||
|
||||
end
|
||||
|
||||
def is_top?
|
||||
self.is_top
|
||||
end
|
||||
|
||||
def update_avliable_language
|
||||
VALID_LOCALES.each do |locale|
|
||||
if (title_translations[locale].blank? rescue true)
|
||||
self["available_for_#{locale}".to_sym] = false
|
||||
else
|
||||
self["available_for_#{locale}".to_sym] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
|
|
Loading…
Reference in New Issue