Add ability to delete synced items

This commit is contained in:
JonnyWong16 2017-11-11 19:41:51 -08:00
parent 718049b9f3
commit a2eeda64df
10 changed files with 227 additions and 48 deletions

View file

@ -45,6 +45,9 @@
<input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music <input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music
</label> </label>
</div> </div>
<div class="btn-group">
<button class="btn btn-dark refresh-history-button" id="refresh-history-list"><i class="fa fa-refresh"></i> Refresh history</button>
</div>
<div class="btn-group colvis-button-bar"></div> <div class="btn-group colvis-button-bar"></div>
</div> </div>
</div> </div>
@ -169,17 +172,18 @@
$('#deleteCount').text(history_to_delete.length); $('#deleteCount').text(history_to_delete.length);
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < history_to_delete.length; i++) { history_to_delete.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_history_rows', url: 'delete_history_rows',
data: { row_id: history_to_delete[i] }, type: 'POST',
data: { row_id: row },
async: true, async: true,
success: function (data) { success: function (data) {
var msg = "History deleted"; var msg = "History deleted";
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
history_table.draw(); history_table.draw();
}); });
} }
@ -199,5 +203,9 @@
}); });
% endif % endif
}); });
$("#refresh-history-list").click(function() {
history_table.draw();
});
</script> </script>
</%def> </%def>

View file

