Fixed #303 Add the ability to rename rooms and recordings (GRN-18) (#304)

* <Added modal for rename>

* <Commit changes and switch branch>

* <Javascript Scaffolding for rename room feature>

* <Created room_block.js>

* <update changes>

* <Updating rename branch>

* <Update rename.js>

* <Update branch>

* <Update branch>

* <Implemented renaming of room blocks>

* <Refactoring code>

* Remove modal due to new design

* <Finished renaming of rooms>

* <Updated renaming of recordings>

* <updating branch>

* <added renaming of recordings>

* <update branch>

* <>

* <Fixed code style>

* <Fixed rspec tests>

* Update application.js
This commit is contained in:
John Ma 2018-12-04 10:48:51 -05:00 committed by Jesus Federico
parent efa9e08dfc
commit 41a543f6b8
13 changed files with 285 additions and 9 deletions

View File

@ -30,3 +30,5 @@
//= require tabler.plugins
//= require turbolinks
//= require_tree .
//= require jquery
//= require jquery_ujs

View File

@ -0,0 +1,163 @@
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
//
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
//
// This program is free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the Free Software
// Foundation; either version 3.0 of the License, or (at your option) any later
// version.
//
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License along
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
$(document).on('turbolinks:load', function(){
var controller = $("body").data('controller');
var action = $("body").data('action');
if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){
// Elements that can be renamed
var room_title = $('#room-title');
var room_blocks = $('#room_block_container').find('.card');
var recording_rows = $('#recording-table').find('tr');
// Configure renaming for room header
configure_room_header(room_title);
// Configure renaming for room blocks
room_blocks.each(function(){
var room_block = $(this)
configure_room_block(room_block)
});
// Configure renaming for recording rows
recording_rows.each(function(){
var recording_title = $(this).find('#recording-title');
configure_recording_row(recording_title);
});
// Set a room block rename event
function configure_room_block(room_block){
if(!room_block.is('#home_room_block')){
// Register a click event on each room_block rename dropdown
room_block.find('#rename-room-button').on('click', function(e){
room_block.find('#room-name').hide();
room_block.find('#room-name-editable').show();
room_block.find('#room-name-editable-input').select()
// Stop automatic refresh
e.preventDefault();
register_window_event(room_block, null, null);
});
}
}
// Set a room header rename event
function configure_room_header(room_title){
room_title.find('.fa-edit').on('click', function(e){
// Remove current window events
$(window).off('mousedown keypress');
room_title.find('#user-text').fadeTo('medium', 0.7);
room_title.find('#user-text').attr("contenteditable", true);
room_title.find('#user-text').focus();
// Stop automatic refresh
e.preventDefault();
register_window_event(room_title, 'user-text', '#edit-room', 'edit-room');
});
}
// Set a recording row rename event
function configure_recording_row(recording_title){
recording_title.find('a').on('click', function(e){
// Remove current window events
$(window).off('mousedown keypress');
recording_title.fadeTo('medium', 0.7);
recording_title.find('text').attr("contenteditable", true);
recording_title.find('text').focus();
// Stop automatic refresh
e.preventDefault();
register_window_event(recording_title, 'recording-text', '#edit-record', 'edit-recordid');
});
}
// Register window event to submit new name
// upon click or upon pressing the enter key
function register_window_event(element, textfield_id, edit_button_id, edit_button_data){
$(window).on('mousedown keypress', function(clickEvent){
// Return if the text is clicked
if(clickEvent.type == "mousedown" && clickEvent.target.id == textfield_id){
return;
}
// Return if the edit icon is clicked
if(clickEvent.type == "mousedown" && $(clickEvent.target).is(edit_button_id) &&
$(clickEvent.target).data(edit_button_data) === element.find(edit_button_id).data(edit_button_data)){
return;
}
// Check if event is keypress and enter key is pressed
if(clickEvent.type != "mousedown" && clickEvent.which !== 13){
return;
}
submit_rename_request(element);
// Remove window event when ajax call to update name is submitted
$(window).off('mousedown keypress');
});
}
// Apply ajax request depending on the element that triggered the event
function submit_rename_request(element){
if(element.data('room-uid')){
submit_update_request({
setting: "rename_block",
room_block_uid: element.data('room-uid'),
room_name: element.find('#room-name-editable-input').val(),
});
}
else if(element.is('#room-title')){
submit_update_request({
setting: "rename_header",
room_name: element.find('#user-text').text(),
});
}
else if(element.is('#recording-title')){
submit_update_request({
setting: "rename_recording",
record_id: element.data('recordid'),
record_name: element.find('text').text(),
});
}
}
// Helper for submitting ajax requests
function submit_update_request(data){
// Send ajax request for update
$.ajax({
url: window.location.pathname,
type: "PATCH",
data: data,
success: function(data){
console.log("Success");
},
});
}
}
});

