Get file sizes for media info table

This commit is contained in:
Jonathan Wong 2016-01-16 18:23:08 -08:00
parent c0f0cb0d9e
commit 35528ef602
7 changed files with 309 additions and 97 deletions

View file

@ -10,6 +10,9 @@ $.ajax({
}
});
var get_file_sizes = false;
var refresh_child_tables = false;
media_info_table_options = {
"destroy": true,
"language": {
@ -99,7 +102,7 @@ media_info_table_options = {
}
}
},
"width": "26%"
"width": "24%"
},
{
"targets": [2],
@ -184,10 +187,12 @@ media_info_table_options = {
"data": "file_size",
"createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== null && cellData !== '') {
$(td).html(Math.round(cellData / 1024 / 1000).toString() + ' MB');
$(td).html(Math.round(cellData / 1024 / 1024).toString() + ' MiB');
} else {
if (rowData['section_type'] != 'photo') { get_file_sizes = true; }
}
},
"width": "5%",
"width": "7%",
"className": "no-wrap hidden-md hidden-sm hidden-xs",
"searchable": false
},
@ -244,6 +249,25 @@ media_info_table_options = {
createChildTableMedia(this, rowData)
}
});
if (get_file_sizes) {
$('#get_file_sizes_message').show();
$('#refresh-media-info-table').prop('disabled', true);
$.ajax({
url: 'get_media_info_file_sizes',
async: true,
data: { section_id: section_id },
complete: function (xhr, status) {
response = JSON.parse(xhr.responseText)
if (response.success == true) {
$('#get_file_sizes_message').hide();
$('#refresh-media-info-table').prop('disabled', false);
media_info_table.draw();
}
}
});
get_file_sizes = false;
}
},
"preDrawCallback": function(settings) {
var msg = "<i class='fa fa-refresh fa-spin'></i>&nbspFetching rows...";
@ -314,7 +338,8 @@ function childTableOptionsMedia(rowData) {
json_data: JSON.stringify(d),
section_id: rowData['section_id'],
section_type: section_type,
rating_key: rowData['rating_key']
rating_key: rowData['rating_key'],
refresh: refresh_child_tables
};
}
}
@ -343,6 +368,26 @@ function childTableOptionsMedia(rowData) {
createChildTableMedia(this, childrowData)
}
});
if (get_file_sizes) {
$('#refresh-media-info-table').prop('disabled', true);
$.ajax({
url: 'get_media_info_file_sizes',
async: true,
data: {
section_id: section_id,
rating_key: rowData['rating_key']
},
complete: function (xhr, status) {
response = JSON.parse(xhr.responseText)
if (response.success == true) {
$('#refresh-media-info-table').prop('disabled', false);
media_info_child_table[rowData['rating_key']].draw();
}
}
});
get_file_sizes = false;
}
}
$(this).closest('div.slider').slideDown();

View file

@ -8,11 +8,11 @@
<%def name="body()">
<div class='container-fluid'>
% if config['update_section_ids'] == 1:
<div id="update_section_ids_mssage" style="text-align: center; margin-top: 20px;">
<div id="update_section_ids_message" style="text-align: center; margin-top: 20px;">
<i class="fa fa-exclamation-triangle"></i> PlexPy needs to update the Library IDs in your databse. Click the "<strong>Refresh libraries</strong>" button below to begin the update.
</div>
% elif config['update_section_ids'] == -1:
<div id="update_section_ids_mssage" style="text-align: center; margin-top: 20px;">
<div id="update_section_ids_message" style="text-align: center; margin-top: 20px;">
<i class="fa fa-refresh fa-spin"></i> PlexPy is updating library IDs in the database. This could take a few minutes depending on the size of your database.
<br />
You may leave this page and come back later.
@ -23,7 +23,11 @@
<span><i class="fa fa-book"></i> All Libraries</span>
</div>
<div class="button-bar">
% if config['update_section_ids'] == -1:
<button class="btn btn-dark refresh-libraries-button" id="refresh-libraries-list" disabled><i class="fa fa-refresh"></i> Refresh libraries</button>
% else:
<button class="btn btn-dark refresh-libraries-button" id="refresh-libraries-list"><i class="fa fa-refresh"></i> Refresh libraries</button>
% endif
<button class="btn btn-danger btn-edit" data-toggle="button" aria-pressed="false" autocomplete="off" id="row-edit-mode">
<i class="fa fa-pencil"></i> Edit mode
</button>&nbsp
@ -172,7 +176,7 @@
$("#refresh-libraries-list").click(function () {
if ("${config['update_section_ids']}" == "1") {
$('#update_section_ids_mssage').html(
$('#update_section_ids_message').html(
'<i class="fa fa-refresh fa-spin"></i> PlexPy is updating library IDs in the database. This could take a few minutes depending on the size of your database.' +
'<br />' +
'You may leave this page and come back later.');
@ -194,9 +198,5 @@
}
});
});
if ("${config['update_section_ids']}" == "-1") {
$("#refresh-libraries-list").prop('disabled', true);
}
</script>
</%def>

