Module: SpotlightSearch::Helpers

Includes:
ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
Defined in:
lib/spotlight_search/helpers.rb

Instance Method Summary collapse

Instance Method Details

#checkbox_row(klass) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/spotlight_search/helpers.rb', line 71

def checkbox_row(klass)
  tag.div class: "row" do
    klass.enabled_columns.each do |column_name|
      concat create_checkbox(column_name)
    end
  end
end

#checkbox_row_v2(klass) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/spotlight_search/helpers.rb', line 86

def checkbox_row_v2(klass)
  tag.div class: "row" do
    SpotlightSearch::Utils.serialize_csv_columns(*klass.enabled_columns).each do |column_path|
      concat create_checkbox_v2(column_path)
    end
  end
end

#cm_paginate(facets) ⇒ Object



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
# File 'lib/spotlight_search/helpers.rb', line 101

def cm_paginate(facets)
  tag.div class: 'text-center' do
    tag.div class: 'nav navbar navbar-inner' do
      tag.ul class: 'pagination' do
        if facets.previous_page != false
          previous_page = tag.li do
            tag.button class: 'btn btn-bordered', data: { behaviour: 'previous-page'} do
              tag.span "Previous"
            end
          end
        end
        current_page =  :li do
          tag.a class: 'btn btn-bordered mx-2', data: {sort_column: facets.sort[:sort_column], sort_direction: facets.sort[:sort_direction], page: facets.current_page, behaviour: 'current-page' } do
            "Showing #{facets.current_page} of #{facets.total_pages} pages"
          end
        end

        if facets.next_page != false
          next_page = tag.li do
            tag.button class: 'btn btn-bordered', data: { behaviour: 'next-page'} do
              tag.span "Next"
            end
          end
        end
        (previous_page || ActiveSupport::SafeBuffer.new) + current_page + (next_page || ActiveSupport::SafeBuffer.new)
      end
    end
  end
end

#column_pop_up(email, klass) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/spotlight_search/helpers.rb', line 21

def column_pop_up(email, klass)
  tag.div class: "modal fade", id: "exportmodal", tabindex: "-1", role: "dialog", aria: {labelledby: "exportModal"} do
    tag.div class: "modal-dialog modal-lg", role: "document" do
      tag.div class: "modal-content" do
        concat pop_ups(email, klass)
      end
    end
  end
end

#create_checkbox(column_name) ⇒ Object



79
80
81
82
83
84
# File 'lib/spotlight_search/helpers.rb', line 79

def create_checkbox(column_name)
  tag.div class: "col-md-4" do
    concat check_box_tag "columns[]", column_name.to_s
    concat column_name.to_s.humanize
  end
end

#create_checkbox_v2(column_path) ⇒ Object



94
95
96
97
98
99
# File 'lib/spotlight_search/helpers.rb', line 94

def create_checkbox_v2(column_path)
  tag.div class: "col-md-4" do
    concat check_box_tag "columns[]", column_path, id: column_path.to_s.gsub('/', '-')
    concat column_path.to_s.gsub('/', '_').humanize
  end
end

#exportable(email, klass, html_class: []) ⇒ Object



14
15
16
17
18
19
# File 'lib/spotlight_search/helpers.rb', line 14

def exportable(email, klass, html_class: [])
  tag.div do
    concat tag.button "Export as excel", class: html_class.append("modal-btn"), data: {toggle: "modal", target: "#exportmodal"}
    concat column_pop_up(email, klass)
  end
end

#params_to_post_helper(params) ⇒ Object



65
66
67
68
69
# File 'lib/spotlight_search/helpers.rb', line 65

def params_to_post_helper(params)
  URI.decode_www_form(params.to_param).each do |param|
    concat hidden_field_tag param[0], param[1]
  end
end

#pop_up_body(email, klass) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/spotlight_search/helpers.rb', line 47

def pop_up_body(email, klass)
  tag.div class: "modal-body" do
    form_tag '/spotlight_search/export_to_file', id: 'export-to-file-form', style: "width: 100%;", class:"spotlight-csv-export-form" do
      concat hidden_field_tag 'email', email, id: 'export-to-file-email'
      concat hidden_field_tag 'class_name', klass.to_s, id: 'export-to-file-klass'
      params_to_post_helper(filters: controller.filter_params) if controller.filter_params
      params_to_post_helper(sort: controller.sort_params) if controller.sort_params
      case SpotlightSearch.exportable_columns_version
      when :v1
        concat checkbox_row(klass)
      when :v2
        concat checkbox_row_v2(klass)
      end
      concat submit_tag 'Export as excel', class: 'btn btn-bordered export-to-file-btn'
    end
  end
end

#pop_up_headerObject



38
39
40
41
42
43
44
45
# File 'lib/spotlight_search/helpers.rb', line 38

def pop_up_header
  tag.div class: "modal-header" do
    tag.button type: "button", class: "close", data: {dismiss: "modal"}, aria: {label: "Close"} do
      tag.span "X", aria: {hidden: "true"}
    end
    tag.h4 "Select columns to export", class: "modal-title", id: "exportModal"
  end
end

#pop_ups(email, klass) ⇒ Object



31
32
33
34
35
36
# File 'lib/spotlight_search/helpers.rb', line 31

def pop_ups(email, klass)
  tag.div do
    concat pop_up_header
    concat pop_up_body(email, klass)
  end
end

#sortable(column, title = "Title", sort_column = "created_at", sort_direction = "asc") ⇒ Object



6
7
8
9
10
11
12
# File 'lib/spotlight_search/helpers.rb', line 6

def sortable(column, title = "Title", sort_column="created_at", sort_direction="asc")
  title ||= column.titleize
  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  # link_to title, '#', {:class => css_class, data: {sort: column, direction: direction}}
  ("a", title, class: css_class, data: {sort_column: column, sort_direction: direction, behaviour: 'sort', type: 'anchor-filter'})
end