photoprism/frontend/src/model/album.js

108 lines
2.4 KiB
JavaScript
Raw Normal View History

import RestModel from "model/rest";
2019-06-17 19:45:06 +00:00
import Api from "common/api";
import {DateTime} from "luxon";
2019-06-17 19:45:06 +00:00
export class Album extends RestModel {
getDefaults() {
return {
UID: "",
Cover: "",
Parent: "",
Folder: "",
Slug: "",
Type: "",
Title: "",
Caption: "",
Category: "",
Description: "",
Notes: "",
Filter: "",
Order: "",
Template: "",
Country: "",
Year: 0,
Month: 0,
Favorite: true,
Private: false,
PhotoCount: 0,
Links: [],
CreatedAt: "",
UpdatedAt: "",
};
}
2019-06-17 19:45:06 +00:00
getEntityName() {
return this.Slug;
2019-06-17 19:45:06 +00:00
}
getId() {
return this.UID;
2019-06-17 19:45:06 +00:00
}
getTitle() {
return this.Title;
2019-06-17 19:45:06 +00:00
}
thumbnailUrl(type) {
2019-06-17 19:45:06 +00:00
return "/api/v1/albums/" + this.getId() + "/thumbnail/" + type;
}
thumbnailSrcset() {
2019-06-17 19:45:06 +00:00
const result = [];
result.push(this.thumbnailUrl("fit_720") + " 720w");
result.push(this.thumbnailUrl("fit_1280") + " 1280w");
result.push(this.thumbnailUrl("fit_1920") + " 1920w");
result.push(this.thumbnailUrl("fit_2560") + " 2560w");
result.push(this.thumbnailUrl("fit_3840") + " 3840w");
2019-06-17 19:45:06 +00:00
return result.join(", ");
}
thumbnailSizes() {
2019-06-17 19:45:06 +00:00
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(", ");
}
getDateString() {
return DateTime.fromISO(this.CreatedAt).toLocaleString(DateTime.DATETIME_MED);
2019-06-17 19:45:06 +00:00
}
toggleLike() {
this.Favorite = !this.Favorite;
2019-06-17 19:45:06 +00:00
if (this.Favorite) {
2019-06-17 19:45:06 +00:00
return Api.post(this.getEntityResource() + "/like");
} else {
return Api.delete(this.getEntityResource() + "/like");
}
}
like() {
this.Favorite = true;
2019-06-17 19:45:06 +00:00
return Api.post(this.getEntityResource() + "/like");
}
unlike() {
this.Favorite = false;
2019-06-17 19:45:06 +00:00
return Api.delete(this.getEntityResource() + "/like");
}
static getCollectionResource() {
return "albums";
}
static getModelName() {
return "Album";
}
}
export default Album;