From 0d216adc527e27e64e289d939c00a445e59aff64 Mon Sep 17 00:00:00 2001 From: jfederico Date: Tue, 18 Oct 2016 16:23:52 -0400 Subject: [PATCH] Implemented refresh URL --- app/assets/javascripts/landing.js | 17 +++++++++++++++++ app/controllers/bbb_controller.rb | 3 --- app/controllers/landing_controller.rb | 15 +++++++++++++-- app/helpers/landing_helper.rb | 8 ++------ app/views/landing/index.html.erb | 13 +++++++++++-- config/routes.rb | 5 +++-- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/landing.js b/app/assets/javascripts/landing.js index 6f5c5ec1..d441eadd 100644 --- a/app/assets/javascripts/landing.js +++ b/app/assets/javascripts/landing.js @@ -15,6 +15,23 @@ } }); }); + $('#url_form_button').click (function (event) { + $.ajax({ + url : $(this).data ('url'), + dataType : "json", + async : true, + type : 'GET', + success : function(data) { + $('#meeting_url').html(data.response.meeting_url); + $('#text_meeting_url a').href(data.response.meeting_url); + $('#text_meeting_url span').html(data.response.meeting_url); + }, + error : function(xhr, status, error) { + }, + complete : function(xhr, status) { + } + }); + }); }; $(document).on("turbolinks:load", function() { diff --git a/app/controllers/bbb_controller.rb b/app/controllers/bbb_controller.rb index e51f7c36..9c9ef648 100644 --- a/app/controllers/bbb_controller.rb +++ b/app/controllers/bbb_controller.rb @@ -20,9 +20,6 @@ class BbbController < ApplicationController end end - def close - end - private def render_response(messageKey, message, status, response={}) respond_to do |format| diff --git a/app/controllers/landing_controller.rb b/app/controllers/landing_controller.rb index b02805b7..166895a8 100644 --- a/app/controllers/landing_controller.rb +++ b/app/controllers/landing_controller.rb @@ -2,7 +2,18 @@ class LandingController < ApplicationController include LandingHelper def index - @meeting_token = params[:id] || @meeting_token = rand.to_s[2..10] - @meeting_url = meeting_url(@meeting_token) + @refreshable = (params[:resource] == 'meeting' && !params.has_key?(:id)) + @meeting_token = params[:id] || @meeting_token = new_meeting_token + @meeting_url = landing_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 + format.json { render :json => { :messageKey => "ok", :message => "New meeting URL created", :status => :ok, :response => { :meeting_url => meeting_url} }, :status => status } + end + end + end diff --git a/app/helpers/landing_helper.rb b/app/helpers/landing_helper.rb index 3f9b3bc7..a9613176 100644 --- a/app/helpers/landing_helper.rb +++ b/app/helpers/landing_helper.rb @@ -1,9 +1,5 @@ module LandingHelper - def meeting_url(meeting_token) - _meeting_url = "#{request.original_url}" - _meeting_url += "meeting" if ( request.original_url == "#{request.base_url}/" ) - _meeting_url += "/" unless _meeting_url.end_with?('/') - _meeting_url += "#{meeting_token}" if !params.has_key?(:id) - _meeting_url.gsub(/\/+$/, '') + def new_meeting_token + rand.to_s[2..10] end end diff --git a/app/views/landing/index.html.erb b/app/views/landing/index.html.erb index 13bee6ad..444cf1f5 100644 --- a/app/views/landing/index.html.erb +++ b/app/views/landing/index.html.erb @@ -6,11 +6,20 @@
+ <% if @refreshable %>

- <%= @meeting_url %> +
+
+ <%= @meeting_url %> +
+ +

+ <% end %>
@@ -27,7 +36,7 @@

Hi Everyone

The meeting will be at this URL

-

<%= @meeting_url %>

+

<%= @meeting_url %>

Please join!

diff --git a/config/routes.rb b/config/routes.rb index e1e04b54..804d4b87 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,11 @@ Rails.application.routes.draw do get 'bbb/join/:id', to: 'bbb#join', as: :bbb_join - get 'meeting(/:id)', to: 'landing#index' + 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' - root to: 'landing#index' + root to: 'landing#index', :resource => "meeting" # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end