aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/navigation.ts
diff options
context:
space:
mode:
authorZero~Informatique2020-05-22 04:14:48 +0200
committerOzoneGrif2020-05-22 04:39:18 +0200
commit74c1c5e34787ac57299c8cbd874e9dcc56da406d (patch)
tree51da8090667290bc27e3580b9a78271ddf4d0e3a /viewer/src/services/navigation.ts
parente20f99b74b55fdb3edbcfe5bfdb700fc1a5e9574 (diff)
downloadldgallery-74c1c5e34787ac57299c8cbd874e9dcc56da406d.tar.gz
viewer: Enumerated item types
Diffstat (limited to 'viewer/src/services/navigation.ts')
-rw-r--r--viewer/src/services/navigation.ts34
1 files changed, 15 insertions, 19 deletions
diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts
index 068d081..a7e752c 100644
--- a/viewer/src/services/navigation.ts
+++ b/viewer/src/services/navigation.ts
@@ -17,12 +17,14 @@
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 { ItemType } from "@/@types/ItemType";
21
20export default class Navigation { 22export default class Navigation {
21 23
22 // Searches for an item by path from a root item (navigation) 24 // Searches for an item by path from a root item (navigation)
23 public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] { 25 public static searchCurrentItemPath(root: Gallery.Item, path: string): Gallery.Item[] {
24 if (path === root.path) return [root]; 26 if (path === root.path) return [root];
25 if (root.properties.type === "directory" && path.startsWith(root.path)) { 27 if (root.properties.type === ItemType.DIRECTORY && path.startsWith(root.path)) {
26 const itemChain = root.properties.items 28 const itemChain = root.properties.items
27 .map(item => this.searchCurrentItemPath(item, path)) 29 .map(item => this.searchCurrentItemPath(item, path))
28 .find(itemChain => itemChain.length > 0); 30 .find(itemChain => itemChain.length > 0);
@@ -40,14 +42,14 @@ export default class Navigation {
40 } 42 }
41 43
42 // Checks if the type of an item matches 44 // Checks if the type of an item matches
43 public static checkType(item: Gallery.Item | null, type: Gallery.ItemType | null): boolean { 45 public static checkType(item: Gallery.Item | null, type: ItemType | null): boolean {
44 return (item?.properties.type ?? null) === type; 46 return (item?.properties.type ?? null) === type;
45 } 47 }
46 48
47 public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { 49 public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory {
48 for (let idx = itemPath.length - 1; idx >= 0; idx--) { 50 for (let idx = itemPath.length - 1; idx >= 0; idx--) {
49 const item = itemPath[idx]; 51 const item = itemPath[idx];
50 if (Navigation.checkType(item, "directory")) return item as Gallery.Directory; 52 if (Navigation.checkType(item, ItemType.DIRECTORY)) return item as Gallery.Directory;
51 } 53 }
52 throw new Error("No directory found"); 54 throw new Error("No directory found");
53 } 55 }
@@ -56,11 +58,11 @@ export default class Navigation {
56 public static directoriesFirst(items: Gallery.Item[]) { 58 public static directoriesFirst(items: Gallery.Item[]) {
57 return [ 59 return [
58 ...items 60 ...items
59 .filter(child => Navigation.checkType(child, "directory")) 61 .filter(child => Navigation.checkType(child, ItemType.DIRECTORY))
60 .sort((a, b) => a.title.localeCompare(b.title)), 62 .sort((a, b) => a.title.localeCompare(b.title)),
61 63
62 ...items 64 ...items
63 .filter(child => !Navigation.checkType(child, "directory")), 65 .filter(child => !Navigation.checkType(child, ItemType.DIRECTORY)),
64 ]; 66 ];
65 } 67 }
66 68
@@ -68,19 +70,13 @@ export default class Navigation {
68 public static getIcon(item: Gallery.Item): string { 70 public static getIcon(item: Gallery.Item): string {
69 if (item.path.length <= 1) return "home"; 71 if (item.path.length <= 1) return "home";
70 switch (item.properties.type) { 72 switch (item.properties.type) {
71 case "picture": 73 case ItemType.PICTURE: return "image";
72 return "image"; 74 case ItemType.PLAINTEXT: return "file-alt";
73 case "plaintext": 75 case ItemType.PDF: return "file-pdf";
74 return "file-alt"; 76 case ItemType.VIDEO: return "file-video";
75 case "pdf": 77 case ItemType.AUDIO: return "file-audio";
76 return "file-pdf"; 78 case ItemType.DIRECTORY: return "folder";
77 case "video": 79 case ItemType.OTHER:
78 return "file-video";
79 case "audio":
80 return "file-audio";
81 case "directory":
82 return "folder";
83 case "other":
84 default: 80 default:
85 return "file"; 81 return "file";
86 } 82 }
@@ -88,7 +84,7 @@ export default class Navigation {
88 84
89 // Get the file name of an item, without its cache timestamp 85 // Get the file name of an item, without its cache timestamp
90 public static getFileName(item: Gallery.Item): string { 86 public static getFileName(item: Gallery.Item): string {
91 if (item.properties.type === "directory") return item.title; 87 if (item.properties.type === ItemType.DIRECTORY) return item.title;
92 const timeStamped = item.properties.resource.split("/").pop() ?? ""; 88 const timeStamped = item.properties.resource.split("/").pop() ?? "";
93 return timeStamped.split("?")[0]; 89 return timeStamped.split("?")[0];
94 } 90 }