Merge branch 'various_bugs' into nccu_master

Conflicts:
	Gemfile.lock
	app/assets/javascripts/ajax_form.js.erb
	app/assets/stylesheets/style.css.erb
	app/controllers/application_controller.rb
	app/controllers/sessions_controller.rb
	app/helpers/admin/web_link_helper.rb
	app/views/admin/attributes/_attribute_field.html.erb
	app/views/admin/designs/_form.html.erb
	app/views/admin/pages/_form.html.erb
	app/views/admin/sites/_side_bar.html.erb
	app/views/layouts/_orbit_bar.html.erb
	app/views/layouts/_side_bar.html.erb
	config/locales/en.yml
	config/locales/zh_tw.yml
	config/mongoid.yml
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/controllers/panel/announcement/front_end/bulletins_controller.rb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletin.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.html.erb
	vendor/built_in_modules/announcement/app/views/panel/announcement/widget/bulletins/_index.html.erb
	vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter.html.erb
	vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_filter_status.html.erb
	vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/_news_bulletin.html.erb
	vendor/built_in_modules/news/app/views/panel/news/back_end/news_bulletins/index.html.erb
	vendor/built_in_modules/web_resource/app/views/panel/web_resource/back_end/web_links/index.html.erb
This commit is contained in:
chris committed 2012-10-29 16:10:07 +08:00
commit 65ac6980c4
2087 files changed
+80434 -3692

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
class CssDefault < Stylesheet
belongs_to :design
end
+5
View File
@@ -0,0 +1,5 @@
class CssReset < Stylesheet
belongs_to :design
end
+16 -18
View File
@@ -3,25 +3,27 @@ class Design
include Mongoid::Timestamps
include ParserLayout
field :title, :type => String
field :author, :type => String
field :intro, :type => String
field :title, :type => String
field :version, :type => String
has_one :css_default, :autosave => true, :dependent => :destroy
has_one :layout, :autosave => true, :dependent => :destroy
has_one :css_reset, :autosave => true, :dependent => :destroy
has_many :images, :autosave => true, :dependent => :destroy
has_many :javascripts, :autosave => true, :dependent => :destroy
has_many :pages
embeds_one :layout, :cascade_callbacks => true
embeds_one :default_css, :class_name => "Stylesheet", :cascade_callbacks => true
embeds_one :reset_css, :class_name => "Stylesheet", :cascade_callbacks => true
embeds_many :themes, :cascade_callbacks => true
embeds_many :javascripts, :cascade_callbacks => true
embeds_many :images, :as => :design_image, :cascade_callbacks => true
# embeds_many :custom_images, :class_name => 'Image', :cascade_callbacks => true
validates_presence_of :title
validates_presence_of :author
has_many :themes, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :images, :allow_destroy => true
accepts_nested_attributes_for :javascripts, :allow_destroy => true
accepts_nested_attributes_for :themes, :allow_destroy => true
validates_presence_of :author, :title
after_save :parse_css_for_images
def new_files=(*attrs)
attrs[0].map do |key,items_ary| #Loop by JSs,Themes,Imgs
@@ -66,13 +68,9 @@ class Design
protected
def parse_css_for_images
if (self.default_css && self.default_css.changed)
self.default_css.parse_urls
end
self.css_default.parse_urls
self.themes.each do |theme|
if theme.changed?
theme.parse_urls
end
theme.parse_urls
end
parse_body_for_images(self)
end
+9 -2
View File
@@ -4,7 +4,14 @@ class DesignFile
mount_uploader :file, AssetUploader
field :to_save, :type => Boolean
field :to_destroy, :type => Boolean
field :name
before_save :set_name
protected
def set_name
self.name = self.file_identifier
end
end
+18 -6
View File
@@ -1,11 +1,23 @@
class Image < DesignFile
class Image
include Mongoid::Document
include Mongoid::Timestamps
field :in_css, :type => Boolean
field :name
field :html_id
field :html_class
embedded_in :design_image, polymorphic: true
field :in_css, :type => Boolean, :default => false
field :in_html, :type => Boolean, :default => false
field :name
mount_uploader :file, ImageUploader
end
belongs_to :design
before_save :set_name
protected
def set_name
self.name = self.file_identifier
end
end
+1 -1
View File
@@ -1,3 +1,3 @@
class Javascript < DesignFile
embedded_in :design
belongs_to :design
end
+1 -1
View File
@@ -6,7 +6,7 @@ class Layout < DesignFile
field :body
embeds_one :menu
embedded_in :design
belongs_to :design
embeds_many :layout_parts
before_save :parse_layout
+4 -2
View File
@@ -1,5 +1,5 @@
class Stylesheet < DesignFile
embedded_in :design
belongs_to :design
mount_uploader :file_orig, AssetUploader
def parse_urls
@@ -11,7 +11,9 @@ class Stylesheet < DesignFile
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
name = File.basename(css_name).gsub(/[\\\"]/, '')
file_name = images.detect{ |i| i.file_identifier.eql?(name) }.file_url rescue nil
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
image.update_attribute(:in_css, true) if image
file_name = image.file_url rescue nil
names << [css_name, file_name]
}
names.each do |name|
+2 -5
View File
@@ -1,14 +1,11 @@
class Theme < Stylesheet
field :name
embedded_in :design
before_save :set_name
belongs_to :design
protected
def set_name
self.name = File.basename(self.file_identifier,".css")
self.name = File.basename(self.file_identifier, ".css")
end
end
+23
View File
@@ -0,0 +1,23 @@
class Desktop
include Mongoid::Document
include Mongoid::Timestamps
field :theme, default: "4f8d3f493b67fcd05f086359"
field :customtheme
field :wallpaper
belongs_to :user
has_many :sections, :autosave => true, :dependent => :destroy
has_many :desktop_widgets, :autosave => true, :dependent => :destroy
before_create :initialize_section
def initialize_section
self.sections.build(name: "Desktop 1")
self.sections.build(name: "Desktop 2")
self.sections.build(name: "Desktop 3")
self.sections.build(name: "Desktop 4")
end
end
+9
View File
@@ -0,0 +1,9 @@
class DesktopTheme
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :author
end
+13
View File
@@ -0,0 +1,13 @@
class DesktopWidget
include Mongoid::Document
include Mongoid::Timestamps
field :name
field :author
field :shape
field :desktop_id
field :status
field :section
belongs_to :desktop
end
+19
View File
@@ -0,0 +1,19 @@
class Group
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :section
has_many :tiles, :autosave => true, :dependent => :destroy
before_create :initialize_tile
def initialize_tile
self.tiles.build(data_category: "widget", data_content: "timetable", position: 1, shape: "w2 h2", title: "Tiime Table")
self.tiles.build(data_category: "app", data_content: "quotes", position: 2, shape: "w1 h1", title: "Quotes")
self.tiles.build(data_category: "widget", data_content: "weather", position: 3, shape: "w2 h2", title: "Weather")
self.tiles.build(data_category: "widget", data_content: "clock", position: 4, shape: "w2 h1", title: "Clock")
self.tiles.build(data_category: "app", data_content: "dailyenglish", position: 5, shape: "w1 h1", title: "Daily English Word")
self.tiles.build(data_category: "widget", data_content: "school_events", position: 6, shape: "w2 h1", title: "School Events")
end
end
+19
View File
@@ -0,0 +1,19 @@
class Journal
include Mongoid::Document
include Mongoid::Timestamps
field :user_id
field :title
belongs_to :user
has_many :papers, :autosave => true, :dependent => :destroy
before_create :initialize_paper
def initialize_paper
for i in 0..11
self.papers.build
end
end
end
+3 -1
View File
@@ -14,7 +14,9 @@ class ModuleApp
field :enable_frontend, type: Boolean, :default => true
field :app_pages ,type: Array
field :widgets ,type: Array
# field :widgets ,type: Array
field :widgets ,type: Hash
field :widget_fields ,type: Array
has_many :managers,as: :managing_app ,:class_name => "AppManager" ,:dependent => :destroy#,:foreign_key => "managing_app_id",:inverse_of => :managing_app
has_many :sub_managers,as: :sub_managing_app ,:class_name => "AppManager", :dependent => :destroy#,:foreign_key => "sub_managing_app_id",:inverse_of => :sub_managing_app
+15
View File
@@ -0,0 +1,15 @@
class OtherAccount
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Encryptor
field :user_id
field :type
field :email
field :encrypted_password
encrypts :encrypted_password, :mode => :symmetric, :password => 'rulingcom'
belongs_to :user
end
+18 -2
View File
@@ -11,14 +11,18 @@ class Page < Item
field :view_count, :type => Integer, :default => 0
field :page_title, localize: true
field :frontend_style
field :frontend_field , :type => Array
field :frontend_data_count
belongs_to :design
belongs_to :module_app
has_many :page_parts, :autosave => true, :dependent => :destroy
has_many :page_contexts, :autosave => true, :dependent => :destroy
has_many :page_metas, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :page_parts, :allow_destroy => true
before_save :create_parts
before_save :create_parts, :delete_empty_frontend_field
# embeds_many :custom_images, :class_name => 'Image', as: :design_image
@@ -44,5 +48,17 @@ class Page < Item
end
end
end
def delete_empty_frontend_field
if self.frontend_field
self.frontend_field.reject! { |ff| (ff[0].blank? || ff[1].blank?) }
# self.frontend_field.each do | ff |
# if ff[0].blank? || ff[1].blank?
# self.frontend_field.delete("") if self.frontend_field
# self.frontend_field.delete(ff)
# end
# end
end
end
end
+15
View File
@@ -11,8 +11,23 @@ class PagePart
field :public_r_tag_option, :default => nil
field :page_title, localize: true
field :widget_path
field :widget_style
field :widget_field , :type => Array
field :widget_data_count
belongs_to :page
belongs_to :module_app
before_save :delete_empty_widget_field
protected
def delete_empty_widget_field
if self.widget_field
self.widget_field.reject! { |wf| (wf[0].blank? || wf[1].blank?) }
end
# self.widget_field.delete("") if self.widget_field
end
end
+12
View File
@@ -0,0 +1,12 @@
class Paper
include Mongoid::Document
include Mongoid::Timestamps
field :keywords, default: "Material, Fracture Mechanism, Reliability Test, Solder Joints, Nano-material"
field :title, default: "The performance and fracture mechanism of solder joints under mechanical reliability test"
field :abstract, default: "The concept of microstructure engineering has gained increasingly attention with the goal to quantitatively link the operational parameters of an industrial process to the properties of its product. The key component of this concept is to accurately model the microstructure evolution along the processing path. Modelling of recrystallization in Cuinterconnects will be presented as an example of a conventional process model. Further, the potential of developing next generation process models will be discussed by using models across different length and time scale. The multi-scale modelling approach will be illustrated with a case study for phase transformation in Fe-Mn alloys."
field :level, default: "SCI"
field :coauthors, default: "Allen, Shelly, Eric, Manson, Chris, Clara, Anna, Albee, Vincent, Devin, Chunchi, Ika, Jaoshua, Ray, Matt, Lin, Spen"
field :created_at, type: Date
belongs_to :journal
end
+40
View File
@@ -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
+17
View File
@@ -0,0 +1,17 @@
class Section
include Mongoid::Document
include Mongoid::Timestamps
field :name
belongs_to :desktop
has_many :groups, :autosave => true, :dependent => :destroy
before_create :initialize_group
def initialize_group
self.groups.build
self.groups.build
end
end
+3 -1
View File
@@ -12,11 +12,13 @@ class Site
field :private_key, :type => Binary
field :public_key, :type => Binary
field :title_always_on, :type => Boolean, :default => false
field :dashbroad_allow_visitor, :type => Boolean, :default => false
field :mail_settings, :type => Hash
field :school
field :department
mount_uploader :default_image, ImageUploader
field :search,:type => Hash
+4
View File
@@ -0,0 +1,4 @@
class SubRoleTag < ProtoTag
has_and_belongs_to_many :sub_roles
end
+1 -38
View File
@@ -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
+14
View File
@@ -0,0 +1,14 @@
class Tile
include Mongoid::Document
include Mongoid::Timestamps
field :data_category
field :data_content
field :position, type: Integer
field :shape
field :title
belongs_to :group
end
+97 -14
View File
@@ -2,29 +2,112 @@ class AttributeField
include Mongoid::Document
include Mongoid::Timestamps
include ::AttributeFieldsHelper
field :key
field :markup
field :markup
field :markup_value ,:type => Hash
field :markup_options,:type => Hash
field :locale, :type => Boolean, :default => true
field :list_options, :type => Array
# field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
field :disabled, :type => Boolean, :default => false
field :title, localize: true
field :add_more,:type => Boolean, :default => false
#field :title, localize: true
field :locale_title, localize: true
field :neutral_title
field :neutral_for
belongs_to :attribute
has_many :attribute_values
# belongs_to :role
has_many :attribute_values,:autosave => true, :dependent => :destroy
# validates_uniqueness_of :key
# Convert the string list_options into an array
def select_list_options=(var)
self.list_options = var.gsub(' ', '').split(',')
def self_defined_markup_options?
(self.attribute.role.method(self[:key].pluralize.to_sym) && self.attribute.role.method(self[:key].pluralize+"_for_"+markup)) rescue false
end
# Convert the array list_options into a string
def select_list_options
self.list_options.to_a.join(', ')
def markup_value=(var)
if !self_defined_markup_options?
self[:markup_value] = (eval(var) rescue {})
end
end
def markup_value
if self_defined_markup_options?
#Class need to have corresponding field and value agent
# Ex: For "status" the class must have field called "statuses" for the relation and "statuses_for_select" for the select function
method = self.attribute.role.method(self[:key].pluralize+"_for_"+markup)
return (method.call rescue {})
elsif self[:markup_value].nil? || (self[:markup_value].empty?)
return {}
else
return self[:markup_value]
end
end
def markup_options=(var)
self[:markup_options] = (eval(var) rescue {})
end
def markup_options
if self[:markup_options].nil?
return {}
else
Hash[self[:markup_options].map{|key,val|[key.to_sym,val]}] rescue {}
end
end
def role
self.attribute.role
end
def title_translations
if locale
return locale_title_translations
else
return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}]
end
end
def title_translations=(var)
if locale
self.locale_title_translations = var
end
end
def title
if locale
return self.locale_title
else
return self.neutral_title
end
end
def title=(var)
# binding.pry
if locale
self.locale_title = var
else
self.neutral_title = var
end
end
# # Convert the string list_options into an array
# def select_list_options=(var)
# self.list_options = var.gsub(' ', '').split(',')
# end
# # Convert the array list_options into a string
# def select_list_options
# self.list_options.to_a.join(', ')
# end
def is_built_in?
self.built_in
+59 -3
View File
@@ -2,14 +2,70 @@ class AttributeValue
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::MultiParameterAttributes
field :key
belongs_to :attribute_field
belongs_to :user
def method_missing(field)
self[field]
before_save :check_key
# NO_MULTI_TAG = ["select","date","radio_button","checkbox","date_durnation"]
def check_key
binding.pry if attribute_field.nil?
self.key = attribute_field.key
end
def method_missing(*field)
if field.size < 1
self[field[0]]
else
self[(field[0].to_s.delete "=")] = field[1]
end
end
def get_value_by_locale(locale)
case self.attribute_field.markup
when "text_field"
self.attribute_field.locale ? self[locale] : self[:value]
when "select"
markup_values = self.attribute_field.self_defined_markup_options? ? self.attribute_field.markup_value : eval(self.attribute_field.markup_value)
markup_values[self[:value]][locale.to_s] rescue 'NoData'
when "text_area"
self.attribute_field.locale ? self[locale] : self[:value]
when "date"
Date.new(self[:value]["(1i)"].to_i,self[:value]["(2i)"].to_i,self[:value]["(3i)"].to_i) rescue nil
when "addr"
self[:value]
when "radio_button"
markup_values = eval(self.attribute_field.markup_value)
markup_values[self[:value].first[0]][locale.to_s]
when "checkbox"
markup_values = eval(self.attribute_field.markup_value)
self[:value].keys.collect{|key| markup_values[key][locale.to_s] }.join(",")
when "date_durnation"
self[:value]
else
self.attribute_field.locale ? self[locale] : self[:value]
end
end
def get_values
unless ['select','checkbox','radio_button'].include?(self.attribute_field.markup )
if self.attribute_field.locale && LIST[:markups][self.attribute_field.markup]["muti_lang_input_supprt"]
return Hash[VALID_LOCALES.collect{|lang| [lang,get_value_by_locale(lang.to_sym)]}]
else
return get_value_by_locale("")
end
else
if self.attribute_field.markup == "select"
self[:value]
else
self[:value].keys rescue self[:value]
end
end
end
end
+9
View File
@@ -10,6 +10,8 @@ class Role
has_many :sub_roles, :autosave => true, :dependent => :destroy
has_many :users
has_many :statuses, :autosave => true, :dependent => :destroy
has_many :attribute_fields, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :sub_roles, :allow_destroy => true
def is_built_in?
@@ -25,4 +27,11 @@ class Role
self.first(:conditions => {:key => key})
end
def statuses_for_select
data = self.statuses.map do |t|
[t.id.to_s,t.title_translations]
end
Hash[data]
end
end
+14
View File
@@ -0,0 +1,14 @@
class Status
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :users
field :key
belongs_to :role
# has_and_belongs_to_many :sub_roles
field :title, localize: true
end
+3 -1
View File
@@ -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 :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})
+126 -20
View File
@@ -9,22 +9,120 @@ class User
field :admin, :type => Boolean, :default => true
field :active_role
field :nccu_ldap_uid
# field :cache_dept
# has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :email
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
has_many :blocked_apps, :inverse_of => :blocked_users, :class_name => "AppAuth", :dependent => :destroy
has_many :privilege_apps, :inverse_of => :privilege_users, :class_name => "AppAuth", :dependent => :destroy
has_many :managing_apps,:class_name => "AppManager", :dependent => :destroy
belongs_to :role
has_one :desktop, :autosave => true, :dependent => :destroy
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
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
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
before_create :initialize_desktop
before_save :rebuild_status_record
before_save :save_roles
scope :remote_account, where(:nccu_id.ne => nil)
validates_uniqueness_of :email,:message=> I18n.t("devise.registrations.email_not_unique")
# def new_attribute_values=(vars)
# binding.pry
# end
# def new_attribute_values(vars)
# binding.pry
# end
## # class << self
## def initialize
## self.define_method("asd"){ p "hi"}
## sub_roles.each do |sr|
## sr_ids = sr.attribute_fields.collect{|t| t.id.to_s}
## self.define_method("attribute_values_for_"+sr.key.to_s) {
## AttributeValue.where(user_id: id ).in(attribute_field_id: sr_ids)
## }
## end
## yield self
## end
# end
# def initialize
# binding.pry
# # yield self
# end
def get_attribute_value(attribute_field)
attribute_values.where(attribute_field_id: attribute_field.id).first
end
def get_sub_roles_by_role(role)
sub_roles.where(role_id: role.id)
end
def disable_sub_role=(var)
var[:id].each do |id,val|
# binding.pry if id == '5052c5b22b5c49ab02000004'
if (val=="true")
self.sub_roles = self.sub_roles.reject{|t| t.id.to_s==id}
elsif(val=="false")
self.sub_roles << SubRole.find(id)
end
end
end
def set_sub_role(sub_role_id,status_id)
self.status_record.merge!(Hash[sub_role_id,status_id])
end
# def get_status(*params)
# param = params[0]
# case param.class.to_s
# when 'String'
# sr = ::SubRole.find sub_role_id
# when 'Hash'
# sr = ::SubRole.first({conditions:{key: param[:key]}})
# end
# if self.sub_roles.include?(sr)
# return ::Status.find(status_record.fetch(sr.id.to_s))
# else
# nil
# end
# end
def new_attribute_values=(fields)
fields.each do |key,field|
self.attribute_values.build(field)
end
end
def self.find_by_status_and_sub_role_key(sub_role_key,status_key) #Query for users by using specific sub_role and status key
sr = ::SubRole.first({conditions: { key: sub_role_key }})
status = ::Status.first({conditions:{role_id: sr.role.id,key: status_key}})
find_by_subrole_and_status(sr.id,status.id)
end
def self.find_by_subrole_and_status(sub_role_id,status_id) #Query for users by using specific sub_role and status key by within ID
User.where("status_record.#{sub_role_id}" => status_id,:sub_role_ids.in => [ sub_role_id ])
end
def self.find_by_status(status_id)
status = ::Status.find status_id
::SubRole.where({role_id: status.role.id.to_s,disabled: false}).collect{|sr|
find_by_subrole_and_status(sr.id.to_s,status_id)
}.uniq!
end
def create_dept_cache
dept_hash = {}
@@ -37,16 +135,6 @@ class User
self.save!
end
def self.current
Thread.current[:user]
end
def self.current=(user)
Thread.current[:user] = user
end
scope :remote_account, where(:nccu_id.ne => nil)
def self.current
Thread.current[:user]
end
@@ -80,11 +168,29 @@ class User
def get_value_from_field_id(field_id)
values = get_attribute_values
value = values.detect {|value| value.attribute_field_id == field_id} rescue nil
value ? value : self.attribute_values.build
value ? value : nil
end
def self.from_id(id)
User.find(id) rescue nil
end
end
def initialize_desktop
self.build_desktop
end
protected
def save_roles
self.roles = self.sub_roles.collect{|t| t.role}.uniq
end
def rebuild_status_record
self.status_record = {}
self.attribute_values.reject{|t| t.key!='status'}.each do |status|
# binding.pry
set_sub_role(status.attribute_field.attribute.id.to_s,status[:value]) rescue nil
end
end
end