Skip to content

Commit

Permalink
Merge pull request #343 from jmalcic/fix-times
Browse files Browse the repository at this point in the history
Fix times
  • Loading branch information
jmalcic committed Apr 3, 2021
2 parents 8130ae8 + 9508fb0 commit 6b7b482
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.1
2.7.2
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
spina-admin-conferences (1.3.10)
spina-admin-conferences (1.3.11)
icalendar (~> 2.5)
rails (~> 6.0)
rails-i18n (~> 6.0)
Expand Down Expand Up @@ -161,7 +161,7 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.0)
marcel (1.0.1)
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.0.3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def build_parts
def conference_params # rubocop:disable Metrics/MethodLength
params.require(:admin_conferences_conference).permit(:start_date, :finish_date, :name,
events_attributes:
%i[id name date start_time finish_time description location],
%i[id name start_datetime finish_datetime description location],
parts_attributes:
[:id, :title, :name, :partable_type, :partable_id,
{ partable_attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def set_presentation
end

def set_conferences
@conferences = Conference.all.to_json methods: %i[name localized_dates],
@conferences = Conference.all.to_json methods: %i[name],
include:
{ presentation_types:
{ methods: [:name], include: { sessions: { methods: [:name] } } } }
Expand All @@ -113,7 +113,7 @@ def set_tabs
end

def presentation_params
params.require(:admin_conferences_presentation).permit(:title, :abstract, :session_id, :date, :start_time,
params.require(:admin_conferences_presentation).permit(:title, :abstract, :session_id, :start_datetime,
presenter_ids: [],
attachments_attributes:
%i[id attachment_id attachment_type_id _destroy])
Expand Down
5 changes: 2 additions & 3 deletions app/jobs/spina/admin/conferences/presentation_import_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class PresentationImportJob < ImportJob
# == Columns
# The CSV should has the following columns. Make sure to include the column names in the header row.
# +session_id+:: The id of the associated session.
# +date+:: The date of the presentation, in ISO 8601 format.
# +start_time+:: The start time of the presentation, in HH:MM format.
# +start_datetime+:: The start time of the presentation, in ISO 8601 format.
# +title+:: The title of the presentation for the default locale.
# +abstract+:: The presentation's abstract.
# +presenter_ids+:: The ids of the presenters.
Expand All @@ -30,7 +29,7 @@ def perform(csv)

def presentation_params(params)
params = ActionController::Parameters.new(params)
params.permit :title, :date, :start_time, :abstract, :session_id, presenter_ids: []
params.permit :title, :start_datetime, :abstract, :session_id, presenter_ids: []
end
end
end
Expand Down
79 changes: 21 additions & 58 deletions app/models/spina/admin/conferences/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Conferences
# Events during conferences.
#
# = Validators
# Presence:: {#name}, {#start_time}, {#finish_time}.
# Conference date (using {ConferenceDateValidator}):: {#start_time}, {#finish_time}.
# Presence:: {#name}, {#:start_datetime}, {#:finish_datetime}, {#:location}.
# Conference date (using {ConferenceDateValidator}):: {#start_datetime}, {#finish_datetime}.
# @see ConferenceDateValidator
#
# = Translations
Expand All @@ -18,23 +18,36 @@ class Event < ApplicationRecord
default_scope { includes(:translations) }

# @!attribute [rw] name
# @return [String, nil] the translated name of the conference
# @return [String, nil] the translated name of the event
# @!attribute [rw] description
# @return [String, nil] the translated description of the conference
# @return [String, nil] the translated description of the event
# @!attribute [rw] start_datetime
# @return [ActiveSupport::TimeWithZone, nil] the start time of the event
# @!attribute [rw] finish_datetime
# @return [ActiveSupport::TimeWithZone, nil] the finish time of the event
# @!attribute [rw] location
# @return [String, nil] the translated location of the conference
# @return [String, nil] the translated location of the event
translates :name, :description, :location, fallbacks: true

# @return [ActiveRecord::Relation] all events, ordered by name
scope :sorted, -> { i18n.order :name }

# @!attribute [rw] start_time
# @return [ActiveSupport::TimeWithZone, nil] the start time (alias)
# @see #start_datetime
alias_attribute :start_time, :start_datetime
# @!attribute [rw] :finish_time
# @return [ActiveSupport::TimeWithZone, nil] the finish time (alias)
# @see #finish_datetime
alias_attribute :finish_time, :finish_datetime

# @!attribute [rw] conference
# @return [Conference, nil] directly associated conferences
belongs_to :conference, -> { includes(:translations) }, inverse_of: :events, touch: true

validates :name, :date, :start_time, :start_datetime, :finish_time, :finish_datetime, :location, presence: true
validates :date, 'spina/admin/conferences/conference_date': true
validates :finish_time, 'spina/admin/conferences/finish_time': true
validates :name, :start_datetime, :finish_datetime, :location, presence: true
validates :start_datetime, :finish_datetime, 'spina/admin/conferences/conference_date': true
validates :finish_datetime, 'spina/admin/conferences/finish_time': true

# @return [Date, nil] the start date of the event. Nil if the event has no start date and time
def date
Expand All @@ -43,56 +56,6 @@ def date
start_datetime.to_date
end

# Sets the date of the presentation.
# @param date [Date] the new date
# @return [void]
def date=(date)
if date.blank? || date.to_date.blank?
self.start_datetime = nil
return
end

self.start_datetime = date.to_date + (start_datetime.try(:seconds_since_midnight) || 0).seconds
end

# @return [ActiveSupport::TimeWithZone, nil] the start time of the event. Nil if the event has no start date and time
def start_time
return if start_datetime.blank?

start_datetime
end

# Sets the start time of the event.
# @param start_time [ActiveSupport::TimeWithZone] the new start time
# @return [void]
def start_time=(start_time)
if start_time.blank?
self.start_datetime = nil
return
end

self.start_datetime = Time.parse(start_time, date).to_datetime.in_time_zone
end

# @return [ActiveSupport::TimeWithZone, nil] the finish time of the event. Nil if the event has no finish date and time
def finish_time
return if finish_datetime.blank?

finish_datetime
end

# Sets the finish time of the event.
# @param finish_time [ActiveSupport::TimeWithZone] the new finish time
# @return [void]
def finish_time=(finish_time)
if finish_time.blank?
self.finish_datetime = nil
return
end

self.finish_datetime = Time.parse(finish_time, date).to_datetime.in_time_zone
end

# @return [Icalendar::Event] the event as an iCal event
def to_event # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
event = Icalendar::Event.new
Expand Down
43 changes: 10 additions & 33 deletions app/models/spina/admin/conferences/presentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Conferences
# - {#title}
# - {#abstract}
class Presentation < ApplicationRecord
# @!attribute [rw] start_datetime
# @return [ActiveSupport::TimeWithZone, nil] the presentation start time

default_scope { includes(:translations) }

# @!attribute [rw] title
Expand Down Expand Up @@ -65,11 +68,16 @@ class Presentation < ApplicationRecord
association_foreign_key: :spina_conferences_delegate_id
accepts_nested_attributes_for :attachments, allow_destroy: true

validates :title, :date, :start_time, :start_datetime, :abstract, :presenters, presence: true
validates :date, 'spina/admin/conferences/conference_date': true
validates :title, :start_datetime, :abstract, :presenters, presence: true
validates :start_datetime, 'spina/admin/conferences/conference_date': true
validates_associated :presenters
validates_associated :attachments

# @!attribute [rw] start_time
# @return [ActiveSupport::TimeWithZone, nil] the start time (alias)
# @see #start_datetime
alias_attribute :start_time, :start_datetime

# Imports a presentation from CSV.
# @param file [String] the CSV file to be read
# @return [void]
Expand All @@ -85,37 +93,6 @@ def date
start_datetime.to_date
end

# Sets the date of the presentation.
# @param date [Date] the new date
# @return [void]
def date=(date)
if date.blank? || date.to_date.blank?
self.start_datetime = nil
return
end

self.start_datetime = date.to_date + (start_datetime.try(:seconds_since_midnight) || 0).seconds
end

# @return [ActiveSupport::TimeWithZone, nil] the start time of the presentation. Nil if the presentation has no start date and time
def start_time
return if start_datetime.blank?

start_datetime
end

# Sets the start time of the presentation.
# @param start_time [ActiveSupport::TimeWithZone] the new start time
# @return [void]
def start_time=(start_time)
if start_time.blank?
self.start_datetime = nil
return
end

self.start_datetime = Time.parse(start_time, date).to_datetime.in_time_zone
end

# @return [Icalendar::Event] the presentation as an iCal event
def to_event # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
event = Icalendar::Event.new
Expand Down
38 changes: 0 additions & 38 deletions app/models/spina/admin/conferences/time_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,6 @@ class TimePart < ApplicationRecord
has_many :parts, as: :partable
has_many :layout_parts, as: :layout_partable
has_many :structure_parts, as: :structure_partable

# @return [Date, nil] the date of the time part. Nil if the time part has no date and time
def date
return if content.blank?

content.to_date
end

# Sets the date of the time part.
# @param date [Date] the new date
# @return [void]
def date=(date)
if date.blank? || date.to_date.blank?
self.content = nil
return
end

self.content = date.to_date + (content.try(:seconds_since_midnight) || 0).seconds
end

# @return [ActiveSupport::TimeWithZone, nil] the time of the time part. Nil if the time part has no date and time
def time
return if content.blank?

content
end

# Sets the start time of the time part.
# @param time [ActiveSupport::TimeWithZone] the new time
# @return [void]
def time=(time)
if time.blank?
self.content = nil
return
end

self.content = Time.parse(time, date).to_datetime.in_time_zone
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@
.horizontal-form-content= f.text_field :name, placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:name), required: true

.structure-form-part
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :date
.horizontal-form-content= f.date_field :date, value: f.object.conference.start_date&.strftime("%Y-%m-%d"),
placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:date),
required: true
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :start_datetime
.horizontal-form-content= f.datetime_field :start_datetime,
placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:start_datetime), required: true

.structure-form-part
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :start_time
.horizontal-form-content= f.time_field :start_time,
value: (f.object.start_time.to_formatted_s(:time) unless f.object.start_time.blank?),
placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:start_time), required: true

