Class: DataEntry
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DataEntry
- Includes:
- RubyLess
- Defined in:
- app/models/data_entry.rb
Overview
A DataEntry stores unversioned information across 4 nodes. The main purpose of this data is to store simple statistical values, registrations or other kinds of lists with nodes.
A data entry has four links to nodes (node_a, node_b, node_c, node_d) and ‘nodes’ (all four links). On the other side of the link, the node has four links to data sets (data_a, data_b, data_c, data_d) and ‘data’ (all four data sets).
The choice of four links is related to simple seizure situations that require up to four relations. For example a time invoicing utility would require ‘contact’ (who did the job), ‘project’ and ‘invoice’ (if billed). An accounting system would require ‘from’ (who paid), ‘for’ (budget position), ‘credit’ and ‘debit’.
DataEntries are signed with ‘creation date’, ‘modification date’ and ‘user_id’.
A visitor needs write access in all nodes the data should link to. A visitor also needs write access to the old node to remove a link to that node.
A visitor can edit a data entry if he/she has write access to the reference node (node_a).
Constant Summary collapse
- NodeLinkSymbols =
[:node_a, :node_b, :node_c, :node_d]
- NodeLinkSymbolsId =
[:node_a_id, :node_b_id, :node_c_id, :node_d_id]
Class Method Summary collapse
-
.create_data_entry(attributes) ⇒ Object
Create a new DataEntry from attributes given by the mean wild web.
-
.transform_attributes(new_attributes, base_node = nil, parse_dates = true) ⇒ Object
modify attributes so ext sees ‘zip’ values but we store ‘ids’.
Instance Method Summary collapse
- #author ⇒ Object
- #can_write? ⇒ Boolean
- #clone ⇒ Object
- #nodes ⇒ Object
- #ref_node ⇒ Object
-
#update_attributes_with_transformation(new_attributes, parse_dates = true) ⇒ Object
Update a data entry’s attributes, transforming the attributes first from the visitor’s context to internal context.
-
#value ⇒ Object
‘value’ is an alias for ‘value_a’.
- #value=(v) ⇒ Object
-
#zip ⇒ Object
needed by zafu for ajaxy stuff.
Class Method Details
.create_data_entry(attributes) ⇒ Object
Create a new DataEntry from attributes given by the mean wild web.
34 35 36 |
# File 'app/models/data_entry.rb', line 34 def self.create_data_entry(attributes) return create(transform_attributes(attributes)) end |
.transform_attributes(new_attributes, base_node = nil, parse_dates = true) ⇒ Object
modify attributes so ext sees ‘zip’ values but we store ‘ids’
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/data_entry.rb', line 39 def self.transform_attributes(new_attributes, base_node = nil, parse_dates = true) attributes = new_attributes.stringify_keys attributes.keys.each do |key| if key == 'date' next unless parse_dates attributes[key] = attributes[key].to_utc(_(Zena::Use::Dates::DATETIME), visitor.tz) elsif key =~ /^(\w+)_id$/ if key[0..4] == 'node_' attributes[key] = Node.translate_pseudo_id(attributes[key], :id, base_node) || attributes[key] else attributes[key] = Node.translate_pseudo_id(attributes[key], :id, base_node) || attributes[key] end elsif key == 'text' # translate zazen value = attributes[key] if value.kind_of?(String) attributes[key] = ZazenParser.new(value,:helper=>self, :node=>base_node).render(:translate_ids=>:zip) end end end attributes end |
Instance Method Details
#author ⇒ Object
86 87 88 |
# File 'app/models/data_entry.rb', line 86 def user.node end |
#can_write? ⇒ Boolean
118 119 120 121 122 |
# File 'app/models/data_entry.rb', line 118 def can_write? ref_node.can_write? rescue nil end |
#clone ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'app/models/data_entry.rb', line 104 def clone new_ent = DataEntry.new NodeLinkSymbols.each do |sym| sym_id = "#{sym}_id" new_ent[sym_id] = self[sym_id] # copy relation information end new_ent end |
#nodes ⇒ Object
90 91 92 93 |
# File 'app/models/data_entry.rb', line 90 def nodes ids = NodeLinkSymbolsId.map { |s| self[s] }.compact.uniq secure!(Node) { Node.find(:all, :conditions => "id IN ('#{ids.join("','")}')") } end |
#ref_node ⇒ Object
95 96 97 |
# File 'app/models/data_entry.rb', line 95 def ref_node @ref_node ||= node_a end |
#update_attributes_with_transformation(new_attributes, parse_dates = true) ⇒ Object
Update a data entry’s attributes, transforming the attributes first from the visitor’s context to internal context.
100 101 102 |
# File 'app/models/data_entry.rb', line 100 def update_attributes_with_transformation(new_attributes, parse_dates = true) update_attributes(DataEntry.transform_attributes(new_attributes, ref_node, parse_dates)) end |
#value ⇒ Object
‘value’ is an alias for ‘value_a’
78 79 80 |
# File 'app/models/data_entry.rb', line 78 def value self[:value_a] end |
#value=(v) ⇒ Object
82 83 84 |
# File 'app/models/data_entry.rb', line 82 def value=(v) self.value_a = v end |
#zip ⇒ Object
needed by zafu for ajaxy stuff
114 115 116 |
# File 'app/models/data_entry.rb', line 114 def zip self[:id] end |