Module: PraisesHelper

Defined in:
app/helpers/praises_helper.rb

Overview

View helper: praises.

Instance Method Summary collapse

Instance Method Details

Builds one "new praise" link per praise type.

Parameters:

  • options (Hash) (defaults to: {})

    any keys besides link_params are forwarded to link_to as HTML options

Options Hash (options):

  • link_params (Hash)

    extra params merged into the new-praise URL

Returns:

  • (Array<String>)

    the link HTML strings



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/praises_helper.rb', line 8

def create_praise_links(options = {})
  Praise.praise_types.keys.map do |praise_type|
    _options = options.dup
    label = case praise_type
            when 'employee_praise'
              fa_icon('bullhorn', text: "New Shoutout")
            else
              "New #{praise_type.titleize}"
            end

    link_params = { praise: { praise_type: praise_type } }.deep_merge(_options.delete(:link_params) || {})
    link_to(label, new_praise_path(link_params), **_options)
  end
end

#new_praise_buttonObject



27
28
29
30
31
# File 'app/helpers/praises_helper.rb', line 27

def new_praise_button
  render_simple_drop_down praises_command_options,
                              main_link_class: 'btn-primary btn-sm',
                              dropdown_options: { class: 'dropdown-menu dropdown-menu-end' }
end


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/praises_helper.rb', line 33

def praise_attachment_link(praise, thumbnail_size: nil)
  return unless praise.image&.stored?

  if /^image/.match?(praise.image.mime_type)
    thumbnail_url = if thumbnail_size
                      praise.image.thumb(thumbnail_size).url
                    else
                      praise.image.url
                    end
    link_to(image_tag(thumbnail_url, class: 'img-fluid'), praise.image.url, class: "thumbnail", data: { fancybox: 'praise-gallery', type: 'image' })
  else
    link_to(praise.image_name, praise.image.url, data: { fancybox: 'praise-gallery', type: 'iframe' })
  end
rescue Dragonfly::Job::Fetch::NotFound
rescue StandardError
end

#praises_command_optionsObject



23
24
25
# File 'app/helpers/praises_helper.rb', line 23

def praises_command_options
  ["Create New"] + create_praise_links
end