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.visibleThumbs = [];
|
||||||
this.thumbnails = [];
|
this.thumbnails = [];
|
||||||
this.notifyPath("thumbnails.length");
|
this.notifyPath("thumbnails.length");
|
||||||
this.cursor = null;
|
|
||||||
Polymer.dom(this.$.thumbnails).innerHTML = "";
|
Polymer.dom(this.$.thumbnails).innerHTML = "";
|
||||||
this.next = false;
|
this.next = false;
|
||||||
this.limit = undefined;
|
this.limit = undefined;
|
||||||
@ -825,6 +824,14 @@
|
|||||||
return;
|
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;
|
var index, start, stop, length = this.thumbnails.length;
|
||||||
|
|
||||||
start = 0;
|
start = 0;
|
||||||
@ -863,6 +870,7 @@
|
|||||||
if (pos != 0) {
|
if (pos != 0) {
|
||||||
console.log("DOM changed or viewport changed and search would never exit; re-scheduling check")
|
console.log("DOM changed or viewport changed and search would never exit; re-scheduling check")
|
||||||
//this.triggerVisibilityChecks();
|
//this.triggerVisibilityChecks();
|
||||||
|
this.processing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -916,6 +924,8 @@
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.visibleThumbs = visible;
|
this.visibleThumbs = visible;
|
||||||
|
|
||||||
|
this.processing = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1039,10 +1049,18 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
processItems: function() {
|
processItems: function() {
|
||||||
|
if (this.processing) {
|
||||||
|
console.log("processItems while processing");
|
||||||
|
this.async(this.processItems.bind(this), 100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.pendingPhotos.length == 0) {
|
if (this.pendingPhotos.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.processing = true;
|
||||||
|
|
||||||
var lastPath = null;
|
var lastPath = null;
|
||||||
var albums = this.querySelectorAll(".album-line");
|
var albums = this.querySelectorAll(".album-line");
|
||||||
if (albums.length) {
|
if (albums.length) {
|
||||||
@ -1053,13 +1071,19 @@
|
|||||||
this.notifyPath("pendingPhotos.length");
|
this.notifyPath("pendingPhotos.length");
|
||||||
|
|
||||||
for (var i = 0; i < photos.length; i++) {
|
for (var i = 0; i < photos.length; i++) {
|
||||||
var photo = photos[i],
|
var photo = photos[i], datetime;
|
||||||
thumbnail = document.createElement("photo-thumbnail"),
|
|
||||||
datetime;
|
var j;
|
||||||
thumbnail.item = photo;
|
for (j = 0; j < this.thumbnails.length; j++) {
|
||||||
// thumbnail.width = this.calcWidth;
|
if (this.thumbnails[j].item.id == photo.id) {
|
||||||
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
break;
|
||||||
thumbnail.addEventListener("load-album", this.loadAlbum.bind(this));
|
}
|
||||||
|
}
|
||||||
|
if (j != this.thumbnails.length) {
|
||||||
|
console.log("Photo already exists in thumbnails list. Did server return dups?");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
datetime = (photo.taken || photo.modified || photo.added).replace(/T.*/, "");
|
datetime = (photo.taken || photo.modified || photo.added).replace(/T.*/, "");
|
||||||
} catch (error) {
|
} 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);
|
Polymer.dom(thumbnails).appendChild(thumbnail);
|
||||||
this.thumbnails.push(thumbnail);
|
this.thumbnails.push(thumbnail);
|
||||||
this.notifyPath("thumbnails.length");
|
this.notifyPath("thumbnails.length");
|
||||||
@ -1129,6 +1158,8 @@
|
|||||||
|
|
||||||
/* If the viewport is at the bottom when it finishes processing, trigger to load more. */
|
/* If the viewport is at the bottom when it finishes processing, trigger to load more. */
|
||||||
this.onScroll();
|
this.onScroll();
|
||||||
|
|
||||||
|
this.processing = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
pathTapped: function(event) {
|
pathTapped: function(event) {
|
||||||
@ -1225,8 +1256,7 @@
|
|||||||
this.appendItems(results.items);
|
this.appendItems(results.items);
|
||||||
|
|
||||||
if (results.more) {
|
if (results.more) {
|
||||||
var cursor = results.items[results.items.length - 1];
|
this._loadPhotos(results.cursor, true, this.limit * 2);
|
||||||
this._loadPhotos(cursor.taken.toString().replace(/T.*/, "") + "_" + cursor.id, true, this.limit * 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this, path));
|
}.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,
|
let limit = parseInt(req.query.limit) || 50,
|
||||||
id, cursor, index;
|
id, cursor, index;
|
||||||
|
|
||||||
if (req.query.next) {
|
if (req.query.next) {
|
||||||
let parts = req.query.next.split("_");
|
let parts = req.query.next.split("_");
|
||||||
cursor = parts[0];
|
cursor = new Date(parts[0]);
|
||||||
id = parseInt(parts[1]);
|
id = parseInt(parts[1]);
|
||||||
} else {
|
} else {
|
||||||
cursor = "";
|
cursor = "";
|
||||||
@ -38,19 +38,23 @@ router.get("/memories/*", function(req, res/*, next*/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
index = "strftime('%m%d',taken)=strftime('%m%d',:date)";
|
index = "strftime('%m-%d',taken)=strftime('%m-%d',:date)";
|
||||||
} else {
|
} else {
|
||||||
index = "(strftime('%Y%m%d',taken)=strftime('%Y%m%d',:date) AND photos.id<"+id+ ")" +
|
index = "((strftime('%Y-%m-%d',taken)=strftime('%Y-%m-%d',:cursor) AND photos.id<"+id+ ") OR " +
|
||||||
" OR (strftime('%m%d',taken)=strftime('%m%d',:date) AND strftime('%Y',taken)!=strftime('%Y',:date))";
|
"(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 " +
|
let query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
"INNER JOIN albums ON (albums.id=photos.albumId) " +
|
"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, {
|
return photoDB.sequelize.query(query, {
|
||||||
replacements: {
|
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 more = photos.length > limit; /* We queried one extra item to see if there are more than LIMIT available */
|
||||||
|
|
||||||
|
let last;
|
||||||
if (more) {
|
if (more) {
|
||||||
photos.splice(limit);
|
photos.splice(limit);
|
||||||
|
last = photos[photos.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = {
|
let results = {
|
||||||
items: photos
|
items: photos.sort(function(a, b) {
|
||||||
|
return new Date(b.taken) - new Date(a.taken);
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (more) {
|
if (more) {
|
||||||
|
results.cursor = new Date(last.taken).toISOString().replace(/T.*/, "") + "_" + last.id;
|
||||||
results.more = true;
|
results.more = true;
|
||||||
}
|
}
|
||||||
return res.status(200).json(results);
|
return res.status(200).json(results);
|
||||||
@ -112,13 +112,13 @@ router.get("/*", function(req, res/*, next*/) {
|
|||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
index = "";
|
index = "";
|
||||||
} else {
|
} 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(/^\//, ""),
|
let path = decodeURI(req.url).replace(/\?.*$/, "").replace(/^\//, ""),
|
||||||
query = "SELECT photos.*,albums.path AS path FROM photos " +
|
query = "SELECT photos.*,albums.path AS path FROM photos " +
|
||||||
"INNER JOIN albums ON (albums.id=photos.albumId AND albums.path LIKE :path) " +
|
"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 = {
|
replacements = {
|
||||||
cursor: cursor,
|
cursor: cursor,
|
||||||
path: path + "%"
|
path: path + "%"
|
||||||
@ -140,7 +140,7 @@ router.get("/*", function(req, res/*, next*/) {
|
|||||||
|
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
cursor = moment(cursor);
|
cursor = moment(cursor);
|
||||||
photos = photos.filter(function(photo) {
|
photos = photos.filter(function(photo) {
|
||||||
if (!cursor.isSame(photo.taken, "day")) {
|
if (!cursor.isSame(photo.taken, "day")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user