From a9d6faf1a364011918f7245922777c626036e1ec Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Thu, 16 Jul 2020 11:25:20 -0700 Subject: [PATCH] Support forcing the order of rooms in the schedule --- app/controllers/admin/rooms_controller.rb | 2 +- app/models/room.rb | 3 +++ app/views/admin/rooms/_form.html.haml | 5 ++--- app/views/admin/rooms/index.html.haml | 5 ++++- db/migrate/20200716181602_add_order_to_rooms.rb | 5 +++++ db/schema.rb | 3 ++- 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20200716181602_add_order_to_rooms.rb diff --git a/app/controllers/admin/rooms_controller.rb b/app/controllers/admin/rooms_controller.rb index 58c2fd83..fd31207d 100644 --- a/app/controllers/admin/rooms_controller.rb +++ b/app/controllers/admin/rooms_controller.rb @@ -48,7 +48,7 @@ module Admin private def room_params - params.require(:room).permit(:name, :size, :url) + params.require(:room).permit(:name, :size, :url, :order) end end end diff --git a/app/models/room.rb b/app/models/room.rb index 4bd88834..027e9c83 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -13,6 +13,9 @@ class Room < ApplicationRecord validates :name, :venue_id, presence: true validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true + validates :order, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true + + default_scope { order(order: :asc) } def conference venue.conference diff --git a/app/views/admin/rooms/_form.html.haml b/app/views/admin/rooms/_form.html.haml index 951e4094..3137f108 100644 --- a/app/views/admin/rooms/_form.html.haml +++ b/app/views/admin/rooms/_form.html.haml @@ -11,8 +11,7 @@ = semantic_form_for(@room, url: (@room.new_record? ? admin_conference_venue_rooms_path : admin_conference_venue_room_path(@conference.short_title, @room))) do |f| = f.input :name, input_html: { autofocus: true } = f.input :size, label: 'Capacity', input_html: {size: 5} - = f.input :url, label: 'URL' - %p.small - The URL is only visible to registered attendees. + = f.input :order, label: 'Order', input_html: {size: 5}, hint: 'Force the order of rooms in the schedule.' + = f.input :url, label: 'URL', hint: 'The URL is only visible to registered attendees.' %p.text-right = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/admin/rooms/index.html.haml b/app/views/admin/rooms/index.html.haml index fd548d59..96487311 100644 --- a/app/views/admin/rooms/index.html.haml +++ b/app/views/admin/rooms/index.html.haml @@ -12,15 +12,18 @@ %thead %th Name %th Capacity + %th Order %th URL %th Actions %tbody - @rooms.each_with_index do |room, index| %tr - %td + %th = room.name %td = room.size + %td + = room.order %td = room.url %td diff --git a/db/migrate/20200716181602_add_order_to_rooms.rb b/db/migrate/20200716181602_add_order_to_rooms.rb new file mode 100644 index 00000000..d6e5f758 --- /dev/null +++ b/db/migrate/20200716181602_add_order_to_rooms.rb @@ -0,0 +1,5 @@ +class AddOrderToRooms < ActiveRecord::Migration[5.2] + def change + add_column :rooms, :order, :int + end +end diff --git a/db/schema.rb b/db/schema.rb index a29ab329..b2b6ee20 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_15_034647) do +ActiveRecord::Schema.define(version: 2020_07_16_181602) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -408,6 +408,7 @@ ActiveRecord::Schema.define(version: 2020_07_15_034647) do t.integer "size" t.integer "venue_id", null: false t.text "url" + t.integer "order" end create_table "schedules", force: :cascade do |t|