From 8cdbf1d5e6a39e221afe0e8597dde9d898c2a40a Mon Sep 17 00:00:00 2001 From: John Ma Date: Thu, 13 Dec 2018 11:58:33 -0500 Subject: [PATCH] Add the ability to Sort Recordings (GRN-43) (#327) * * * * * * * * * * * * * * * * * <> * * * * * * * * * Update sort.js --- app/assets/javascripts/sort.js | 95 +++++++++++++++++++ app/views/shared/_sessions.html.erb | 10 +- .../components/_public_recording_row.html.erb | 6 +- .../shared/components/_recording_row.html.erb | 4 +- config/routes.rb | 1 + 5 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/sort.js diff --git a/app/assets/javascripts/sort.js b/app/assets/javascripts/sort.js new file mode 100644 index 00000000..3cb637d6 --- /dev/null +++ b/app/assets/javascripts/sort.js @@ -0,0 +1,95 @@ +// 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"){ + + // Choose active header + // (Name, Length or Users) + $('th').each(function(){ + if($(this).data("header")){ + $(this).on('click', function(){ + set_active_header($(this).data("header")); + sort_by($(this).data("header"), $(this).data('order')); + }); + } + }); + + // Based on the header (Name, Length or Users) clicked, + // Modify the ui for the tables + function set_active_header(active_header){ + $('th').each(function(){ + if($(this).data("header") == active_header){ + configure_order($(this)); + } + else{ + $(this).text($(this).data("header")); + $(this).data('order', 'none'); + } + }); + } + + // Based on the header (Name, Length or Users) clicked, + // Modify the ui for the tables + function configure_order(header_elem){ + if(header_elem.data('order') === 'asc'){ // asc + header_elem.text(header_elem.data("header") + " ↓"); + header_elem.data('order', 'desc'); + } + else if(header_elem.data('order') === 'desc'){ // desc + header_elem.text(header_elem.data("header")); + header_elem.data('order', 'none'); + } + else{ // none + header_elem.text(header_elem.data("header") + " ↑"); + header_elem.data('order', 'asc'); + } + } + + // Given a label and an order, sort recordings by order + // under a given label + function sort_by(label, order){ + var recording_list_tbody = $('.table-responsive').find('tbody'); + if(label === "Name"){ + sort_recordings(recording_list_tbody, order, "#recording-title"); + } + else if(label === "Length"){ + sort_recordings(recording_list_tbody, order, "#recording-length"); + } + else if(label === "Users"){ + sort_recordings(recording_list_tbody, order, "#recording-users"); + } + } + + // Generalized function for sorting recordings + function sort_recordings(recording_list_tbody, order, recording_id){ + recording_list_tbody.find('tr').sort(function(a, b){ + a_val = $.trim($(a).find(recording_id).text()); + b_val = $.trim($(b).find(recording_id).text()); + + if(order === "asc"){ + return a_val.localeCompare(b_val); + } + else if(order === "desc"){ + return b_val.localeCompare(a_val); + } + }).appendTo(recording_list_tbody); + } + } +}); diff --git a/app/views/shared/_sessions.html.erb b/app/views/shared/_sessions.html.erb index ee8886a3..138103aa 100644 --- a/app/views/shared/_sessions.html.erb +++ b/app/views/shared/_sessions.html.erb @@ -24,12 +24,16 @@ - + <% if recording_thumbnails? %> <% end %> - - + + <% unless only_public %> diff --git a/app/views/shared/components/_public_recording_row.html.erb b/app/views/shared/components/_public_recording_row.html.erb index 59b2df78..22bfbeac 100644 --- a/app/views/shared/components/_public_recording_row.html.erb +++ b/app/views/shared/components/_public_recording_row.html.erb @@ -15,7 +15,7 @@ <% end %> - - <% end %> - -
<%= t("recording.table.name") %>" data-order="none"><%= t("recording.table.name") %><%= t("recording.table.thumbnails") %><%= t("recording.table.length") %><%= t("recording.table.users") %>" data-order="none"> + <%= t("recording.table.length") %> + " data-order="none"> + <%= t("recording.table.users") %> + <%= t("recording.table.visibility") %> <%= t("recording.table.formats") %>
-
+
<% if recording[:metadata][:name] %> <%= recording[:metadata][:name] %> @@ -38,13 +38,13 @@ <% end %>
+
<%= t("recording.table.length") %>
<%= recording_length(recording[:playbacks]) %>
+
<%= t("recording.table.users") %>
diff --git a/app/views/shared/components/_recording_row.html.erb b/app/views/shared/components/_recording_row.html.erb index fdfa7bd0..eed8afd5 100644 --- a/app/views/shared/components/_recording_row.html.erb +++ b/app/views/shared/components/_recording_row.html.erb @@ -39,10 +39,10 @@ <% end %>
+ <%= recording_length(recording[:playbacks]) %> + <%= recording[:participants] || "-" %> diff --git a/config/routes.rb b/config/routes.rb index 0ed866b1..69b429fd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Rails.application.routes.draw do post '/start', to: 'rooms#start', as: :start_room get '/logout', to: 'rooms#logout', as: :logout_room + # Manage recordings scope '/:record_id' do post '/', to: 'rooms#update_recording', as: :update_recording delete '/', to: 'rooms#delete_recording', as: :delete_recording