Module: App::ViewHelpers

Instance Method Summary collapse

Instance Method Details

#add_book_buttonObject


30
31
32
33
# File 'app/helpers.rb', line 30

def add_book_button
  "<a href='/new-book' class='btn btn-primary btn-lg'>Add New Book</a>"  # "<a href='/new-book' class='btn btn-primary btn-lg disabled'>Add New Book (disabled for demo)</a>"

end

#adminObject


4
5
6
# File 'app/helpers.rb', line 4

def admin
  @admin
end

#admin?Boolean


74
75
76
77
78
# File 'app/helpers.rb', line 74

def admin?
  if @user
    @user.admin?
  end
end

#app_nameObject


131
132
133
# File 'app/helpers.rb', line 131

def app_name
  @app_name
end

#base_urlObject


135
136
137
# File 'app/helpers.rb', line 135

def base_url
  @base_url
end

#book_permittedObject


54
55
56
# File 'app/helpers.rb', line 54

def book_permitted
  admin? || @book.users.include?(@user) 
end

#count_instances(place, book) ⇒ Object


110
111
112
# File 'app/helpers.rb', line 110

def count_instances(place, book)
  place.instances_per.count(book)
end

35
36
37
# File 'app/helpers.rb', line 35

def external_link_glyph(link)
  "<a href='#{link}' target='_blank'><span class='fa fa-external-link' aria-hidden='true'></span></a>"
end

#flag_modal_buttonObject


24
25
26
27
28
# File 'app/helpers.rb', line 24

def flag_modal_button
  <<-EOF
      <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#addFlagModal">Flag this</button>
  EOF
end

#flagsObject


80
81
82
83
84
85
86
87
88
89
# File 'app/helpers.rb', line 80

def flags
  if @flags
    @flags.map{ |f| {
      comment: f.comment,
      added_on: f.added_on,
      user_name: f.user.name,
      user_username: f.user.username
    } }
  end
end

#get_instances_per_page(total_pages, instances) ⇒ Object


106
107
108
# File 'app/helpers.rb', line 106

def get_instances_per_page(total_pages, instances)
  total_pages == 0 ? 0 : (instances.to_f / total_pages.to_f).round(2)
end

#instance_permittedObject


62
63
64
# File 'app/helpers.rb', line 62

def instance_permitted
  admin? || @instance.user == @user
end

#instances_by_names(place, book) ⇒ Object


114
115
116
117
118
119
120
121
# File 'app/helpers.rb', line 114

def instances_by_names(place, book)
  string = "<ul style='margin-left: 1em; padding: 0; margin-bottom: 0px;'>"
  place.instances_by_names(book).each do |name|
    string = string + "<li>#{name[0]}: #{name[1]}</li>"
  end
  string = string + "</ul>"
  string.gsub(/"/, "")
end

#javascriptsObject


16
17
18
# File 'app/helpers.rb', line 16

def javascripts
  @js
end

#json_fileObject


20
21
22
# File 'app/helpers.rb', line 20

def json_file
  @json_file
end

#logged_inObject

def user_sentence(userlist)

list = userlist.map do |user|
  user.name
end
list.to_sentence

end


50
51
52
# File 'app/helpers.rb', line 50

def logged_in
  @user
end

#map_heightObject


139
140
141
# File 'app/helpers.rb', line 139

def map_height
  "500px;"
end

#metadataObject


12
13
14
# File 'app/helpers.rb', line 12

def 
  @metadata
end

#not_empty(text) ⇒ Object


123
124
125
126
127
128
129
# File 'app/helpers.rb', line 123

def not_empty(text)
  case text
  when nil then false
  when "" then false
  else true
  end
end

#place_permittedObject


58
59
60
# File 'app/helpers.rb', line 58

def place_permitted
  admin? || @place.user == @user
end

#placesObject


91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers.rb', line 91

def places
  if @places
    @places.map do |p|
      { lat: p.lat, lon: p.lon, 
        name: p.name, 
        count: count_instances(p, @book),
        place_names: instances_by_names(p, @book),
        place_names_sentence: p.names_to_sentence(@book),
        slug: p.slug,
        confidence: p.confidence
      } 
    end
  end
end

#rendered_flashObject


39
40
41
# File 'app/helpers.rb', line 39

def rendered_flash
  @rendered_flash
end

#stylesheetsObject


8
9
10
# File 'app/helpers.rb', line 8

def stylesheets
  @css
end

#user_nameObject


66
67
68
69
70
71
72
# File 'app/helpers.rb', line 66

def user_name
  if @user
    @user.name
  else
    "Guest"
  end
end