From 4790e8e62da8d6487d6e5382a94ad03af60bd77f Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Mon, 8 Oct 2018 17:45:49 -0700 Subject: [PATCH] Timing problems while deleting assets. Signed-off-by: James Ketrenos --- frontend/elements/photo-thumbnail.html | 5 ++- frontend/src/ketr-photos/ketr-photos.html | 42 ++++++++++++++++++++--- server/app.js | 1 + server/routes/photos.js | 32 ++++++++--------- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/frontend/elements/photo-thumbnail.html b/frontend/elements/photo-thumbnail.html index df7510f..9b39ada 100755 --- a/frontend/elements/photo-thumbnail.html +++ b/frontend/elements/photo-thumbnail.html @@ -3,6 +3,7 @@ + @@ -41,10 +42,12 @@ } #actions { + display: flex; padding: 0.5em; background-color: rgba(0, 0, 0, 0.5); opacity: 0; font-size: 0.6em; + color: #ddd; } :host(:hover) #info, @@ -54,7 +57,7 @@ -
+
diff --git a/frontend/src/ketr-photos/ketr-photos.html b/frontend/src/ketr-photos/ketr-photos.html index cab5b80..0af12c9 100755 --- a/frontend/src/ketr-photos/ketr-photos.html +++ b/frontend/src/ketr-photos/ketr-photos.html @@ -182,6 +182,7 @@ text-overflow: ellipsis; padding: 0.5em 0; font-weight: bold; + transition: opacity 0.25s ease-in-out; } .date-line .album-line { @@ -909,7 +910,9 @@ return; } } - this.thumbnails[index].visible = false; + if (this.thumbnails[index]) { + this.thumbnails[index].visible = false; + } }.bind(this)); /* Randomly index the visible array, keeping the center @@ -1054,6 +1057,7 @@ console.log("Total pending: " + this.pendingPhotos.length); }, + /* Asynchronously load items into the DOM */ processItems: function() { if (this.processing) { console.log("processItems while processing"); @@ -1236,7 +1240,6 @@ }, _imageAction: function(event) { - console.log(event.detail); switch (event.detail) { case "delete": /* Delete image */ var thumbnail = event.currentTarget; @@ -1244,15 +1247,46 @@ thumbnail.style.pointerEvents = "none"; this.async(function(thumbnail) { - thumbnail.parentElement.removeChild(thumbnail); + var parent = thumbnail.parentElement; + for (var i = 0; i < this.thumbnails.length; i++) { if (this.thumbnails[i] == thumbnail) { - console.log("Found thumbnail"); + console.log("Found thumbnail", this.thumbnails.length); + if (thumbnail.visible) { + console.log("Removing from visible list"); + thumbnail.visible = false; + var j = this.visibleThumbs.indexOf(i); + if (j != -1) { + console.log("Removing visible thumb", this.visibleThumbs.length); + this.visibleThumbs.splice(j, 1); + } + } this.thumbnails.splice(i, 1); this.notifyPath("thumbnails.length"); break; } } + + Polymer.dom(parent).removeChild(thumbnail); + + if (parent.querySelectorAll("photo-thumbnail").length == 0) { + /* There are no more thumbnails, so look up the document ancestors + * until we find the element with the date-line class, and then + * remove it from it's parent */ + while (parent && !parent.classList.contains("date-line")) { + parent = parent.parentElement; + } + if (!parent) { + return; + } + parent.style.opacity = 0; + this.async(function(parent) { + Polymer.dom(this.$.thumbnails).removeChild(parent); + this.triggerVisibilityChecks(); + }.bind(this, parent), 250); + } else { + this.triggerVisibilityChecks(); + } }.bind(this, thumbnail), 250); break; case "text-format": /* Rename this image */ diff --git a/server/app.js b/server/app.js index 1c91650..1e22f51 100755 --- a/server/app.js +++ b/server/app.js @@ -62,6 +62,7 @@ app.use(bodyParser.urlencoded({ /* Any path starting with the following won't be logged via morgan */ const logSkipPaths = new RegExp("^" + basePath + "(" + [ + ".*\/thumbs\/", "bower_components", ].join(")|(") + ")"); app.use(morgan('common', { diff --git a/server/routes/photos.js b/server/routes/photos.js index e44a581..ef8f5ef 100755 --- a/server/routes/photos.js +++ b/server/routes/photos.js @@ -159,17 +159,19 @@ router.get("/*", function(req, res/*, next*/) { if (id == -1) { index = ""; } else { - index = "AND ((strftime('%m-%d',taken)=strftime('%m-%d',:cursor) AND photos.id<"+id+ ") OR DATE(taken) limit; /* We queried one extra item to see if there are more than LIMIT available */ + let last; if (more) { photos.splice(limit); + last = photos[photos.length - 1]; } let results = { - items: photos + items: photos.sort(function(a, b) { + return new Date(b.taken) - new Date(a.taken); + }) }; + if (more) { + results.cursor = new Date(last.taken).toISOString().replace(/T.*/, "") + "_" + last.id; results.more = true; } return res.status(200).json(results);