From 895af7494ee8c88dc4640069a73ed56989d058bc Mon Sep 17 00:00:00 2001 From: John Ma Date: Thu, 6 Dec 2018 10:24:22 -0500 Subject: [PATCH] Fixed #280 Search/Paginate recordings (GRN-12) (#281) * * * * * * * * * * * * * * * * * <> * * * Update search.js --- app/assets/javascripts/search.js | 53 +++++++++++++++++++ app/controllers/rooms_controller.rb | 1 - app/views/shared/_sessions.html.erb | 27 ++++++---- .../components/_public_recording_row.html.erb | 12 +++-- .../shared/components/_subtitle.html.erb | 10 ++-- config/locales/en.yml | 1 + config/routes.rb | 1 - spec/controllers/rooms_controller_spec.rb | 16 ++++++ 8 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 app/assets/javascripts/search.js diff --git a/app/assets/javascripts/search.js b/app/assets/javascripts/search.js new file mode 100644 index 00000000..ca211b35 --- /dev/null +++ b/app/assets/javascripts/search.js @@ -0,0 +1,53 @@ +// 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 . + +$(document).on('turbolinks:load', function(){ + var controller = $("body").data('controller'); + var action = $("body").data('action'); + + if(controller == "rooms" && action == "show" || controller == "rooms" && action == "update"){ + search_input = $('#search_bar'); + + search_input.bind("keyup", function(event){ + + // Retrieve the current search query + search_query = search_input.find(".form-control").val(); + + //Search for recordings and display them based on name match + var recordings_found = 0; + + recordings = $('#recording-table').find('tr'); + + recordings.each(function(){ + if($(this).find('text').text().toLowerCase().includes(search_query.toLowerCase())){ + recordings_found = recordings_found + 1; + $(this).show(); + } + else{ + $(this).hide(); + } + }); + + // Show "No recordings match your search" if no recordings found + if(recordings_found == 0){ + $('#no_recordings_found').show(); + } + else{ + $('#no_recordings_found').hide(); + } + }); + } +}); diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 72aefe33..5f20b2ed 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -66,7 +66,6 @@ class RoomsController < ApplicationController # POST /:room_uid def join opts = default_meeting_options - unless @room.owned_by?(current_user) # Assign join name if passed. if params[@room.invite_path] diff --git a/app/views/shared/_sessions.html.erb b/app/views/shared/_sessions.html.erb index 28db684f..ee8886a3 100644 --- a/app/views/shared/_sessions.html.erb +++ b/app/views/shared/_sessions.html.erb @@ -38,21 +38,26 @@ - <% if recordings.empty? %> - - - <%= t("recording.no_recordings", inject: only_public ? t("recording.visibility.public").downcase + " " : "") %> + + + <%= t("recording.no_matched_recordings", inject: only_public ? t("recording.visibility.public").downcase + " " : "") %> - <% else %> - <% recordings.each do |recording| %> - <% if only_public %> - <%= render "shared/components/public_recording_row", recording: recording %> - <% else %> - <%= render "shared/components/recording_row", recording: recording %> + <% if recordings.empty? %> + + + <%= t("recording.no_recordings", inject: only_public ? t("recording.visibility.public").downcase + " " : "") %> + + + <% else %> + <% recordings.each do |recording| %> + <% if only_public %> + <%= render "shared/components/public_recording_row", recording: recording %> + <% else %> + <%= render "shared/components/recording_row", recording: recording %> + <% end %> <% end %> <% end %> - <% end %> diff --git a/app/views/shared/components/_public_recording_row.html.erb b/app/views/shared/components/_public_recording_row.html.erb index 194162e7..59b2df78 100644 --- a/app/views/shared/components/_public_recording_row.html.erb +++ b/app/views/shared/components/_public_recording_row.html.erb @@ -16,11 +16,13 @@
- <% if recording[:metadata][:name] %> - <%= recording[:metadata][:name] %> - <% else %> - <%= recording[:name] %> - <% end %> + + <% if recording[:metadata][:name] %> + <%= recording[:metadata][:name] %> + <% else %> + <%= recording[:name] %> + <% end %> +
<%= t("recording.recorded_on", date: recording_date(recording[:startTime])) %> diff --git a/app/views/shared/components/_subtitle.html.erb b/app/views/shared/components/_subtitle.html.erb index b6952941..efeeb061 100644 --- a/app/views/shared/components/_subtitle.html.erb +++ b/app/views/shared/components/_subtitle.html.erb @@ -18,16 +18,14 @@

<%= subtitle %>

<% if search %> - <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index a406da1d..20ed59b1 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -114,6 +114,7 @@ en: recording: email: Email Recording no_recordings: This room has no %{inject}recordings. + no_matched_recordings: No %{inject} recordings match your search. recorded_on: Recorded on %{date} table: name: Name diff --git a/config/routes.rb b/config/routes.rb index 90f6d854..0ed866b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,7 +65,6 @@ Rails.application.routes.draw do post '/start', to: 'rooms#start', as: :start_room get '/logout', to: 'rooms#logout', as: :logout_room - # Mange recordings. scope '/:record_id' do post '/', to: 'rooms#update_recording', as: :update_recording delete '/', to: 'rooms#delete_recording', as: :delete_recording diff --git a/spec/controllers/rooms_controller_spec.rb b/spec/controllers/rooms_controller_spec.rb index c5f16b74..89b86468 100644 --- a/spec/controllers/rooms_controller_spec.rb +++ b/spec/controllers/rooms_controller_spec.rb @@ -43,6 +43,14 @@ describe RoomsController, type: :controller do expect(assigns(:is_running)).to eql(@owner.main_room.running?) end + it "should be able to search recordings if user is owner" do + @request.session[:user_id] = @owner.id + + get :show, params: { room_uid: @owner.main_room, search: :none } + + expect(assigns(:recordings)).to eql([]) + end + it "should render join if user is not owner" do @request.session[:user_id] = @user.id @@ -51,6 +59,14 @@ describe RoomsController, type: :controller do expect(response).to render_template(:join) end + it "should be able to search public recordings if user is not owner" do + @request.session[:user_id] = @user.id + + get :show, params: { room_uid: @owner.main_room, search: :none } + + expect(assigns(:recordings)).to eql(nil) + end + it "should raise if room is not valid" do expect do get :show, params: { room_uid: "non_existent" }