Module: Databaseformalizer::EntitiesHelper
- Defined in:
- app/helpers/databaseformalizer/entities_helper.rb
Class Method Summary collapse
- .initAttrVals(entity) ⇒ Object
- .removeAttrVals(params, entity) ⇒ Object
- .setAttrVals(params, entity, parent = nil) ⇒ Object
- .setModelGraph(uri) ⇒ Object
Instance Method Summary collapse
Class Method Details
permalink .initAttrVals(entity) ⇒ Object
[View source]
3 4 5 6 7 8 9 10 11 |
# File 'app/helpers/databaseformalizer/entities_helper.rb', line 3 def EntitiesHelper.initAttrVals(entity) entityDef = entity.entity_def entityDef.attrDefs.each do |attrDef| attrVal = AttrVal.new(:attrDef => attrDef) entity.attr_vals << attrVal attrVal.save end end |
permalink .removeAttrVals(params, entity) ⇒ Object
[View source]
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/helpers/databaseformalizer/entities_helper.rb', line 57 def EntitiesHelper.removeAttrVals(params, entity) if params == nil; params = []; end params.each do |attrType,attrFormValue| attrDef = AttrDef.find(attrType); attrVal = entity.attr_vals.find_all_by_attr_def_name(attrType) if attrVal.size > 1 attrVal = entity.attr_vals.find(:first, :conditions => ["attr_def_name = ? and value = ?", attrType, attrFormValue]) else attrVal = attrVal[0] end case attrVal.attrDef.dataType when "String" || "Date" || "aChoice" attrVal.destroy when "checkList" EntitiesHelper.removeAttrVals(attrFormValue, entity) attrVal.destroy when "selectOneInList" #TODO implement when "openList" attrFormValue.delete("_destroy") map = attrFormValue.map{|a| [a[0][0..-14], a[1]]} EntitiesHelper.removeAttrVals(map, entity) attrVal.value = "isList" when "entityDef" attrVal.destroy end end end |
permalink .setAttrVals(params, entity, parent = nil) ⇒ Object
[View source]
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/helpers/databaseformalizer/entities_helper.rb', line 12 def EntitiesHelper.setAttrVals(params, entity, parent = nil ) if params == nil; params = []; end params.each do |attrType,attrFormValue| attrDef = AttrDef.find(attrType); attrVal = entity.attr_vals.find_by_attr_def_name(attrType) #check if item exist or if is in an insert or update if attrVal == nil || (attrVal != nil && parent != nil && parent.attrDef.dataType == "openList" ) attrVal = AttrVal.new(:attrDef => attrDef) entity.attr_vals << attrVal if parent != nil parent.attrValChilds << attrVal end end case attrVal.attrDef.dataType when "String" attrVal.value = attrFormValue when "Date" attrVal.value = "25/10/2010" when "aChoice" attrVal.value = "selected" when "checkList" #first, we remove unselected items attrFormValue.reject!{ |k,val| val == "0" } EntitiesHelper.setAttrVals(attrFormValue, entity, attrVal) attrVal.value = "isList" when "selectOneInList" EntitiesHelper.setAttrVals({ attrFormValue => 1 }, entity, attrVal) attrVal.value = "isList" when "openList" attrFormValue.delete("_destroy") map = attrFormValue.map{|a| [a[0][0..-14], a[1]]} EntitiesHelper.setAttrVals(map, entity, attrVal) attrVal.value = "isList" when "entityDef" attrVal.value = attrFormValue else attrVal.value = attrFormValue end attrVal.save end end |
permalink .setModelGraph(uri) ⇒ Object
[View source]
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/helpers/databaseformalizer/entities_helper.rb', line 94 def EntitiesHelper.setModelGraph(uri ) require 'graphviz' # Create a new graph g = GraphViz.new( :G, :type => :digraph ) # Graph configuration g.node[:color] = "#ddaa66" g.node[:style] = "filled" g.node[:shape] = "box" g.node[:penwidth] = "1" g.node[:fontname] = "Trebuchet MS" g.node[:fontsize] = "8" g.node[:fillcolor]= "#ffeecc" g.node[:fontcolor]= "#000000" g.node[:margin] = "0.05" # set global edge options g.edge[:color] = "#999999" g.edge[:weight] = "1" g.edge[:fontsize] = "6" g.edge[:fontcolor]= "#444444" g.edge[:fontname] = "Verdana" # Create two nodes nodesMap = {} @links = Array.new Entity.all.each do |entity| if entity.entity_def == nil next end attrs = ''; entity.attr_vals.each do |attrVal| if attrVal.attrDef.dataType == "entityDef" #we need to add a link if attrVal.attrDef.childEntityDef != nil @links.push([attrVal.value,entity.id.to_s]) begin attrs += attrVal.attrDef.label+':'+attrVal.attrDef.dataType+'="'+CGI.escapeHTML(attrVal.value)+'"\l' rescue end else attrs += '+ '+attrVal.attrDef.label+' : null\l' end else begin attrs += attrVal.attrDef.label+':'+attrVal.attrDef.dataType+'="'+CGI.escapeHTML(attrVal.value)+'"\l' rescue end end end begin nodesMap[entity.id.to_s] = g.add_nodes( entity.id.to_s, "shape" => "record", "label" => '{'+entity.label+':'+entity.entity_def.id.to_s+'|'+attrs+'}' ) g.add_nodes( entity.id.to_s,"shape" => "record", "label" => '{'+entity.label+':'+entity.entity_def.id.to_s+'|'+attrs+'}' ) rescue end end @links.each do |link| begin g.add_edges( nodesMap[link[0]], nodesMap[link[1]]) rescue end end # Generate output image g.output( :png => uri ) end |
Instance Method Details
permalink #link_to_add_attrlistvalue(name, f, parent) ⇒ Object
[View source]
87 88 89 90 91 92 |
# File 'app/helpers/databaseformalizer/entities_helper.rb', line 87 def link_to_add_attrlistvalue(name, f, parent) #fields = f.fields_for parent.id do |builder| fields = render("attr_val_openList_element_form", :f => f, :parent => parent) #end link_to_function(name, "add_attrlistvalues(this, \"#{parent.attr_def_name}\", \"#{escape_javascript(fields)}\")") end |