aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/indexfactory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/services/indexfactory.ts')
-rw-r--r--viewer/src/services/indexfactory.ts26
1 files changed, 19 insertions, 7 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts
index e402185..4b28a60 100644
--- a/viewer/src/services/indexfactory.ts
+++ b/viewer/src/services/indexfactory.ts
@@ -18,19 +18,19 @@
18*/ 18*/
19 19
20import { Operation } from "@/@types/Operation"; 20import { Operation } from "@/@types/Operation";
21import { ItemType } from "@/@types/ItemType";
21import Navigation from "@/services/navigation"; 22import Navigation from "@/services/navigation";
22 23
23export default class IndexFactory { 24export default class IndexFactory {
24
25 public static generateTags(root: Gallery.Item | null): Tag.Index { 25 public static generateTags(root: Gallery.Item | null): Tag.Index {
26 let tagsIndex: Tag.Index = {}; 26 const tagsIndex: Tag.Index = {};
27 if (root) IndexFactory.pushTagsForItem(tagsIndex, root); 27 if (root) IndexFactory.pushTagsForItem(tagsIndex, root);
28 return tagsIndex; 28 return tagsIndex;
29 } 29 }
30 30
31 // Pushes all tags for a root item (and its children) to the index 31 // Pushes all tags for a root item (and its children) to the index
32 private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void { 32 private static pushTagsForItem(tagsIndex: Tag.Index, item: Gallery.Item): void {
33 if (item.properties.type === "directory") { 33 if (item.properties.type === ItemType.DIRECTORY) {
34 item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item)); 34 item.properties.items.forEach(item => this.pushTagsForItem(tagsIndex, item));
35 return; // Directories are not indexed 35 return; // Directories are not indexed
36 } 36 }
@@ -50,7 +50,15 @@ export default class IndexFactory {
50 } 50 }
51 51
52 private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { 52 private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node {
53 if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, childPart: !rootPart, items: [], children: {} }; 53 if (!index)
54 index = {
55 tag: part,
56 tagfiltered: Navigation.normalize(part),
57 rootPart,
58 childPart: !rootPart,
59 items: [],
60 children: {},
61 };
54 else if (rootPart) index.rootPart = true; 62 else if (rootPart) index.rootPart = true;
55 else index.childPart = true; 63 else index.childPart = true;
56 64
@@ -60,7 +68,6 @@ export default class IndexFactory {
60 68
61 // --- 69 // ---
62 70
63
64 public static searchTags(tagsIndex: Tag.Index, filter: string, strict: boolean): Tag.Search[] { 71 public static searchTags(tagsIndex: Tag.Index, filter: string, strict: boolean): Tag.Search[] {
65 let search: Tag.Search[] = []; 72 let search: Tag.Search[] = [];
66 if (tagsIndex && filter) { 73 if (tagsIndex && filter) {
@@ -105,7 +112,12 @@ export default class IndexFactory {
105 ); 112 );
106 } 113 }
107 114
108 private static searchTagsFromFilter(tagsIndex: Tag.Index, operation: Operation, filter: string, strict: boolean): Tag.Search[] { 115 private static searchTagsFromFilter(
116 tagsIndex: Tag.Index,
117 operation: Operation,
118 filter: string,
119 strict: boolean
120 ): Tag.Search[] {
109 filter = Navigation.normalize(filter); 121 filter = Navigation.normalize(filter);
110 return Object.values(tagsIndex) 122 return Object.values(tagsIndex)
111 .filter(node => IndexFactory.matches(node, filter, strict)) 123 .filter(node => IndexFactory.matches(node, filter, strict))
@@ -114,7 +126,7 @@ export default class IndexFactory {
114 126
115 private static matches(node: Tag.Node, filter: string, strict: boolean): boolean { 127 private static matches(node: Tag.Node, filter: string, strict: boolean): boolean {
116 if (strict) return node.tagfiltered === filter; 128 if (strict) return node.tagfiltered === filter;
117 return node.tagfiltered.includes(filter) 129 return node.tagfiltered.includes(filter);
118 } 130 }
119 131
120 // --- 132 // ---