aboutsummaryrefslogtreecommitdiff
path: root/viewer/src
diff options
context:
space:
mode:
authorZero~Informatique2020-04-04 01:36:34 +0200
committerZero~Informatique2020-04-04 01:42:40 +0200
commitce04802f300ba627a3b9e9612d938b825045e63f (patch)
tree94dd291de63cf97bae93573f2620b2d30040be3f /viewer/src
parent09ec37a772802980d68264f2fed040be36e14c82 (diff)
downloadldgallery-ce04802f300ba627a3b9e9612d938b825045e63f.tar.gz
viewer: tag categories implementation
fixed single tags not appearing in the "Other filters" special category, following code review GitHub: Resolves #29
Diffstat (limited to 'viewer/src')
-rw-r--r--viewer/src/@types/tag.d.ts1
-rw-r--r--viewer/src/services/indexfactory.ts19
2 files changed, 14 insertions, 6 deletions
diff --git a/viewer/src/@types/tag.d.ts b/viewer/src/@types/tag.d.ts
index 425a995..229c418 100644
--- a/viewer/src/@types/tag.d.ts
+++ b/viewer/src/@types/tag.d.ts
@@ -21,6 +21,7 @@ declare namespace Tag {
21 interface Node { 21 interface Node {
22 tag: Gallery.RawTag; 22 tag: Gallery.RawTag;
23 tagfiltered: Gallery.RawTag; 23 tagfiltered: Gallery.RawTag;
24 rootPart: boolean;
24 items: Gallery.Item[]; 25 items: Gallery.Item[];
25 children: Index; 26 children: Index;
26 } 27 }
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;