aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/Gallery.vue
diff options
context:
space:
mode:
authorZero~Informatique2019-12-24 02:22:56 +0100
committerZero~Informatique2019-12-24 02:22:56 +0100
commit7c2576b0cfb0a15b2a14f6f5ea96de16f0c23b44 (patch)
tree1096617e6795916aa90e81ab50a7736f7d656943 /viewer/src/views/Gallery.vue
parent139e2b76d23b13d2b3bb70fb1d5c1ea9dc255513 (diff)
downloadldgallery-7c2576b0cfb0a15b2a14f6f5ea96de16f0c23b44.tar.gz
viewer: Plugin for Optional chaining and Coalesce. Implemented tag operations (intersection, addition, substraction). Unified Tag.Search
Diffstat (limited to 'viewer/src/views/Gallery.vue')
-rw-r--r--viewer/src/views/Gallery.vue46
1 files changed, 41 insertions, 5 deletions
diff --git a/viewer/src/views/Gallery.vue b/viewer/src/views/Gallery.vue
index 38199b9..f04b276 100644
--- a/viewer/src/views/Gallery.vue
+++ b/viewer/src/views/Gallery.vue
@@ -8,6 +8,7 @@
8 8
9<script lang="ts"> 9<script lang="ts">
10import { Component, Vue, Prop } from "vue-property-decorator"; 10import { Component, Vue, Prop } from "vue-property-decorator";
11import { Operation } from '@/@types/tag/Operation';
11import GallerySearch from "./GallerySearch.vue"; 12import GallerySearch from "./GallerySearch.vue";
12import GalleryDirectory from "./GalleryDirectory.vue"; 13import GalleryDirectory from "./GalleryDirectory.vue";
13import GalleryImage from "./GalleryImage.vue"; 14import GalleryImage from "./GalleryImage.vue";
@@ -29,10 +30,10 @@ export default class Gallery extends Vue {
29 30
30 // Results of the search (by tags) 31 // Results of the search (by tags)
31 get currentSearch(): Gallery.Item[] { 32 get currentSearch(): Gallery.Item[] {
32 const currentTags = this.$uiStore.currentTags; 33 const byOperation = this.extractTagsByOperation(this.$uiStore.currentTags);
33 let items = new Set<Gallery.Item>(); 34 const intersection = this.extractIntersection(byOperation);
34 currentTags.flatMap(tag => tag.items).forEach(item => items.add(item)); 35 const substraction = this.extractSubstraction(byOperation);
35 return [...items]; 36 return this.aggregateAll(byOperation, intersection, substraction);
36 } 37 }
37 38
38 // Item pointed by the URL (navigation) 39 // Item pointed by the URL (navigation)
@@ -45,7 +46,42 @@ export default class Gallery extends Vue {
45 // --- 46 // ---
46 47
47 private checkType(type: string): boolean { 48 private checkType(type: string): boolean {
48 return (this.currentItem && this.currentItem.properties.type === type) || false; 49 return this.currentItem?.properties.type === type ?? false;
50 }
51
52 private extractTagsByOperation(currentTags: Tag.Search[]): Tag.SearchByOperation {
53 let byOperation: Tag.SearchByOperation = {};
54 Object.values(Operation)
55 .forEach(operation => byOperation[operation] = currentTags.filter(tag => tag.operation === operation));
56 return byOperation;
57 }
58
59 private extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
60 let intersection = new Set<Gallery.Item>();
61 if (byOperation[Operation.INTERSECTION].length > 0) {
62 byOperation[Operation.INTERSECTION]
63 .map(tag => tag.items)
64 .reduce((a,b) => a.filter(c => b.includes(c)))
65 .flatMap(items=>items)
66 .forEach(item => intersection.add(item));
67 }
68 return intersection;
69 }
70
71 private extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
72 let substraction = new Set<Gallery.Item>();
73 if (byOperation[Operation.SUBSTRACTION].length > 0) {
74 byOperation[Operation.SUBSTRACTION]
75 .flatMap(tag => tag.items)
76 .forEach(item => substraction.add(item));
77 }
78 return substraction;
79 }
80
81 private aggregateAll(byOperation: Tag.SearchByOperation, intersection: Set<Gallery.Item>, substraction: Set<Gallery.Item>): Gallery.Item[] {
82 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
83 substraction.forEach(item => intersection.delete(item));
84 return [...intersection];
49 } 85 }
50} 86}
51</script> 87</script>