Thanksgiving
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
c787cd186c
commit
63e44c5ad3
@ -13,6 +13,7 @@
|
||||
<link rel="import" href="../../bower_components/iron-icon/iron-icon.html">
|
||||
<link rel="import" href="../../bower_components/iron-icons/iron-icons.html">
|
||||
<link rel="import" href="../../bower_components/iron-icons/image-icons.html">
|
||||
<link rel="import" href="../../bower_components/iron-icons/maps-icons.html">
|
||||
<link rel="import" href="../../bower_components/iron-iconset/iron-iconset.html">
|
||||
<link rel="import" href="../../bower_components/iron-pages/iron-pages.html">
|
||||
<link rel="import" href="../../bower_components/iron-resizable-behavior/iron-resizable-behavior.html">
|
||||
@ -313,6 +314,7 @@
|
||||
<!--paper-tab tab="time"><paper-icon-button icon="date-range"></paper-icon-button></paper-tab-->
|
||||
<paper-tab tab="memories"><paper-icon-button icon="today"></paper-icon-button></paper-tab>
|
||||
<paper-tab tab="albums"><paper-icon-button icon="folder"></paper-icon-button></paper-tab>
|
||||
<paper-tab tab="thanksgiving"><paper-icon-button icon="maps:local-dining"></paper-icon-button></paper-tab>
|
||||
<paper-tab hidden$="[[!user.maintainer]]" tab="duplicates"><paper-icon-button icon="compare-arrows"></paper-icon-button></paper-tab>
|
||||
<paper-tab hidden$="[[!user.maintainer]]" tab="trash"><paper-icon-button icon="delete"></paper-icon-button></paper-tab>
|
||||
</paper-tabs>
|
||||
@ -384,6 +386,7 @@
|
||||
<div tabindex="0" on-tap="loadPath">[[item.name]] /</div>
|
||||
</template>
|
||||
</div>
|
||||
<div mode="thanksgiving">Thanksgiving!</div>
|
||||
<div mode="time">time</div>
|
||||
<div mode="memories">Photos taken on <b on-tap="drawerToggle">[[memoryDate]]</b></div>
|
||||
</iron-pages>
|
||||
@ -1692,6 +1695,8 @@
|
||||
path = "";
|
||||
} else if (mode == "memories") {
|
||||
path = "memories/" + (this.date.replace(this.year + "-", "") || "");
|
||||
} else if (mode == "thanksgiving") {
|
||||
path = "thanksgiving/";
|
||||
}
|
||||
}
|
||||
var username = this.user ? this.user.username : "";
|
||||
@ -1706,6 +1711,7 @@
|
||||
if ((username != (this.user ? this.user.username : "")) ||
|
||||
(mode != this.mode) ||
|
||||
((mode == "albums") && (path != (this.path || ""))) ||
|
||||
((mode == "thanksgiving") && (path != ("thanksgiving/"))) ||
|
||||
((mode == "memories") && (path != ("memories/" + (this.date.replace(this.year + "-", "") || ""))))) {
|
||||
console.log("Skipping results for old query. Triggering re-fetch of photos for new path or mode.");
|
||||
this._loadPhotos();
|
||||
|
@ -565,34 +565,29 @@ router.get("/thanksgiving", function(req, res/*, next*/) {
|
||||
"2017-11-23",
|
||||
"2018-11-22",
|
||||
"2019-11-28",
|
||||
"2020-11-26",
|
||||
"2020-11-26"
|
||||
];
|
||||
|
||||
]
|
||||
let dayIsThanksgiving = "";
|
||||
thanksgiving.forEach(function(date) {
|
||||
let comparison = "strftime('%Y-%m-%d',taken)='" + date + "'";
|
||||
if (!dayIsThanksgiving) {
|
||||
dayIsThanksgiving = comparison;
|
||||
} else {
|
||||
dayIsThanksgiving += " OR " + comparison;
|
||||
}
|
||||
});
|
||||
|
||||
index = "strftime('%m-%d',taken)=strftime('%m-%d',:date)";
|
||||
} else {
|
||||
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("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 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.*/, ""));
|
||||
// }
|
||||
"WHERE (photos.duplicate=0 AND photos.deleted=0 AND photos.scanned NOT NULL AND (" + dayIsThanksgiving + ")) " +
|
||||
"ORDER BY strftime('%Y-%m-%d', taken) DESC,id DESC";
|
||||
|
||||
return photoDB.sequelize.query(query, {
|
||||
replacements: {
|
||||
cursor: cursor,
|
||||
date: date
|
||||
},
|
||||
type: photoDB.Sequelize.QueryTypes.SELECT
|
||||
}).then(function(photos) {
|
||||
console.log(query);
|
||||
console.log(JSON.stringify(photos));
|
||||
photos.forEach(function(photo) {
|
||||
for (var key in photo) {
|
||||
if (photo[key] instanceof Date) {
|
||||
@ -601,25 +596,10 @@ router.get("/thanksgiving", function(req, res/*, next*/) {
|
||||
}
|
||||
});
|
||||
|
||||
let more = photos.length > limit; /* We queried one extra item to see if there are more than LIMIT available */
|
||||
return res.status(200).json({
|
||||
items: photos
|
||||
});
|
||||
|
||||
let last;
|
||||
if (more) {
|
||||
photos.splice(limit);
|
||||
last = photos[photos.length - 1];
|
||||
}
|
||||
|
||||
let results = {
|
||||
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);
|
||||
}).catch(function(error) {
|
||||
console.error("Query failed: " + query);
|
||||
return Promise.reject(error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user