Skip to content
Snippets Groups Projects
Commit a28be02e authored by James Lopez's avatar James Lopez
Browse files

starting to use the new dynamic stuff on the import

parent d29c816d
No related branches found
No related tags found
2 merge requests!3142Project import functionality,!3114Export project functionality
Pipeline #
Loading
@@ -7,6 +7,10 @@ module Projects
Loading
@@ -7,6 +7,10 @@ module Projects
{ only: atts_only[:project], include: build_hash(tree) } { only: atts_only[:project], include: build_hash(tree) }
end end
   
def tree
config[:project_tree]
end
private private
   
def config def config
Loading
@@ -21,10 +25,6 @@ module Projects
Loading
@@ -21,10 +25,6 @@ module Projects
config[:attributes_except] config[:attributes_except]
end end
   
def tree
config[:project_tree]
end
def build_hash(array) def build_hash(array)
array.map do |el| array.map do |el|
if el.is_a?(Hash) if el.is_a?(Hash)
Loading
Loading
Loading
@@ -25,32 +25,41 @@ module Projects
Loading
@@ -25,32 +25,41 @@ module Projects
#TODO Definitely refactor this method! #TODO Definitely refactor this method!
#TODO Think about having a yaml file to describe the tree instead of just hashes? #TODO Think about having a yaml file to describe the tree instead of just hashes?
def create_relations(relation_list = default_relation_list, tree_hash = @tree_hash) def create_relations(relation_list = default_relation_list, tree_hash = @tree_hash)
members_map # TODO remove this and fix project_members
relation_list.each do |relation| relation_list.each do |relation|
relation_hash = nil if relation.is_a?(Hash)
# FIXME relation.values.each do |value|
# next if tree_hash[relation.to_s].blank? create_relations(value, @tree_hash[relation.to_s])
if (relation.is_a?(Hash) && relation.values.first[:include])
#TODO name stuff properly
relation_sym = relation.keys.first
#TODO remove sub-relation hashes from here so we can save the parent relation first
relation_hash = create_relation(relation_sym, tree_hash[relation_sym.to_s])
sub_relations = []
sub_relation = relation.values.first[:include]
sub_relation_hash_list = tree_hash[relation.keys.first.to_s]
sub_relation_hash_list.each do |sub_relation_hash|
sub_relations << create_relation(relation, sub_relation_hash[relation.to_s])
end end
relation_hash.update_attribute(sub_relation, sub_relations)
end end
relation_hash ||= create_relation(relation, tree_hash[relation.to_s]) relation_hash = create_relation(relation, tree_hash[relation.to_s])
project.update_attribute(relation, relation_hash) project.update_attribute(relation, relation_hash)
# relation_hash = nil
# # FIXME
# # next if tree_hash[relation.to_s].blank?
# if (relation.is_a?(Hash) && relation.values.first[:include])
# #TODO name stuff properly
# relation_sym = relation.keys.first
# #TODO remove sub-relation hashes from here so we can save the parent relation first
# relation_hash = create_relation(relation_sym, tree_hash[relation_sym.to_s])
# sub_relations = []
# sub_relation = relation.values.first[:include]
# sub_relation_hash_list = tree_hash[relation.keys.first.to_s]
# sub_relation_hash_list.each do |sub_relation_hash|
# sub_relations << create_relation(relation, sub_relation_hash[relation.to_s])
# end
# relation_hash.update_attribute(sub_relation, sub_relations)
# end
# relation_hash ||= create_relation(relation, tree_hash[relation.to_s])
# project.update_attribute(relation, relation_hash)
end end
end end
   
def default_relation_list def default_relation_list
ImportExport.project_tree.reject do |rel| Projects::ImportExport::ImportExportReader.tree
rel.is_a?(Hash) && !rel[:project_members].blank? # ImportExport.project_tree.reject do |rel|
end # rel.is_a?(Hash) && !rel[:project_members].blank?
# end
end end
   
def project def project
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment