From 9165cc1efcf7791f78b61b2c51a9de651b1b09aa Mon Sep 17 00:00:00 2001
From: Zero~Informatique
Date: Fri, 2 Jul 2021 22:53:16 +0200
Subject: viewer: types normalization - gallery.d.ts
GitHub: closes #301
---
viewer/src/services/indexfactory.ts | 13 +++++++------
viewer/src/services/indexsearch.ts | 17 +++++++++--------
viewer/src/services/itemComparators.ts | 13 +++++++------
viewer/src/services/ldzoom.ts | 7 ++++---
viewer/src/services/navigation.ts | 15 ++++++++-------
5 files changed, 35 insertions(+), 30 deletions(-)
(limited to 'viewer/src/services')
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts
index 4b28a60..0c5fdc5 100644
--- a/viewer/src/services/indexfactory.ts
+++ b/viewer/src/services/indexfactory.ts
@@ -17,19 +17,20 @@
-- along with this program. If not, see .
*/
-import { Operation } from "@/@types/Operation";
+import { Item, RawTag } from "@/@types/gallery";
import { ItemType } from "@/@types/ItemType";
+import { Operation } from "@/@types/Operation";
import Navigation from "@/services/navigation";
export default class IndexFactory {
- public static generateTags(root: Gallery.Item | null): Tag.Index {
+ public static generateTags(root: Item | null): Tag.Index {
const tagsIndex: Tag.Index = {};
if (root) IndexFactory.pushTagsForItem(tagsIndex, root);
return tagsIndex;
}
// Pushes all tags for a root item (and its children) to the index
- private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void {
+ private static pushTagsForItem(tagsIndex: Tag.Index, item: Item): void {
if (item.properties.type === ItemType.DIRECTORY) {
item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item));
return; // Directories are not indexed
@@ -49,7 +50,7 @@ export default class IndexFactory {
}
}
- private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node {
+ private static pushPartToIndex(index: Tag.Node, part: string, item: Item, rootPart: boolean): Tag.Node {
if (!index)
index = {
tag: part,
@@ -131,7 +132,7 @@ export default class IndexFactory {
// ---
- public static generateCategories(tagsIndex: Tag.Index, categoryTags?: Gallery.RawTag[]): Tag.Category[] {
+ public static generateCategories(tagsIndex: Tag.Index, categoryTags?: RawTag[]): Tag.Category[] {
if (!categoryTags?.length) return [{ tag: "", index: tagsIndex }];
const tagsCategories: Tag.Category[] = [];
@@ -149,7 +150,7 @@ export default class IndexFactory {
return tagsCategories;
}
- private static isDiscriminantTagOnly(tags: Gallery.RawTag[], node: Tag.Node): boolean {
+ private static isDiscriminantTagOnly(tags: RawTag[], node: Tag.Node): boolean {
return !tags.includes(node.tag) || !node.childPart;
}
}
diff --git a/viewer/src/services/indexsearch.ts b/viewer/src/services/indexsearch.ts
index 00f8cfc..eda1b27 100644
--- a/viewer/src/services/indexsearch.ts
+++ b/viewer/src/services/indexsearch.ts
@@ -17,11 +17,12 @@
-- along with this program. If not, see .
*/
+import { Item } from "@/@types/gallery";
import { Operation } from "@/@types/Operation";
export default class IndexSearch {
// Results of the search (by tags)
- public static search(searchTags: Tag.Search[]): Gallery.Item[] {
+ public static search(searchTags: Tag.Search[]): Item[] {
const byOperation = this.extractTagsByOperation(searchTags);
const intersection = this.extractIntersection(byOperation);
const substraction = this.extractSubstraction(byOperation);
@@ -36,8 +37,8 @@ export default class IndexSearch {
return byOperation;
}
- private static extractIntersection(byOperation: Tag.SearchByOperation): Set {
- const intersection = new Set();
+ private static extractIntersection(byOperation: Tag.SearchByOperation): Set- {
+ const intersection = new Set
- ();
if (byOperation[Operation.INTERSECTION].length > 0) {
byOperation[Operation.INTERSECTION]
.map(tag => tag.items)
@@ -48,8 +49,8 @@ export default class IndexSearch {
return intersection;
}
- private static extractSubstraction(byOperation: Tag.SearchByOperation): Set {
- const substraction = new Set();
+ private static extractSubstraction(byOperation: Tag.SearchByOperation): Set
- {
+ const substraction = new Set
- ();
if (byOperation[Operation.SUBSTRACTION].length > 0) {
byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item));
}
@@ -58,9 +59,9 @@ export default class IndexSearch {
private static aggregateAll(
byOperation: Tag.SearchByOperation,
- intersection: Set,
- substraction: Set
- ): Gallery.Item[] {
+ intersection: Set
- ,
+ substraction: Set
-
+ ): Item[] {
byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
substraction.forEach(item => intersection.delete(item));
return [...intersection];
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts
index bd9accb..aceff79 100644
--- a/viewer/src/services/itemComparators.ts
+++ b/viewer/src/services/itemComparators.ts
@@ -16,14 +16,15 @@
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see .
*/
-import { TranslateResult } from "vue-i18n";
+import { Item, ItemSortStr } from "@/@types/gallery";
import i18n from "@/plugins/i18n";
+import { TranslateResult } from "vue-i18n";
-export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number;
+export type ItemComparator = (left: Item, right: Item) => number;
export type ItemSort = { text: TranslateResult; fn: ItemComparator };
export default class ItemComparators {
- static readonly ITEM_SORTS: Record = {
+ static readonly ITEM_SORTS: Record = {
title_asc: {
text: i18n.t("command.sort.byTitleAsc"),
fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc),
@@ -40,7 +41,7 @@ export default class ItemComparators {
static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc;
- static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number {
+ static sortByPathAsc(left: Item, right: Item): number {
return left.path.localeCompare(right.path, undefined, {
sensitivity: "base",
ignorePunctuation: true,
@@ -48,7 +49,7 @@ export default class ItemComparators {
});
}
- static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number {
+ static sortByTitleAsc(left: Item, right: Item): number {
return left.title.localeCompare(right.title, undefined, {
sensitivity: "base",
ignorePunctuation: true,
@@ -56,7 +57,7 @@ export default class ItemComparators {
});
}
- static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number {
+ static sortByDateAsc(left: Item, right: Item): number {
return left.datetime.localeCompare(right.datetime); // TODO: handle timezones
}
diff --git a/viewer/src/services/ldzoom.ts b/viewer/src/services/ldzoom.ts
index 0fb0848..33a64c8 100644
--- a/viewer/src/services/ldzoom.ts
+++ b/viewer/src/services/ldzoom.ts
@@ -17,6 +17,7 @@
-- along with this program. If not, see .
*/
+import { PictureProperties, Resolution } from "@/@types/gallery";
import "hammerjs";
/**
@@ -25,7 +26,7 @@ import "hammerjs";
export default class LdZoom {
readonly containerElement: HTMLDivElement;
readonly imageElement: HTMLImageElement;
- readonly pictureProperties: Gallery.PictureProperties;
+ readonly pictureProperties: PictureProperties;
readonly maxScaleFactor: number;
readonly scrollZoomSpeed: number;
scaleFactor: number = 0.0;
@@ -33,7 +34,7 @@ export default class LdZoom {
constructor(
containerElement: HTMLDivElement,
imageElement: HTMLImageElement,
- pictureProperties: Gallery.PictureProperties,
+ pictureProperties: PictureProperties,
maxScaleFactor: number,
scrollZoomSpeed: number
) {
@@ -83,7 +84,7 @@ export default class LdZoom {
/**
* Returns the picture resolution as it should be displayed.
*/
- private getDisplayResolution(): Gallery.Resolution {
+ private getDisplayResolution(): Resolution {
return {
width: this.pictureProperties.resolution.width * this.scaleFactor,
height: this.pictureProperties.resolution.height * this.scaleFactor,
diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts
index 5b0716d..9bbd90c 100644
--- a/viewer/src/services/navigation.ts
+++ b/viewer/src/services/navigation.ts
@@ -17,6 +17,7 @@
-- along with this program. If not, see .
*/
+import { DirectoryItem, Item } from "@/@types/gallery";
import { ItemType } from "@/@types/ItemType";
export default class Navigation {
@@ -31,7 +32,7 @@ export default class Navigation {
};
// Searches for an item by path from a root item (navigation)
- public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] {
+ public static searchCurrentItemPath(root: Item, path: string): Item[] {
if (path === root.path) return [root];
if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) {
const itemChain = root.properties.items
@@ -51,20 +52,20 @@ export default class Navigation {
}
// Checks if the type of an item matches
- public static checkType(item: Gallery.Item | null, type: ItemType | null): boolean {
+ public static checkType(item: Item | null, type: ItemType | null): boolean {
return (item?.properties.type ?? null) === type;
}
- public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory {
+ public static getLastDirectory(itemPath: Item[]): DirectoryItem {
for (let idx = itemPath.length - 1; idx >= 0; idx--) {
const item = itemPath[idx];
- if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as Gallery.Directory;
+ if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as DirectoryItem;
}
throw new Error("No directory found");
}
// Sort a list of items, moving the directories to the beginning of the list
- public static directoriesFirst(items: Gallery.Item[]) {
+ public static directoriesFirst(items: Item[]) {
return [
...items
.filter(child => Navigation.checkType(child, ItemType.DIRECTORY))
@@ -75,13 +76,13 @@ export default class Navigation {
}
// Get the icon for an item
- public static getIcon(item: Gallery.Item): string {
+ public static getIcon(item: Item): string {
if (item.path.length <= 1) return "home";
return Navigation.ICON_BY_TYPE[item.properties.type];
}
// Get the file name of an item, without its cache timestamp
- public static getFileName(item: Gallery.Item): string {
+ public static getFileName(item: Item): string {
if (item.properties.type === ItemType.DIRECTORY) return item.title;
const timeStamped = item.properties.resource.split("/").pop() ?? "";
return timeStamped.split("?")[0];
--
cgit v1.2.3