diff options
author | Zero~Informatique | 2020-04-03 03:42:35 +0200 |
---|---|---|
committer | Zero~Informatique | 2020-04-03 03:42:35 +0200 |
commit | 577f49ab6e1fd9cd8007804a13dea1471ee2fb1f (patch) | |
tree | e9a911b580b839474cc1697fa4b9c83fe20788a3 /viewer/src/services | |
parent | 54790c6c73d7c51ff22cf5e9722b141cdc0249df (diff) | |
download | ldgallery-577f49ab6e1fd9cd8007804a13dea1471ee2fb1f.tar.gz |
viewer: tag categories implementation
GitHub: Resolves #29
Diffstat (limited to 'viewer/src/services')
-rw-r--r-- | viewer/src/services/indexfactory.ts | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index a31f3ef..466b509 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts | |||
@@ -112,4 +112,23 @@ export default class IndexFactory { | |||
112 | if (strict) return node.tagfiltered === filter; | 112 | if (strict) return node.tagfiltered === filter; |
113 | return node.tagfiltered.includes(filter) | 113 | return node.tagfiltered.includes(filter) |
114 | } | 114 | } |
115 | |||
116 | // --- | ||
117 | |||
118 | public static generateCategories(tagsIndex: Tag.Index, tags?: Gallery.RawTag[]): Tag.Category[] { | ||
119 | if (!tags?.length) return [{ tag: "", index: tagsIndex }]; | ||
120 | |||
121 | const tagsCategories: Tag.Category[] = []; | ||
122 | const tagsRemaining = new Map(Object.entries(tagsIndex)); | ||
123 | tags | ||
124 | .map(tag => ({ tag, index: tagsIndex[tag]?.children })) | ||
125 | .filter(category => category.index && Object.keys(category.index).length) | ||
126 | .forEach(category => { | ||
127 | tagsCategories.push(category); | ||
128 | tagsRemaining.delete(category.tag); | ||
129 | Object.values(category.index).map(node => node.tag).forEach(tag => tagsRemaining.delete(tag)); | ||
130 | }); | ||
131 | tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); | ||
132 | return tagsCategories; | ||
133 | } | ||
115 | } | 134 | } |