View File

@ -58,6 +58,10 @@ a {
cursor: pointer;
}
.disable-click {
pointer-events: none;
}
.header {
height: $header-height;
}
@ -117,3 +121,7 @@ a {
overflow: scroll;
height: 55vh;
}
[contenteditable]:focus {
outline: 0px solid transparent;
}

View File

@ -43,3 +43,11 @@
.btn-del-room {
width: 70% !important;
}
.edit_hover_class a{
visibility: hidden;
}
.edit_hover_class:hover a {
visibility: visible;
}

View File

@ -50,6 +50,19 @@ class RoomsController < ApplicationController
end
end
# PATCH /:room_uid
def update
if params[:setting] == "rename_block"
@room = Room.find_by!(uid: params[:room_block_uid])
update_room_attributes
elsif params[:setting] == "rename_header"
update_room_attributes
elsif params[:setting] == "rename_recording"
@room.update_recording(params[:record_id], "meta_name" => params[:record_name])
end
redirect_to room_path
end
# POST /:room_uid
def join
opts = default_meeting_options
@ -159,6 +172,12 @@ class RoomsController < ApplicationController
private
def update_room_attributes
if @room.owned_by?(current_user) && @room != current_user.main_room
@room.update_attributes(name: params[:room_name])
end
end
def room_params
params.require(:room).permit(:name, :auto_join)
end

View File

@ -25,11 +25,14 @@
<div class="container">
<div class="row pt-9">
<div class="col-lg-9 col-sm-12">
<h1 id="user-text" class="display-3 text-left mb-3 font-weight-400"><%= @room.name %>
<div id="room-title" class="display-3 form-inline <%= 'edit_hover_class' if current_user.main_room != @room %>">
<h1 contenteditable=false id="user-text" class="display-3 text-left mb-3 font-weight-400"><%= @room.name %></h1>
<% if current_user.main_room == @room %>
<i class="fas fa-home align-top home-indicator"></i>
<a class="disable-click"><i class="fas fa-home align-top home-indicator ml-2"></i></a>
<% else %>
<a><i id="edit-room" class="fa fa-edit align-top home-indicator ml-2" data-edit-room="<%= @room.uid %>"></i></a>
<% end %>
</h1>
</div>
<h4 class="text-left mb-6"><%= @room.sessions %> <%= t("room.sessions") %> | <%= @recordings.length %> <%= t("room.recordings") %></h4>
<label class="form-label"><%= t("room.invite_participants") %></label>
<form class="form-inline">
@ -54,7 +57,7 @@
</div>
</div>
<div class="row pt-7 pb-2">
<div id="room_block_container" class="row pt-7 pb-2">
<% if current_user.rooms.length > 1 %>
<div class="col-lg-4 col-md-6 col-sm-12">
<%= link_to current_user.main_room do %>

View File

@ -37,7 +37,7 @@
<% end %>
</tr>
</thead>
<tbody>
<tbody id="recording-table">
<% if recordings.empty? %>
<tr>
<td colspan="7" class="text-center h4 p-6 font-weight-normal">

View File

@ -15,7 +15,13 @@
<tr>
<td>
<div><%= recording[:name] %></div>
<div>
<% if recording[:metadata][:name] %>
<%= recording[:metadata][:name] %>
<% else %>
<%= recording[:name] %>
<% end %>
</div>
<div class="small text-muted">
<%= t("recording.recorded_on", date: recording_date(recording[:startTime])) %>
</div>

View File

