Fixed #398 Fixed issue with recording length and sort (GRN-83) (#426)

* Fixed issue with recording length and sort

* Made js run on any page with a table element on it

* Scrutinizer fix
This commit is contained in:
farhatahmad 2019-04-10 16:32:28 -04:00 committed by Jesus Federico
parent 95a98f6574
commit 4d648534f7
5 changed files with 25 additions and 27 deletions

View File

@ -121,7 +121,7 @@ $(document).on('turbolinks:load', function(){
submit_update_request({
setting: "rename_header",
room_name: element.find('#user-text').text(),
});
}, element.data('path'));
}
else if(element.is('#recording-title')){
submit_update_request({
@ -129,27 +129,15 @@ $(document).on('turbolinks:load', function(){
record_id: element.data('recordid'),
record_name: element.find('text').text(),
room_uid: element.data('room-uid'),
});
}, element.data('path'));
}
}
// Helper for submitting ajax requests
var submit_update_request = function(data){
var update_path = window.location.pathname
if ('room_uid' in data) {
update_path = $("body").data('relative-root')
if (!update_path.endsWith("/")) {
update_path += "/"
}
update_path += data.room_uid
}
var submit_update_request = function(data, path){
// Send ajax request for update
$.ajax({
url: update_path,
url: path,
type: "PATCH",
data: data,
});

View File

@ -15,16 +15,14 @@
// 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"){
// Check if there is a table on this page
if ($("table").length) {
// Choose active header
// (Name, Length or Users)
$('th').each(function(){
if($(this).data("header")){
$(this).on('click', function(){
$(this).on('click', function(){
set_active_header($(this).data("header"));
sort_by($(this).data("header"), $(this).data('order'));
});
@ -80,8 +78,14 @@ $(document).on('turbolinks:load', function(){
// Generalized function for sorting recordings
var sort_recordings = function(recording_list_tbody, order, recording_id){
recording_list_tbody.find('tr').sort(function(a, b){
var a_val = $.trim($(a).find(recording_id).text());
var b_val = $.trim($(b).find(recording_id).text());
var a_val, b_val;
if (recording_id == "#recording-length") {
a_val = $.trim($(a).find(recording_id).data("full-length"));
b_val = $.trim($(b).find(recording_id).data("full-length"));
} else {
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);
@ -89,6 +93,8 @@ $(document).on('turbolinks:load', function(){
else if(order === "desc"){
return b_val.localeCompare(a_val);
}
}).appendTo(recording_list_tbody);
}
}

View File

@ -30,7 +30,7 @@ module RecordingsHelper
len = valid_playbacks.first[:length]
if len > 60
"#{(len / 60).round} hrs"
"#{(len / 60).to_i} hrs #{len % 60} mins"
elsif len == 0
"< 1 min"
else
@ -42,4 +42,8 @@ module RecordingsHelper
def safe_recording_images(images)
Array.wrap(images)
end
def room_uid_from_bbb(bbb_id)
Room.find_by(bbb_id: bbb_id)[:uid]
end
end

View File

@ -15,7 +15,7 @@
<tr>
<td>
<div id="recording-title">
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>" data-room-uid="<%= room_uid_from_bbb(recording[:meetingID]) %>" data-path="<%= update_room_path(room_uid: room_uid_from_bbb(recording[:meetingID])) %>">
<text>
<% if recording[:metadata][:name] %>
<%= recording[:metadata][:name] %>
@ -38,7 +38,7 @@
<% end %>
</td>
<% end %>
<td id="recording-length" class="text-left">
<td id="recording-length" class="text-left" data-full-length="<%=recording[:playbacks].first[:length]%>">
<div class="small text-muted text-uppercase">
<%= t("recording.table.length") %>
</div>

View File

@ -15,7 +15,7 @@
<tr>
<td>
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>" data-room-uid="<%= recording[:room_uid] %>">
<div id="recording-title" class="form-inline edit_hover_class" data-recordid="<%= recording[:recordID] %>" data-room-uid="<%= room_uid_from_bbb(recording[:meetingID]) %>" data-path="<%= update_room_path(room_uid: room_uid_from_bbb(recording[:meetingID])) %>">
<text id='recording-text'>
<% if recording[:metadata][:name] %>
<%= recording[:metadata][:name] %>