From c51365adb506c1dac96567ea4c55627d92ae834b Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Sun, 29 Apr 2018 06:44:25 +0700 Subject: [PATCH] Updated dashboard Bulk deleting files and adding/removing selected files from album will no longer refresh the current view to the first page. It will now instead try to refresh the current page. There will be cases where the current page ends up empty (when bulk deleting or moving files from the current album), but I figured that isn't much of an issue when compared with the advantages. --- controllers/uploadController.js | 1 + public/js/dashboard.js | 52 +++++++++++++++++++++------------ views/_globals.njk | 2 +- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index a56671c..9492641 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -444,6 +444,7 @@ uploadsController.processFilesForDisplay = async (req, res, files, existingFiles } uploadsController.delete = async (req, res) => { + // TODO: Wrap utils.bulkDeleteFilesByIds() instead const user = await utils.authorize(req, res) if (!user) { return } const id = req.body.id diff --git a/public/js/dashboard.js b/public/js/dashboard.js index 594d49e..7fc26a6 100644 --- a/public/js/dashboard.js +++ b/public/js/dashboard.js @@ -11,7 +11,11 @@ const panel = { selectAlbumContainer: undefined, checkboxes: undefined, lastSelected: undefined, - albums: [] + albums: [], + currentView: { + album: undefined, + page: undefined + } } panel.preparePage = () => { @@ -135,12 +139,12 @@ panel.getUploads = (album, page, element) => {
- + - + @@ -152,12 +156,12 @@ panel.getUploads = (album, page, element) => { - + - + @@ -207,12 +211,12 @@ panel.getUploads = (album, page, element) => { - + - + @@ -286,12 +290,12 @@ panel.getUploads = (album, page, element) => { - + - + @@ -309,16 +313,19 @@ panel.getUploads = (album, page, element) => { const selectAll = document.getElementById('selectAll') if (selectAll) { selectAll.checked = true } } + + panel.currentView.album = album + panel.currentView.page = page }).catch(error => { console.log(error) return swal('An error occurred!', 'There was an error with the request, please check the console for more information.', 'error') }) } -panel.setFilesView = (view, album, page, element) => { +panel.setFilesView = (view, element) => { localStorage.filesView = view panel.filesView = view - panel.getUploads(album, page, element) + panel.getUploads(panel.currentView.album, panel.currentView.page, element) } panel.displayThumbnailModal = thumb => { @@ -431,7 +438,8 @@ panel.clearSelection = async () => { return swal('Cleared selection!', `Unselected ${count} ${suffix}.`, 'success') } -panel.deleteFile = (id, album, page) => { +panel.deleteFile = id => { + // TODO: Share function with bulk delete, just like 'add selected files to album' and 'add single file to album' swal({ title: 'Are you sure?', text: 'You won\'t be able to recover the file!', @@ -457,7 +465,7 @@ panel.deleteFile = (id, album, page) => { } swal('Deleted!', 'The file has been deleted.', 'success') - panel.getUploads(album, page) + panel.getUploads(panel.currentView.album, panel.currentView.page) }) .catch(error => { console.log(error) @@ -466,7 +474,7 @@ panel.deleteFile = (id, album, page) => { }) } -panel.deleteSelectedFiles = async album => { +panel.deleteSelectedFiles = async () => { const count = panel.selectedFiles.length if (!count) { return swal('An error occurred!', 'You have not selected any files.', 'error') @@ -516,16 +524,16 @@ panel.deleteSelectedFiles = async album => { localStorage.selectedFiles = JSON.stringify(panel.selectedFiles) swal('Deleted!', `${deleted} file${deleted === 1 ? ' has' : 's have'} been deleted.`, 'success') - return panel.getUploads(album) + return panel.getUploads(panel.currentView.album, panel.currentView.page) } -panel.addSelectedFilesToAlbum = async album => { +panel.addSelectedFilesToAlbum = async () => { const count = panel.selectedFiles.length if (!count) { return swal('An error occurred!', 'You have not selected any files.', 'error') } - const failedids = await panel.addToAlbum(panel.selectedFiles, album) + const failedids = await panel.addFilesToAlbum(panel.selectedFiles) if (!failedids) { return } if (failedids.length) { panel.selectedFiles = panel.selectedFiles.filter(id => failedids.includes(id)) @@ -533,9 +541,16 @@ panel.addSelectedFilesToAlbum = async album => { panel.selectedFiles = [] } localStorage.selectedFiles = JSON.stringify(panel.selectedFiles) + panel.getUploads(panel.currentView.album, panel.currentView.page) } -panel.addToAlbum = async (ids, album) => { +panel.addSingleFileToAlbum = async id => { + const failedids = await panel.addFilesToAlbum([id]) + if (!failedids) { return } + panel.getUploads(panel.currentView.album, panel.currentView.page) +} + +panel.addFilesToAlbum = async ids => { const count = ids.length const proceed = await swal({ title: 'Are you sure?', @@ -636,7 +651,6 @@ panel.addToAlbum = async (ids, album) => { } swal('Woohoo!', `Successfully ${albumid < 0 ? 'removed' : 'added'} ${added} ${suffix} ${albumid < 0 ? 'from' : 'to'} the album.`, 'success') - panel.getUploads(album) return add.data.failedids } diff --git a/views/_globals.njk b/views/_globals.njk index ae8f7dc..e851f86 100644 --- a/views/_globals.njk +++ b/views/_globals.njk @@ -12,7 +12,7 @@ v1: CSS and JS files. v2: Images and config files (manifest.json, browserconfig.xml, etcetera). #} -{% set v1 = "cDnmwkVVmk" %} +{% set v1 = "vixJhF5oKZ" %} {% set v2 = "MSEpgpfFIQ" %} {#