From 9dc9bdcbed75fc861b4620e93f3fa6722408c5c7 Mon Sep 17 00:00:00 2001 From: Andres J Ruiz Torres Date: Sat, 11 Jul 2020 17:08:52 -0400 Subject: [PATCH 1/4] Add basic support for bulk deleting all devices Make it easier to purge all devices from the device list. Api calls are done in parallel, without error handling, but it should be a relatively fast operation Fixes #1435 --- .../dashboard/devices/devices.html | 1 + src/controllers/dashboard/devices/devices.js | 49 +++++++++++++++---- src/strings/en-us.json | 3 ++ 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/controllers/dashboard/devices/devices.html b/src/controllers/dashboard/devices/devices.html index 63c348c900..e2504cd3e7 100644 --- a/src/controllers/dashboard/devices/devices.html +++ b/src/controllers/dashboard/devices/devices.html @@ -5,6 +5,7 @@

${HeaderDevices}

${Help} +
diff --git a/src/controllers/dashboard/devices/devices.js b/src/controllers/dashboard/devices/devices.js index 1178a0f1bd..58f9fd0901 100644 --- a/src/controllers/dashboard/devices/devices.js +++ b/src/controllers/dashboard/devices/devices.js @@ -10,10 +10,41 @@ import 'cardStyle'; /* eslint-disable indent */ + // Local cache of loaded + let deviceIds = []; + function canDelete(deviceId) { return deviceId !== ApiClient.deviceId(); } + function deleteViaApi(id) { + return ApiClient.ajax({ + type: 'DELETE', + url: ApiClient.getUrl('Devices', { + Id: id + }) + }); + } + + function deleteAllDevices(page) { + let msg = globalize.translate('DeleteDevicesConfirmation'); + + require(['confirm'], async function (confirm) { + await confirm({ + text: msg, + title: globalize.translate('HeaderDeleteDevices'), + confirmText: globalize.translate('ButtonDelete'), + primary: 'delete' + }); + + loading.show(); + await Promise.all( + deviceIds.filter(canDelete).map((id) => deleteViaApi(id)) + ); + loadData(page); + }); + } + function deleteDevice(page, id) { const msg = globalize.translate('DeleteDeviceConfirmation'); @@ -23,16 +54,10 @@ import 'cardStyle'; title: globalize.translate('HeaderDeleteDevice'), confirmText: globalize.translate('Delete'), primary: 'delete' - }).then(function () { + }).then(async () => { loading.show(); - ApiClient.ajax({ - type: 'DELETE', - url: ApiClient.getUrl('Devices', { - Id: id - }) - }).then(function () { - loadData(page); - }); + await deleteViaApi(id); + loadData(page); }); }); } @@ -129,6 +154,7 @@ import 'cardStyle'; loading.show(); ApiClient.getJSON(ApiClient.getUrl('Devices')).then(function (result) { load(page, result.Items); + deviceIds = result.Items.map((device) => device.Id); loading.hide(); }); } @@ -145,6 +171,9 @@ import 'cardStyle'; view.addEventListener('viewshow', function () { loadData(this); }); - } + view.querySelector('#deviceDeleteAll').addEventListener('click', function() { + deleteAllDevices(view); + }); + } /* eslint-enable indent */ diff --git a/src/strings/en-us.json b/src/strings/en-us.json index b3a1579b1e..891c7ccc0a 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -150,6 +150,8 @@ "DefaultSubtitlesHelp": "Subtitles are loaded based on the default and forced flags in the embedded metadata. Language preferences are considered when multiple options are available.", "DeinterlaceMethodHelp": "Select the deinterlacing method to use when software transcoding interlaced content. When hardware acceleration supporting hardware deinterlacing is enabled the hardware deinterlacer will be used instead of this setting.", "Delete": "Delete", + "DeleteAll": "Delete All", + "DeleteDevicesConfirmation": "Are you sure you wish to delete all devices? All other sessions will be logged out. Devices will reappear the next time a user signs in.", "DeleteDeviceConfirmation": "Are you sure you wish to delete this device? It will reappear the next time a user signs in with it.", "DeleteImage": "Delete Image", "DeleteImageConfirmation": "Are you sure you wish to delete this image?", @@ -298,6 +300,7 @@ "HeaderDateIssued": "Date Issued", "HeaderDefaultRecordingSettings": "Default Recording Settings", "HeaderDeleteDevice": "Delete Device", + "HeaderDeleteDevices": "Delete All Devices", "HeaderDeleteItem": "Delete Item", "HeaderDeleteItems": "Delete Items", "HeaderDeleteProvider": "Delete Provider", From dcd324bae57914e24f4edf507b33214d2117a06c Mon Sep 17 00:00:00 2001 From: Andres J Ruiz Torres Date: Sat, 11 Jul 2020 19:21:34 -0400 Subject: [PATCH 2/4] Remove trailing space --- src/controllers/dashboard/devices/devices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/dashboard/devices/devices.js b/src/controllers/dashboard/devices/devices.js index 58f9fd0901..0a9586bddf 100644 --- a/src/controllers/dashboard/devices/devices.js +++ b/src/controllers/dashboard/devices/devices.js @@ -10,7 +10,7 @@ import 'cardStyle'; /* eslint-disable indent */ - // Local cache of loaded + // Local cache of loaded let deviceIds = []; function canDelete(deviceId) { From d6ef8a1b970e8d356834d989c60c4b9b4099fe30 Mon Sep 17 00:00:00 2001 From: Andres J Ruiz Torres Date: Sat, 17 Oct 2020 22:21:32 -0400 Subject: [PATCH 3/4] Move delete to use new API method --- src/controllers/dashboard/devices/devices.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/controllers/dashboard/devices/devices.js b/src/controllers/dashboard/devices/devices.js index 0a9586bddf..77aca79d0a 100644 --- a/src/controllers/dashboard/devices/devices.js +++ b/src/controllers/dashboard/devices/devices.js @@ -17,15 +17,6 @@ import 'cardStyle'; return deviceId !== ApiClient.deviceId(); } - function deleteViaApi(id) { - return ApiClient.ajax({ - type: 'DELETE', - url: ApiClient.getUrl('Devices', { - Id: id - }) - }); - } - function deleteAllDevices(page) { let msg = globalize.translate('DeleteDevicesConfirmation'); @@ -39,7 +30,7 @@ import 'cardStyle'; loading.show(); await Promise.all( - deviceIds.filter(canDelete).map((id) => deleteViaApi(id)) + deviceIds.filter(canDelete).map((id) => ApiClient.deleteDevice(id)) ); loadData(page); }); @@ -56,7 +47,7 @@ import 'cardStyle'; primary: 'delete' }).then(async () => { loading.show(); - await deleteViaApi(id); + await ApiClient.deleteDevice(id); loadData(page); }); }); From 2bd78f86589708edfa843d6d02b3a95eab0d9d17 Mon Sep 17 00:00:00 2001 From: Andres J Ruiz Torres Date: Sat, 17 Oct 2020 22:21:47 -0400 Subject: [PATCH 4/4] Fix eslint warning --- src/controllers/dashboard/devices/devices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/dashboard/devices/devices.js b/src/controllers/dashboard/devices/devices.js index 77aca79d0a..c6e7281645 100644 --- a/src/controllers/dashboard/devices/devices.js +++ b/src/controllers/dashboard/devices/devices.js @@ -18,7 +18,7 @@ import 'cardStyle'; } function deleteAllDevices(page) { - let msg = globalize.translate('DeleteDevicesConfirmation'); + const msg = globalize.translate('DeleteDevicesConfirmation'); require(['confirm'], async function (confirm) { await confirm({