Module: QueryFormat

Includes:
GeneralUtils
Included in:
DocsHelper
Defined in:
app/helpers/query_format.rb

Instance Method Summary collapse

Methods included from GeneralUtils

#genLink, #getHR, #get_date_index, #get_search_param, #paramMatch?

Instance Method Details

#genOptionHtml(f, index) ⇒ Object

Generate html for the matching option


48
49
50
51
# File 'app/helpers/query_format.rb', line 48

def genOptionHtml(f, index)
  return '<option data-type="' + f["Type"] +
         '"  value="' + f["Field Name"] + '_sindex_'+index+'">' + f["Human Readable Name"] + '</option>'
end

#group_by_datasetObject

Group by dataset


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/query_format.rb', line 22

def group_by_dataset
  # Gen form
  outhtml = '<form action="" class="navbar-form navbar-left input-group-addon">                                                    
   <select name="ftypes" id="ftypes">'
  outhtml += '<option data-type="all" value="all" selected>All</option>'
  
  # Gen search form (all for all datasets)
  run_all do |dataspec, model|
    outhtml = outhtml + '<optgroup label="'+dataspec.dataset_name+'">'
    outhtml += group_by_type(dataspec)
    outhtml += '</optgroup>'
  end
  outhtml += '</select></form>'
  return outhtml
end

#group_by_type(dataspec) ⇒ Object

Groups fields by type


39
40
41
42
43
44
45
# File 'app/helpers/query_format.rb', line 39

def group_by_type(dataspec)
  outhtml = '<option data-type="all" value="all_sindex_'+dataspec.index_name+'">'+'All '+dataspec.dataset_name+'</option>'
  outhtml = outhtml + '<optgroup label="Text">'+
            raw(matchFieldTypes(["Title", "Description", "Short Text", "Medium Text", "Long Text"], dataspec)) + '</optgroup>'
  outhtml = outhtml + '<optgroup label="Date">'+ raw(matchFieldTypes(["Date"], dataspec))+ '</optgroup>'
  outhtml = outhtml + '<optgroup label="Categories">'+raw(matchFieldTypes(["Category"], dataspec))+'</optgroup>'
end

#matchFieldTypes(match_type, dataspec) ⇒ Object

Get all searchable fields


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

def matchFieldTypes(match_type, dataspec)
  outhtml = ""
  
  # Go through all searchable fields
  sortFields(dataspec.searchable_fields, dataspec.field_info).each do |field|
    f = getFieldDetails(field, dataspec.field_info)

    # If display type matches, add html
    if match_type.include?(f["Display Type"])
      outhtml += genOptionHtml(f, dataspec.index_name)
    end
  end

  return outhtml
end