Merge branch 'new_member' of github.com:Rulingcom/orbit into new_member

Conflicts:
	app/helpers/attribute_fields_helper.rb
	app/views/admin/infos/_form.html.erb
	config/locales/zh_tw.yml
This commit is contained in:
Matthew K. Fu JuYuan committed 2012-11-16 15:42:39 +08:00
commit b4a2737407
373 files changed
+10342 -6551

No files matched your search

+3 -3
View File
@@ -2,11 +2,11 @@ class AppManager
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :user
belongs_to :user,index: true
belongs_to :managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id"
belongs_to :managing_app, :polymorphic => true,index: true #,:class_name => 'ModuleApp',:inverse_of => :managers,:foreign_key => "user_id"
belongs_to :sub_managing_app, :polymorphic => true #,:class_name => 'ModuleApp',:inverse_of => :sub_manager,:foreign_key => "sub_user_id"
belongs_to :rule_creator,:class_name => 'User'
end
+4 -1
View File
@@ -1,5 +1,8 @@
class CssDefault < Stylesheet
belongs_to :design
# belongs_to :design
# belongs_to :desktop_widget
belongs_to :css, polymorphic: true
end
+3 -3
View File
@@ -8,11 +8,11 @@ class Design
field :title, :type => String
field :version, :type => String
has_one :css_default, :autosave => true, :dependent => :destroy
has_one :css_default, as: :css, :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 :images,as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_many :pages
has_many :themes, :autosave => true, :dependent => :destroy
+4 -1
View File
@@ -10,7 +10,10 @@ class Image
mount_uploader :file, ImageUploader
belongs_to :design
# belongs_to :design
# belongs_to :desktop_widget
belongs_to :imgs, polymorphic: true
before_save :set_name
+4 -1
View File
@@ -1,3 +1,6 @@
class Javascript < DesignFile
belongs_to :design
# belongs_to :design
# belongs_to :desktop_widget
belongs_to :js, polymorphic: true
end
+40 -36
View File
@@ -1,36 +1,40 @@
class Stylesheet < DesignFile
belongs_to :design
mount_uploader :file_orig, AssetUploader
def parse_urls
orig_content = content = self.file.read.force_encoding("UTF-8")
# self.remove_file!
# self.remove_file_orig!
names = []
images = self.design.images
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
name = File.basename(css_name).gsub(/[\\\"]/, '')
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|
content.gsub!(name[0], name[1]) if name[1]
end
Dir.mktmpdir('f_path') { |dir|
orig_file_name = self.file_identifier
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write orig_content.force_encoding("UTF-8")
self.file_orig = temp_file
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write content.force_encoding("UTF-8")
self.file = temp_file
self.save
}
end
end
class Stylesheet < DesignFile
# belongs_to :design
mount_uploader :file_orig, AssetUploader
def parse_urls
orig_content = content = self.file.read.force_encoding("UTF-8")
# self.remove_file!
# self.remove_file_orig!
names = {}
images = self.css.images
content.scan(/(?<=url)(.*?)(?=\))/){
css_name = $1.gsub(' ','').gsub('(','')
unless names.has_key?(css_name)
name = File.basename(css_name).gsub(/[\\\"]/, '')
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
if image
image.update_attribute(:in_css, true)
file_name = image.file_url
names.merge!({css_name => file_name})
end
end
}
names.each_pair do |key, value|
content.gsub!(key, value)
end
Dir.mktmpdir('f_path') { |dir|
orig_file_name = self.file_identifier
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write orig_content.force_encoding("UTF-8")
self.file_orig = temp_file
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
temp_file.write content.force_encoding("UTF-8")
self.file = temp_file
self.save
}
end
end
@@ -2,14 +2,15 @@ class Desktop
include Mongoid::Document
include Mongoid::Timestamps
field :theme, default: "4f8d3f493b67fcd05f086359"
field :theme, default: "4f8d3f533b67fcd05f08635a"
field :customtheme
field :wallpaper
belongs_to :user
has_and_belongs_to_many :desktop_widgets, :autosave => true
has_many :sections, :autosave => true, :dependent => :destroy
has_many :desktop_widgets, :autosave => true, :dependent => :destroy
# has_many :desktop_widgets, :autosave => true, :dependent => :destroy
before_create :initialize_section
File renamed without changes.
+33
View File
@@ -0,0 +1,33 @@
class DesktopWidget
include Mongoid::Document
include Mongoid::Timestamps
include ParserLayoutWidget
field :name
field :author
field :shape
field :version, :type => String
has_one :css_default, as: :css, :autosave => true, :dependent => :destroy
has_one :widget_layout, :autosave => true, :dependent => :destroy
has_many :images, as: :imgs, :autosave => true, :dependent => :destroy
has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :desktops, :autosave => true
belongs_to :tiles, :autosave => true
accepts_nested_attributes_for :images, :allow_destroy => true
accepts_nested_attributes_for :javascripts, :allow_destroy => true
after_save :parse_css_for_images
# belongs_to :desktop
protected
def parse_css_for_images
self.css_default.parse_urls
parse_widget_for_images(self)
end
end
+18
View File
@@ -0,0 +1,18 @@
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: "app", data_content: "quotes", position: 5, shape: "w1 h1", title: "Quotes")
self.tiles.build(data_category: "app", data_content: "dailyenglish", position: 6, shape: "w1 h1", title: "Daily English Word")
widgets = self.section.desktop.desktop_widgets.collect{|widget| widget.id}
for i in 0..3
self.tiles.build(data_category: "widget", position: i+1,desktop_widget_id: widgets[i])
end
end
end
File renamed without changes.
File renamed without changes.
@@ -9,6 +9,6 @@ class Tile
field :title
belongs_to :group
has_one :desktop_widget
end
+18
View File
@@ -0,0 +1,18 @@
class WidgetLayout < DesignFile
attr_reader :content
field :body
belongs_to :desktop_widget
def content
self.file.read.force_encoding("UTF-8") rescue ''
end
def self.exist_one?
WidgetLayout.count > 0
end
end
-13
View File
@@ -1,13 +0,0 @@
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
@@ -1,19 +0,0 @@
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
+3 -3
View File
@@ -48,7 +48,7 @@ class ModuleApp
def assign_manager(user,assigner)
manager = AppManager.first(conditions: {managing_app_id: self.id,user_id: user.id}) rescue nil
if manager.nil?
manager = self.managers.create(:user => user,:rule_creator => assigner)
manager = self.managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil))
end
manager
end
@@ -56,7 +56,7 @@ class ModuleApp
def assign_sub_manager(user,assigner)
submanager = AppManager.first(conditions: {sub_managing_app_id: self.id,user_id: user.id}) rescue nil
if submanager.nil? && !self.managing_users.include?(user)
submanager = self.sub_managers.create(:user => user,:rule_creator => assigner)
submanager = self.sub_managers.create(:user_id => user.id,:rule_creator_id => (assigner.id rescue nil) )
end
submanager
end
@@ -82,7 +82,7 @@ class ModuleApp
protected
def set_key
self.key = self.title.underscore if self.title
self.key = self.title.underscore.singularize if self.title
end
+11 -6
View File
@@ -2,23 +2,28 @@ class ObjectAuth < PrototypeAuth
include OrbitCoreLib::ObjectTokenUnility
validates_uniqueness_of :title ,:scope => [:obj_authable_type,:obj_authable_id] #{ |c| }
belongs_to :obj_authable, polymorphic: true
after_save :check_user_has_app_auth
after_save :check_user_has_can_access_app
# > - Something.find_with_auth(query)
# > - or Something.find(query).auth
def siblings
ObjectAuth.where({obj_authable_type: obj_authable_type,title: title})
end
def auth_obj
class_obj = eval(self.obj_authable_type)
class_obj.find self.obj_authable_id
end
def check_user_has_app_auth
sub_managing_users = auth_obj.app_auth.sub_managing_users rescue []
app_auth = auth_obj.app_auth
def check_user_has_can_access_app
sub_managing_users = auth_obj.module_app.sub_managing_users rescue []
module_app = auth_obj.module_app
self.auth_users.each do |auth_user|
if !sub_managing_users.include? auth_user && !auth_user.admin?
app_auth.assign_sub_manager(auth_user,User.current)
app_auth.save!
module_app.assign_sub_manager(auth_user,User.current)
module_app.save
end
end
end
end
+110
View File
@@ -0,0 +1,110 @@
class Preview
include Mongoid::Document
include Mongoid::Timestamps
# field :object_f, :type => Hash
field :object, :type=> Hash
field :preview_at_link
field :expired_at , :type => DateTime
field :link_args, :type => Array
field :object_class_type
has_many :preview_files, :autosave => true, :dependent => :destroy
has_many :preview_associations, :autosave => true, :dependent => :destroy
# def object=(params)
# save_upload_temp_link(params,"news_bulletin_files_attributes") #unless params[]
# self.object_f = params
# end
# def object
# return object_f
# end
# def save_upload_temp_link(params,field_name = "bulletin_files_attributes")
# image = preview_files.build(:file=>params[:image])
# params[:image] = image.id
# params[field_name].each_with_index do |item,index|
# bfa = preview_files.build(:file=>params[field_name][index.to_s][:file])
# params[field_name][index.to_s] = bfa.id
# end unless params[field_name].nil?
# end
# def dig_in_hash(hash,paths_ary)
# hash.each_pair do |key,in_hash|
# if in_hash.kind_of? Array
# dig_in_array(hash,paths_ary)
# elsif in_hash.kind_of? Hash
# dig_in_hash(hash,paths_ary)
# else
# puts("\n End Node: \t #{paths_ary.join } #{in_hash.class} : #{key}##{in_hash}")
# end
# end
# end
# def dig_in_array(array,paths_ary)
# array.each do |item|
# if item.kind_of? Array
# dig_in_array(hash,paths_ary)
# elsif item.kind_of? Hash
# dig_in_hash(hash,paths_ary)
# else
# puts("\n End Node: \t #{paths_ary.join } #{item.class} : {item}")
# end
# end
# end
# def dig_in_hash_old(hash,paths_ary)
# hash.each_pair do |k,in_hash|
# if (!in_hash.kind_of? Array and !in_hash.kind_of? Hash)
# #p "UploadedFile : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}"
# #in_hash = "no file" if in_hash.is_a? ActionDispatch::Http::UploadedFile
# #in_hash.select{|key,hash| hash.is_a? ActionDispatch::Http::UploadedFile}
# puts("\n End Node:# \n")
# p "#{paths_ary.join } #{in_hash.class} : #{in_hash}"
# #p "UploadedFile(#{in_hash}) : #{in_hash.is_a? ActionDispatch::Http::UploadedFile}"
# else
# if (!in_hash.first.kind_of? Array and !in_hash.first.kind_of? Hash)
# paths_ary << "[#{in_hash.first}]"
# end
# puts("\n Go Down [#{in_hash.first}]\n")
# dig_in_hash(in_hash,paths_ary)
# puts("\n Go Out \n")
# end
# puts "This is last"
# paths_ary.pop
# end
# end
def get_arg_hash
object.slice(*link_args).inject({}){|la,(k,v)| la[k.to_sym] = v; la}
end
def get_preview_link
ap = Rails.application.routes.url_helpers
ap.send preview_at_link,({:id=>id,:preview=>true}.merge get_arg_hash)
#func = eval("Rails.application.routes.url_helpers.#{preview_at_link}").send
end
def get_virtual_object
virtual_object = eval(self.object_class_type).new object
preview_files.each do |file|
if file.file_in_array
eval("virtual_object.#{file.field_name_for_rebuild}.build :file=>file.file")
else
eval("virtual_object.#{file.field_name_for_rebuild} = file.file")
end
end
preview_associations.each do |local_object|
if local_object.object_in_array
eval("virtual_object.#{local_object.field_name_for_rebuild}.build local_object.object")
else
eval("virtual_object.#{local_object.field_name_for_rebuild} = local_object.object")
end
end
virtual_object
end
end
+16
View File
@@ -0,0 +1,16 @@
class PreviewAssociation
include Mongoid::Document
include Mongoid::Timestamps
field :object, :type=> Hash
field :field_name_for_rebuild
field :object_in_array , :type => Boolean,default: false
# field :to_save, :type => Boolean
field :should_destroy, :type => Boolean
belongs_to :preview
# embedded_in :news_bulletin
end
+19
View File
@@ -0,0 +1,19 @@
class PreviewFile
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, AssetUploader
field :title, localize: true
field :description, localize: true
field :field_name_for_rebuild
field :file_in_array , :type => Boolean,default: false
# field :to_save, :type => Boolean
field :should_destroy, :type => Boolean
belongs_to :preview
# embedded_in :news_bulletin
end
+1 -4
View File
@@ -9,10 +9,7 @@ class User
field :admin, :type => Boolean, :default => true
field :active_role
field :nccu_ldap_uid
field :email
# 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
@@ -180,7 +177,7 @@ class User
end
def initialize_desktop
self.build_desktop
self.build_desktop(desktop_widget_ids: DesktopWidget.all.collect{|widget| widget.id})
end
protected