Fix #6 - memories now shows all items
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
51c057df2e
commit
a930d27860
@ -686,7 +686,6 @@
|
||||
this.visibleThumbs = [];
|
||||
this.thumbnails = [];
|
||||
this.notifyPath("thumbnails.length");
|
||||
this.cursor = null;
|
||||
Polymer.dom(this.$.thumbnails).innerHTML = "";
|
||||
this.next = false;
|
||||
this.limit = undefined;
|
||||
@ -825,6 +824,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.processing) {
|
||||
console.log("hide-or-show while processing");
|
||||
this.async(this.triggerVisibilityChecks.bind(this), 100);
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing = true;
|
||||
|
||||
var index, start, stop, length = this.thumbnails.length;
|
||||
|
||||
start = 0;
|
||||
@ -863,6 +870,7 @@
|
||||
if (pos != 0) {
|
||||
console.log("DOM changed or viewport changed and search would never exit; re-scheduling check")
|
||||
//this.triggerVisibilityChecks();
|
||||
this.processing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -916,6 +924,8 @@
|
||||
}.bind(this));
|
||||
|
||||
this.visibleThumbs = visible;
|
||||
|
||||
this.processing = false;
|
||||
});
|
||||
},
|
||||
|
||||
@ -1039,10 +1049,18 @@
|
||||
},
|
||||
|
||||
processItems: function() {
|
||||
if (this.processing) {
|
||||
console.log("processItems while processing");
|
||||
this.async(this.processItems.bind(this), 100);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.pendingPhotos.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing = true;
|
||||
|
||||
var lastPath = null;
|
||||
var albums = this.querySelectorAll(".album-line");
|
||||
if (albums.length) {
|
||||
@ -1053,13 +1071,19 @@
|
||||
this.notifyPath("pendingPhotos.length");
|
||||
|
||||
for (var i = 0; i < photos.length; i++) {
|
||||
var photo = photos[i],
|
||||
thumbnail = document.createElement("photo-thumbnail"),
|
||||
datetime;
|
||||
thumbnail.item = photo;
|
||||
// thumbnail.width = this.calcWidth;
|
||||
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
||||
thumbnail.addEventListener("load-album", this.loadAlbum.bind(this));
|
||||
var photo = photos[i], datetime;
|
||||
|
||||
var j;
|
||||
for (j = 0; j < this.thumbnails.length; j++) {
|
||||
if (this.thumbnails[j].item.id == photo.id) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j != this.thumbnails.length) {
|
||||
console.log("Photo already exists in thumbnails list. Did server return dups?");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
datetime = (photo.taken || photo.modified || photo.added).replace(/T.*/, "");
|
||||
} catch (error) {
|
||||
@ -1122,6 +1146,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
var thumbnail = document.createElement("photo-thumbnail");
|
||||
thumbnail.item = photo;
|
||||
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
||||
thumbnail.addEventListener("load-album", this.loadAlbum.bind(this));
|
||||
|
||||
Polymer.dom(thumbnails).appendChild(thumbnail);
|
||||
this.thumbnails.push(thumbnail);
|
||||
this.notifyPath("thumbnails.length");
|
||||
@ -1129,6 +1158,8 @@
|
||||
|
||||
/* If the viewport is at the bottom when it finishes processing, trigger to load more. */
|
||||
this.onScroll();
|
||||
|
||||
this.processing = false;
|
||||
},
|
||||
|
||||
pathTapped: function(event) {
|
||||
@ -1225,8 +1256,7 @@
|
||||
this.appendItems(results.items);
|
||||
|
||||
if (results.more) {
|
||||
var cursor = results.items[results.items.length - 1];
|
||||
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, true, this.limit * 2);
|
||||
this._loadPhotos(results.cursor, true, this.limit * 2);
|
||||
}
|
||||
|
||||
}.bind(this, path));
|
||||
|
@ -24,13 +24,13 @@ const router = express.Router();
|
||||
|
||||
*/
|
||||
|
||||
router.get("/memories/*", function(req, res/*, next*/) {
|
||||
router.get("/memories/:date?", function(req, res/*, next*/) {
|
||||
let limit = parseInt(req.query.limit) || 50,
|
||||
id, cursor, index;
|
||||
|
||||
if (req.query.next) {
|
||||
let parts = req.query.next.split("_");
|
||||
cursor = parts[0];
|
||||
cursor = new Date(parts[0]);
|
||||
id = parseInt(parts[1]);
|
||||
} else {
|
||||
cursor = "";
|
||||
@ -38,19 +38,23 @@ router.get("/memories/*", function(req, res/*, next*/) {
|
||||
}
|
||||
|
||||
if (id == -1) {
|
||||
index = "strftime('%m%d',taken)=strftime('%m%d',:date)";
|
||||
index = "strftime('%m-%d',taken)=strftime('%m-%d',:date)";
|
||||
} else {
|
||||
index = "(strftime('%Y%m%d',taken)=strftime('%Y%m%d',:date) AND photos.id<"+id+ ")" +
|
||||
" OR (strftime('%m%d',taken)=strftime('%m%d',:date) AND strftime('%Y',taken)!=strftime('%Y',:date))";
|
||||
index = "((strftime('%Y-%m-%d',taken)=strftime('%Y-%m-%d',:cursor) AND photos.id<"+id+ ") OR " +
|
||||
"(strftime('%m-%d',taken)=strftime('%m-%d',:cursor) AND strftime('%Y',taken)<strftime('%Y',:cursor)))";
|
||||
}
|
||||
|
||||
let date = new Date(decodeURI(req.url).replace(/\?.*$/, ""));
|
||||
let date = new Date("2016-" + req.params.date);
|
||||
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||
"INNER JOIN albums ON (albums.id=photos.albumId) " +
|
||||
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL AND " + index + ") ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
|
||||
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL AND " + index + ") " +
|
||||
"ORDER BY strftime('%Y-%m-%d',taken) DESC,id DESC LIMIT " + (limit + 1);
|
||||
|
||||
// console.log("Memories for " + date.toISOString().replace(/^2016-(.*)T.*$/, "$1"));
|
||||
// if (cursor) {
|
||||
// console.log("Cursor" + cursor.toISOString().replace(/T.*/, ""));
|
||||
// }
|
||||
|
||||
// console.log("Memories for " + date.toISOString().replace(/T.*/, ""));
|
||||
// console.log(query);
|
||||
|
||||
return photoDB.sequelize.query(query, {
|
||||
replacements: {
|
||||
@ -67,26 +71,22 @@ router.get("/memories/*", function(req, res/*, next*/) {
|
||||
}
|
||||
});
|
||||
|
||||
if (cursor) {
|
||||
cursor = moment(cursor);
|
||||
photos = photos.filter(function(photo) {
|
||||
if (!cursor.isSame(photo.taken, "day")) {
|
||||
return true;
|
||||
}
|
||||
return photo.id < id;
|
||||
});
|
||||
}
|
||||
|
||||
let more = photos.length > 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);
|
||||
@ -112,13 +112,13 @@ 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)<DATE(:cursor))";
|
||||
index = "AND ((strftime('%m-%d',taken)=strftime('%m-%d',:cursor) AND photos.id<"+id+ ") OR DATE(taken)<DATE(:cursor))";
|
||||
}
|
||||
|
||||
let path = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
|
||||
query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||
"INNER JOIN albums ON (albums.id=photos.albumId AND albums.path LIKE :path) " +
|
||||
"WHERE (photos.duplicate=0 AND photos.scanned AND photos.deleted=0 NOT NULL " + index + ") ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1),
|
||||
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL " + index + ") ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1),
|
||||
replacements = {
|
||||
cursor: cursor,
|
||||
path: path + "%"
|
||||
@ -140,7 +140,7 @@ router.get("/*", function(req, res/*, next*/) {
|
||||
|
||||
if (cursor) {
|
||||
cursor = moment(cursor);
|
||||
photos = photos.filter(function(photo) {
|
||||
photos = photos.filter(function(photo) {
|
||||
if (!cursor.isSame(photo.taken, "day")) {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user