diff --git a/lib/orbit_model.rb b/lib/orbit_model.rb new file mode 100644 index 000000000..9c44a2ba6 --- /dev/null +++ b/lib/orbit_model.rb @@ -0,0 +1,4 @@ +require "orbit_model/approval" +require "orbit_model/language_restrict" +require "orbit_model/status" +require "orbit_model/time_frame" diff --git a/lib/orbit_model/approval.rb b/lib/orbit_model/approval.rb new file mode 100644 index 000000000..99c27c0d5 --- /dev/null +++ b/lib/orbit_model/approval.rb @@ -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 diff --git a/lib/orbit_model/language_restrict.rb b/lib/orbit_model/language_restrict.rb new file mode 100644 index 000000000..4eebfb723 --- /dev/null +++ b/lib/orbit_model/language_restrict.rb @@ -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 \ No newline at end of file diff --git a/lib/orbit_model/status.rb b/lib/orbit_model/status.rb new file mode 100644 index 000000000..98c8bd041 --- /dev/null +++ b/lib/orbit_model/status.rb @@ -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 diff --git a/lib/orbit_model/time_frame.rb b/lib/orbit_model/time_frame.rb new file mode 100644 index 000000000..c6ce38053 --- /dev/null +++ b/lib/orbit_model/time_frame.rb @@ -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 \ No newline at end of file diff --git a/lib/orbit_tag.rb b/lib/orbit_tag.rb index 61912534c..600e0da48 100644 --- a/lib/orbit_tag.rb +++ b/lib/orbit_tag.rb @@ -1 +1,3 @@ +require "orbit_tag/merging" require "orbit_tag/taggable" +require "orbit_tag/tagging" diff --git a/lib/orbit_tag/merging.rb b/lib/orbit_tag/merging.rb new file mode 100644 index 000000000..eddb1db38 --- /dev/null +++ b/lib/orbit_tag/merging.rb @@ -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 diff --git a/lib/orbit_tag/taggable.rb b/lib/orbit_tag/taggable.rb index 896bf355e..067c853a6 100644 --- a/lib/orbit_tag/taggable.rb +++ b/lib/orbit_tag/taggable.rb @@ -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 diff --git a/lib/orbit_tag/tagging.rb b/lib/orbit_tag/tagging.rb new file mode 100644 index 000000000..8068b6dda --- /dev/null +++ b/lib/orbit_tag/tagging.rb @@ -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 diff --git a/vendor/built_in_modules/announcement/app/models/bulletin.rb b/vendor/built_in_modules/announcement/app/models/bulletin.rb index e84b020fc..afa5270cb 100644 --- a/vendor/built_in_modules/announcement/app/models/bulletin.rb +++ b/vendor/built_in_modules/announcement/app/models/bulletin.rb @@ -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| diff --git a/vendor/built_in_modules/faq/app/models/qa.rb b/vendor/built_in_modules/faq/app/models/qa.rb index 1a99c3a24..caca89f71 100644 --- a/vendor/built_in_modules/faq/app/models/qa.rb +++ b/vendor/built_in_modules/faq/app/models/qa.rb @@ -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 diff --git a/vendor/built_in_modules/personal_book/app/models/writing_book.rb b/vendor/built_in_modules/personal_book/app/models/writing_book.rb index e6c59c8b6..e273746f7 100644 --- a/vendor/built_in_modules/personal_book/app/models/writing_book.rb +++ b/vendor/built_in_modules/personal_book/app/models/writing_book.rb @@ -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| diff --git a/vendor/built_in_modules/personal_conference/app/models/writing_conference.rb b/vendor/built_in_modules/personal_conference/app/models/writing_conference.rb index c23b75533..b7504dbab 100644 --- a/vendor/built_in_modules/personal_conference/app/models/writing_conference.rb +++ b/vendor/built_in_modules/personal_conference/app/models/writing_conference.rb @@ -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 diff --git a/vendor/built_in_modules/personal_diploma/app/models/diploma.rb b/vendor/built_in_modules/personal_diploma/app/models/diploma.rb index 041fbc49b..8cd4c5ce6 100644 --- a/vendor/built_in_modules/personal_diploma/app/models/diploma.rb +++ b/vendor/built_in_modules/personal_diploma/app/models/diploma.rb @@ -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 diff --git a/vendor/built_in_modules/personal_experience/app/models/experience.rb b/vendor/built_in_modules/personal_experience/app/models/experience.rb index 29deafb4b..fda0ab8f5 100644 --- a/vendor/built_in_modules/personal_experience/app/models/experience.rb +++ b/vendor/built_in_modules/personal_experience/app/models/experience.rb @@ -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 diff --git a/vendor/built_in_modules/personal_honor/app/models/honor.rb b/vendor/built_in_modules/personal_honor/app/models/honor.rb index 67f9f5f5f..c44f5aee4 100644 --- a/vendor/built_in_modules/personal_honor/app/models/honor.rb +++ b/vendor/built_in_modules/personal_honor/app/models/honor.rb @@ -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 diff --git a/vendor/built_in_modules/personal_journal/app/models/writing_journal.rb b/vendor/built_in_modules/personal_journal/app/models/writing_journal.rb index c4739f6bc..ab54d055b 100644 --- a/vendor/built_in_modules/personal_journal/app/models/writing_journal.rb +++ b/vendor/built_in_modules/personal_journal/app/models/writing_journal.rb @@ -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 diff --git a/vendor/built_in_modules/personal_lab/app/models/lab.rb b/vendor/built_in_modules/personal_lab/app/models/lab.rb index 9d6b48097..e924e1ae1 100644 --- a/vendor/built_in_modules/personal_lab/app/models/lab.rb +++ b/vendor/built_in_modules/personal_lab/app/models/lab.rb @@ -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| diff --git a/vendor/built_in_modules/personal_patent/app/models/writing_patent.rb b/vendor/built_in_modules/personal_patent/app/models/writing_patent.rb index 72c876227..f6c5ebf3b 100644 --- a/vendor/built_in_modules/personal_patent/app/models/writing_patent.rb +++ b/vendor/built_in_modules/personal_patent/app/models/writing_patent.rb @@ -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| diff --git a/vendor/built_in_modules/personal_project/app/models/project.rb b/vendor/built_in_modules/personal_project/app/models/project.rb index 1b0b86059..bbe52c264 100644 --- a/vendor/built_in_modules/personal_project/app/models/project.rb +++ b/vendor/built_in_modules/personal_project/app/models/project.rb @@ -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| diff --git a/vendor/built_in_modules/personal_research/app/models/research.rb b/vendor/built_in_modules/personal_research/app/models/research.rb index 4c7194578..f9ad4d6b4 100644 --- a/vendor/built_in_modules/personal_research/app/models/research.rb +++ b/vendor/built_in_modules/personal_research/app/models/research.rb @@ -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| diff --git a/vendor/built_in_modules/web_resource/app/models/web_link.rb b/vendor/built_in_modules/web_resource/app/models/web_link.rb index 3028cae30..2c3a01901 100644 --- a/vendor/built_in_modules/web_resource/app/models/web_link.rb +++ b/vendor/built_in_modules/web_resource/app/models/web_link.rb @@ -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