View file

@ -196,6 +196,15 @@ DOCUMENTATION :: END
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
% if data['section_id'] in config['get_file_sizes']['section_ids']:
<div id="get_file_sizes_message" style="text-align: center; margin-top: 20px;">
% else:
<div id="get_file_sizes_message" style="text-align: center; margin-top: 20px; display: none;">
% endif
<i class="fa fa-refresh fa-spin"></i> PlexPy is getting the file sizes for the library's media info. This could take a few minutes depending on the size of your library.
<br />
You may leave this page and come back later.
</div>
<div class='table-card-header'>
<div class="header-bar">
<span>
@ -205,9 +214,15 @@ DOCUMENTATION :: END
</span>
</div>
<div class="button-bar">
% if data['section_id'] in config['get_file_sizes']['section_ids']:
<button class="btn btn-dark refresh-media-info-table-button" id="refresh-media-info-table" style="margin-right: 5px;" disabled>
<i class="fa fa-refresh"></i> Refresh media info
</button>
% else:
<button class="btn btn-dark refresh-media-info-table-button" id="refresh-media-info-table" style="margin-right: 5px;">
<i class="fa fa-refresh"></i> Refresh media info
</button>
% endif
<div class="colvis-button-bar hidden-xs" id="button-bar-media-info"></div>
</div>
</div>
@ -293,20 +308,20 @@ DOCUMENTATION :: END
<script src="interfaces/default/js/dataTables.bootstrap.min.js"></script>
<script src="interfaces/default/js/dataTables.bootstrap.pagination.js"></script>
% if data:
<script>
% if str(data['section_id']).isdigit():
var section_id = ${data['section_id']};
% else:
var section_id = null;
% endif
var section_name = '${data['section_name'].replace("'", "\\'")}';
var refresh_table = false;
</script>
<script src="interfaces/default/js/moment-with-locale.js"></script>
<script src="interfaces/default/js/tables/history_table.js"></script>
<script src="interfaces/default/js/tables/media_info_table.js"></script>
<script>
$(document).ready(function () {
% if str(data['section_id']).isdigit():
var section_id = ${data['section_id']};
% else:
var section_id = null;
% endif
var section_name = '${data['section_name'].replace("'", "\\'")}';
$("#edit-library-tooltip").tooltip();
// Populate watch time stats
@ -357,7 +372,8 @@ DOCUMENTATION :: END
data: function ( d ) {
return {
json_data: JSON.stringify( d ),
section_id: section_id
section_id: section_id,
refresh: refresh_table
};
}
}
@ -377,15 +393,11 @@ DOCUMENTATION :: END
});
$("#refresh-media-info-table").click(function () {
$.ajax({
url: 'delete_datatable_media_info_cache',
cache: false,
async: true,
data: { section_id: section_id },
complete: function(xhr, status) {
media_info_table.draw()
}
});
media_info_child_table = {};
refresh_table = true;
refresh_child_tables = true;
media_info_table.draw();
refresh_table = false;
});
// Load edit library modal