basic function
This commit is contained in:
1 parent
9eed9ec7b6
commit
19db9d0037
26 files changed
+420
-185
No files matched your search
@@ -0,0 +1,40 @@
|
||||
class ProtoTag
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Impressionist::Impressionable
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
field :key
|
||||
field :view_count, :type => Integer, :default => 0
|
||||
#field :cloud_amper,:type: Integer,:default=> 0
|
||||
|
||||
def self.sorted_for_cloud
|
||||
tags = {}
|
||||
self.all.each{ |tag|
|
||||
tags.merge!({tag => self.get_impressionist(tag)})
|
||||
}
|
||||
if !tags.blank?
|
||||
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
|
||||
sorted_tags[0][1] = :hot1
|
||||
offset = (sorted_tags.size - 1) / 3
|
||||
i = 1
|
||||
class_i = 2
|
||||
sorted_tags[1..-1].collect!{ |x|
|
||||
x[1] = "hot#{class_i}"
|
||||
i == offset ? i = 1 : i += 1 if class_i < 4
|
||||
class_i += 1 if i == offset && class_i < 4
|
||||
}
|
||||
sorted_tags
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.get_impressionist(item_tag = self)
|
||||
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
class SubRoleTag < ProtoTag
|
||||
has_and_belongs_to_many :sub_roles
|
||||
|
||||
end
|
||||
+1
-38
@@ -1,41 +1,4 @@
|
||||
class Tag
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include Impressionist::Impressionable
|
||||
|
||||
is_impressionable :counter_cache => { :column_name => :view_count }
|
||||
|
||||
field :key
|
||||
field :view_count, :type => Integer, :default => 0
|
||||
#field :cloud_amper,:type: Integer,:default=> 0
|
||||
class Tag < ProtoTag
|
||||
belongs_to :module_app
|
||||
|
||||
def self.sorted_for_cloud
|
||||
tags = {}
|
||||
self.all.each{ |tag|
|
||||
tags.merge!({tag => self.get_impressionist(tag)})
|
||||
}
|
||||
if !tags.blank?
|
||||
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
|
||||
sorted_tags[0][1] = :hot1
|
||||
offset = (sorted_tags.size - 1) / 3
|
||||
i = 1
|
||||
class_i = 2
|
||||
sorted_tags[1..-1].collect!{ |x|
|
||||
x[1] = "hot#{class_i}"
|
||||
i == offset ? i = 1 : i += 1 if class_i < 4
|
||||
class_i += 1 if i == offset && class_i < 4
|
||||
}
|
||||
sorted_tags
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.get_impressionist(item_tag = self)
|
||||
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
|
||||
end
|
||||
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class AttributeField
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :key
|
||||
field :markup
|
||||
field :markup #[select,text_field,email,date,addr]
|
||||
field :locale, :type => Boolean, :default => true
|
||||
field :list_options, :type => Array
|
||||
field :built_in, :type => Boolean, :default => false
|
||||
@@ -15,10 +15,14 @@ class AttributeField
|
||||
field :neutral_title
|
||||
|
||||
belongs_to :attribute
|
||||
belongs_to :role
|
||||
# belongs_to :role
|
||||
has_many :attribute_values
|
||||
|
||||
# validates_uniqueness_of :key
|
||||
def role
|
||||
self.attribute.role
|
||||
end
|
||||
|
||||
def title_translations
|
||||
if locale
|
||||
return locale_title_translations
|
||||
@@ -29,7 +33,7 @@ class AttributeField
|
||||
|
||||
def title_translations=(var)
|
||||
if locale
|
||||
self.locale_title = var
|
||||
self.locale_title_translations = var
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ class Status
|
||||
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
has_and_belongs_to_many :users
|
||||
|
||||
|
||||
belongs_to :role
|
||||
has_and_belongs_to_many :sub_roles
|
||||
# has_and_belongs_to_many :sub_roles
|
||||
|
||||
field :title, localize: true
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ class SubRole < Attribute
|
||||
|
||||
belongs_to :role
|
||||
has_and_belongs_to_many :users
|
||||
has_and_belongs_to_many :statuses, :autosave => true, :dependent => :destroy
|
||||
#has_and_belongs_to_many :statuses, :autosave => true, :dependent => :destroy
|
||||
has_and_belongs_to_many :tags, :class_name => "SubRoleTag", :autosave => true
|
||||
|
||||
# Get an sub_role from key
|
||||
def self.get_sub_role_from_key(key)
|
||||
self.first(:conditions => {:key => key})
|
||||
|
||||
@@ -14,6 +14,7 @@ class User
|
||||
# field :cache_dept
|
||||
# has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
field :cache_dept,type: Hash
|
||||
field :status_record,type: Hash
|
||||
|
||||
has_many :attribute_values, :autosave => true, :dependent => :destroy
|
||||
has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists
|
||||
@@ -25,9 +26,9 @@ class User
|
||||
has_many :other_accounts, :autosave => true, :dependent => :destroy
|
||||
has_many :journals, :autosave => true, :dependent => :destroy
|
||||
has_many :papers, :autosave => true, :dependent => :destroy
|
||||
has_and_belongs_to_many :sub_role_tags
|
||||
|
||||
|
||||
belongs_to :role
|
||||
has_and_belongs_to_many :statuses
|
||||
has_and_belongs_to_many :roles
|
||||
has_and_belongs_to_many :sub_roles
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
Reference in new issue
Block a user