aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/MainGallery.vue
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/views/MainGallery.vue')
-rw-r--r--viewer/src/views/MainGallery.vue108
1 files changed, 108 insertions, 0 deletions
diff --git a/viewer/src/views/MainGallery.vue b/viewer/src/views/MainGallery.vue
new file mode 100644
index 0000000..06cf512
--- /dev/null
+++ b/viewer/src/views/MainGallery.vue
@@ -0,0 +1,108 @@
1<!-- ldgallery - A static generator which turns a collection of tagged
2-- pictures into a searchable web gallery.
3--
4-- Copyright (C) 2019-2020 Guillaume FOUET
5--
6-- This program is free software: you can redistribute it and/or modify
7-- it under the terms of the GNU Affero General Public License as
8-- published by the Free Software Foundation, either version 3 of the
9-- License, or (at your option) any later version.
10--
11-- This program is distributed in the hope that it will be useful,
12-- but WITHOUT ANY WARRANTY; without even the implied warranty of
13-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14-- GNU Affero General Public License for more details.
15--
16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18-->
19
20<template>
21 <div>
22 <gallery-search v-if="$uiStore.isModeSearch" :items="currentSearch" />
23 <gallery-directory v-else-if="checkType('directory')" :directory="$galleryStore.currentItem" />
24 <gallery-picture v-else-if="checkType('picture')" :picture="$galleryStore.currentItem" />
25 <div v-else>{{$t("gallery.unknowntype")}}</div>
26 </div>
27</template>
28
29<script lang="ts">
30import { Component, Vue, Prop, Watch } from "vue-property-decorator";
31import { Operation } from "@/@types/tag/Operation";
32import Tools from "@/tools";
33import GallerySearch from "./GallerySearch.vue";
34import GalleryDirectory from "./GalleryDirectory.vue";
35import GalleryPicture from "./GalleryPicture.vue";
36
37@Component({
38 components: { GallerySearch, GalleryDirectory, GalleryPicture },
39})
40export default class Gallery extends Vue {
41 @Prop(String) readonly pathMatch!: string;
42
43 mounted() {
44 this.pathChanged();
45 }
46
47 @Watch("pathMatch")
48 pathChanged() {
49 console.log("Path: ", this.pathMatch);
50 this.$galleryStore.setCurrentPath(this.pathMatch);
51 }
52
53 // Results of the search (by tags)
54 get currentSearch(): Gallery.Item[] {
55 const byOperation = this.extractTagsByOperation(this.$uiStore.currentTags);
56 const intersection = this.extractIntersection(byOperation);
57 const substraction = this.extractSubstraction(byOperation);
58 return this.aggregateAll(byOperation, intersection, substraction);
59 }
60
61 // ---
62
63 private checkType(type: Gallery.ItemType): boolean {
64 return Tools.checkType(this.$galleryStore.currentItem, type);
65 }
66
67 private extractTagsByOperation(currentTags: Tag.Search[]): Tag.SearchByOperation {
68 let byOperation: Tag.SearchByOperation = {};
69 Object.values(Operation).forEach(
70 operation => (byOperation[operation] = currentTags.filter(tag => tag.operation === operation))
71 );
72 return byOperation;
73 }
74
75 private extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
76 let intersection = new Set<Gallery.Item>();
77 if (byOperation[Operation.INTERSECTION].length > 0) {
78 byOperation[Operation.INTERSECTION]
79 .map(tag => tag.items)
80 .reduce((a, b) => a.filter(c => b.includes(c)))
81 .flatMap(items => items)
82 .forEach(item => intersection.add(item));
83 }
84 return intersection;
85 }
86
87 private extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
88 let substraction = new Set<Gallery.Item>();
89 if (byOperation[Operation.SUBSTRACTION].length > 0) {
90 byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item));
91 }
92 return substraction;
93 }
94
95 private aggregateAll(
96 byOperation: Tag.SearchByOperation,
97 intersection: Set<Gallery.Item>,
98 substraction: Set<Gallery.Item>
99 ): Gallery.Item[] {
100 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
101 substraction.forEach(item => intersection.delete(item));
102 return [...intersection];
103 }
104}
105</script>
106
107<style lang="scss">
108</style>