Skip to content

Commit

Permalink
Merge pull request #1800 from codebar/timezone-events
Browse files Browse the repository at this point in the history
feat(1493): events have timezones
  • Loading branch information
matyikriszta committed Jan 6, 2024
2 parents 83add19 + d96df26 commit 5d2170f
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 36 deletions.
13 changes: 7 additions & 6 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
//= require font_awesome5

$(function() {
$('#meeting_local_date, #workshop_local_date, #event_date_and_time, #workshop_rsvp_open_local_date').pickadate({
$("body").removeClass("no-js");

$('#event_local_date, #meeting_local_date, #workshop_local_date, #workshop_rsvp_open_local_date').pickadate({
format: 'dd/mm/yyyy'
});

$('#announcement_expires_at, #ban_expires_at').pickadate();
$('#meeting_local_time, #workshop_local_time, #workshop_local_end_time, #event_begins_at, #event_ends_at, #meeting_local_end_time, #workshop_rsvp_open_local_time').pickatime({
format: 'HH:i'
$(
"#meeting_local_time, #meeting_local_end_time, #event_local_time, #event_local_end_time, #workshop_local_time, #workshop_local_end_time, #workshop_rsvp_open_local_time"
).pickatime({
format: "HH:i",
});

$('body').removeClass('no-js');

// Chosen hides inputs and selects, which becomes problematic when they are
// required: browser validation doesn't get shown to the user.
// This fix places "the original input behind the Chosen input, matching the
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def set_event

def event_params
params.require(:event).permit(
:virtual, :name, :slug, :date_and_time, :begins_at, :ends_at, :description, :info, :schedule, :venue_id,
:external_url, :coach_spaces, :student_spaces, :email, :announce_only, :tito_url, :invitable,
:student_questionnaire, :confirmation_required, :surveys_required, :audience, :coach_questionnaire,
:show_faq, :display_coaches, :display_students, bronze_sponsor_ids: [], silver_sponsor_ids: [],
gold_sponsor_ids: [], sponsor_ids: [], chapter_ids: []
:virtual, :name, :slug, :date_and_time, :local_date, :local_time, :local_end_time, :description,
:info, :schedule, :venue_id, :external_url, :coach_spaces, :student_spaces, :email, :announce_only,
:tito_url, :invitable, :time_zone, :student_questionnaire, :confirmation_required, :surveys_required,
:audience, :coach_questionnaire, :show_faq, :display_coaches, :display_students,
bronze_sponsor_ids: [], silver_sponsor_ids: [], gold_sponsor_ids: [], sponsor_ids: [],
chapter_ids: []
)
end

Expand Down
18 changes: 4 additions & 14 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class Event < ApplicationRecord
include DateTimeConcerns
include Listable
include Invitable
include DateTimeConcerns
include EventHelper

attr_accessor :begins_at
attr_accessor :local_date, :local_time, :local_end_time

resourcify :permissions, role_cname: 'Permission', role_table_name: :permission

Expand All @@ -27,11 +27,9 @@ class Event < ApplicationRecord
validate :silver_sponsors_uniqueness
validate :gold_sponsors_uniqueness
validate :venue_or_remote_must_be_present
validates :date_and_time, :ends_at, presence: true

before_save do
begins_at = Time.parse(self.begins_at)
self.date_and_time = date_and_time.change(hour: begins_at.hour, min: begins_at.min)
end
before_validation :set_date_and_time, :set_end_date_and_time

def to_s
name
Expand Down Expand Up @@ -65,10 +63,6 @@ def student_spaces?
!coaches_only? && student_spaces > attending_students.count
end

def date
I18n.l(date_and_time, format: :dashboard)
end

def invitability
errors.add(:coach_spaces, :required) if coach_spaces.blank?
errors.add(:student_spaces, :required) if student_spaces.blank?
Expand Down Expand Up @@ -100,10 +94,6 @@ def sponsors?(level = nil)

private

def time_zone
'London'
end

def duplicated_sponsors
@duplicated_sponsors ||= fetch_duplicated_sponsors
end
Expand Down
10 changes: 7 additions & 3 deletions app/views/admin/events/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
.col-12.col-md-6
= f.input :slug, placeholder: 'for URI, e.g. 24-pull-requests'
.col-12
= f.input :date_and_time, as: :string, required: true, label: 'Date'
= f.input :local_date, label: 'Date', as: :string, required: true, input_html: { data: { value: @event.date_and_time.try(:strftime, '%d/%m/%Y') } }
.col-12.col-md-6
= f.input :begins_at, as: :string, required: true
= f.input :local_time, label: 'Starts at', as: :string, required: true, input_html: { data: { value: @event.time.try(:strftime, '%H:%M') } }
.col-12.col-md-6
= f.input :ends_at, as: :string, required: true
= f.input :local_end_time, label: 'Ends at', as: :string, required: true, input_html: { data: { value: @event.ends_at.try(:strftime, '%H:%M') } }
.col-12
.mb-3
%label.form-label{ for: "event_timezone" } Time zone
= f.time_zone_select :time_zone, nil, {}, { class: 'form-control'}
.col-12
= f.input :description, as: :text, input_html: { rows: 3 },
hint: 'Use this space to write an invitation message and description of the event. This copy will also be used in the email invitation. You can use HTML here!'
Expand Down
12 changes: 8 additions & 4 deletions app/views/admin/events/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
.col-12.col-md-6
= f.input :slug
.col-12
= f.input :date_and_time, as: :string, required: true, label: 'Date', input_html: { data: { value: @event.date_and_time.strftime('%d/%m/%Y') } }
= f.input :local_date, label: 'Date', as: :string, required: true, input_html: { data: { value: @event.date_and_time.try(:strftime, '%d/%m/%Y') } }
.col-12.col-md-6
= f.input :begins_at, as: :string, required: true, input_html: { data: { value: @event.date_and_time.time.strftime('%H:%M') }}
.col-6.col-md-6
= f.input :ends_at, as: :string, required: true, input_html: { data: { value: @event.ends_at.strftime('%H:%M') }}
= f.input :local_time, label: 'Starts at', as: :string, required: true, input_html: { data: { value: @event.time.try(:strftime, '%H:%M') } }
.col-12.col-md-6
= f.input :local_end_time, label: 'Ends at', as: :string, required: true, input_html: { data: { value: @event.ends_at.try(:strftime, '%H:%M') } }
.col-12
.mb-3
%label.form-label{ for: "event_timezone" } Time zone
= f.time_zone_select :time_zone, nil, {}, { class: 'form-control'}
.col-12
= f.input :description, as: :text, input_html: { rows: 3 },
hint: 'Use this space to write an invitation message and description of the event. This copy will also be used in the email invitation. You can use HTML here!'
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/simple_form_bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
b.use :input, class: 'form-check-input', error_class: 'is-invalid', valid_class: 'is-valid'
b.use :label, class: 'form-check-label'
b.use :full_error, wrap_with: { tag: 'div', class: 'invalid-feedback' }
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted' }
b.use :hint, wrap_with: { tag: 'small', class: 'form-text text-muted ms-1' }
end

# vertical input for radio buttons and check boxes
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220820215847_add_time_zone_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTimeZoneToEvents < ActiveRecord::Migration[4.2]
def change
add_column :events, :time_zone, :string, null: false, default: 'London'
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
t.boolean "surveys_required", default: false
t.string "audience"
t.boolean "virtual", default: false, null: false
t.string "time_zone", default: "London", null: false
t.index ["slug"], name: "index_events_on_slug", unique: true
t.index ["venue_id"], name: "index_events_on_venue_id"
end
Expand Down
1 change: 0 additions & 1 deletion spec/fabricators/event_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
student_spaces 2
slug { Fabricate.sequence(:slug) }
info Faker::Lorem.sentence
begins_at '11:00'
chapters { [Fabricate(:chapter)] }
after_build do |event|
Fabricate(:sponsorship, event: event, sponsor: Fabricate(:sponsor))
Expand Down
4 changes: 2 additions & 2 deletions spec/features/admin/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
fill_in 'Event Name', with: 'A test event'
fill_in 'Slug', with: 'a-test-event'
fill_in 'Date', with: date
fill_in 'Begins at', with: '16:00'
fill_in 'Starts at', with: '16:00'
fill_in 'Ends at', with: '18:00'
fill_in 'Description', with: 'A test event description'
fill_in 'RSVP instructions', with: 'Some instructions'
Expand Down Expand Up @@ -54,7 +54,7 @@
fill_in 'Event Name', with: 'A test virtual event'
fill_in 'Slug', with: 'a-test-virtual-event'
fill_in 'Date', with: date
fill_in 'Begins at', with: '16:00'
fill_in 'Starts at', with: '16:00'
fill_in 'Ends at', with: '18:00'
fill_in 'Description', with: 'A test virtual event description'
fill_in 'RSVP instructions', with: 'Some instructions'
Expand Down
3 changes: 3 additions & 0 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
RSpec.describe Event, type: :model do
subject(:event) { Fabricate(:event) }
include_examples "Invitable", :invitation, :event
include_examples DateTimeConcerns, :event

context 'validates' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:slug) }
it { is_expected.to validate_presence_of(:info) }
it { is_expected.to validate_presence_of(:schedule) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_presence_of(:date_and_time) }
it { is_expected.to validate_presence_of(:ends_at) }
it { is_expected.to validate_uniqueness_of(:slug) }
it { is_expected.to validate_numericality_of(:coach_spaces) }
it { is_expected.to validate_numericality_of(:student_spaces) }
Expand Down

0 comments on commit 5d2170f

Please sign in to comment.