Merge pull request #11 from jfederico/master

Fixes and refactoring to views and controllers
This commit is contained in:
Jesus Federico 2016-10-19 14:03:17 -04:00 committed by GitHub
commit d26d4a86bd
16 changed files with 133 additions and 112 deletions

View File

@ -57,5 +57,6 @@ gem 'bigbluebutton-api-ruby'
gem 'bootstrap-sass', '3.3.0.0'
gem 'bootstrap-social-rails', '~> 4.12'
gem 'font-awesome-rails'
gem 'jquery-ui-rails'
gem 'jquery-datatables-rails', '~> 3.4.0'

View File

@ -65,6 +65,8 @@ GEM
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.14)
font-awesome-rails (4.6.3.1)
railties (>= 3.2, < 5.1)
globalid (0.3.7)
activesupport (>= 4.1.0)
hashie (3.4.4)
@ -209,6 +211,7 @@ DEPENDENCIES
byebug
coffee-rails (~> 4.2)
dotenv-rails
font-awesome-rails
jbuilder (~> 2.5)
jquery-datatables-rails (~> 3.4.0)
jquery-rails

View File

@ -15,6 +15,7 @@
}
});
});
$('#url_form_button').click (function (event) {
$.ajax({
url : $(this).data ('url'),
@ -36,7 +37,7 @@
$(document).on("turbolinks:load", function() {
if ($("body[data-controller=landing]").get(0)) {
if ($("body[data-action=index]").get(0)) {
if ($("body[data-action=meeting]").get(0) || $("body[data-action=room]").get(0)) {
initIndex();
}
}

View File

@ -5,6 +5,8 @@
// Bootstrap
@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap-social";
@import "font-awesome";
.room {
.room-link {

View File

@ -1,16 +1,14 @@
class BbbController < ApplicationController
include BbbHelper
# GET /join
# GET /join.json
def join
logger.info params.to_json
if ( !params.has_key?(:id) )
render_response("missing_parameter", "meeting token was not included", :bad_request)
elsif ( !params.has_key?(:name) )
render_response("missing_parameter", "user name was not included", :bad_request)
else
bbb_join_url = bbb_join_url(params[:id], false, params[:name], false)
bbb_join_url = helpers.bbb_join_url(params[:id], false, params[:name], false, "#{request.base_url}/#{params[:resource]}/#{params[:id]}")
if bbb_join_url[:returncode]
logger.info "#Execute the redirect"
render_response("ok", "execute the redirect", :ok, {:join_url => bbb_join_url[:join_url]})

View File

@ -1,17 +1,16 @@
class LandingController < ApplicationController
include LandingHelper
def index
@refreshable = (params[:resource] == 'meeting' && !params.has_key?(:id))
@meeting_token = params[:id] || @meeting_token = new_meeting_token
@meeting_url = landing_url(@meeting_token)
def meeting
@refreshable = (params[:resource] == 'meetings' && !params.has_key?(:id))
@meeting_token = params[:id] || @meeting_token = helpers.new_meeting_token
@resource = params[:resource]
@resource_url = meeting_url(@meeting_token)
end
# GET /token.json
def new_meeting
respond_to do |format|
meeting_url = landing_url(new_meeting_token)
logger.info meeting_url
meeting_url = meeting_url(helpers.new_meeting_token)
format.json { render :json => { :messageKey => "ok", :message => "New meeting URL created", :status => :ok, :response => { :meeting_url => meeting_url} }, :status => status }
end
end
@ -19,6 +18,9 @@ class LandingController < ApplicationController
def room
@room_name = params[:name]
@user = User.find_by(username: @room_name)
@meeting_token = @room_name
@resource = params[:resource]
@resource_url = room_url(@meeting_token)
if @user.nil?
redirect_to root_path
end

View File

@ -1,15 +1,2 @@
module ApplicationHelper
def bbb_endpoint
Rails.application.secrets[:bbb_endpoint]
end
def bbb_secret
Rails.application.secrets[:bbb_secret]
end
def random_password(length)
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
password = (0...length).map { o[rand(o.length)] }.join
return password
end
end

View File

@ -1,6 +1,20 @@
module BbbHelper
def bbb_join_url(meeting_token, meeting_recorded=false, user_fullname='User', user_is_moderator=false)
bbb ||= BigBlueButton::BigBlueButtonApi.new(helpers.bbb_endpoint + "api", bbb_secret, "0.8", true)
def bbb_endpoint
Rails.application.secrets[:bbb_endpoint]
end
def bbb_secret
Rails.application.secrets[:bbb_secret]
end
def random_password(length)
o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten
password = (0...length).map { o[rand(o.length)] }.join
return password
end
def bbb_join_url(meeting_token, meeting_recorded=false, user_fullname='User', user_is_moderator=false, meeting_logout_url=nil)
bbb ||= BigBlueButton::BigBlueButtonApi.new(bbb_endpoint + "api", bbb_secret, "0.8", true)
if !bbb
return { :returncode => false, :messageKey => "BBBAPICallInvalid", :message => "BBB API call invalid." }
else
@ -14,7 +28,7 @@ module BbbHelper
logger.info "Message for the log file #{exc.key}: #{exc.message}"
# Prepare parameters for create
logout_url = "#{request.base_url}/meeting/#{meeting_token}"
logout_url = meeting_logout_url || logout_url = "#{request.base_url}"
moderator_password = random_password(12)
viewer_password = random_password(12)
meeting_options = {:record => meeting_recorded.to_s, :logoutURL => logout_url, :moderatorPW => moderator_password, :attendeePW => viewer_password }

View File

@ -0,0 +1,3 @@
<div id="landing_page_footer_message">
<p>Bookmark this page to reuse this meeting URL, or click refresh button to generate a new meeting URL</p>
</div>

View File

@ -0,0 +1,19 @@
<div id="landing_page_footer_oauth_append">
<% if current_user.nil? %>
<p>You can have a personal URL (with recordings) by signing in below</p>
<div class="text-center">
<%= link_to('/auth/twitter', :class => "btn icon btn-lg btn-social-icon btn-twitter") do %>
<span class="fa fa-twitter"></span>
<% end %>
<%= link_to('/auth/google', :class => "btn icon btn-lg btn-social-icon btn-google") do %>
<span class="fa fa-google"></span>
<% end %>
</div>
<% else %>
<div>Hello <%= current_user.name %></div>
<div><%= link_to 'Personal Room', current_user.room_url %></div>
<div><%= link_to 'Logout', '/logout' %></div>
<% end %>
</div>
</div>

View File

@ -0,0 +1,28 @@
<div class="jumbotron">
<!-- Meeting URL -->
<h4 class="display-3">
<div id="landing_page_url" class="center-block">
<form id="url_form" class="form-inline">
<div class="form-group">
<span id="meeting_url"><%= @resource_url %></span>
</div>
<% if @refreshable %>
<button id="url_form_button" type="button" class="btn btn-default" data-url="<%= new_meeting_path() %>">
<span class="glyphicon glyphicon-refresh"></span>
</button>
<% end %>
</form>
</div>
</h4>
<!-- Join form -->
<div id="landing_page_join">
<form id="join_form" class="form-inline">
<div class="form-group">
<label for="join_form_name" class="sr-only">Name</label>
<input id="join_form_name" type="text" class="form-control input" id="name" placeholder="Your name" required>
</div>
<button id="join_form_button" type="button" class="btn btn-success" data-url="<%= bbb_join_path(@resource, @meeting_token) %>">Join</button>
</form>
</div>
</div>

View File

@ -0,0 +1,6 @@
<figure class=highlight><pre><figcaption class="text" data-lang="text">
<p>Hi Everyone</p>
<p>The meeting will be at this URL</p>
<p><a id="text_meeting_url" href="<%= @resource_url %>"><%= @resource_url %></a></p>
<p>Please join!</p>
</figcaption></pre></figure>

View File

@ -1,65 +0,0 @@
<div class='container'>
<!-- Body -->
<div class='body'>
<div class="container">
<div class="jumbotron">
<!-- Meeting URL -->
<% if @refreshable %>
<h4 class="display-3">
<div id="landing_page_url" class="center-block">
<form id="url_form" class="form-inline">
<div class="form-group">
<span id="meeting_url"><%= @meeting_url %></span>
</div>
<button id="url_form_button" type="button" class="btn btn-default" data-url="<%= new_meeting_url() %>">
<span class="glyphicon glyphicon-refresh"></span>
</button>
</form>
</div>
</h4>
<% end %>
<!-- Join form -->
<div id="landing_page_join">
<form id="join_form" class="form-inline">
<div class="form-group">
<label for="join_form_name" class="sr-only">Name</label>
<input id="join_form_name" type="text" class="form-control input" id="name" placeholder="Your name" required>
</div>
<button id="join_form_button" type="button" class="btn btn-success" data-url="<%= bbb_join_path(@meeting_token) %>">Join</button>
</form>
</div>
</div>
<figure class=highlight><pre><figcaption class="text" data-lang="text">
<p>Hi Everyone</p>
<p>The meeting will be at this URL</p>
<p><a id="text_meeting_url" href="<%= @meeting_url %>"><%= @meeting_url %></a></p>
<p>Please join!</p>
</figcaption></pre></figure>
<div id="landing_page_footer_message">
<p>Bookmark this page to reuse this meeting URL, or click refresh button to generate a new meeting URL</p>
</div>
<div id="landing_page_footer_oauth_append">
<% if current_user.nil? %>
<p>You can have a personal URL (with recordings) by signing in below</p>
<ul>
<li><%= link_to 'Twitter', '/auth/twitter' %></li>
<li><%= link_to 'Google', '/auth/google' %></li>
</ul>
<% else %>
<div>Hello <%= current_user.name %></div>
<div><%= link_to 'Personal Room', current_user.room_url %></div>
<div><%= link_to 'Logout', '/logout' %></div>
<% end %>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,14 @@
<!-- Body -->
<div class='body'>
<div class="container">
<%= render 'landing/join_form' %>
<%= render 'landing/sharing_text' %>
<%= render 'landing/footer_message' %>
<%= render 'landing/footer_oauth_append' %>
</div>
</div>

View File

@ -1,19 +1,26 @@
<div class="page-wrapper room">
<div class="row">
<div class="col-sm-2 col-sm-offset-10">
<% if admin? %>
<span class="user"><%= current_user.name %></span>
<%= link_to "Logout", "/logout" %>
<% else %>
<%= link_to "Login", "/auth/twitter" %>
<% end %>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="room-link">
Room Link: <%= link_to "/rooms/#{@room_name}", "/rooms/#{@room_name}" %>
<!-- Body -->
<div class='body'>
<div class="page-wrapper room">
<div class="row">
<div class="col-sm-2 col-sm-offset-10">
<% if admin? %>
<span class="user"><%= current_user.name %></span>
<%= link_to "Logout", "/logout" %>
<% else %>
<%= link_to "Login", "/auth/twitter" %>
<% end %>
</div>
</div>
</div>
<div class="container">
<%= render 'landing/join_form' %>
<%= render 'landing/sharing_text' %>
<%= render 'landing/footer_message' %>
</div>
</div>

View File

@ -1,12 +1,13 @@
Rails.application.routes.draw do
get 'bbb/join/:id', to: 'bbb#join', as: :bbb_join
get 'bbb/join/:resource/:id', to: 'bbb#join', as: :bbb_join
get '/meetings/new', to: 'landing#new_meeting', as: :new_meeting
get '/meetings(/:id)', to: 'landing#meeting', as: :meeting, :resource => "meetings"
get '/rooms/:name', to: 'landing#room', as: :room, :resource => "rooms"
get '/meeting/new', to: 'landing#new_meeting', as: :new_meeting
get '/meeting(/:id)', to: 'landing#index', as: :landing, :resource => "meeting"
get '/auth/:provider/callback', to: 'sessions#create'
get '/logout', to: 'sessions#destroy'
get '/rooms/:name', to: 'landing#room'
root to: 'landing#index', :resource => "meeting"
root to: 'landing#meeting', :resource => "meetings"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end