Skip to content

Commit

Permalink
Merge branch 'main' into 187436627-registration-only-textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead authored May 15, 2024
2 parents cd30e51 + 6036e2c commit cc9e113
Show file tree
Hide file tree
Showing 43 changed files with 404 additions and 79 deletions.
29 changes: 29 additions & 0 deletions app/assets/javascripts/osem-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ $(document).ready( function() {
$('.unscheduled-events .schedule-event-delete-button').hide();
$('.non_schedulable .schedule-event-delete-button').hide();

$('#current-event-btn').on('click', function() {
var now = new Date();
var closestEventId = null;
var smallestDiff = Infinity;
var i = 0;

$('.event-item').each(function() {

var eventTimeStr = $(this).data('time');

if (eventTimeStr) {
var eventTime = new Date(eventTimeStr);
var diff = Math.abs(eventTime - now);

if (diff < smallestDiff) {
smallestDiff = diff;
closestEventId = $(this).attr('class').split(' ')[1];
}
}
});

if (closestEventId) {
//Instead of relying on hash it's probably better to scroll using javascript
//Since the users and click button->scroll->click again, which won't re-scroll
$('.highlighted').removeClass('highlighted');
$('.' + closestEventId).addClass('highlighted').get(0).scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});

// set events as draggable
$('.schedule-event').not('.non_schedulable').draggable({
snap: '.schedule-room-slot',
Expand Down
7 changes: 7 additions & 0 deletions app/assets/stylesheets/osem-schedule.scss
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,10 @@
h3.event-panel-title small {
line-height: 1.4;
}

#current-event-btn {
position: fixed;
bottom: 40px;
right: 40px;
z-index: 1000;
}
4 changes: 3 additions & 1 deletion app/controllers/admin/commercials_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def aggregate_errors(errors)
end

def commercial_params
params.require(:commercial).permit(:title, :url)
params.require(:commercial).permit(:title, :url).tap do |params|
params[:url] = Commercial.generate_snap_embed(params[:url]) if params[:url]
end
end
end
end
11 changes: 11 additions & 0 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ def toggle_attendance
end
end

def destroy
@event = Event.find(params[:id])
if @event.destroy
flash[:notice] = 'Event successfully deleted.'
redirect_to admin_conference_program_events_path(@conference.short_title)
else
flash[:alert] = 'Event could not be deleted.'
redirect_to admin_conference_program_event_path(@conference.short_title, @event)
end
end

private

def event_params
Expand Down
56 changes: 56 additions & 0 deletions app/controllers/admin/schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Admin
class SchedulesController < Admin::BaseController
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
# the schedule of a conference, which should not be accessed in the first place
before_action :set_conference
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource :schedule, through: :program, except: %i[new create]
Expand Down Expand Up @@ -68,8 +69,63 @@ def destroy
end
end

def upload_csv
authorize! :update, @conference
return flash[:alert] = 'No file was attached!' unless file_present?

if process_csv
flash[:notice] = 'Schedule uploaded successfully!'
else
flash[:alert] = 'Failed to process CSV file.'
end

redirect_to admin_conference_schedules_path(@conference)
end

private

def set_conference
@conference = Conference.find_by!(short_title: params[:conference_id])
end

def file_present?
params[:schedule] && params[:schedule][:file].present?
end

def process_csv
file = params[:schedule][:file]
CSV.foreach(file.path, headers: true) do |row|
process_row(row)
end
true
rescue StandardError => e
Rails.logger.error "CSV Processing Error: #{e.message}"
false
end

def process_row(row)
event_date = parse_date(row['Date'])
event_time = parse_time(row['Start_Time'])
event_start_time = combine_datetime(event_date, event_time)

room = Room.find_or_create_by(name: row['Room'])
event = Event.find_by(id: row['Event_ID'])

event&.update(start_time: event_start_time, room: room)
end

def parse_date(date_str)
Date.strptime(date_str, '%m/%d/%y')
end

def parse_time(time_str)
Time.parse(time_str)
end

def combine_datetime(date, time)
DateTime.new(date.year, date.month, date.day, time.hour, time.min, time.sec, time.zone)
end

def schedule_params
params.require(:schedule).permit(:track_id) if params[:schedule]
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/admin/splashpages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def splashpage_params
:include_venue, :include_registrations,
:include_tickets, :include_lodgings,
:include_sponsors, :include_social_media,
:include_booths, :include_happening_now)
:include_booths, :include_happening_now,
:include_committee)
end
end
end
15 changes: 10 additions & 5 deletions app/controllers/conference_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ def new
end

def show
@total_price = Ticket.total_price_user(@conference, current_user, paid: true)
@tickets = current_user.ticket_purchases.by_conference(@conference).paid
@total_price_per_ticket = @tickets.group(:ticket_id).sum('amount_paid * quantity')
@ticket_payments = @tickets.group_by(&:ticket_id)
@total_quantity = @tickets.group(:ticket_id).sum(:quantity)
@purchases = current_user.ticket_purchases.by_conference(@conference).paid
summed_per_ticket_per_currency = @purchases.group(:ticket_id, :currency).sum('amount_paid_cents * quantity')
@total_price_per_ticket_per_currency = summed_per_ticket_per_currency.each_with_object({}) do |((ticket_id, currency), amount), hash|
hash[[ticket_id, currency]] = Money.new(amount, currency)
end
@total_quantity = @purchases.group(:ticket_id, :currency).sum(:quantity)
sum_total_currency = @purchases.group(:currency).sum('amount_paid_cents * quantity')
@total_price_per_currency = sum_total_currency.each_with_object({}) do |(currency, amount), hash|
hash[currency] = Money.new(amount, currency)
end
end

def edit; end
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/conferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def index
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def show
# load conference with header content
@conference = Conference.unscoped.eager_load(
Expand Down Expand Up @@ -66,8 +67,12 @@ def show
).order('sponsorship_levels.position ASC', 'sponsors.name')
@sponsors = @conference.sponsors
end
if @splashpage.include_committee?
@organizers = User.with_role(:organizer, @conference)
end
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

def calendar
respond_to do |format|
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def new
@has_registration_ticket = params[:has_registration_ticket]
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)

@converted_prices = {}
@unpaid_ticket_purchases.each do |ticket_purchase|
@converted_prices[ticket_purchase.id] = ticket_purchase.amount_paid
end
@currency = selected_currency
end

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class UsersController < ApplicationController
before_action :authenticate_user!, only: :search
before_action :set_currency_options, only: [:edit, :new, :create, :update]
load_and_authorize_resource

# GET /users/1
Expand Down Expand Up @@ -40,7 +41,7 @@ def search

def user_params
params[:user][:timezone] = params[:user][:timezone].presence || nil
params.require(:user).permit(:name, :biography, :nickname, :affiliation,
params.require(:user).permit(:name, :biography, :nickname, :affiliation, :default_currency,
:picture, :picture_cache, :timezone)
end

Expand All @@ -49,5 +50,9 @@ def user_params
def load_user
@user ||= (params[:id] && params[:id] != 'current' && User.find(params[:id])) || current_user
end

# rubocop:enable Naming/MemoizedInstanceVariableName
def set_currency_options
@currency_options = CurrencyConversion::VALID_CURRENCIES.map { |currency| [currency, currency] }
end
end
29 changes: 29 additions & 0 deletions app/models/commercial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Commercial < ApplicationRecord

def self.render_from_url(url)
register_provider
url = generate_snap_embed(url)
begin
resource = OEmbed::Providers.get(url, maxwidth: 560, maxheight: 315)
{ html: resource.html.html_safe }
Expand All @@ -39,6 +40,34 @@ def self.render_from_url(url)
end
end

def self.generate_snap_embed(url)
return url unless url

uri = URI.parse(url)
if uri.host == 'snap.berkeley.edu' && uri.path == '/project'
args = URI.decode_www_form(uri.query).to_h
else
return url
end
if args.key?('username') && args.key?('projectname')
new_query = URI.encode_www_form({
'projectname' => args['projectname'],
'username' => args['username'],
'showTitle' => 'true',
'showAuthor' => 'true',
'editButton' => 'true',
'pauseButton' => 'true'
})
new_uri = URI::HTTPS.build(
host: uri.host,
path: '/embed',
query: new_query
)
return new_uri.to_s
end
url
end

def self.iframe_fallback(url)
"<iframe width=560 height=315 frameborder=0 allowfullscreen=true src=\"#{url}\"></iframe>".html_safe
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/currency_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CurrencyConversion < ApplicationRecord
VALID_CURRENCIES = %w[AUD CAD CHF CNY EUR GBP JPY USD].freeze
belongs_to :conference
validates :rate, numericality: { greater_than: 0 }
# Ensure from_currency and to_currency are among the VALID_CURRENCIES
validates :from_currency, :to_currency, inclusion: { in: VALID_CURRENCIES }
validates :from_currency, uniqueness: { scope: :to_currency }, on: :create

def self.convert_currency(conference, amount, from_currency, to_currency)
Expand Down
1 change: 1 addition & 0 deletions app/models/splashpage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# banner_photo_updated_at :datetime
# include_booths :boolean
# include_cfp :boolean default(FALSE)
# include_committee :boolean
# include_happening_now :boolean
# include_lodgings :boolean
# include_program :boolean
Expand Down
7 changes: 1 addition & 6 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,11 @@ def self.total_price(conference, user, paid: false)
result || Money.new(0, 'USD')
end

def self.total_price_user(conference, user, paid: false)
tickets = TicketPurchase.where(conference: conference, user: user, paid: paid)
tickets.inject(0) { |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end

def tickets_turnover_total(id)
ticket = Ticket.find(id)
return Money.new(0, 'USD') unless ticket

sum = ticket.ticket_purchases.paid.total
sum = ticket.price_cents * ticket.ticket_purchases.paid.total_quantity
Money.new(sum, ticket.price_currency)
end

Expand Down
21 changes: 14 additions & 7 deletions app/models/ticket_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ class TicketPurchase < ApplicationRecord

delegate :title, to: :ticket
delegate :description, to: :ticket
delegate :price, to: :ticket
delegate :price_cents, to: :ticket
delegate :price_currency, to: :ticket

has_many :physical_tickets

monetize :amount_paid_cents, with_model_currency: :currency, as: 'purchase_price'

scope :paid, -> { where(paid: true) }
scope :unpaid, -> { where(paid: false) }
scope :by_conference, ->(conference) { where(conference_id: conference.id) }
Expand Down Expand Up @@ -72,12 +73,13 @@ def self.purchase_ticket(conference, quantity, ticket, user, currency)
purchase.pay(nil)
end
if quantity > 0
purchase = new(ticket_id: ticket.id,
conference_id: conference.id,
user_id: user.id,
quantity: quantity,
amount_paid: converted_amount,
currency: currency)
purchase = new(ticket_id: ticket.id,
conference_id: conference.id,
user_id: user.id,
quantity: quantity,
amount_paid: converted_amount.to_f,
amount_paid_cents: converted_amount.fractional,
currency: currency)
purchase.pay(nil) if converted_amount.zero?
end
purchase
Expand All @@ -98,6 +100,11 @@ def self.total
sum('amount_paid * quantity')
end

# Total quantity
def self.total_quantity
sum('quantity')
end

def pay(payment)
update(paid: true, payment: payment)
PhysicalTicket.transaction do
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# confirmed_at :datetime
# current_sign_in_at :datetime
# current_sign_in_ip :string
# default_currency :string
# email :string default(""), not null
# email_public :boolean default(FALSE)
# encrypted_password :string default(""), not null
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/events/_proposal.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
= link_to 'Preview', conference_program_proposal_path(@conference.short_title, @event.id), class: 'btn btn-mini btn-primary'
= link_to 'Registrations', registrations_admin_conference_program_event_path(@conference.short_title, @event), class: 'btn btn-success'
= link_to 'Edit', edit_admin_conference_program_event_path(@conference.short_title, @event), class: 'btn btn-mini btn-primary'
= link_to 'Delete', admin_conference_program_event_path(@conference.short_title, @event), method: :delete, data: { confirm: 'Are you sure you want to delete this event?' }, class: 'btn btn-mini btn-danger'


.row
.col-md-12
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/physical_tickets/_physical_ticket.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
%td= physical_ticket.ticket.title
%td= physical_ticket.ticket.registration_ticket? ? 'Yes' : 'No'
%td= physical_ticket.user&.email
%td= humanized_money_with_symbol physical_ticket.ticket_purchase.amount_paid
%td= humanized_money_with_symbol(physical_ticket.ticket_purchase.purchase_price)
%td= physical_ticket.ticket_purchase.currency || 'USD'
%td
- if physical_ticket.ticket_scannings.present?
%span Checked in:
Expand Down
1 change: 1 addition & 0 deletions app/views/admin/physical_tickets/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
%th Registration?
%th User
%th Paid
%th Currency
%th Attedance
%th Actions
%tbody
Expand Down
Loading

0 comments on commit cc9e113

Please sign in to comment.