2019-05-09 04:48:10 +00:00
|
|
|
import Abstract from "model/abstract";
|
|
|
|
import Api from "common/api";
|
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() {
|
|
|
|
return this.ID;
|
|
|
|
}
|
|
|
|
|
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-05-09 04:48:10 +00:00
|
|
|
return "https://www.google.com/maps/place/" + this.PhotoLat + "," + this.PhotoLong;
|
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
|
|
|
}
|
|
|
|
|
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-05-08 02:37:45 +00:00
|
|
|
hasLocation() {
|
|
|
|
return this.PhotoLat !== 0 || this.PhotoLong !== 0;
|
|
|
|
}
|
|
|
|
|
2018-09-24 17:07:43 +00:00
|
|
|
getLocation() {
|
|
|
|
const location = [];
|
|
|
|
|
|
|
|
if (this.LocationID) {
|
|
|
|
if (this.LocName && !this.LocCity && !this.LocCounty) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocName);
|
2018-09-24 17:07:43 +00:00
|
|
|
} else if (this.LocCity) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCity);
|
2018-09-24 17:07:43 +00:00
|
|
|
} else if (this.LocCounty) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCounty);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 17:26:25 +00:00
|
|
|
if (this.LocState && this.LocState !== this.LocCity) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocState);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocCountry) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCountry);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
} else if (this.CountryName) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.CountryName);
|
2018-09-24 17:07:43 +00:00
|
|
|
} else {
|
2019-05-09 04:48:10 +00:00
|
|
|
location.push("Unknown");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
return location.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getFullLocation() {
|
|
|
|
const location = [];
|
|
|
|
|
|
|
|
if (this.LocationID) {
|
|
|
|
if (this.LocName) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocName);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocCity) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCity);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocPostcode) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocPostcode);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocCounty) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCounty);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocState) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocState);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.LocCountry) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.LocCountry);
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
} else if (this.CountryName) {
|
2019-05-09 04:18:22 +00:00
|
|
|
location.push(this.CountryName);
|
2018-09-24 17:07:43 +00:00
|
|
|
} else {
|
2019-05-09 04:48:10 +00:00
|
|
|
location.push("Unknown");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 04:48:10 +00:00
|
|
|
return location.join(", ");
|
2018-09-24 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getCamera() {
|
|
|
|
if (this.CameraModel) {
|
2019-05-09 04:18:22 +00:00
|
|
|
return 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
|
|
|
}
|
|
|
|
|
2018-10-31 02:33:18 +00:00
|
|
|
like(liked) {
|
|
|
|
if (liked === true) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|