Archived
complete preview for both new and announcement
This commit is contained in:
1 parent
8bd5481b3f
commit
6044857fea
24 files changed
+301
-67
No files matched your search
+79
-2
@@ -2,12 +2,81 @@ class Preview
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :object, :type => Hash
|
||||
# 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
|
||||
|
||||
# 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
|
||||
@@ -19,7 +88,15 @@ class Preview
|
||||
end
|
||||
|
||||
def get_virtual_object
|
||||
eval(self.object_class_type).new 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
|
||||
virtual_object
|
||||
end
|
||||
|
||||
end
|
||||
@@ -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
|
||||
Reference in new issue
Block a user