add recordings table

This commit is contained in:
Zachary Chai 2016-10-28 16:39:32 -04:00
parent 3871e0129c
commit db9d06b72f
8 changed files with 122 additions and 10 deletions

View File

@ -12,6 +12,8 @@
// //
//= require jquery2 //= require jquery2
//= require jquery-ui //= require jquery-ui
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require bootstrap-sprockets //= require bootstrap-sprockets
//= require turbolinks //= require turbolinks
//= require_self //= require_self

View File

@ -1,4 +1,6 @@
(function() { (function() {
var recordingsTable = null;
var waitForModerator = function(url) { var waitForModerator = function(url) {
$.get(url + "/wait", function(html) { $.get(url + "/wait", function(html) {
$(".center-panel-wrapper").html(html); $(".center-panel-wrapper").html(html);
@ -72,8 +74,103 @@
window.location.hostname + window.location.hostname +
meetingURL.data('path'); meetingURL.data('path');
meetingURL.val(link); meetingURL.val(link);
// initialize recordings datatable
recordingsTable = $('#recordings').dataTable({
data: [],
rowId: 'id',
paging: false,
searching: false,
info: false,
ordering: false,
language: {
emptyTable: "Past recordings are shown here."
},
columns: [
{ title: "Date Recorded", data: "start_time" },
{ title: "Duration", data: "duration" },
{ title: "Views", data: "playbacks" },
{ title: "Actions", data: "id" }
],
columnDefs: [
{
targets: 2,
render: function(data, type, row) {
if (type === 'display') {
var str = "";
for(let i in data) {
str += '<a href="'+data[i].url+'">'+data[i].type+'</a> ';
}
return str;
}
return data;
}
},
{
targets: -1,
render: function(data, type, row) {
if (type === 'display') {
var roomName = window.location.pathname.split('/').pop();
var published = row.published;
var eye = (published) ? 'eye' : 'eye-slash'
return '<button type="button" class="btn btn-default recording-update" data-id="'+data+'" data-room="'+roomName+'" data-published="'+published+'">' +
'<i class="fa fa-'+eye+'" aria-hidden="true"></i></button> ' +
'<button type="button" class="btn btn-default recording-delete" data-id="'+data+'" data-room="'+roomName+'">' +
'<i class="fa fa-trash-o" aria-hidden="true"></i></button>';
}
return data;
}
}
]
});
$('#recordings').on('click', '.recording-update', function(event) {
var room = $(this).data('room');
var id = $(this).data('id');
var published = $(this).data('published');
$.ajax({
method: 'PATCH',
url: '/rooms/'+room+'/recordings/'+id,
data: {published: (!published).toString()}
}).done(function(data) {
$(this).prop("disabled", true);
});
});
$('#recordings').on('click', '.recording-delete', function(event) {
var room = $(this).data('room');
var id = $(this).data('id');
$.ajax({
method: 'DELETE',
url: '/rooms/'+room+'/recordings/'+id
}).done(function() {
$('tr[id="'+id+'"]').remove();
});
});
refreshRecordings();
}; };
var refreshRecordings = function() {
if (!recordingsTable) {
return;
}
table = recordingsTable.api();
$.get("/rooms/"+window.location.pathname.split('/').pop()+"/recordings", function(data) {
var i;
for (i = 0; i < data.recordings.length; i++) {
var totalMinutes = Math.round((new Date(data.recordings[i].end_time) - new Date(data.recordings[i].start_time)) / 1000 / 60);
data.recordings[i].duration = totalMinutes;
data.recordings[i].start_time = new Date(data.recordings[i].start_time)
.toLocaleString([], {month: 'long', day: 'numeric', year: 'numeric', hour12: 'true', hour: '2-digit', minute: '2-digit'});
}
table.clear();
table.rows.add(data.recordings);
table.columns.adjust().draw();
});
}
$(document).on("turbolinks:load", function() { $(document).on("turbolinks:load", function() {
init(); init();
if ($("body[data-controller=landing]").get(0)) { if ($("body[data-controller=landing]").get(0)) {

View File

@ -1,3 +1,9 @@
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
}
});
var meetingInstance = null; var meetingInstance = null;
class Meeting { class Meeting {
constructor(url, name) { constructor(url, name) {

View File

@ -11,7 +11,7 @@
* It is generally better to create a new file per style scope. * It is generally better to create a new file per style scope.
* *
*= require jquery-ui *= require jquery-ui
*= require dataTables/jquery.dataTables *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
*= require_tree . *= require_tree .
*= require_self *= require_self
*/ */

View File

@ -1,3 +1,9 @@
// Place all the styles related to the landing controller here. // Place all the styles related to the landing controller here.
// They will automatically be included in application.css. // They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/ // You can use Sass (SCSS) here: http://sass-lang.com/
.rooms {
.table-wrapper {
padding: 40px 50px 10px 50px;
}
}

View File

@ -49,14 +49,13 @@ class BbbController < ApplicationController
# PATCH /rooms/:id/recordings/:record_id # PATCH /rooms/:id/recordings/:record_id
def update_recordings def update_recordings
bbb_res = helpers.bbb_update_recordings(params[:record_id], params[:published] == 'true') bbb_res = helpers.bbb_update_recordings(params[:record_id], params[:published] == 'true')
render_bbb_response bbb_res, bbb_res[:recordings] render_bbb_response bbb_res
end end
# DELETE /rooms/:id/recordings/:record_id # DELETE /rooms/:id/recordings/:record_id
def delete_recordings def delete_recordings
byebug
bbb_res = helpers.bbb_delete_recordings(params[:record_id]) bbb_res = helpers.bbb_delete_recordings(params[:record_id])
render_bbb_response bbb_res, bbb_res[:recordings] render_bbb_response bbb_res
end end
private private
@ -69,7 +68,7 @@ class BbbController < ApplicationController
render head(:unauthorized) && return render head(:unauthorized) && return
end end
recordings = helpers.bbb_get_recordings(params[:record_id])[:recordings] recordings = helpers.bbb_get_recordings(params[:id])[:recordings]
recordings.each do |recording| recordings.each do |recording|
if recording[:recordID] == params[:record_id] if recording[:recordID] == params[:record_id]
return true return true
@ -78,7 +77,7 @@ class BbbController < ApplicationController
render head(:not_found) && return render head(:not_found) && return
end end
def render_bbb_response(bbb_res, response) def render_bbb_response(bbb_res, response={})
@messageKey = bbb_res[:messageKey] @messageKey = bbb_res[:messageKey]
@message = bbb_res[:message] @message = bbb_res[:message]
@status = bbb_res[:status] @status = bbb_res[:status]

View File

@ -15,7 +15,7 @@
</div> </div>
<% end %> <% end %>
<div class="page-wrapper meeting"> <div class="page-wrapper meetings">
<div class='container-fluid'> <div class='container-fluid'>
<%= render 'shared/title', title: 'Start A New Session' %> <%= render 'shared/title', title: 'Start A New Session' %>

View File

@ -16,7 +16,7 @@
</div> </div>
<% end %> <% end %>
<div class="page-wrapper room"> <div class="page-wrapper rooms">
<div class="container-fluid"> <div class="container-fluid">
<%= render 'shared/title', title: page_title %> <%= render 'shared/title', title: page_title %>
@ -34,7 +34,9 @@
<% end %> <% end %>
</div> </div>
<table id="recordings" class="table table-striped table-bordered dt-responsive" width="100%"></table> <div class="table-wrapper">
<h3>Past Recordings</h3>
<table id="recordings" class="table" width="100%"></table>
</div>
</div> </div>
</div> </div>