.structure-form-part
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :finish_time
.horizontal-form-content= f.time_field :finish_time,
value: (f.object.finish_time.to_formatted_s(:time) unless f.object.finish_time.blank?),
placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:finish_time), required: true
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :finish_datetime
.horizontal-form-content= f.datetime_field :finish_datetime,
placeholder: Spina::Admin::Conferences::Event.human_attribute_name(:finish_datetime), required: true

.structure-form-part
.horizontal-form-label= Spina::Admin::Conferences::Event.human_attribute_name :location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,10 @@
.select-dropdown= select_tag :admin_conferences_presentation_type_id, options_from_collection_for_select((@presentation.conference || Spina::Admin::Conferences::Conference.first).presentation_types, :id, :name, (@presentation.presentation_type.id unless @presentation.presentation_type.blank?)), include_blank: true, required: true, data: { action: 'spina--admin--conferences--select-options#setVisibility','spina--admin--conferences--select_options_target': 'select', key_path: 'presentation_types', text_key: 'name' }
.select-dropdown= f.collection_select :session_id, (@presentation.presentation_type || Spina::Admin::Conferences::Conference.first).sessions, :id, :name, { include_blank: true }, required: true, data: {'spina--admin--conferences--select_options_target': 'select', key_path: 'presentation_types:sessions', text_key: 'name' }