@ -392,6 +392,9 @@ DOCUMENTATION :: END
</button> </button>
</div> </div>
% endif % endif
<div class="btn-group">
<button class="btn btn-dark refresh-history-button" id="refresh-history-list"><i class="fa fa-refresh"></i> Refresh history</button>
</div>
<div class="btn-group colvis-button-bar"></div> <div class="btn-group colvis-button-bar"></div>
</div> </div>
</div> </div>
@ -576,17 +579,18 @@ DOCUMENTATION :: END
$('#deleteCount').text(history_to_delete.length); $('#deleteCount').text(history_to_delete.length);
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < history_to_delete.length; i++) { history_to_delete.forEach(function (row, idx) {
$.ajax({ $.ajax({
url: 'delete_history_rows', url: 'delete_history_rows',
data: { row_id: history_to_delete[i] }, type: 'POST',
data: { row_id: row },
async: true, async: true,
success: function (data) { success: function (data) {
var msg = "History deleted"; var msg = "History deleted";
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
history_table.draw(); history_table.draw();
}); });
} }
@ -606,6 +610,10 @@ DOCUMENTATION :: END
}); });
}); });
$("#refresh-history-list").click(function () {
history_table.draw();
});
// Send recently added notification // Send recently added notification
$('#send-recently-added-notification').on('click', function () { $('#send-recently-added-notification').on('click', function () {
var rating_key = $(this).data('id'); var rating_key = $(this).data('id');

View file

@ -1,3 +1,5 @@
var syncs_to_delete = [];
sync_table_options = { sync_table_options = {
"processing": false, "processing": false,
"serverSide": false, "serverSide": false,
@ -19,6 +21,19 @@ sync_table_options = {
"columnDefs": [ "columnDefs": [
{ {
"targets": [0], "targets": [0],
"data": null,
"createdCell": function (td, cellData, rowData, row, col) {
$(td).html('<div class="edit-sync-toggles">' +
'<button class="btn btn-xs btn-warning delete-sync" data-id="' + rowData['sync_id'] + '" data-toggle="button"><i class="fa fa-trash-o fa-fw"></i> Delete</button>&nbsp' +
'</div>');
},
"width": "7%",
"className": "delete-control no-wrap hidden",
"searchable": false,
"orderable": false
},
{
"targets": [1],
"data": "state", "data": "state",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData === 'pending') { if (cellData === 'pending') {
@ -31,7 +46,7 @@ sync_table_options = {
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [1], "targets": [2],
"data": "friendly_name", "data": "friendly_name",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') { if (cellData !== '') {
@ -47,7 +62,7 @@ sync_table_options = {
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [2], "targets": [3],
"data": "title", "data": "title",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData !== '') { if (cellData !== '') {
@ -61,7 +76,7 @@ sync_table_options = {
"className": "datatable-wrap" "className": "datatable-wrap"
}, },
{ {
"targets": [3], "targets": [4],
"data": "metadata_type", "data": "metadata_type",
"render": function ( data, type, full ) { "render": function ( data, type, full ) {
return data.toProperCase(); return data.toProperCase();
@ -69,17 +84,17 @@ sync_table_options = {
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [4], "targets": [5],
"data": "platform", "data": "platform",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [5], "targets": [6],
"data": "device_name", "data": "device_name",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [6], "targets": [7],
"data": "total_size", "data": "total_size",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (cellData > 0 ) { if (cellData > 0 ) {
@ -92,22 +107,22 @@ sync_table_options = {
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [7], "targets": [8],
"data": "item_count", "data": "item_count",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [8], "targets": [9],
"data": "item_complete_count", "data": "item_complete_count",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [9], "targets": [10],
"data": "item_downloaded_count", "data": "item_downloaded_count",
"className": "no-wrap" "className": "no-wrap"
}, },
{ {
"targets": [10], "targets": [11],
"data": "item_downloaded_percent_complete", "data": "item_downloaded_percent_complete",
"createdCell": function (td, cellData, rowData, row, col) { "createdCell": function (td, cellData, rowData, row, col) {
if (rowData['item_count'] > 0 ) { if (rowData['item_count'] > 0 ) {
@ -130,3 +145,19 @@ sync_table_options = {
showMsg(msg, false, false, 0) showMsg(msg, false, false, 0)
} }
} }
$('#sync_table').on('click', 'td.delete-control > .edit-sync-toggles > button.delete-sync', function () {
var tr = $(this).parents('tr');
var row = sync_table.row(tr);
var rowData = row.data();
var index_delete = syncs_to_delete.findIndex(x => x.client_id == rowData['client_id'] && x.sync_id == rowData['sync_id']);
if (index_delete === -1) {
syncs_to_delete.push({ client_id: rowData['client_id'], sync_id: rowData['sync_id'] });
} else {
syncs_to_delete.splice(index_delete, 1);
}
$(this).toggleClass('btn-warning').toggleClass('btn-danger');
});

View file

@ -148,10 +148,11 @@
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < libraries_to_delete.length; i++) { libraries_to_delete.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_library', url: 'delete_library',
data: { section_id: libraries_to_delete[i] }, type: 'POST',
data: { section_id: row },
cache: false, cache: false,
async: true, async: true,
success: function (data) { success: function (data) {
@ -159,11 +160,12 @@
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
for (var i = 0; i < libraries_to_purge.length; i++) { libraries_to_purge.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_all_library_history', url: 'delete_all_library_history',
data: { section_id: libraries_to_purge[i] }, type: 'POST',
data: { section_id: row },
cache: false, cache: false,
async: true, async: true,
success: function (data) { success: function (data) {
@ -171,7 +173,7 @@
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
libraries_list_table.draw(); libraries_list_table.draw();
}); });
} }

View file

@ -190,6 +190,9 @@ DOCUMENTATION :: END
</button>&nbsp; </button>&nbsp;
</div> </div>
% endif % endif
<div class="btn-group">
<button class="btn btn-dark refresh-history-button" id="refresh-history-list"><i class="fa fa-refresh"></i> Refresh history</button>
</div>
<div class="btn-group colvis-button-bar" id="button-bar-history"></div> <div class="btn-group colvis-button-bar" id="button-bar-history"></div>
</div> </div>
</div> </div>
@ -471,17 +474,18 @@ DOCUMENTATION :: END
$('#deleteCount').text(history_to_delete.length); $('#deleteCount').text(history_to_delete.length);
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < history_to_delete.length; i++) { history_to_delete.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_history_rows', url: 'delete_history_rows',
data: { row_id: history_to_delete[i] }, type: 'POST',
data: { row_id: row },
async: true, async: true,
success: function (data) { success: function (data) {
var msg = "History deleted"; var msg = "History deleted";
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
history_table.draw(); history_table.draw();
}); });
} }
@ -501,6 +505,10 @@ DOCUMENTATION :: END
}); });
% endif % endif
$("#refresh-history-list").click(function () {
history_table.draw();
});
function recentlyWatched() { function recentlyWatched() {
// Populate recently watched // Populate recently watched
$.ajax({ $.ajax({

View file

@ -19,6 +19,17 @@
<span><i class="fa fa-cloud-download"></i> Synced Items</span> <span><i class="fa fa-cloud-download"></i> Synced Items</span>
</div> </div>
<div class="button-bar"> <div class="button-bar">
% if _session['user_group'] == 'admin':
<div class="alert alert-danger alert-edit" role="alert" id="row-edit-mode-alert"><i class="fa fa-exclamation-triangle"></i>&nbspSelect syncs to delete. Data is deleted upon exiting edit mode.</div>
<div class="btn-group">
<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
</div>
% endif
<div class="btn-group">
<button class="btn btn-dark refresh-syncs-button" id="refresh-syncs-list"><i class="fa fa-refresh"></i> Refresh synced items</button>
</div>
<div class="btn-group colvis-button-bar"></div> <div class="btn-group colvis-button-bar"></div>
</div> </div>
</div> </div>
@ -26,17 +37,18 @@
<table class="display" id="sync_table" width="100%"> <table class="display" id="sync_table" width="100%">
<thead> <thead>
<tr> <tr>
<th align='left' id="state">State</th> <th align="left" id="delete_row">Delete</th>
<th align='left' id="user">User</th> <th align="left" id="state">State</th>
<th align='left' id="title">Title</th> <th align="left" id="user">User</th>
<th align='left' id="type">Type</th> <th align="left" id="title">Title</th>
<th align='left' id="platform">Platform</th> <th align="left" id="type">Type</th>
<th align='left' id="device">Device</th> <th align="left" id="platform">Platform</th>
<th align='left' id="size">Total Size</th> <th align="left" id="device">Device</th>
<th align='left' id="items">Total Items</th> <th align="left" id="size">Total Size</th>
<th align='left' id="converted">Converted</th> <th align="left" id="items">Total Items</th>
<th align='left' id="downloaded">Downloaded</th> <th align="left" id="converted">Converted</th>
<th align='left' id="percent_complete">Complete</th> <th align="left" id="downloaded">Downloaded</th>
<th align="left" id="percent_complete">Complete</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -47,6 +59,24 @@
</%def> </%def>
<%def name="modalIncludes()"> <%def name="modalIncludes()">
<div class="modal fade" id="confirm-modal-delete" tabindex="-1" role="dialog" aria-labelledby="confirm-modal-delete">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-remove"></i></button>
<h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
</div>
<div class="modal-body" style="text-align: center;">
<p>Are you REALLY sure you want to delete <strong><span id="deleteCount"></span></strong> sync item(s)?</p>
<p>This is permanent and cannot be undone!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-dark" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger btn-ok" data-dismiss="modal" id="confirm-delete">Delete</button>
</div>
</div>
</div>
</div>
</%def> </%def>
<%def name="javascriptIncludes()"> <%def name="javascriptIncludes()">
@ -64,10 +94,57 @@
} }
} }
sync_table = $('#sync_table').DataTable(sync_table_options); sync_table = $('#sync_table').DataTable(sync_table_options);
var colvis = new $.fn.dataTable.ColVis( sync_table, { buttonText: '<i class="fa fa-columns"></i> Select columns', buttonClass: 'btn btn-dark' } ); var colvis = new $.fn.dataTable.ColVis( sync_table, { buttonText: '<i class="fa fa-columns"></i> Select columns', buttonClass: 'btn btn-dark', exclude: [0] } );
$( colvis.button() ).appendTo('div.colvis-button-bar'); $( colvis.button() ).appendTo('div.colvis-button-bar');
clearSearchButton('sync_table', sync_table); clearSearchButton('sync_table', sync_table);
% if _session['user_group'] == 'admin':
$('#row-edit-mode').on('click', function() {
$('#row-edit-mode-alert').fadeIn(200);
if ($(this).hasClass('active')) {
if (syncs_to_delete.length > 0) {
$('#deleteCount').text(syncs_to_delete.length);
$('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () {
syncs_to_delete.forEach(function(row, idx) {
$.ajax({
url: 'delete_sync_rows',
type: 'POST',
data: {
client_id: row.client_id,
sync_id: row.sync_id
},
async: true,
success: function (data) {
var msg = "Sync deleted";
showMsg(msg, false, true, 2000);
}
});
});
sync_table.draw();
});
}
$('.delete-control').each(function () {
$(this).addClass('hidden');
$('#row-edit-mode-alert').fadeOut(200);
});
} else {
syncs_to_delete = [];
$('.delete-control').each(function() {
$(this).find('button.btn-danger').toggleClass('btn-warning').toggleClass('btn-danger');
$(this).removeClass('hidden');
});
}
});
% endif
});
$("#refresh-syncs-list").click(function() {
sync_table.draw();
}); });
</script> </script>
</%def> </%def>

View file

@ -169,6 +169,9 @@ DOCUMENTATION :: END
<input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music <input type="radio" name="media_type-filter" id="history-music" value="track" autocomplete="off"> Music
</label> </label>
</div> </div>
<div class="btn-group">
<button class="btn btn-dark refresh-history-button" id="refresh-history-list"><i class="fa fa-refresh"></i> Refresh history</button>
</div>
<div class="btn-group colvis-button-bar" id="button-bar-history"></div> <div class="btn-group colvis-button-bar" id="button-bar-history"></div>
</div> </div>
</div> </div>
@ -517,17 +520,18 @@ DOCUMENTATION :: END
$('#deleteCount').text(history_to_delete.length); $('#deleteCount').text(history_to_delete.length);
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < history_to_delete.length; i++) { history_to_delete.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_history_rows', url: 'delete_history_rows',
data: { row_id: history_to_delete[i] }, type: 'POST',
data: { row_id: row },
async: true, async: true,
success: function (data) { success: function (data) {
var msg = "History deleted"; var msg = "History deleted";
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
history_table.draw(); history_table.draw();
}); });
} }
@ -547,6 +551,10 @@ DOCUMENTATION :: END
}); });
% endif % endif
$("#refresh-history-list").click(function () {
history_table.draw();
});
function recentlyWatched() { function recentlyWatched() {
// Populate recently watched // Populate recently watched
$.ajax({ $.ajax({

View file

@ -134,10 +134,11 @@
$('#confirm-modal-delete').modal(); $('#confirm-modal-delete').modal();
$('#confirm-modal-delete').one('click', '#confirm-delete', function () { $('#confirm-modal-delete').one('click', '#confirm-delete', function () {
for (var i = 0; i < users_to_delete.length; i++) { users_to_delete.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_user', url: 'delete_user',
data: { user_id: users_to_delete[i] }, type: 'POST',
data: { user_id: row },
cache: false, cache: false,
async: true, async: true,
success: function (data) { success: function (data) {
@ -145,11 +146,12 @@
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
for (var i = 0; i < users_to_purge.length; i++) { users_to_purge.forEach(function(row, idx) {
$.ajax({ $.ajax({
url: 'delete_all_user_history', url: 'delete_all_user_history',
data: { user_id: users_to_purge[i] }, type: 'POST',
data: { user_id: row },
cache: false, cache: false,
async: true, async: true,
success: function (data) { success: function (data) {
@ -157,7 +159,7 @@
showMsg(msg, false, true, 2000); showMsg(msg, false, true, 2000);
} }
}); });
} });
users_list_table.draw(); users_list_table.draw();
}); });
} }

View file

@ -296,7 +296,7 @@ class PlexTV(object):
return request return request
def get_plextv_sync_lists(self, machine_id='', output_format=''): def get_plextv_sync_lists(self, machine_id='', output_format=''):
uri = '/servers/' + machine_id + '/sync_lists' uri = '/servers/%s/sync_lists' % machine_id
request = self.request_handler.make_request(uri=uri, request = self.request_handler.make_request(uri=uri,
proto=self.protocol, proto=self.protocol,
request_type='GET', request_type='GET',
@ -337,6 +337,24 @@ class PlexTV(object):
return request return request
def delete_plextv_device_sync_lists(self, client_id='', output_format=''):
uri = '/devices/%s/sync_items' % client_id
request = self.request_handler.make_request(uri=uri,
proto=self.protocol,
request_type='GET',
output_format=output_format)
return request
def delete_plextv_sync(self, client_id='', sync_id='', output_format=''):
uri = '/devices/%s/sync_items/%s' % (client_id, sync_id)
request = self.request_handler.make_request(uri=uri,
proto=self.protocol,
request_type='DELETE',
output_format=output_format)
return request
def get_full_users_list(self): def get_full_users_list(self):
friends_list = self.get_plextv_friends() friends_list = self.get_plextv_friends()
own_account = self.get_plextv_user_details() own_account = self.get_plextv_user_details()
@ -425,7 +443,8 @@ class PlexTV(object):
logger.warn(u"PlexPy PlexTV :: Unable to parse XML for get_synced_items.") logger.warn(u"PlexPy PlexTV :: Unable to parse XML for get_synced_items.")
else: else:
for a in xml_head: for a in xml_head:
client_id = helpers.get_xml_attr(a, 'id') sync_id = helpers.get_xml_attr(a, 'id')
client_id = helpers.get_xml_attr(a, 'clientIdentifier')
sync_device = a.getElementsByTagName('Device') sync_device = a.getElementsByTagName('Device')
for device in sync_device: for device in sync_device:
device_user_id = helpers.get_xml_attr(device, 'userID') device_user_id = helpers.get_xml_attr(device, 'userID')
@ -505,6 +524,7 @@ class PlexTV(object):
"video_quality": settings_video_quality, "video_quality": settings_video_quality,
"total_size": status_total_size, "total_size": status_total_size,
"failure": status_failure, "failure": status_failure,
"client_id": client_id,
"sync_id": sync_id "sync_id": sync_id
} }
@ -512,6 +532,10 @@ class PlexTV(object):
return session.filter_session_info(synced_items, filter_key='user_id') return session.filter_session_info(synced_items, filter_key='user_id')
def delete_sync(self, client_id, sync_id):
logger.info(u"PlexPy PlexTV :: Deleting sync item '%s'." % sync_id)
self.delete_plextv_sync(client_id=client_id, sync_id=sync_id)
def get_server_urls(self, include_https=True): def get_server_urls(self, include_https=True):
if plexpy.CONFIG.PMS_IDENTIFIER: if plexpy.CONFIG.PMS_IDENTIFIER:

View file

@ -2271,6 +2271,17 @@ class WebInterface(object):
return output return output
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))
def delete_sync_rows(self, client_id, sync_id, **kwargs):
if client_id and sync_id:
plex_tv = plextv.PlexTV()
delete_row = plex_tv.delete_sync(client_id=client_id, sync_id=sync_id)
return {'message': 'Sync deleted'}
else:
return {'message': 'no data received'}
##### Logs ##### ##### Logs #####
@cherrypy.expose @cherrypy.expose