Module: JsonHelper

Defined in:
public/app/helpers/json_helper.rb

Instance Method Summary collapse

Instance Method Details

#merge_notes(note_1, note_2) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'public/app/helpers/json_helper.rb', line 21

def merge_notes(note_1, note_2)
  if note_1['label'].blank?
    # Our first label
    note_1['label'] = note_2['label']
  elsif note_1['label'] != note_2['label']
    # Add a secondary label as an inline label
    note_2_text = "<span class='inline-label'>#{note_2['label']}</span> #{note_2['note_text']}"
  end

  note_1['note_text'] = "#{note_1['note_text']}<br/><br/> #{note_2_text}"

  if note_2.has_key?('subnotes')
    note_1['subnotes'] ||= []
    note_1['subnotes'] = note_1['subnotes'] + note_2['subnotes'].map {|sub|
      sub_copy = sub.clone
      sub_copy['_inline_label'] = note_2['label']
      sub_copy
    }
  end

  note_1
end

#process_json_notes(notes, req = nil) ⇒ Object

process the entire notes structure. If req is specified, process and return only the notes that match the requested types (may be nil)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'public/app/helpers/json_helper.rb', line 5

def process_json_notes(notes, req = nil)
  notes_hash = {}
  ASUtils.wrap(notes).each do |note|
    type = note['type'] || note['jsonmodel_type']

    next unless !req || req.include?(type)
    next unless note['publish']

    note_struct = handle_note_structure(note, type)
    notes_hash[type] ||= []
    notes_hash[type] << note_struct
  end

  notes_hash
end