.horizontal-form-group
.horizontal-form-label= Spina::Admin::Conferences::Presentation.human_attribute_name :date
.horizontal-form-content
.select-dropdown= f.select :date, (@presentation.conference || Spina::Admin::Conferences::Conference.first).dates.collect { |date| [l(date, format: :short), date.to_formatted_s(:iso8601)] }, { include_blank: true }, required: true, data: {'spina--admin--conferences--select_options_target': 'select', key_path: 'localized_dates', text_key: 'localization', value_key: 'date' }

.horizontal-form-group
.horizontal-form-label
= Spina::Admin::Conferences::Presentation.human_attribute_name :start_time
%small= t '.start_time_instructions'
.horizontal-form-content= f.time_field :start_time, value: (@presentation.start_time.to_formatted_s(:time) unless @presentation.start_time.blank?), placeholder: Spina::Admin::Conferences::Presentation.human_attribute_name(:start_time), required: true
= Spina::Admin::Conferences::Presentation.human_attribute_name :start_datetime
.horizontal-form-content= f.datetime_field :start_datetime, required: true

.horizontal-form-group
.horizontal-form-label= Spina::Admin::Conferences::Presentation.human_attribute_name :title
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.horizontal-form-label
= f.object.title
= f.fields_for :partable, f.object.partable do |ff|
.horizontal-form-content
.input-group
= ff.date_field :date
= ff.time_field :time
.horizontal-form-content
= f.fields_for :partable, f.object.partable do |ff|
= ff.datetime_field :content
11 changes: 5 additions & 6 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ en:
attributes:
spina/admin/conferences/conference:
name: Name
start_date: Start date
finish_date: Finish date
start_datetime: Start time
finish_datetime: Finish time
events: Events
spina/admin/conferences/event:
name: Name
location: Location
start_time: Start time
finish_time: Finish time
start_datetime: Start time
finish_datetime: Finish time
description: Description
spina/admin/conferences/delegate:
first_name: First name
Expand All @@ -313,8 +313,7 @@ en:
dietary_requirements: Dietary requirements
spina/admin/conferences/presentation:
title: Title
date: Date
start_time: Start time
start_datetime: Start time
abstract: Abstract
room_type: Type
presenters: Presenters
Expand Down
2 changes: 1 addition & 1 deletion lib/spina/admin/conferences/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Spina
module Admin
module Conferences
# Version number.
VERSION = '1.3.10'
VERSION = '1.3.11'
end
end
end
2 changes: 1 addition & 1 deletion test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0

config.time_zone = 'London'
config.time_zone = 'Ulaanbaatar'

# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
Expand Down
Loading

0 comments on commit 6b7b482

Please sign in to comment.