Skip to content

Commit

Permalink
Merge pull request #388 from snap-cloud/schedule-tweaks
Browse files Browse the repository at this point in the history
Snap!Con 2024 fixes
  • Loading branch information
cycomachead authored Aug 1, 2024
2 parents fdb8db9 + e842f06 commit 6f2c406
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 53 deletions.
29 changes: 13 additions & 16 deletions app/assets/javascripts/osem-schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,27 @@ $(document).ready( function() {

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

$('.event-item').each(function() {
let $event = $(this), eventTimeStr = $event.data('time');

var eventTimeStr = $(this).data('time');
if (!eventTimeStr) { return; }

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

if (diff < smallestDiff) {
smallestDiff = diff;
closestEventId = $(this).attr('class').split(' ')[1];
}
}
var eventTime = new Date(eventTimeStr);
var diff = Math.abs(eventTime - now);
if (diff < smallestDiff) {
smallestDiff = diff;
closestEvent = $event;
}
});

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
if (closestEvent) {
// 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' });
$(closestEvent).addClass('highlighted').get(0).scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def create
notice: 'Thanks! Your ticket is booked successfully.'
end
else
@total_amount_to_pay = convert_currency(@conference, Ticket.total_price(@conference, current_user, paid: false), from_currency, selected_currency)
# TODO-SNAPCON: This case is not tested at all
@total_amount_to_pay = CurrencyConversion.convert_currency(@conference, Ticket.total_price(@conference, current_user, paid: false), from_currency, selected_currency)
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
flash.now[:error] = @payment.errors.full_messages.to_sentence + ' Please try again with correct credentials.'
render :new
Expand Down
2 changes: 2 additions & 0 deletions app/views/schedules/_date_event_types.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
The conference timezone is #{timezone_mapping(conference.timezone)}.
- if current_user
Visit your #{link_to('user profile page', edit_user_path(current_user.id))} to set your timezone.
- else
(#{link_to('Log in', new_user_session_path)} to view the schedule in your preferred timezone.)
- if current_user
%p.text-center
Click the star next to each event to add or remove it from
Expand Down
2 changes: 1 addition & 1 deletion app/views/schedules/_event.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

%h3.event-panel-title
= link_to conference_program_proposal_path(@conference.short_title, event.id),
style: color_style do
style: "#{color_style}; line-height: 1.7" do
= event.title
- if event.subtitle.present?
%br
Expand Down
4 changes: 2 additions & 2 deletions app/views/schedules/_event_mini.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
%span= " at #{new_start_time.strftime('%l:%M %P')}"
= join_event_link(event, event_schedule, current_user, small: true)
%p
= truncate(markdown(event.abstract), length: 250, escape: false)
- if event.subevents.present?
= markdown(truncate(event.abstract, length: 256))
- if event.program_subevents.present?
%ul
- event.program_subevents.each do |subevent|
%li= link_to(subevent.title, conference_program_proposal_path(@conference.short_title, subevent.id))
47 changes: 21 additions & 26 deletions app/views/schedules/events.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,33 @@
.row
/ scheduled events
:ruby
date = nil
time = nil
tz_object = current_user&.timezone ? current_user : @conference
prev_date, prev_time = nil
display_tz = current_user&.timezone.presence || @conference.timezone

/ TODO-SNAPCON: Explore caching this.
- @events_schedules.each do |event_schedule|
- next if event_schedule.event.parent_event.present?
- new_start_time = convert_timezone(event_schedule.start_time, @conference.timezone, tz_object.timezone)
- start_ymd = new_start_time.strftime('%Y-%m-%d')
- unless start_ymd.eql?(date)
.col-xs-12.col-md-12
.date-content
%span.date-title
= inyourtz(event_schedule.start_time, @conference.timezone) do
= date = start_ymd
%a.pull-right{ title: "Go up", href: "#program" }
%i.fa-solid.fa-angles-up.fa-lg{ 'aria-hidden': true }
.col-xs-12.col-md-1
- if !event_schedule.start_time.strftime('%H:%M').eql?(time) || !start_ymd.eql?(date)
- time = new_start_time.strftime('%H:%M')
= inyourtz(event_schedule.start_time, @conference.timezone) do
= time + ' ' + timezone_text(tz_object)
.col-xs-12.col-md-11
- cache [@program, event_schedule, event_schedule.event, current_user, event_schedule.happening_now?, '#scheduled#full#panel'] do
.event-item{ data: { time: event_schedule.start_time.iso8601 }, class: "event-#{event_schedule.event.id}" }
= render 'event', event: event_schedule.event, event_schedule: event_schedule
- @events_schedules.select { |es| es.event.parent_event.nil? }.each do |event_schedule|
- event = event_schedule.event
- start_time = convert_timezone(event_schedule.start_time, @conference.timezone, display_tz)

- unless start_time.to_date.eql?(prev_date)
.date-content
%h2.date-title{ style: "margin: 0;" }
= prev_date = start_time.to_date
%a.pull-right{ title: "Go up", href: "#program" }
%i.fa-solid.fa-angles-up.fa-lg{ 'aria-hidden': true }
- if !start_time.eql?(prev_time)
- prev_time = start_time
%h3= start_time.strftime('%H:%M %p %Z')
.col-12
-# - cache [@program, event_schedule, event, current_user, event_schedule.happening_now?, '#scheduled#full#panel'] do
.event-item{ data: { time: event_schedule.start_time.iso8601 }, id: dom_id(event) }
= render 'event', event: event, event_schedule: event_schedule

/ confirmed events that are not scheduled
- if @unscheduled_events.any?
.col-xs-12.col-md-12
.col-12
.date-content
%span.date-title#unscheduled
%h2.date-title#unscheduled{ style: "margin: 0;" }
Unscheduled events
%a.pull-right{ title: "Go up", href: "#program" }
%i.fa-solid.fa-angles-up.fa-lg{ 'aria-hidden': true }
Expand Down
2 changes: 1 addition & 1 deletion db/migrate/20230418211420_create_currency_conversions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CreateCurrencyConversions < ActiveRecord::Migration[7.0]
def change
create_table :currency_conversions do |t|
create_table :currency_conversions, if_not_exists: true do |t|
t.decimal :rate
t.string :from_currency
t.string :to_currency
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_07_22_183008) do
ActiveRecord::Schema[7.0].define(version: 2024_04_22_200831) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down Expand Up @@ -545,8 +545,8 @@
t.integer "payment_id"
t.integer "week"
t.float "amount_paid", default: 0.0
t.integer "amount_paid_cents", default: 0
t.string "currency"
t.integer "amount_paid_cents", default: 0
end

create_table "ticket_scannings", force: :cascade do |t|
Expand Down
4 changes: 2 additions & 2 deletions features/conferences/all_events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Scenario: Display events using the conference's timezone
And I should see "All events are currently displayed in PDT (UTC -7)."
And I should see the following data: 8:00 am - 8:30 am PDT, 8:30 am - 9:00 am PDT
And I should see the following data in order: Dates, 2014-05-03, 2014-05-04, 2014-05-05, 2014-05-06, 2014-05-07, Unscheduled
And I should see the following data in order: 2014-05-03, 08:00 PDT, first_scheduled_event, 8:00 am, first_scheduled_subevent, 08:30 PDT, multiple_speaker_event
And I should see the following data in order: 2014-05-03, 08:00 AM PDT, first_scheduled_event, 8:00 am, first_scheduled_subevent, 08:30 AM PDT, multiple_speaker_event

Scenario: Display events using the user's timezone
Given I sign in with username "admin" and password "password123"
Expand All @@ -18,4 +18,4 @@ Scenario: Display events using the user's timezone
And I should see "All events are currently displayed in AEST (UTC 10)."
And I should see the following data: 1:00 am - 1:30 am AEST, 1:30 am - 2:00 am AEST
And I should see the following data in order: Dates, 2014-05-04, 2014-05-05, 2014-05-06, 2014-05-07, 2014-05-08, Unscheduled
And I should see the following data in order: 2014-05-04, 01:00 AEST, first_scheduled_event, 1:00 am, first_scheduled_subevent, 01:30 AEST, multiple_speaker_event
And I should see the following data in order: 2014-05-04, 01:00 AM AEST, first_scheduled_event, 1:00 am, first_scheduled_subevent, 01:30 AM AEST, multiple_speaker_event
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/factories/payments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# id :bigint not null, primary key
# amount :integer
# authorization_code :string
# currency :string
# last4 :string
# status :integer default("unpaid"), not null
# created_at :datetime not null
Expand Down
2 changes: 1 addition & 1 deletion spec/features/event_schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
it 'jumps to the closest event' do
find('#current-event-btn').click
highlighted_element = page.find('.highlighted', visible: true, wait: 1)
expect(highlighted_element[:class]).to include("event-#{scheduled_event_mid.id}")
expect(highlighted_element[:id]).to include("event_#{scheduled_event_mid.id}")
end
end

0 comments on commit 6f2c406

Please sign in to comment.