2019-05-09 04:48:10 +00:00
|
|
|
import Abstract from "model/abstract";
|
|
|
|
import Api from "common/api";
|
2019-09-19 21:23:39 +00:00
|
|
|
import { DateTime } from "luxon";
|
2018-08-07 18:17:14 +00:00
|
|
|
|
|
|
|
class Photo extends Abstract {
|
|
|
|
getEntityName() {
|
2018-09-12 14:37:30 +00:00
|
|
|
return this.PhotoTitle;
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getId() {
|
2019-12-04 14:14:04 +00:00
|
|
|
return this.PhotoUUID;
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
getTitle() {
|
|
|
|
return this.PhotoTitle;
|
|
|
|
}
|
|
|
|
|
2019-04-26 00:22:53 +00:00
|
|
|
getColor() {
|
|
|
|
switch (this.PhotoColor) {
|
2019-05-09 04:48:10 +00:00
|
|
|
case "brown":
|
|
|
|
case "black":
|
|
|
|
case "white":
|
|
|
|
case "grey":
|
|
|
|
return "grey lighten-2";
|
2019-05-09 04:18:22 +00:00
|
|
|
default:
|
2019-05-09 04:48:10 +00:00
|
|
|
return this.PhotoColor + " lighten-4";
|
2019-04-26 00:22:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-18 15:27:08 +00:00
|
|
|
|
|
|
|
getColors() {
|
|
|
|
return this.PhotoColors;
|
|
|
|
}
|
|
|
|
|
2018-08-09 21:10:05 +00:00
|
|
|
getGoogleMapsLink() {
|
2019-12-20 19:23:16 +00:00
|
|
|
return "https://www.google.com/maps/place/" + this.PhotoLat + "," + this.PhotoLng;
|
2018-08-09 21:10:05 +00:00
|
|
|
}
|
|
|
|
|
2019-05-13 16:01:50 +00:00
|
|
|
getThumbnailUrl(type) {
|
|
|
|
return "/api/v1/thumbnails/" + this.FileHash + "/" + type;
|
2018-09-24 09:27:46 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 16:16:35 +00:00
|
|
|
getDownloadUrl() {
|
|
|
|
return "/api/v1/download/" + this.FileHash;
|
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getThumbnailSrcset() {
|
|
|
|
const result = [];
|
|
|
|
|
2019-05-13 16:01:50 +00:00
|
|
|
result.push(this.getThumbnailUrl("fit_720") + " 720w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_1280") + " 1280w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_1920") + " 1920w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_2560") + " 2560w");
|
|
|
|
result.push(this.getThumbnailUrl("fit_3840") + " 3840w");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
return result.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
calculateSize(width, height) {
|
|
|
|
if(width >= this.FileWidth && height >= this.FileHeight) { // Smaller
|
|
|
|
return {width: this.FileWidth, height: this.FileHeight};
|
2019-05-13 16:01:50 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:04:17 +00:00
|
|
|
const srcAspectRatio = this.FileWidth / this.FileHeight;
|
|
|
|
const maxAspectRatio = width / height;
|
|
|
|
|
|
|
|
let newW, newH;
|
|
|
|
|
|
|
|
if (srcAspectRatio > maxAspectRatio) {
|
|
|
|
newW = width;
|
|
|
|
newH = Math.round(newW / srcAspectRatio);
|
|
|
|
|
2019-05-13 16:01:50 +00:00
|
|
|
} else {
|
2019-05-14 14:04:17 +00:00
|
|
|
newH = height;
|
|
|
|
newW = Math.round(newH * srcAspectRatio);
|
2019-05-13 16:01:50 +00:00
|
|
|
}
|
2019-05-14 14:04:17 +00:00
|
|
|
|
|
|
|
return {width: newW, height: newH};
|
2019-02-11 21:55:29 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getThumbnailSizes() {
|
|
|
|
const result = [];
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
result.push("(min-width: 2560px) 3840px");
|
|
|
|
result.push("(min-width: 1920px) 2560px");
|
|
|
|
result.push("(min-width: 1280px) 1920px");
|
|
|
|
result.push("(min-width: 720px) 1280px");
|
2019-05-13 16:01:50 +00:00
|
|
|
result.push("720px");
|
2018-09-24 17:07:43 +00:00
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
return result.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 22:04:34 +00:00
|
|
|
getDateString() {
|
2019-09-19 21:23:39 +00:00
|
|
|
if(this.TimeZone) {
|
|
|
|
return DateTime.fromISO(this.TakenAt).setZone(this.TimeZone).toLocaleString(DateTime.DATETIME_FULL);
|
|
|
|
} else if(this.TakenAt) {
|
|
|
|
return DateTime.fromISO(this.TakenAt).toLocaleString(DateTime.DATE_HUGE);
|
|
|
|
} else {
|
|
|
|
return "Unknown";
|
|
|
|
}
|
2019-06-06 22:04:34 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 02:37:45 +00:00
|
|
|
hasLocation() {
|
2019-12-20 19:23:16 +00:00
|
|
|
return this.PhotoLat !== 0 || this.PhotoLng !== 0;
|
2019-05-08 02:37:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getLocation() {
|
2019-12-27 04:18:52 +00:00
|
|
|
if (this.LocPlace) {
|
|
|
|
return this.LocPlace;
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-12-21 16:24:29 +00:00
|
|
|
return "Unknown";
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getCamera() {
|
|
|
|
if (this.CameraModel) {
|
2019-05-16 10:24:13 +00:00
|
|
|
return this.CameraMake + " " + this.CameraModel;
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
return "Unknown";
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 15:59:12 +00:00
|
|
|
toggleLike() {
|
|
|
|
this.PhotoFavorite = !this.PhotoFavorite;
|
|
|
|
|
|
|
|
if(this.PhotoFavorite) {
|
2019-05-09 04:48:10 +00:00
|
|
|
return Api.post(this.getEntityResource() + "/like");
|
2018-10-31 02:33:18 +00:00
|
|
|
} else {
|
2019-05-09 04:48:10 +00:00
|
|
|
return Api.delete(this.getEntityResource() + "/like");
|
2018-10-31 02:33:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 15:59:12 +00:00
|
|
|
like() {
|
|
|
|
this.PhotoFavorite = true;
|
|
|
|
return Api.post(this.getEntityResource() + "/like");
|
|
|
|
}
|
|
|
|
|
|
|
|
unlike() {
|
|
|
|
this.PhotoFavorite = false;
|
|
|
|
return Api.delete(this.getEntityResource() + "/like");
|
|
|
|
}
|
|
|
|
|
2018-08-07 18:17:14 +00:00
|
|
|
static getCollectionResource() {
|
2019-05-09 04:48:10 +00:00
|
|
|
return "photos";
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static getModelName() {
|
2019-05-09 04:48:10 +00:00
|
|
|
return "Photo";
|
2018-08-07 18:17:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Photo;
|