@ -15,7 +15,16 @@
<tr>
<td>
<div><%= recording[:name] %></div>
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>">
<text id='recording-text'>
<% if recording[:metadata][:name] %>
<%= recording[:metadata][:name] %>
<% else %>
<%= recording[:name] %>
<% end %>
</text>
<a><i id="edit-record" class="fa fa-edit align-top ml-2" data-edit-recordid="<%= recording[:recordID] %>"></i></a>
</div>
<div class="small text-muted">
<%= t("recording.recorded_on", date: recording_date(recording[:startTime])) %>
</div>

View File

@ -13,7 +13,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
%>
<div class="card">
<div id="<%= 'home_room_block' if room == current_user.main_room %>" data-room-uid=<%= room.uid %> class="card">
<div class="card-body p-1">
<table class="table table-hover table-vcenter text-wrap table-no-border">
<tbody class="no-border-top">
@ -27,7 +27,12 @@
</span>
</td>
<td>
<h4 class="m-0 force-text-normal"><%= room.name %></h4>
<div id="room-name">
<h4 contenteditable="false" class="m-0 force-text-normal" ><%= room.name %></h4>
</div>
<div id="room-name-editable" style="display: none">
<input id="room-name-editable-input" class="form-control input-sm w-100 h-4" value="<%= room.name %>">
</div>
<div class="small text-muted">
<% if room.sessions > 0 %>
<i><%= t("room.last_session", session: recording_date(room.last_session)) %></i>
@ -47,6 +52,9 @@
<i class="dropdown-icon fas fa-cog"></i> <%= t("room.settings") %>
<% end %>
-->
<a href="" id="rename-room-button" class="dropdown-item">
<i class="dropdown-icon far fa-edit"></i> <%= t("rename") %>
</a>
<a href="" data-toggle="modal" data-target="#deleteRoomModal_<%= room.uid %>"class="dropdown-item">
<i class="dropdown-icon far fa-trash-alt"></i> <%= t("delete") %>
</a>

View File

@ -100,6 +100,11 @@ en:
login:
or: or
with: Sign in with %{provider}
rename_recording:
rename_room:
name_placeholder: Enter a new room name...
name_update_success: Room name successfully changed!
omniauth_error: An error occured while authenticating with omniauth. Please try again or contact an administrator!
password: Password
provider:
@ -120,6 +125,7 @@ en:
visibility:
public: Public
unlisted: Unlisted
rename: Rename
room:
invited: You have been invited to join
invite_participants: Invite Participants

View File

@ -61,6 +61,7 @@ Rails.application.routes.draw do
# Extended room routes.
scope '/:room_uid' do
post '/', to: 'rooms#join'
patch '/', to: 'rooms#update', as: :update_room
post '/start', to: 'rooms#start', as: :start_room
get '/logout', to: 'rooms#logout', as: :logout_room

View File

@ -18,6 +18,15 @@
require "rails_helper"
def random_valid_room_params
{
room: {
name: Faker::Name.first_name,
auto_join: false,
},
}
end
describe RoomsController, type: :controller do
describe "GET #show" do
before do
@ -186,4 +195,38 @@ describe RoomsController, type: :controller do
expect(response).to redirect_to(root_path)
end
end
describe "PATCH #update" do
before do
@user = create(:user)
@secondary_room = create(:room, owner: @user)
@editable_room = create(:room, owner: @user)
end
it "properly updates room name through room block and redirects to current page" do
@request.session[:user_id] = @user.id
patch :update, params: { room_uid: @secondary_room, room_block_uid: @editable_room,
setting: :rename_block, room_name: :name }
expect(response).to redirect_to(@secondary_room)
end
it "properly updates room name through room header and redirects to current page" do
@request.session[:user_id] = @user.id
patch :update, params: { room_uid: @secondary_room, setting: :rename_header, room_name: :name }
expect(response).to redirect_to(@secondary_room)
end
it "properly updates recording name and redirects to current page" do
@request.session[:user_id] = @user.id
patch :update, params: { room_uid: @secondary_room, recordid: :recordid,
setting: :rename_recording, record_name: :name }
expect(response).to redirect_to(@secondary_room)
end
end
end