photoprism/frontend/src/model/photo.js

197 lines
4.7 KiB
JavaScript
Raw Normal View History

import Abstract from "model/abstract";
import Api from "common/api";
2018-08-07 18:17:14 +00:00
class Photo extends Abstract {
getEntityName() {
return this.PhotoTitle;
2018-08-07 18:17:14 +00:00
}
getId() {
return this.ID;
}
getTitle() {
return this.PhotoTitle;
}
getColor() {
switch (this.PhotoColor) {
case "brown":
case "black":
case "white":
case "grey":
return "grey lighten-2";
default:
return this.PhotoColor + " lighten-4";
}
}
getColors() {
return this.PhotoColors;
}
2018-08-09 21:10:05 +00:00
getGoogleMapsLink() {
return "https://www.google.com/maps/place/" + this.PhotoLat + "," + this.PhotoLong;
2018-08-09 21:10:05 +00:00
}
getThumbnailUrl(type) {
return "/api/v1/thumbnails/" + this.FileHash + "/" + type;
}
2019-05-14 16:16:35 +00:00
getDownloadUrl() {
return "/api/v1/download/" + this.FileHash;
}
getThumbnailSrcset() {
const result = [];
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");
return result.join(", ");
}
calculateSize(width, height) {
if(width >= this.FileWidth && height >= this.FileHeight) { // Smaller
return {width: this.FileWidth, height: this.FileHeight};
}
const srcAspectRatio = this.FileWidth / this.FileHeight;
const maxAspectRatio = width / height;
let newW, newH;
if (srcAspectRatio > maxAspectRatio) {
newW = width;
newH = Math.round(newW / srcAspectRatio);
} else {
newH = height;
newW = Math.round(newH * srcAspectRatio);
}
return {width: newW, height: newH};
}
getThumbnailSizes() {
const result = [];
result.push("(min-width: 2560px) 3840px");
result.push("(min-width: 1920px) 2560px");
result.push("(min-width: 1280px) 1920px");
result.push("(min-width: 720px) 1280px");
result.push("720px");
return result.join(", ");
}
hasLocation() {
return this.PhotoLat !== 0 || this.PhotoLong !== 0;
}
getLocation() {
const location = [];
if (this.LocationID) {
if (this.LocName && !this.LocCity && !this.LocCounty) {
location.push(this.LocName);
} else if (this.LocCity) {
location.push(this.LocCity);
} else if (this.LocCounty) {
location.push(this.LocCounty);
}
2018-09-24 17:26:25 +00:00
if (this.LocState && this.LocState !== this.LocCity) {
location.push(this.LocState);
}
if (this.LocCountry) {
location.push(this.LocCountry);
}
} else if (this.CountryName) {
location.push(this.CountryName);
} else {
location.push("Unknown");
}
return location.join(", ");
}
getFullLocation() {
const location = [];
if (this.LocationID) {
if (this.LocName) {
location.push(this.LocName);
}
if (this.LocCity) {
location.push(this.LocCity);
}
if (this.LocPostcode) {
location.push(this.LocPostcode);
}
if (this.LocCounty) {
location.push(this.LocCounty);
}
if (this.LocState) {
location.push(this.LocState);
}
if (this.LocCountry) {
location.push(this.LocCountry);
}
} else if (this.CountryName) {
location.push(this.CountryName);
} else {
location.push("Unknown");
}
return location.join(", ");
}
getCamera() {
if (this.CameraModel) {
return this.CameraMake + " " + this.CameraModel;
}
return "Unknown";
}
toggleLike() {
this.PhotoFavorite = !this.PhotoFavorite;
if(this.PhotoFavorite) {
return Api.post(this.getEntityResource() + "/like");
} else {
return Api.delete(this.getEntityResource() + "/like");
}
}
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() {
return "photos";
2018-08-07 18:17:14 +00:00
}
static getModelName() {
return "Photo";
2018-08-07 18:17:14 +00:00
}
}
export default Photo;