From 5b1a730e199fc637697c472657cc107d85ba5675 Mon Sep 17 00:00:00 2001 From: hitman Date: Fri, 10 Mar 2017 02:18:26 +0530 Subject: [PATCH] rearrange helper functions --- app/helpers/application_helper.rb | 36 +++++++++++++------------------ app/helpers/date_time_helper.rb | 35 ------------------------------ app/helpers/events_helper.rb | 12 +++++++++++ app/helpers/format_helper.rb | 9 +++----- app/helpers/paths_helper.rb | 9 -------- 5 files changed, 30 insertions(+), 71 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 09014502..f6f11e00 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,4 @@ module ApplicationHelper - ## # Returns a string build from the start and end date of the given conference. # # If the conference is only one day long @@ -34,23 +33,6 @@ module ApplicationHelper result end - # Returns time with conference timezone - def time_with_timezone(time) - time.strftime('%F %R') + ' ' + @conference.timezone.to_s - end - - ## - # Checks if the voting has already started, or if it has already ended - # - def voting_open_or_close(program) - return if program.voting_period? - if program.voting_start_date > Time.current - return 'Voting period has not started yet!' - else # voting_end_date > Date.today because voting_start_date < voting_end_date - return 'Voting period is over!' - end - end - # Set resource_name for devise so that we can call the devise help links (views/devise/shared/_links) from anywhere (eg sign_up form in proposals#new) def resource_name :user @@ -130,9 +112,21 @@ module ApplicationHelper object end - def quantity_left_of(resource) - return '-/-' if resource.quantity.blank? - "#{resource.quantity - resource.used}/#{resource.quantity}" + def normalize_array_length(hashmap, length) + hashmap.each do |_, value| + if value.length < length + value.fill(value[-1], value.length...length) + end + end + end + + # Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to() + def redirect_back_or_to(options = {}, response_status = {}) + if request.env['HTTP_REFERER'] + redirect_to :back + else + redirect_to options, response_status + end end def concurrent_events(event) diff --git a/app/helpers/date_time_helper.rb b/app/helpers/date_time_helper.rb index 0acb2aef..a8e4f660 100644 --- a/app/helpers/date_time_helper.rb +++ b/app/helpers/date_time_helper.rb @@ -2,41 +2,6 @@ module DateTimeHelper ## # Includes functions related to date or time manipulations ## - ## - # Returns a string build from the start and end date of the given conference. - # - # If the conference is only one day long - # * %B %d %Y (January 17 2014) - # If the conference starts and ends in the same month and year - # * %B %d - %d, %Y (January 17 - 21 2014) - # If the conference ends in another month but in the same year - # * %B %d - %B %d, %Y (January 31 - February 02 2014) - # All other cases - # * %B %d, %Y - %B %d, %Y (December 30, 2013 - January 02, 2014) - def date_string(start_date, end_date) - startstr = 'Unknown - ' - endstr = 'Unknown' - # When the conference is in the same month - if start_date.month == end_date.month && start_date.year == end_date.year - if start_date.day == end_date.day - startstr = start_date.strftime('%B %d') - endstr = end_date.strftime(' %Y') - else - startstr = start_date.strftime('%B %d - ') - endstr = end_date.strftime('%d, %Y') - end - elsif start_date.month != end_date.month && start_date.year == end_date.year - startstr = start_date.strftime('%B %d - ') - endstr = end_date.strftime('%B %d, %Y') - else - startstr = start_date.strftime('%B %d, %Y - ') - endstr = end_date.strftime('%B %d, %Y') - end - - result = startstr + endstr - result - end - ## # Gets an EventType object, and returns its length in timestamp format (HH:MM) # ====Gets diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 38b380b5..8f078db1 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -10,6 +10,18 @@ module EventsHelper "Registered: #{event.registrations.count}" end + ## + # Checks if the voting has already started, or if it has already ended + # + def voting_open_or_close(program) + return if program.voting_period? + if program.voting_start_date > Time.current + return 'Voting period has not started yet!' + else # voting_end_date > Date.today because voting_start_date < voting_end_date + return 'Voting period is over!' + end + end + def event_types(conference) all = conference.program.event_types.map { |et| et.title.pluralize } first = all[0...-1] diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb index da9ee598..bd64e3ac 100644 --- a/app/helpers/format_helper.rb +++ b/app/helpers/format_helper.rb @@ -192,11 +192,8 @@ module FormatHelper markdown("#{text} Please look at #{link_to '**Markdown Syntax**', 'https://daringfireball.net/projects/markdown/syntax', target: '_blank'} to format your text") end - def normalize_array_length(hashmap, length) - hashmap.each do |_, value| - if value.length < length - value.fill(value[-1], value.length...length) - end - end + def quantity_left_of(resource) + return '-/-' if resource.quantity.blank? + "#{resource.quantity - resource.used}/#{resource.quantity}" end end diff --git a/app/helpers/paths_helper.rb b/app/helpers/paths_helper.rb index 8b235ccd..3633292a 100644 --- a/app/helpers/paths_helper.rb +++ b/app/helpers/paths_helper.rb @@ -30,13 +30,4 @@ module PathsHelper return '' end end - - # Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to() - def redirect_back_or_to(options = {}, response_status = {}) - if request.env['HTTP_REFERER'] - redirect_to :back - else - redirect_to options, response_status - end - end end