refactor: days query to enum

Signed-off-by: Varun Patil <varunpatil@ucla.edu>
pull/563/head
Varun Patil 2023-03-23 20:06:08 -07:00
parent f1461b720c
commit 5ae7c83147
2 changed files with 46 additions and 29 deletions

View File

@ -159,7 +159,7 @@ import PeopleIcon from "vue-material-design-icons/AccountMultiple.vue";
import CheckCircle from "vue-material-design-icons/CheckCircle.vue"; import CheckCircle from "vue-material-design-icons/CheckCircle.vue";
import ImageMultipleIcon from "vue-material-design-icons/ImageMultiple.vue"; import ImageMultipleIcon from "vue-material-design-icons/ImageMultiple.vue";
import ArchiveIcon from "vue-material-design-icons/PackageDown.vue"; import ArchiveIcon from "vue-material-design-icons/PackageDown.vue";
import { API } from "../services/API"; import { API, DaysFilterType } from "../services/API";
const SCROLL_LOAD_DELAY = 100; // Delay in loading data when scrolling const SCROLL_LOAD_DELAY = 100; // Delay in loading data when scrolling
const DESKTOP_ROW_HEIGHT = 200; // Height of row on desktop const DESKTOP_ROW_HEIGHT = 200; // Height of row on desktop
@ -624,75 +624,70 @@ export default defineComponent({
/** Get query string for API calls */ /** Get query string for API calls */
getQuery() { getQuery() {
const query = new URLSearchParams(); const query: { [key: string]: string } = {};
// Favorites // Favorites
if (this.$route.name === "favorites") { if (this.$route.name === "favorites") {
query.set("fav", "1"); API.DAYS_FILTER(query, DaysFilterType.FAVORITES);
} }
// Videos // Videos
if (this.$route.name === "videos") { if (this.$route.name === "videos") {
query.set("vid", "1"); API.DAYS_FILTER(query, DaysFilterType.VIDEOS);
} }
// Folder // Folder
if (this.$route.name === "folders") { if (this.$route.name === "folders") {
query.set("folder", utils.getFolderRoutePath(this.config_foldersPath)); const path = utils.getFolderRoutePath(this.config_foldersPath);
API.DAYS_FILTER(query, DaysFilterType.FOLDER, path);
if (this.$route.query.recursive) { if (this.$route.query.recursive) {
query.set("recursive", "1"); API.DAYS_FILTER(query, DaysFilterType.RECURSIVE);
} }
} }
// Archive // Archive
if (this.$route.name === "archive") { if (this.$route.name === "archive") {
query.set("archive", "1"); API.DAYS_FILTER(query, DaysFilterType.ARCHIVE);
} }
// Albums // Albums
if (this.$route.name === "albums" && this.$route.params.name) { const user = <string>this.$route.params.user;
const user = <string>this.$route.params.user; const name = <string>this.$route.params.name;
const name = <string>this.$route.params.name; if (this.$route.name === "albums" && user && name) {
query.set("albums", `${user}/${name}`); API.DAYS_FILTER(query, DaysFilterType.ALBUM, `${user}/${name}`);
} }
// People // People
if ( if (this.routeIsPeople && user && name) {
this.routeIsPeople && const filter = <DaysFilterType>this.$route.name;
this.$route.params.user && API.DAYS_FILTER(query, filter, `${user}/${name}`);
this.$route.params.name
) {
query.set(
<string>this.$route.name, // "recognize" or "facerecognition"
`${this.$route.params.user}/${this.$route.params.name}`
);
// Face rect // Face rect
if (this.config_showFaceRect) { if (this.config_showFaceRect) {
query.set("facerect", "1"); API.DAYS_FILTER(query, DaysFilterType.FACE_RECT);
} }
} }
// Places // Places
if (this.$route.name === "places" && this.$route.params.name) { if (this.$route.name === "places" && name) {
const name = <string>this.$route.params.name; const id = <string>name.split("-", 1)[0];
query.set("places", <string>name.split("-", 1)[0]); API.DAYS_FILTER(query, DaysFilterType.PLACE, id);
} }
// Tags // Tags
if (this.$route.name === "tags" && this.$route.params.name) { if (this.$route.name === "tags" && name) {
query.set("tags", <string>this.$route.params.name); API.DAYS_FILTER(query, DaysFilterType.TAG, name);
} }
// Map Bounds // Map Bounds
if (this.$route.name === "map" && this.$route.query.b) { if (this.$route.name === "map" && this.$route.query.b) {
query.set("mapbounds", <string>this.$route.query.b); API.DAYS_FILTER(query, DaysFilterType.MAP_BOUNDS, <string>this.$route.query.b);
} }
// Month view // Month view
if (this.isMonthView) { if (this.isMonthView) {
query.set("monthView", "1"); API.DAYS_FILTER(query, DaysFilterType.MONTH_VIEW);
query.set("reverse", "1"); API.DAYS_FILTER(query, DaysFilterType.REVERSE);
} }
return query; return query;

View File

@ -17,6 +17,24 @@ function tok(url: string) {
return url; return url;
} }
export enum DaysFilterType {
FAVORITES = "fav",
VIDEOS = "vid",
FOLDER = "folder",
ARCHIVE = "archive",
ALBUM = "albums",
RECOGNIZE = "recognize",
FACERECOGNITION = "facerecognition",
PLACE = "places",
TAG = "tags",
MAP_BOUNDS = "mapbounds",
FACE_RECT = "facerect",
RECURSIVE = "recursive",
MONTH_VIEW = "monthView",
REVERSE = "reverse",
}
export class API { export class API {
static Q( static Q(
url: string, url: string,
@ -47,6 +65,10 @@ export class API {
return tok(gen(`${BASE}/days/{id}`, { id })); return tok(gen(`${BASE}/days/{id}`, { id }));
} }
static DAYS_FILTER(query: any, filter: DaysFilterType, value: string = '1') {
query[filter] = value;
}
static ALBUM_LIST(t: 1 | 2 | 3 = 3) { static ALBUM_LIST(t: 1 | 2 | 3 = 3) {
return gen(`${BASE}/clusters/albums?t=${t}`); return gen(`${BASE}/clusters/albums?t=${t}`);
} }