From 1078e6f6e5c0003a8707f13b7b95369ec3a35184 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 3 Jan 2019 16:04:38 -0700 Subject: [PATCH] Remove taken book and notify if what you are looking at is taken --- public/js/little-library.js | 14 +++++++++++++- server.js | 5 ++++- templates/elements/book.html | 4 ++-- templates/elements/bookInfo.html | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/public/js/little-library.js b/public/js/little-library.js index 7accc82..249323a 100644 --- a/public/js/little-library.js +++ b/public/js/little-library.js @@ -4,10 +4,19 @@ $(document).ready(function() { var downloadButton; socket.on('get book', function(url) { - console.log(url); $(downloadButton).replaceWith('Download'); }); + socket.on('remove book', function(bookId) { + var book = $('#book_' + bookId); + var modal = $(''); + modal.find('.modal-background, .modal-close').click(function() { + modal.remove(); + }); + book.after(modal); + book.remove(); + }); + $('.navbar-burger').click(function() { if ($(this).hasClass('is-active')) { $(this).removeClass('is-active'); @@ -32,6 +41,9 @@ $(document).ready(function() { $('.take-book').click(function() { var id = $(this).data('book'); + $('#book_' + id).find('.box') + .removeClass('box').addClass(['notification', 'is-success']) + .attr('title', 'This can be downloaded until you leave this page'); socket.emit('take book', id); downloadButton = this; $(this).addClass('is-loading'); diff --git a/server.js b/server.js index 37a273b..23a5c8d 100644 --- a/server.js +++ b/server.js @@ -144,10 +144,12 @@ function Server () { console.log(socket.id + ' removed ' + bookId); const downloadLocation = fileLocation.substr(fileLocation.lastIndexOf('/')); socket.emit('get book', encodeURI('./files' + downloadLocation)); + socket.broadcast.emit('remove book', bookId); } }); socket.on('disconnect', () => { + // console.log(socket.id + ' disconnected'); this.broadcastVisitors(); this.deleteBooks(socket.id); }); @@ -240,7 +242,7 @@ Server.prototype.generateHistoryPage = function (req) { const id = fileName.replace('.json', ''); const added = fecha.format(new Date(bookData.added), 'hh:mm:ssA on dddd MMMM Do, YYYY'); const removed = fecha.format(new Date(parseInt(id)), 'hh:mm:ssA on dddd MMMM Do, YYYY'); - const removedTag = '
Taken' + removed + '
'; + const removedTag = '
Taken' + removed + '
'; const modal = this.fillTemplate('./templates/elements/modalCard.html', { id, header: '

' + bookData.title + '

' + bookData.author + '

', @@ -353,6 +355,7 @@ Server.prototype.deleteBooks = function (socketId) { if (data.socketId === socketId) { const check = this.checkId(data.bookId, (bookPath, bookDataPath) => { fs.unlinkSync(bookPath); + // console.log('removed ' + bookPath); fs.renameSync(bookDataPath, unusedFilename.sync(path.resolve(this.historyLocation, Date.now() + '.json'))); }); if (check === false) { diff --git a/templates/elements/book.html b/templates/elements/book.html index 517c56f..328f4a6 100644 --- a/templates/elements/book.html +++ b/templates/elements/book.html @@ -1,10 +1,10 @@ -
+
diff --git a/templates/elements/bookInfo.html b/templates/elements/bookInfo.html index 6f1c8c3..05cd125 100644 --- a/templates/elements/bookInfo.html +++ b/templates/elements/bookInfo.html @@ -4,7 +4,7 @@
File Format - {{fileFormat}} + {{fileFormat}}