aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/navigation.ts
diff options
context:
space:
mode:
authorZero~Informatique2021-07-02 22:53:16 +0200
committerZero~Informatique2021-07-03 00:05:22 +0200
commit9165cc1efcf7791f78b61b2c51a9de651b1b09aa (patch)
tree111cfdc74ddaf7b19ff27508f16ab84694b27670 /viewer/src/services/navigation.ts
parent08ac32103fb5f8cca1861267dfd07a7c0d2faf62 (diff)
downloadldgallery-9165cc1efcf7791f78b61b2c51a9de651b1b09aa.tar.gz
viewer: types normalization - gallery.d.ts
GitHub: closes #301
Diffstat (limited to 'viewer/src/services/navigation.ts')
-rw-r--r--viewer/src/services/navigation.ts15
1 files changed, 8 insertions, 7 deletions
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 @@
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18*/ 18*/
19 19
20import { DirectoryItem, Item } from "@/@types/gallery";
20import { ItemType } from "@/@types/ItemType"; 21import { ItemType } from "@/@types/ItemType";
21 22
22export default class Navigation { 23export default class Navigation {
@@ -31,7 +32,7 @@ export default class Navigation {
31 }; 32 };
32 33
33 // Searches for an item by path from a root item (navigation) 34 // Searches for an item by path from a root item (navigation)
34 public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { 35 public static searchCurrentItemPath(root: Item, path: string): Item[] {
35 if (path === root.path) return [root]; 36 if (path === root.path) return [root];
36 if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) { 37 if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) {
37 const itemChain = root.properties.items 38 const itemChain = root.properties.items
@@ -51,20 +52,20 @@ export default class Navigation {
51 } 52 }
52 53
53 // Checks if the type of an item matches 54 // Checks if the type of an item matches
54 public static checkType(item: Gallery.Item | null, type: ItemType | null): boolean { 55 public static checkType(item: Item | null, type: ItemType | null): boolean {
55 return (item?.properties.type ?? null) === type; 56 return (item?.properties.type ?? null) === type;
56 } 57 }
57 58
58 public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { 59 public static getLastDirectory(itemPath: Item[]): DirectoryItem {
59 for (let idx = itemPath.length - 1; idx >= 0; idx--) { 60 for (let idx = itemPath.length - 1; idx >= 0; idx--) {
60 const item = itemPath[idx]; 61 const item = itemPath[idx];
61 if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as Gallery.Directory; 62 if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as DirectoryItem;
62 } 63 }
63 throw new Error("No directory found"); 64 throw new Error("No directory found");
64 } 65 }
65 66
66 // Sort a list of items, moving the directories to the beginning of the list 67 // Sort a list of items, moving the directories to the beginning of the list
67 public static directoriesFirst(items: Gallery.Item[]) { 68 public static directoriesFirst(items: Item[]) {
68 return [ 69 return [
69 ...items 70 ...items
70 .filter(child => Navigation.checkType(child, ItemType.DIRECTORY)) 71 .filter(child => Navigation.checkType(child, ItemType.DIRECTORY))
@@ -75,13 +76,13 @@ export default class Navigation {
75 } 76 }
76 77
77 // Get the icon for an item 78 // Get the icon for an item
78 public static getIcon(item: Gallery.Item): string { 79 public static getIcon(item: Item): string {
79 if (item.path.length <= 1) return "home"; 80 if (item.path.length <= 1) return "home";
80 return Navigation.ICON_BY_TYPE[item.properties.type]; 81 return Navigation.ICON_BY_TYPE[item.properties.type];
81 } 82 }
82 83
83 // Get the file name of an item, without its cache timestamp 84 // Get the file name of an item, without its cache timestamp
84 public static getFileName(item: Gallery.Item): string { 85 public static getFileName(item: Item): string {
85 if (item.properties.type === ItemType.DIRECTORY) return item.title; 86 if (item.properties.type === ItemType.DIRECTORY) return item.title;
86 const timeStamped = item.properties.resource.split("/").pop() ?? ""; 87 const timeStamped = item.properties.resource.split("/").pop() ?? "";
87 return timeStamped.split("?")[0]; 88 return timeStamped.split("?")[0];