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.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts
index 466b509..0a84951 100644
--- a/viewer/src/services/indexfactory.ts
+++ b/viewer/src/services/indexfactory.ts
@@ -38,18 +38,19 @@ export default class IndexFactory {
38 const parts = tag.split(':'); 38 const parts = tag.split(':');
39 let lastPart: string | null = null; 39 let lastPart: string | null = null;
40 for (const part of parts) { 40 for (const part of parts) {
41 tagsIndex[part] = IndexFactory.pushPartToIndex(tagsIndex[part], part, item); 41 tagsIndex[part] = IndexFactory.pushPartToIndex(tagsIndex[part], part, item, !Boolean(lastPart));
42 if (lastPart) { 42 if (lastPart) {
43 const children = tagsIndex[lastPart].children; 43 const children = tagsIndex[lastPart].children;
44 children[part] = IndexFactory.pushPartToIndex(children[part], part, item); 44 children[part] = IndexFactory.pushPartToIndex(children[part], part, item, false);
45 } 45 }
46 lastPart = part; 46 lastPart = part;
47 } 47 }
48 } 48 }
49 } 49 }
50 50
51 private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item): Tag.Node { 51 private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node {
52 if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} }; 52 if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, items: [], children: {} };
53 else if (rootPart) index.rootPart = true;
53 if (!index.items.includes(item)) index.items.push(item); 54 if (!index.items.includes(item)) index.items.push(item);
54 return index; 55 return index;
55 } 56 }
@@ -125,8 +126,14 @@ export default class IndexFactory {
125 .filter(category => category.index && Object.keys(category.index).length) 126 .filter(category => category.index && Object.keys(category.index).length)
126 .forEach(category => { 127 .forEach(category => {
127 tagsCategories.push(category); 128 tagsCategories.push(category);
128 tagsRemaining.delete(category.tag); 129
129 Object.values(category.index).map(node => node.tag).forEach(tag => tagsRemaining.delete(tag)); 130 if (!tagsIndex[category.tag].rootPart)
131 tagsRemaining.delete(category.tag);
132
133 Object.values(category.index)
134 .map(node => node.tag)
135 .filter(tag => !tagsIndex[tag].rootPart)
136 .forEach(tag => tagsRemaining.delete(tag));
130 }); 137 });
131 tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); 138 tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) });
132 return tagsCategories; 139 return tagsCategories;