2014-03-23 00:22:25 +00:00
|
|
|
module ApplicationHelper
|
2014-04-06 14:14:03 +00:00
|
|
|
def full_title(page_title)
|
2014-05-16 21:24:49 +00:00
|
|
|
base_title = "NSL"
|
2020-03-26 01:52:05 +00:00
|
|
|
base_title << " " + Rails.env.upcase unless Rails.env.production?
|
2014-04-08 23:28:46 +00:00
|
|
|
|
2014-04-06 14:14:03 +00:00
|
|
|
if page_title.empty?
|
|
|
|
base_title
|
|
|
|
else
|
|
|
|
"#{base_title} | #{page_title}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-11 10:27:59 +00:00
|
|
|
def active_theme
|
2014-08-10 22:56:18 +00:00
|
|
|
if cuser && cuser.profile
|
|
|
|
cuser.current_layout
|
|
|
|
else
|
|
|
|
'default'
|
|
|
|
end
|
2014-05-11 10:27:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def theme_stylesheet_link_tag
|
|
|
|
stylesheet_link_tag "themes/#{active_theme}/theme"
|
|
|
|
end
|
|
|
|
|
2020-04-01 02:00:53 +00:00
|
|
|
def namelink(model, length = nil)
|
2014-03-23 00:22:25 +00:00
|
|
|
return if model.nil?
|
|
|
|
model = case model.class.to_s
|
|
|
|
when "DataFile"
|
|
|
|
model.movie ? model.movie : model
|
|
|
|
when "Comment"
|
|
|
|
model.commentable
|
|
|
|
when "Post"
|
2020-03-22 17:47:24 +00:00
|
|
|
model.topic
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
|
|
|
model
|
|
|
|
end
|
|
|
|
str = model.to_s
|
2020-04-01 02:00:53 +00:00
|
|
|
|
2020-03-22 17:47:24 +00:00
|
|
|
# Reduce length of too long model names
|
2014-03-23 00:22:25 +00:00
|
|
|
if length and str.length > length
|
2020-04-01 02:00:53 +00:00
|
|
|
link_to(str.to_s[0, length] + "...", model, class: model.class.to_s.downcase)
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
2020-04-01 02:00:53 +00:00
|
|
|
link_to(str, model, class: model.class.to_s.downcase)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def directory_links(directory)
|
|
|
|
output = ""
|
|
|
|
Directory.directory_traverse(directory).reverse_each do |dir|
|
|
|
|
output << namelink(dir) + "\n"
|
|
|
|
unless dir == directory
|
|
|
|
output << " » \n"
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
2020-04-01 02:00:53 +00:00
|
|
|
output.html_safe
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def shorten str, length
|
|
|
|
if length and str and str.to_s.length > length
|
|
|
|
str = str.to_s[0, length] + "..."
|
|
|
|
end
|
|
|
|
str
|
|
|
|
end
|
|
|
|
|
|
|
|
def longtime time
|
|
|
|
printtime time, "%d %B %y %H:%M"
|
|
|
|
end
|
|
|
|
|
2014-04-29 20:02:20 +00:00
|
|
|
def longertime time
|
|
|
|
printtime time, "%e %B %Y - %H:%M %Z"
|
|
|
|
end
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
def shorttime time
|
|
|
|
printtime time, "%d/%b/%y %H:%M"
|
|
|
|
end
|
|
|
|
|
|
|
|
def shortdate time
|
|
|
|
printtime time, "%d %b %y"
|
|
|
|
end
|
|
|
|
|
|
|
|
def longdate time
|
2014-04-21 18:19:03 +00:00
|
|
|
printtime time, "%e %B %Y"
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def printtime time, format
|
|
|
|
return unless time
|
2014-04-16 08:44:36 +00:00
|
|
|
|
2014-04-29 20:02:20 +00:00
|
|
|
content_tag(:span, style: 'font-style: italic') do
|
|
|
|
Time.use_zone(timezone_offset) { time.strftime(format) }
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
2020-04-01 02:40:17 +00:00
|
|
|
# Print the attributes from the list
|
2014-03-23 00:22:25 +00:00
|
|
|
def cascade model, list
|
2020-04-01 02:40:17 +00:00
|
|
|
return "" if model.nil?
|
|
|
|
|
2014-04-16 08:44:36 +00:00
|
|
|
out = list.map do |element|
|
2014-03-23 00:22:25 +00:00
|
|
|
name = key = element
|
2014-04-16 08:44:36 +00:00
|
|
|
item = ""
|
2014-03-23 00:22:25 +00:00
|
|
|
result = ""
|
|
|
|
|
|
|
|
if element.instance_of?(Array)
|
|
|
|
name = element[0]
|
|
|
|
key = element[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
if m = key.to_s.match(/^(.*)_b$/)
|
|
|
|
name = m[1]
|
|
|
|
key = m[1]
|
2020-04-01 02:40:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
str = eval("model.#{key}")
|
|
|
|
rescue
|
|
|
|
next
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
2020-04-01 02:40:17 +00:00
|
|
|
next if str == "" or str.nil?
|
2014-03-23 00:22:25 +00:00
|
|
|
|
2020-03-23 02:10:50 +00:00
|
|
|
if model[key].instance_of?(Time) or model[key].instance_of?(ActiveSupport::TimeWithZone)
|
2020-03-22 17:47:24 +00:00
|
|
|
# result << shorttime(str)
|
|
|
|
result << model[key].to_formatted_s(:long_ordinal)
|
2014-03-23 00:22:25 +00:00
|
|
|
elsif element.instance_of?(Symbol)
|
|
|
|
result << namelink(str)
|
|
|
|
elsif key.to_s.match(/^(.*)_b$/)
|
|
|
|
result << str.bbcode_to_html
|
|
|
|
else
|
|
|
|
result << h(str)
|
|
|
|
end
|
|
|
|
|
2014-04-16 08:44:36 +00:00
|
|
|
item << content_tag(:dt) do
|
2014-04-17 07:55:19 +00:00
|
|
|
"#{name.to_s.capitalize.gsub(/_s/, '').gsub(/_/, ' ')}".html_safe
|
2014-04-16 08:44:36 +00:00
|
|
|
end
|
|
|
|
item << content_tag(:dd) do
|
2014-04-17 07:55:19 +00:00
|
|
|
result.html_safe
|
2014-04-16 08:44:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
item
|
|
|
|
end
|
|
|
|
|
|
|
|
content_tag(:dl) do
|
|
|
|
out.join.html_safe
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def abslink text, url
|
|
|
|
raw link_to text, url
|
|
|
|
end
|
|
|
|
|
|
|
|
def flag country
|
2014-04-08 23:28:46 +00:00
|
|
|
if country and country.to_s.size > 0
|
2017-08-23 20:45:09 +00:00
|
|
|
image_tag 'shared/blank.gif', class: "flag flag-#{country.downcase}"
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
2017-08-23 20:45:09 +00:00
|
|
|
image_tag 'shared/blank.gif', class: 'flag'
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-06 14:14:03 +00:00
|
|
|
def add_comments(object)
|
|
|
|
@comment = Comment.new(commentable: object)
|
2014-03-23 00:22:25 +00:00
|
|
|
@comments = object.comments.ordered.with_userteam
|
2014-04-06 14:14:03 +00:00
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
return_here
|
2014-04-06 14:14:03 +00:00
|
|
|
render partial: "comments/index"
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def bbcode
|
2014-04-06 14:14:03 +00:00
|
|
|
link_to "(BBCode)", article_url(id: 536)
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sortable(column, title = nil)
|
|
|
|
title ||= column.titleize
|
|
|
|
css_class = (column == sort_column) ? "current #{sort_direction}" : nil
|
|
|
|
direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"
|
2014-04-06 14:14:03 +00:00
|
|
|
link_to title, { sort: column, direction: direction }, { class: css_class }
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def link_to_remove_fields(name, f)
|
|
|
|
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)")
|
|
|
|
end
|
|
|
|
|
2020-04-02 02:51:37 +00:00
|
|
|
# FIXME: this won't work.
|
2014-03-23 00:22:25 +00:00
|
|
|
def link_to_add_fields(name, f, association)
|
|
|
|
new_object = f.object.class.reflect_on_association(association).klass.new
|
2014-04-06 14:14:03 +00:00
|
|
|
fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder|
|
|
|
|
render(association.to_s.singularize, f: builder)
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
link_to_function(name, ("add_fields(this, '#{association}', '#{escape_javascript(fields)}')"))
|
|
|
|
end
|
2014-04-01 23:07:21 +00:00
|
|
|
|
|
|
|
def timezone_offset
|
|
|
|
if @cuser
|
|
|
|
@cuser.time_zone
|
|
|
|
else
|
|
|
|
Time.zone.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-02 23:02:09 +00:00
|
|
|
def calendar
|
|
|
|
@calendar ||= GoogleCalendar.new(ENV['GOOGLE_CALENDAR_ID'], timezone_offset)
|
|
|
|
end
|
|
|
|
|
|
|
|
def event_start_time event
|
|
|
|
event.start.date_time.to_datetime.in_time_zone(timezone_offset)
|
|
|
|
end
|
2015-07-18 10:33:09 +00:00
|
|
|
|
2014-04-01 23:07:21 +00:00
|
|
|
def upcoming_matches
|
2020-03-25 23:33:23 +00:00
|
|
|
ENV['GOOGLE_CALENDAR'] == "disabled" ? (calendar.upcoming || []) : []
|
2015-07-18 10:33:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def upcoming_nsltv
|
2020-03-25 23:33:23 +00:00
|
|
|
ENV['GOOGLE_CALENDAR'] == "disabled" ? (calendar.upcoming || []) : []
|
2014-04-01 23:07:21 +00:00
|
|
|
end
|
2014-04-15 09:59:52 +00:00
|
|
|
|
2015-09-18 12:35:17 +00:00
|
|
|
def gathers_url
|
|
|
|
if Rails.env.production?
|
2017-04-17 22:04:18 +00:00
|
|
|
"https://gathers.ensl.org"
|
2015-09-18 12:35:17 +00:00
|
|
|
else
|
2017-04-18 14:01:36 +00:00
|
|
|
"https://gathers.staging.ensl.org"
|
2015-09-18 12:35:17 +00:00
|
|
|
end
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|