mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Refactoring rooms
This commit is contained in:
parent
2c98ba9711
commit
6a373b5f6c
11 changed files with 135 additions and 52 deletions
|
|
@ -1,26 +1,55 @@
|
||||||
module Admin
|
module Admin
|
||||||
class RoomsController < Admin::BaseController
|
class RoomsController < Admin::BaseController
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
authorize_resource through: :conference
|
load_and_authorize_resource through: :conference
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize! :index, Room.new(conference_id: @conference.id)
|
authorize! :index, Room.new(conference_id: @conference.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def edit; end
|
||||||
render :rooms_list
|
|
||||||
|
def new
|
||||||
|
@room = @conference.rooms.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@room = @conference.rooms.new(room_params)
|
||||||
|
if @room.save
|
||||||
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||||
|
notice: 'Room successfully created.')
|
||||||
|
else
|
||||||
|
flash[:error] = "Creating Room failed: #{@room.errors.full_messages.join('. ')}."
|
||||||
|
render :new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @conference.update_attributes(params[:conference])
|
if @room.update_attributes(room_params)
|
||||||
redirect_to(admin_conference_rooms_path(
|
redirect_to(admin_conference_rooms_path(
|
||||||
conference_id: @conference.short_title),
|
conference_id: @conference.short_title),
|
||||||
notice: 'Rooms were successfully updated.')
|
notice: 'Room successfully updated.')
|
||||||
else
|
else
|
||||||
redirect_to(admin_conference_rooms_path(
|
flash[:error] = "Update Room failed: #{@room.errors.full_messages.join('. ')}."
|
||||||
conference_id: @conference.short_title),
|
render :edit
|
||||||
notice: 'Room update failed.')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @room.destroy
|
||||||
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||||
|
notice: 'Room successfully deleted.')
|
||||||
|
else
|
||||||
|
redirect_to(admin_conference_rooms_path(conference_id: @conference.short_title),
|
||||||
|
error: 'Destroying room failed! ' \
|
||||||
|
"#{@room.errors.full_messages.join('. ')}.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def room_params
|
||||||
|
params[:room]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,16 @@ class Room < ActiveRecord::Base
|
||||||
|
|
||||||
before_create :generate_guid
|
before_create :generate_guid
|
||||||
|
|
||||||
|
validates :name, presence: true
|
||||||
|
|
||||||
|
validates :size, numericality: { only_integer: true, greater_than: 0 }, allow_nil: true
|
||||||
|
|
||||||
|
validates :size, presence: true, if: :public?
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_guid
|
def generate_guid
|
||||||
guid = SecureRandom.urlsafe_base64
|
guid = SecureRandom.urlsafe_base64
|
||||||
# begin
|
|
||||||
# guid = SecureRandom.urlsafe_base64
|
|
||||||
# end while Person.where(:guid => guid).exists?
|
|
||||||
self.guid = guid
|
self.guid = guid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
4
app/views/admin/rooms/_form.html.haml
Normal file
4
app/views/admin/rooms/_form.html.haml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
= f.input :name
|
||||||
|
= f.input :size, :input_html => {:size => 5}
|
||||||
|
= f.input :public, :as => :boolean
|
||||||
|
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
<div class="nested-fields">
|
|
||||||
<%= f.inputs do %>
|
|
||||||
<%= f.input :name %>
|
|
||||||
<%= f.input :size, :input_html => {:size => 5} %>
|
|
||||||
<%= f.input :public, :as => :boolean %>
|
|
||||||
<%= remove_association_link :room, f %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
8
app/views/admin/rooms/edit.html.haml
Normal file
8
app/views/admin/rooms/edit.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
%h1 Editing Room
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col-md-8
|
||||||
|
= semantic_form_for @room, url: admin_conference_room_path(conference_id: @conference.short_title, id: @room.id) do |f|
|
||||||
|
= render 'form', f: f
|
||||||
|
|
||||||
|
= link_to 'Back', admin_conference_rooms_path
|
||||||
|
|
@ -1,5 +1,32 @@
|
||||||
.row
|
%h1 Rooms
|
||||||
.col-md-8
|
|
||||||
= semantic_form_for(@conference, :url => admin_conference_room_path(@conference.short_title, @conference.rooms)) do |f|
|
- if @conference.rooms.any?
|
||||||
= dynamic_association :rooms, "Rooms", f
|
.row
|
||||||
= f.action :submit, :as => :button, :button_html => {:class => "btn btn-primary"}
|
.col-md-12
|
||||||
|
%table.table
|
||||||
|
%thead
|
||||||
|
%th #
|
||||||
|
%th Name
|
||||||
|
%th Size
|
||||||
|
%th Public
|
||||||
|
%th Edit
|
||||||
|
%th Delete
|
||||||
|
%tbody
|
||||||
|
- @conference.rooms.each_with_index do |room, index|
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
= index + 1
|
||||||
|
%td
|
||||||
|
= room.name
|
||||||
|
%td
|
||||||
|
= room.size
|
||||||
|
%td
|
||||||
|
= room.public
|
||||||
|
%td
|
||||||
|
= link_to 'Edit', edit_admin_conference_room_path(@conference.short_title, room.id),
|
||||||
|
method: :get, class: 'btn btn-primary'
|
||||||
|
%td
|
||||||
|
= link_to 'Delete', admin_conference_room_path(@conference.short_title, room.id),
|
||||||
|
method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete #{room.name}?" }
|
||||||
|
|
||||||
|
= link_to 'New Room', new_admin_conference_room_path(@conference.short_title), class: 'btn btn-success'
|
||||||
|
|
|
||||||
7
app/views/admin/rooms/new.html.haml
Normal file
7
app/views/admin/rooms/new.html.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 New Room
|
||||||
|
.row
|
||||||
|
.col-md-8
|
||||||
|
= semantic_form_for @room, url: admin_conference_rooms_path(conference_id: @conference.short_title) do |f|
|
||||||
|
= render 'form', f: f
|
||||||
|
|
||||||
|
= link_to 'Back', admin_conference_rooms_path
|
||||||
|
|
@ -44,7 +44,7 @@ Osem::Application.routes.draw do
|
||||||
|
|
||||||
resources :difficulty_levels, only: [:show, :update, :index]
|
resources :difficulty_levels, only: [:show, :update, :index]
|
||||||
|
|
||||||
resources :rooms, only: [:show, :update, :index]
|
resources :rooms, except: [:show]
|
||||||
|
|
||||||
resources :tracks, only: [:show, :update, :index]
|
resources :tracks, only: [:show, :update, :index]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class SetRoomPublicDefaultToFalse < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column :rooms, :public, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141106141750) do
|
ActiveRecord::Schema.define(version: 20141109172204) do
|
||||||
|
|
||||||
create_table "ahoy_events", force: true do |t|
|
create_table "ahoy_events", force: true do |t|
|
||||||
t.uuid "visit_id"
|
t.uuid "visit_id"
|
||||||
|
|
@ -369,11 +369,11 @@ ActiveRecord::Schema.define(version: 20141106141750) do
|
||||||
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id"
|
add_index "roles_users", ["user_id", "role_id"], name: "index_roles_users_on_user_id_and_role_id"
|
||||||
|
|
||||||
create_table "rooms", force: true do |t|
|
create_table "rooms", force: true do |t|
|
||||||
t.string "guid", null: false
|
t.string "guid", null: false
|
||||||
t.integer "conference_id"
|
t.integer "conference_id"
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.integer "size"
|
t.integer "size"
|
||||||
t.boolean "public", default: true
|
t.boolean "public", default: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "social_events", force: true do |t|
|
create_table "social_events", force: true do |t|
|
||||||
|
|
|
||||||
|
|
@ -6,39 +6,47 @@ feature Room do
|
||||||
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
|
let!(:organizer) { create(:user, role_ids: [organizer_role.id]) }
|
||||||
|
|
||||||
shared_examples 'rooms' do
|
shared_examples 'rooms' do
|
||||||
scenario 'adds and updates rooms', feature: true, js: true do
|
scenario 'adds a room', feature: true, js: true do
|
||||||
|
|
||||||
sign_in organizer
|
sign_in organizer
|
||||||
visit admin_conference_rooms_path(
|
visit admin_conference_rooms_path(
|
||||||
conference_id: conference.short_title)
|
conference_id: conference.short_title)
|
||||||
|
|
||||||
|
expect(page.has_content?('Room Name')).to be false
|
||||||
|
expect(page.has_content?('100')).to be false
|
||||||
|
|
||||||
# Add room
|
# Add room
|
||||||
click_link 'Add room'
|
click_link 'New Room'
|
||||||
expect(page.all('div.nested-fields').count == 1).to be true
|
|
||||||
|
|
||||||
page.
|
fill_in 'room_name', with: 'Room Name'
|
||||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) input').
|
fill_in 'room_size', with: '100'
|
||||||
set('Example room')
|
|
||||||
|
|
||||||
page.
|
click_button 'Create Room'
|
||||||
find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) input').
|
|
||||||
set('100')
|
|
||||||
|
|
||||||
click_button 'Update Conference'
|
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
expect(flash).to eq('Rooms were successfully updated.')
|
expect(flash).to eq('Room successfully created.')
|
||||||
expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(1) input').
|
|
||||||
value).to eq('Example room')
|
|
||||||
expect(find('div.nested-fields:nth-of-type(1) div:nth-of-type(2) input').
|
|
||||||
value).to eq('100')
|
|
||||||
|
|
||||||
# Remove room
|
expect(page.has_content?('Room Name')).to be true
|
||||||
click_link 'Remove room'
|
expect(page.has_content?('100')).to be true
|
||||||
expect(page.all('div.nested-fields').count == 0).to be true
|
end
|
||||||
click_button 'Update Conference'
|
|
||||||
expect(flash).to eq('Rooms were successfully updated.')
|
scenario 'updates a room', feature: true, js: true do
|
||||||
expect(page.all('div.nested-fields').count == 0).to be true
|
room = create(:room, conference_id: conference.id)
|
||||||
|
sign_in organizer
|
||||||
|
visit edit_admin_conference_room_path(
|
||||||
|
conference_id: conference.short_title, id: room.id)
|
||||||
|
|
||||||
|
fill_in 'room_name', with: 'Room Name'
|
||||||
|
fill_in 'room_size', with: '100'
|
||||||
|
|
||||||
|
click_button 'Update Room'
|
||||||
|
|
||||||
|
# Validations
|
||||||
|
expect(flash).to eq('Room successfully updated.')
|
||||||
|
expect(page.has_content?('Room Name')).to be true
|
||||||
|
expect(page.has_content?('100')).to be true
|
||||||
|
room.reload
|
||||||
|
expect(room.name).to eq('Room Name')
|
||||||
|
expect(room.size).to eq(100)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue