osem-fcy/app/helpers/application_helper.rb

160 lines
5.6 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2013-01-07 09:04:09 +01:00
module ApplicationHelper
2017-03-10 02:18:26 +05:30
# Returns a string build from the start and end date of the given conference.
#
2017-03-10 02:18:26 +05:30
# 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
2017-03-10 02:18:26 +05:30
result = startstr + endstr
result
end
# Returns time with conference timezone
def time_with_timezone(time)
time.strftime('%F %R') + ' ' + @conference.timezone.to_s
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)
2015-04-18 21:44:40 +03:00
def resource_name
:user
end
2013-01-07 09:04:09 +01:00
def add_association_link(association_name, form_builder, div_class, html_options = {})
link_to_add_association 'Add ' + association_name.to_s.singularize, form_builder, div_class, html_options.merge(class: 'assoc btn btn-success')
2013-01-07 09:04:09 +01:00
end
def remove_association_link(association_name, form_builder)
link_to_remove_association('Remove ' + association_name.to_s.singularize, form_builder, class: 'assoc btn btn-danger') + tag(:hr)
2013-01-07 09:04:09 +01:00
end
def dynamic_association(association_name, title, form_builder, options = {})
render 'shared/dynamic_association', association_name: association_name, title: title, f: form_builder, hint: options[:hint]
2013-01-07 09:04:09 +01:00
end
def tracks(conference)
conference.confirmed_tracks.collect(&:name).to_sentence
end
def difficulty_levels(conference)
conference.program.difficulty_levels.map(&:title).to_sentence
end
def unread_notifications(user)
Comment.accessible_by(current_ability).find_since_last_login(user)
end
2016-06-20 17:09:39 +02:00
2020-10-30 18:06:43 +09:00
# Receives a PaperTrail::Version object
# Outputs the list of attributes that were changed in the version (ignoring changes from one blank value to another)
# Eg: If version.changeset = '{"title"=>[nil, "Premium"], "description"=>[nil, "Premium = Super cool"], "conference_id"=>[nil, 3]}'
# Output will be 'title, description and conference'
def updated_attributes(version)
2017-04-06 23:19:58 -04:00
version.changeset
.reject{ |_, values| values[0].blank? && values[1].blank? }
.keys.map{ |key| key.gsub('_id', '').tr('_', ' ')}.join(', ')
.reverse.sub(',', ' dna ').reverse
end
2017-03-10 02:18:26 +05:30
def normalize_array_length(hashmap, length)
hashmap.each_value do |value|
2017-03-10 02:18:26 +05:30
if value.length < length
value.fill(value[-1], value.length...length)
end
end
end
def concurrent_events(event)
return nil unless event.scheduled? && event.program.selected_event_schedules
2018-11-13 18:01:49 -08:00
Implement track scheduling Add track association to schedule Show schedules in admin sidebar to track organizers Allow track organizers to manage the schedules of their tracks Don't allow self-organized track events to be dragged or unscheduled in a conference schedule Make scheduled events of self-organized tracks appear semitransparent in conference schedules Make the rooms of confirmed self_organized tracks appear semitransparent and don't allow events to be scheduled to it in the conference schedules during the dates of its track Create admin/SchedulesController#new action Add a button in admin/Schedules#index to create schedules for tracks Add self_organized scope to Track Modify Schedules#show to handle track schedules and show a unified schedule Allow track organizers to create new schedules for their tracks Correctly identify scheduled and unscheduled events in Schedules#events Fix Event#room and Event#time for when the event is scheduled in a track schedule Modify Program#selected_event_schedules to include the event_schedules of selected track schedules Modify Track#revoke_role_and_cleanup to destroy the track's schedules and revert its events' state to new Add tabs for conference and track schedules in admin/Schedules#index Add button to Create/Show a tracks schedule in Tracks#index and #show Fix concurrent_events in application_helper because of changes in Program#selected_event_schedules Do not take into account cfp_active in Event#valid_track Modify EventsController#get_tracks accordingly Enforce cfp_active of track to be enabled for proposals in ProposalsController#create and #update Add support for multiple schedules per track Add selected_schedule_id to Track Load EventSchedules of selected track schedules for conference schedules in admin/SchedulesController#show Modify SchedulesController#show to take into account only the selected track schedules Create Event#selected_schedule_id and use it in Event#scheduled? and Event#time Validate that an EventSchedule for an event of a self-organized track belongs to one of the track's schedules Add 'Manage' button in Tracks#index, #show that sends you to the admin side of things Add admin/TracksController#update_selected_schedule to update the selected_schedule_id of tracks
2017-08-09 18:12:20 +03:00
event_schedule = event.program.selected_event_schedules.find { |es| es.event == event }
other_event_schedules = event.program.selected_event_schedules.reject { |other_event_schedule| other_event_schedule == event_schedule }
concurrent_events = []
event_time_range = (event_schedule.start_time.strftime '%Y-%m-%d %H:%M')...(event_schedule.end_time.strftime '%Y-%m-%d %H:%M')
other_event_schedules.each do |other_event_schedule|
next unless other_event_schedule.event.confirmed?
2018-11-13 18:01:49 -08:00
other_event_time_range = (other_event_schedule.start_time.strftime '%Y-%m-%d %H:%M')...(other_event_schedule.end_time.strftime '%Y-%m-%d %H:%M')
if (event_time_range.to_a & other_event_time_range.to_a).present?
concurrent_events << other_event_schedule.event
end
end
concurrent_events
end
def speaker_links(event)
safe_join(event.speakers.map{ |speaker| link_to speaker.name, admin_user_path(speaker) }, ',')
end
def event_types_sentence(conference)
conference.event_types.map { |et| et.title.pluralize }.to_sentence
2017-03-16 22:30:03 +05:30
end
def rescheduling_hint(affected_event_count)
if affected_event_count > 0
"You have #{affected_event_count} scheduled #{'event'.pluralize(affected_event_count)}. Changing the conference hours will unschedule those scheduled outside the conference hours."
end
end
##
# ====Gets
# a conference object
# ==== Returns
# class hidden if conference is over
def hidden_if_conference_over(conference)
'hidden' if Date.today > conference.end_date
end
def nav_root_link_for(conference)
link_text = (
2024-06-07 16:19:29 +02:00
ENV.fetch('OSEM_NAME', 'OSEM')
)
link_to(
link_text,
root_path,
class: 'navbar-brand',
title: 'Open Source Event Manager'
)
end
# returns the url to be used for logo on basis of sponsorship level position
def get_logo(object)
if object.try(:sponsorship_level)
if object.sponsorship_level.position == 1
object.picture.first.url
elsif object.sponsorship_level.position == 2
object.picture.second.url
else
object.picture.others.url
end
else
object.picture.large.url
end
end
2013-01-07 09:04:09 +01:00
end