mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-17 05:34:04 +00:00
Merge pull request #1143 from Ana06/schedule-times
Make the schedule times changeable
This commit is contained in:
commit
390e68b1ac
10 changed files with 71 additions and 12 deletions
|
|
@ -95,7 +95,9 @@ Metrics/BlockNesting:
|
|||
Max: 4
|
||||
|
||||
Metrics/ClassLength:
|
||||
Max: 575
|
||||
Max: 300
|
||||
Exclude:
|
||||
- 'app/models/conference.rb'
|
||||
|
||||
# avoid redundunt curly braces when it is obvious that hash is used
|
||||
Style/BracesAroundHashParameters:
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ module Admin
|
|||
short_title = @conference.short_title
|
||||
@conference.assign_attributes(conference_params)
|
||||
send_mail_on_conf_update = @conference.notify_on_dates_changed?
|
||||
delete_event_schedules if @conference.start_hour_changed? || @conference.end_hour_changed?
|
||||
|
||||
if @conference.update_attributes(conference_params)
|
||||
ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update
|
||||
|
|
@ -177,7 +178,8 @@ module Admin
|
|||
|
||||
def conference_params
|
||||
params.require(:conference).permit(:title, :short_title, :description, :timezone,
|
||||
:start_date, :end_date, :rooms_attributes, :tracks_attributes,
|
||||
:start_date, :end_date, :start_hour, :end_hour,
|
||||
:rooms_attributes, :tracks_attributes,
|
||||
:tickets_attributes, :event_types_attributes,
|
||||
:picture, :picture_cache, :questions_attributes,
|
||||
:question_ids, :answers_attributes, :answer_ids, :difficulty_levels_attributes,
|
||||
|
|
@ -187,5 +189,14 @@ module Admin
|
|||
:targets, :targets_attributes,
|
||||
:campaigns, :campaigns_attributes, :registration_limit)
|
||||
end
|
||||
|
||||
def delete_event_schedules
|
||||
event_schedules = EventSchedule.select do |e|
|
||||
e.start_time.strftime('%H').to_i < @conference.start_hour ||
|
||||
e.end_time.strftime('%H').to_i > @conference.end_hour ||
|
||||
(e.end_time.strftime('%H').to_i == @conference.end_hour && e.end_time.strftime('%M').to_i > 0)
|
||||
end
|
||||
event_schedules.each(&:destroy)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,16 +14,15 @@ class SchedulesController < ApplicationController
|
|||
@events_xml = schedules.map(&:event).group_by{ |event| event.time.to_date } if schedules
|
||||
@dates = @conference.start_date..@conference.end_date
|
||||
@step_minutes = EventType::LENGTH_STEP.minutes
|
||||
@conf_start = 9
|
||||
conf_end = 20
|
||||
@conf_period = conf_end - @conf_start
|
||||
@conf_start = @conference.start_hour
|
||||
@conf_period = @conference.end_hour - @conf_start
|
||||
|
||||
# the schedule takes you to today if it is a date of the schedule
|
||||
@current_day = @conference.current_conference_day
|
||||
@day = @current_day.present? ? @current_day : @dates.first
|
||||
return unless @current_day
|
||||
# the schedule takes you to the current time if it is beetween the start and the end time.
|
||||
@hour_column = @conference.hours_from_start_time(@conf_start, conf_end)
|
||||
@hour_column = @conference.hours_from_start_time(@conf_start, @conference.end_hour)
|
||||
end
|
||||
|
||||
def events
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
# rubocop:disable Metrics/ClassLength
|
||||
##
|
||||
# This class represents a conference
|
||||
class Conference < ActiveRecord::Base
|
||||
require 'uri'
|
||||
serialize :events_per_week, Hash
|
||||
|
|
@ -54,7 +51,9 @@ class Conference < ActiveRecord::Base
|
|||
validates_presence_of :title,
|
||||
:short_title,
|
||||
:start_date,
|
||||
:end_date
|
||||
:end_date,
|
||||
:start_hour,
|
||||
:end_hour
|
||||
|
||||
validates_uniqueness_of :short_title
|
||||
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
|
||||
|
|
@ -62,6 +61,7 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
# This validation is needed since a conference with a start date greater than the end date is not possible
|
||||
validate :valid_date_range?
|
||||
validate :valid_times_range?
|
||||
before_create :generate_guid
|
||||
before_create :add_color
|
||||
before_create :create_email_settings
|
||||
|
|
@ -678,6 +678,19 @@ class Conference < ActiveRecord::Base
|
|||
errors.add(:start_date, 'Start date is greater than End date') if start_date && end_date && start_date > end_date
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if start hour of the conference is greater or equal than the end hour
|
||||
# and that both hours are beetween 0 and 24
|
||||
#
|
||||
# Reports an error when such a condition is found
|
||||
def valid_times_range?
|
||||
if start_hour && end_hour
|
||||
errors.add(:start_hour, 'is lower than 0') if start_hour < 0
|
||||
errors.add(:end_hour, 'is lower or equal than start hour') if end_hour <= start_hour
|
||||
errors.add(:end_hour, 'is greater than 24') if end_hour > 24
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Calculates the weeks from a start and a end week.
|
||||
#
|
||||
|
|
@ -1065,4 +1078,3 @@ class Conference < ActiveRecord::Base
|
|||
result
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/ClassLength
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
= f.input :timezone, :as => :time_zone, :hint => "The conference time zone"
|
||||
= f.input :start_date, :as => :string, :input_html => { :id => "conference-start-datepicker", :readonly => "readonly" }
|
||||
= f.input :end_date, :as => :string, :input_html => { :id => "conference-end-datepicker", :readonly => "readonly" }
|
||||
= f.input :start_hour, :input_html => {size: 2, type: 'number', min: 0, max: 23}
|
||||
= f.input :end_hour, :input_html => {size: 2, type: 'number', min: 1, max: 24}
|
||||
= f.inputs name: "Registrations" do
|
||||
= f.input :registration_limit, as: :number, in: 0..9999, hint: "Limit the number of registrations to the conference (0 no limit)"
|
||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
.room-name
|
||||
- room_date_event_schedules = date_event_schedules.select{ |e| e.room == room }
|
||||
= room.name
|
||||
- (9*cells_per_hour..18*cells_per_hour).each do |slot|
|
||||
- (@conference.start_hour * cells_per_hour..@conference.end_hour * cells_per_hour).each do |slot|
|
||||
- hour = slot / cells_per_hour
|
||||
- minutes = (EventType::LENGTH_STEP * (slot % cells_per_hour)).to_s.rjust(2, '0')
|
||||
- time = "#{hour}:#{minutes}"
|
||||
|
|
|
|||
6
db/migrate/20160815094215_add_times_to_conferences.rb
Normal file
6
db/migrate/20160815094215_add_times_to_conferences.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class AddTimesToConferences < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :conferences, :start_hour, :integer, default: 9
|
||||
add_column :conferences, :end_hour, :integer, default: 20
|
||||
end
|
||||
end
|
||||
|
|
@ -98,6 +98,8 @@ ActiveRecord::Schema.define(version: 20170213145807) do
|
|||
t.text "description"
|
||||
t.integer "registration_limit", default: 0
|
||||
t.string "picture"
|
||||
t.integer "start_hour", default: 9
|
||||
t.integer "end_hour", default: 20
|
||||
end
|
||||
|
||||
create_table "conferences_questions", id: false, force: :cascade do |t|
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ FactoryGirl.define do
|
|||
timezone { Faker::Address.time_zone }
|
||||
start_date { Date.today }
|
||||
end_date { 6.days.from_now }
|
||||
start_hour 9
|
||||
end_hour 20
|
||||
registration_limit 0
|
||||
description { Faker::Hipster.paragraph }
|
||||
|
||||
|
|
|
|||
|
|
@ -1545,6 +1545,14 @@ describe Conference do
|
|||
should validate_presence_of(:end_date)
|
||||
end
|
||||
|
||||
it 'is not valid without a start date' do
|
||||
should validate_presence_of(:start_hour)
|
||||
end
|
||||
|
||||
it 'is not valid without an end date' do
|
||||
should validate_presence_of(:end_hour)
|
||||
end
|
||||
|
||||
it 'is not valid with a duplicate short title' do
|
||||
should validate_uniqueness_of(:short_title)
|
||||
end
|
||||
|
|
@ -1572,6 +1580,21 @@ describe Conference do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'valid_times_range?' do
|
||||
|
||||
it 'is not valid if start hour is lower than 0' do
|
||||
expect(subject.start_hour).to be >= 0
|
||||
end
|
||||
|
||||
it 'is not valid if end hour is lower or equal than start hour' do
|
||||
expect(subject.start_hour).to be < subject.end_hour
|
||||
end
|
||||
|
||||
it 'is not valid if end hour is greater than 24' do
|
||||
expect(subject.end_hour).to be <= 24
|
||||
end
|
||||
end
|
||||
|
||||
describe 'before create callbacks' do
|
||||
|
||||
it 'has an email setting after creation' do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue