aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/Gallery.vue
diff options
context:
space:
mode:
authorpacien2020-05-02 04:11:24 +0200
committerpacien2020-05-02 04:11:24 +0200
commit8e3ac8fe44bebb38e1882ca7f06b8100078ad88d (patch)
treea748fa1e639cb3b5e1f24a8150e89dbb28c980cb /viewer/src/views/Gallery.vue
parent7042ffc06326fa8ffe70f5a59747709250166c16 (diff)
parent0e0b5b0ae44da7c1d67983dedd8f8d8d3516236f (diff)
downloadldgallery-8e3ac8fe44bebb38e1882ca7f06b8100078ad88d.tar.gz
Merge branch 'develop': release v1.0v1.0
Diffstat (limited to 'viewer/src/views/Gallery.vue')
-rw-r--r--viewer/src/views/Gallery.vue104
1 files changed, 0 insertions, 104 deletions
diff --git a/viewer/src/views/Gallery.vue b/viewer/src/views/Gallery.vue
deleted file mode 100644
index fad7cc3..0000000
--- a/viewer/src/views/Gallery.vue
+++ /dev/null
@@ -1,104 +0,0 @@
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 GallerySearch from "./GallerySearch.vue";
33import GalleryDirectory from "./GalleryDirectory.vue";
34import GalleryPicture from "./GalleryPicture.vue";
35
36@Component({
37 components: { GallerySearch, GalleryDirectory, GalleryPicture },
38})
39export default class Gallery extends Vue {
40 @Prop(String) readonly pathMatch!: string;
41
42 mounted() {
43 this.pathChanged()
44 }
45
46 @Watch("pathMatch")
47 pathChanged() {
48 console.log("Path: ", this.pathMatch);
49 this.$galleryStore.setCurrentPath(this.pathMatch);
50 }
51
52 // Results of the search (by tags)
53 get currentSearch(): Gallery.Item[] {
54 const byOperation = this.extractTagsByOperation(this.$uiStore.currentTags);
55 const intersection = this.extractIntersection(byOperation);
56 const substraction = this.extractSubstraction(byOperation);
57 return this.aggregateAll(byOperation, intersection, substraction);
58 }
59
60 // ---
61
62 private checkType(type: string): boolean {
63 return this.$galleryStore.currentItem?.properties.type === type ?? false;
64 }
65
66 private extractTagsByOperation(currentTags: Tag.Search[]): Tag.SearchByOperation {
67 let byOperation: Tag.SearchByOperation = {};
68 Object.values(Operation)
69 .forEach(operation => byOperation[operation] = currentTags.filter(tag => tag.operation === operation));
70 return byOperation;
71 }
72
73 private extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
74 let intersection = new Set<Gallery.Item>();
75 if (byOperation[Operation.INTERSECTION].length > 0) {
76 byOperation[Operation.INTERSECTION]
77 .map(tag => tag.items)
78 .reduce((a,b) => a.filter(c => b.includes(c)))
79 .flatMap(items=>items)
80 .forEach(item => intersection.add(item));
81 }
82 return intersection;
83 }
84
85 private extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
86 let substraction = new Set<Gallery.Item>();
87 if (byOperation[Operation.SUBSTRACTION].length > 0) {
88 byOperation[Operation.SUBSTRACTION]
89 .flatMap(tag => tag.items)
90 .forEach(item => substraction.add(item));
91 }
92 return substraction;
93 }
94
95 private aggregateAll(byOperation: Tag.SearchByOperation, intersection: Set<Gallery.Item>, substraction: Set<Gallery.Item>): Gallery.Item[] {
96 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
97 substraction.forEach(item => intersection.delete(item));
98 return [...intersection];
99 }
100}
101</script>
102
103<style lang="scss">
104</style>