Module: Vulgata::ApplicationHelper

Defined in:
app/helpers/vulgata/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_class_for(flash_type) ⇒ Object



127
128
129
# File 'app/helpers/vulgata/application_helper.rb', line 127

def bootstrap_class_for flash_type
  { success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type.to_sym] || flash_type.to_s
end

#context_path_for(object) ⇒ Object



4
5
6
7
8
9
10
11
# File 'app/helpers/vulgata/application_helper.rb', line 4

def context_path_for object
  # use the provided context path helper to link to appropriate context
  if object.vulgata_context_path && object.vulgata_context_path_param
    main_app.send(object.vulgata_context_path, object.send(object.vulgata_context_path_param))
  else # if not provided, fallback to current object's path
    main_app.url_for(object) rescue nil
  end
end

#current_query_paramsObject



68
69
70
71
72
73
74
75
# File 'app/helpers/vulgata/application_helper.rb', line 68

def current_query_params
  opts = {}
  opts[:resource] = params[:resource] if params[:resource].present?
  opts[:status] = params[:status] if params[:status].present?
  opts[:q] = params[:q] if params[:q].present?
  opts[:sort] = params[:sort] if params[:sort].present?
  opts
end

#flash_messages(opts = {}) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'app/helpers/vulgata/application_helper.rb', line 131

def flash_messages(opts = {})
  flash.each do |msg_type, message|
    concat((:div, message, class: "alert #{bootstrap_class_for(msg_type)} fade in") do
             concat (:button, 'x', class: "close", data: { dismiss: 'alert' })
             concat message
    end)
  end
  nil
end

#language_flag_and_label(locale) ⇒ Object



111
112
113
114
115
116
# File 'app/helpers/vulgata/application_helper.rb', line 111

def language_flag_and_label locale
   :span do
    concat flag_icon(Vulgata.configuration.locale_flags[locale.to_sym], class: "flag-icon-vlg") if Vulgata.configuration.locale_flags[locale.to_sym]
    concat Vulgata::LanguageTools.language_name(locale)
  end
end

#language_flag_or_label(locale) ⇒ Object



118
119
120
121
# File 'app/helpers/vulgata/application_helper.rb', line 118

def language_flag_or_label locale
  flag_code = Vulgata.configuration.locale_flags[locale.to_sym]
  flag_code.present? ? flag_icon(flag_code, class: "flag-icon-vlg") : locale
end

#sorting_dropdown(path) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/helpers/vulgata/application_helper.rb', line 38

def sorting_dropdown path
  opts = current_query_params

  updated_class, updated_sort_param = case params[:sort]
     when 'updated_at_desc' then ['active sorted-desc', 'updated_at_asc']
     when 'updated_at_asc' then ['active sorted-asc', 'updated_at_desc']
     else [nil, 'updated_at_desc']
  end

  priority_class, priority_sort_param = case params[:sort]
     when 'priority_desc' then ['active sorted-desc', 'priority_asc']
     when 'priority_asc' then ['active sorted-asc', 'priority_desc']
     else [nil, 'priority_desc']
  end

  (:ul, class: 'nav navbar-nav navbar-right') do
     concat((:li, class: (params[:sort].blank? ? 'active' : nil)) do
              (:p, class:'navbar-text') do
                "Sort by:"
              end
     end)
     concat((:li, class: priority_class) do
              link_to("Priority", self.send(path, opts.merge({sort: priority_sort_param})))
     end)
     concat((:li, class: updated_class) do
              link_to("Date", self.send(path, opts.merge({sort: updated_sort_param})))
     end)
  end
end

#status_tab_class(status) ⇒ Object



77
78
79
80
81
82
83
84
# File 'app/helpers/vulgata/application_helper.rb', line 77

def status_tab_class status
  if params[:status] == status ||
      ((params[:status].blank? || params[:status] == 'all')  && status == :all)
    'active'
  else
    ''
  end
end

#status_tabs(path, klass = nil, items_count = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/vulgata/application_helper.rb', line 13

def status_tabs path, klass = nil, items_count = nil
  status_counts = items_count || Vulgata::TranslationState.group(:status).count
  all_count = status_counts.except(Vulgata::TranslationState.statuses[:source], nil).values.sum

   :ul, class: "nav nav-tabs" do
    # 'All' tab
    concat((:li, class: status_tab_class(:all)) do
             link_to(self.send(path, current_query_params.except(:status))) do
               concat("All (#{all_count})")
             end
    end)
    # all other tabs
    Vulgata::TranslationState.statuses.except(:source, :rejected).each do |status, status_value|
      opts = current_query_params
      opts[:status] = status.to_s
      concat((:li, class: status_tab_class(status)) do
               link_to(self.send(path, opts)) do
                 concat(status.to_s.humanize)
                 concat(" (#{status_counts[status_value] || 0})")
               end
      end)
    end
  end
end

#translation_status_label(status) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/vulgata/application_helper.rb', line 86

def translation_status_label status
  label_class = nil

  case status
  when :source
    label_class = 'label label-default'
  when :pending
    label_class = 'label label-primary'
  when :in_progress
    label_class = 'label label-warning'
  when :done
    label_class = 'label label-info'
  when :proofreading
    label_class = 'label label-warning'
  when :rejected
    label_class = 'label label-danger'
  when :approved
    label_class = 'label label-success'
  else
    label_class = 'label label-danger'
  end

  (:span, status.to_s.humanize, class: label_class)
end

#translator_name(translation_state) ⇒ Object



123
124
125
# File 'app/helpers/vulgata/application_helper.rb', line 123

def translator_name translation_state
  translation_state.user.present? ? translation_state.user.name : nil
end