-
+
@@ -321,12 +323,17 @@
mode: {
type: String,
value: "time"
+ },
+ date: {
+ type: String,
+ value: new Date().toISOString().replace(/T.*/, "")
}
},
observers: [
"widthChanged(calcWidth)",
- "modeChanged(mode)"
+ "modeChanged(mode)",
+ "dateChanged(date)"
],
shouldShowAlbums: function(order) {
@@ -340,6 +347,17 @@
}
},
+ dateChanged: function(date) {
+ this.pendingPhotos = [];
+ this.visibleThumbs = [];
+ this.thumbnails = [];
+ this.cursor = null;
+ Polymer.dom(this.$.thumbnails).innerHTML = "";
+ this.next = false;
+ this.limit = undefined;
+ this._loadPhotos();
+ },
+
modeChanged: function(mode) {
console.log("Mode changed to " + mode);
this.path = "";
@@ -803,13 +821,17 @@
path = "/" + mode;
if (mode == "time") {
path = "";
+ } else {
+ path = "/memories/" + (this.date || "");
}
}
console.log("Requesting " + this.limit + " photos.");
window.fetch("api/v1/photos" + path + query, function(path, error, xhr) {
this.loading = false;
- if ((mode != this.mode) || ((mode == "albums") && (path != (this.path || "")))) {
+ if ((mode != this.mode) ||
+ ((mode == "albums") && (path != (this.path || ""))) ||
+ ((mode == "memories") && (path != ("/memories/" + (this.date || ""))))) {
console.log("Skipping results for old query. Triggering re-fetch of photos for new path or mode.");
this._loadPhotos();
return;
diff --git a/server/routes/photos.js b/server/routes/photos.js
index e8a304f..b2a137e 100755
--- a/server/routes/photos.js
+++ b/server/routes/photos.js
@@ -1,10 +1,5 @@
"use strict";
-/*
-Memories:
-echo "select id,taken from photos where strftime('%m%d',taken)=strftime('%m%d',CURRENT_TIMESTAMP) order by taken desc;" | sqlite3 photos.db
-*/
-
const express = require("express"),
fs = require("fs"),
url = require("url"),
@@ -29,7 +24,7 @@ const router = express.Router();
*/
-router.get("/memories", function(req, res/*, next*/) {
+router.get("/memories/*", function(req, res/*, next*/) {
let limit = parseInt(req.query.limit) || 50,
id, cursor, index;
@@ -52,13 +47,15 @@ router.get("/memories", function(req, res/*, next*/) {
}
}
- let query = "SELECT * FROM photos WHERE strftime('%m%d',taken)=strftime('%m%d',CURRENT_TIMESTAMP) " + index + " ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
+ let date = new Date(decodeURI(req.url).replace(/\?.*$/, ""));
+ let query = "SELECT * FROM photos WHERE strftime('%m%d',taken)=strftime('%m%d',:date) " + index + " ORDER BY taken DESC,id DESC LIMIT " + (limit * 2 + 1);
-// console.log("Memories query", query);
+ console.log("Memories query", date.replace(/T.*/, "");
return photoDB.sequelize.query(query, {
replacements: {
- cursor: cursor
+ cursor: cursor,
+ date: date
},
type: photoDB.Sequelize.QueryTypes.SELECT
}).then(function(photos) {