Skip to content

Commit

Permalink
handle errors and fix join form
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-arts committed Jun 11, 2018
1 parent 2b0f75e commit 2b065eb
Show file tree
Hide file tree
Showing 23 changed files with 114 additions and 239 deletions.
3 changes: 3 additions & 0 deletions app/assets/javascripts/errors.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
7 changes: 7 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ a {
width: 60%;
}

.center-page {
position: absolute;
top: 50%;
left:50%;
transform: translate(-50%,-50%);
}

iframe{
position: absolute;
top: 0;
Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/errors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Errors controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
8 changes: 0 additions & 8 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ def allow_greenlight_users?
end
helper_method :allow_greenlight_users?

# Generate a URL to start a meeting.
def owner_meeting_url
opts = default_meeting_options
opts[:user_is_moderator] = true
@room.meeting.join_path(current_user.name, opts)
end
helper_method :owner_meeting_url

# Determines if a form field needs the is-invalid class.
def form_is_invalid?(obj, key)
'is-invalid' if !obj.errors.messages[key].empty?
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ErrorsController < ApplicationController

def not_found
render status: 404
end

def unprocessable
render status: 422
end

def internal_error
render status: 500
end
end
12 changes: 8 additions & 4 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,18 @@ def join
opts = default_meeting_options

# Assign join name if passed.
if params[@room.invite_path]
if params[@room.invite_path][:join_name]
@join_name = params[@room.invite_path][:join_name]
else
# Join name not passed.
return
end

if @room.is_running?
if current_user
redirect_to @room.join_path(current_user, opts)
elsif join_name = params[:join_name] || params[@room.invite_path][:join_name]
redirect_to @room.join_path(current_user.name, opts, current_user.uid)
else
join_name = params[@room.invite_path][:join_name]
redirect_to @room.join_path(join_name, opts)
end
else
Expand All @@ -65,7 +69,7 @@ def start
opts = default_meeting_options
opts[:user_is_moderator] = true

redirect_to @room.join_path(current_user, opts)
redirect_to @room.join_path(current_user.name, opts, current_user.uid)

# Notify users that the room has started.
# Delay 5 seconds to allow for server start, although the request will retry until it succeeds.
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/errors_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ErrorsHelper
end
37 changes: 17 additions & 20 deletions app/models/room.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Room < ApplicationRecord
belongs_to :owner, class_name: 'User', foreign_key: :user_id
has_one :meeting

ROOM_ICONS = %w(circle star certificate play cloud heart square bookmark cog)
RETURNCODE_SUCCESS = "SUCCESS"

# Determines if a user owns a room.
Expand All @@ -21,19 +20,6 @@ def is_running?
bbb.is_meeting_running?(bbb_id)
end

# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end

# Determines the invite URL for the room.
def invite_path
"/r/#{uid}"
Expand Down Expand Up @@ -68,7 +54,7 @@ def start_session(options = {})
end

# Returns a URL to join a user into a meeting.
def join_path(user, options = {})
def join_path(name, options = {}, uid = nil)
# Create the meeting if it isn't running.
start_session(options) unless is_running?

Expand All @@ -95,10 +81,10 @@ def join_path(user, options = {})
end

# Generate the join URL.
if user.is_a?(User)
bbb.join_meeting_url(bbb_id, user.name, password, {userID: user.uid})
if uid
bbb.join_meeting_url(bbb_id, name, password, {userID: uid})
else
bbb.join_meeting_url(bbb_id, user, password)
bbb.join_meeting_url(bbb_id, name, password)
end
end

Expand All @@ -109,6 +95,19 @@ def notify_waiting
})
end

# Retrieves all the users in a room.
def participants
begin
res = bbb.get_meeting_info(bbb_id, nil)
res[:attendees].map do |att|
User.find_by(uid: att[:userID], name: att[:fullName])
end
rescue BigBlueButton::BigBlueButtonException => exc
# The meeting is most likely not running.
[]
end
end

# Fetches all recordings for a meeting.
def recordings
res = bbb.get_recordings(meetingID: bbb_id)
Expand Down Expand Up @@ -168,8 +167,6 @@ def bbb
def setup
self.uid = [owner.firstname, (0...9).map { (65 + rand(26)).chr }.join].join('-').downcase
self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s

self.icon = ROOM_ICONS.sample
end

# Rereives the loadbalanced BigBlueButton credentials for a user.
Expand Down
7 changes: 7 additions & 0 deletions app/views/errors/internal_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oh no!</h1>
<h3>Looks like something went wrong on our end.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>
8 changes: 8 additions & 0 deletions app/views/errors/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Whoops!</h1>
<h2>Looks like we can't find that resource.</h2>
<h3>Is it possible its been removed?</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>
7 changes: 7 additions & 0 deletions app/views/errors/unprocessable.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="text-center center-page">
<h1 class="display-2 font-weight-400">Oops!</h1>
<h3>Request is unprocessable.</h3>
<%= link_to root_url do %>
<h4>Return to home page.</h4>
<% end %>
</div>
7 changes: 6 additions & 1 deletion app/views/rooms/join.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<%= render 'shared/room_event' do %>
<%= form_for room_path, method: :post do |f| %>
<div class="input-group" style="height: 48px;">
<%= f.text_field :join_name, class: "form-control main-large", placeholder: "Enter your name!", value: "#{current_user ? current_user.name : ''}" %>
<%= f.text_field :join_name,
required: true,
class: "form-control main-large",
placeholder: "Enter your name!",
value: "#{current_user ? current_user.name : ''}",
readonly: !current_user.nil? %>
<span class="input-group-append">
<%= f.submit "Join", class: "btn btn-primary px-7 main-large" %>
</span>
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/components/_subtitle.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<p class="subtitle"><%= subtitle %></p>
</div>
<% if search %>
<!--
<div class="col-3">
<div class="input-icon">
<span class="input-icon-addon">
Expand All @@ -11,6 +12,7 @@
<input type="text" class="form-control btn-pill" placeholder="Search...">
</div>
</div>
-->
<% end %>
</div>
<hr class="mt-0">
4 changes: 3 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Application < Rails::Application
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

config.exceptions_app = self.routes

config.loadbalanced_configuration = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true")

# Setup BigBlueButton configuration.
Expand All @@ -33,4 +35,4 @@ class Application < Rails::Application
# Determine if GreenLight should allow non-omniauth signup/login.
config.greenlight_accounts = (ENV['ALLOW_GREENLIGHT_ACCOUNTS'] == "true")
end
end
end
4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# Do not eager load code on boot.
config.eager_load = false

# Show full error reports.
config.consider_all_requests_local = true
# Show custom error pages in development.
config.consider_all_requests_local = false

# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Rails.application.routes.draw do

# Error routes.
match '/404', to: 'errors#not_found', via: :all
match '/422', to: 'errors#unprocessable', via: :all
match '/500', to: 'errors#internal_error', via: :all

# Room resources.
resources :rooms, only: [:create, :show, :destroy], param: :room_uid, path: '/r'

Expand Down
1 change: 0 additions & 1 deletion db/migrate/20180504131705_create_rooms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def change
t.string :name, index: true
t.string :uid, index: true
t.string :bbb_id, index: true
t.string :icon, index: true
t.integer :sessions, index: true, default: 0
t.datetime :last_session, index: true

Expand Down
2 changes: 0 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
t.string "name"
t.string "uid"
t.string "bbb_id"
t.string "icon"
t.integer "sessions", default: 0
t.datetime "last_session"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["bbb_id"], name: "index_rooms_on_bbb_id"
t.index ["icon"], name: "index_rooms_on_icon"
t.index ["last_session"], name: "index_rooms_on_last_session"
t.index ["name"], name: "index_rooms_on_name"
t.index ["sessions"], name: "index_rooms_on_sessions"
Expand Down
67 changes: 0 additions & 67 deletions public/404.html

This file was deleted.

Loading

0 comments on commit 2b065eb

Please sign in to comment.