aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/MainGallery.vue
diff options
context:
space:
mode:
authorZero~Informatique2020-02-14 09:19:53 +0100
committerZero~Informatique2020-02-24 00:04:39 +0100
commit370e3db3455f548699ff5e046e0f8dcc304991ac (patch)
treee29fe9e2afb940eea74c8ed510c46a1eb0fa4d84 /viewer/src/views/MainGallery.vue
parente42f4e864bac21ed3b19d1869df2cdd4f8c3433c (diff)
downloadldgallery-370e3db3455f548699ff5e046e0f8dcc304991ac.tar.gz
viewer: major code and search mode overhaul
Updated libraries to the lastest version SCSS Formatter as suggested VSC extensions Renamed toolbar-color by scrollbar-color LD components use Props in favor of touching the stores directly (when possible) Moved most common algorithms to a "services" folder Complete search overhaul (lots of code change)
Diffstat (limited to 'viewer/src/views/MainGallery.vue')
-rw-r--r--viewer/src/views/MainGallery.vue110
1 files changed, 0 insertions, 110 deletions
diff --git a/viewer/src/views/MainGallery.vue b/viewer/src/views/MainGallery.vue
deleted file mode 100644
index 5767cce..0000000
--- a/viewer/src/views/MainGallery.vue
+++ /dev/null
@@ -1,110 +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 <ld-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/Operation";
32import Tools from "@/tools";
33import GallerySearch from "./GallerySearch.vue";
34import GalleryDirectory from "./GalleryDirectory.vue";
35
36@Component({
37 components: {
38 GallerySearch,
39 GalleryDirectory,
40 },
41})
42export default class Gallery extends Vue {
43 @Prop(String) readonly pathMatch!: string;
44
45 mounted() {
46 this.pathChanged();
47 }
48
49 @Watch("pathMatch")
50 pathChanged() {
51 console.log("Path: ", this.pathMatch);
52 this.$galleryStore.setCurrentPath(this.pathMatch);
53 }
54
55 // Results of the search (by tags)
56 get currentSearch(): Gallery.Item[] {
57 const byOperation = this.extractTagsByOperation(this.$uiStore.currentTags);
58 const intersection = this.extractIntersection(byOperation);
59 const substraction = this.extractSubstraction(byOperation);
60 return this.aggregateAll(byOperation, intersection, substraction);
61 }
62
63 // ---
64
65 private checkType(type: Gallery.ItemType): boolean {
66 return Tools.checkType(this.$galleryStore.currentItem, type);
67 }
68
69 private extractTagsByOperation(currentTags: Tag.Search[]): Tag.SearchByOperation {
70 let byOperation: Tag.SearchByOperation = {};
71 Object.values(Operation).forEach(
72 operation => (byOperation[operation] = currentTags.filter(tag => tag.operation === operation))
73 );
74 return byOperation;
75 }
76
77 private extractIntersection(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
78 let intersection = new Set<Gallery.Item>();
79 if (byOperation[Operation.INTERSECTION].length > 0) {
80 byOperation[Operation.INTERSECTION]
81 .map(tag => tag.items)
82 .reduce((a, b) => a.filter(c => b.includes(c)))
83 .flatMap(items => items)
84 .forEach(item => intersection.add(item));
85 }
86 return intersection;
87 }
88
89 private extractSubstraction(byOperation: Tag.SearchByOperation): Set<Gallery.Item> {
90 let substraction = new Set<Gallery.Item>();
91 if (byOperation[Operation.SUBSTRACTION].length > 0) {
92 byOperation[Operation.SUBSTRACTION].flatMap(tag => tag.items).forEach(item => substraction.add(item));
93 }
94 return substraction;
95 }
96
97 private aggregateAll(
98 byOperation: Tag.SearchByOperation,
99 intersection: Set<Gallery.Item>,
100 substraction: Set<Gallery.Item>
101 ): Gallery.Item[] {
102 byOperation[Operation.ADDITION].flatMap(tag => tag.items).forEach(item => intersection.add(item));
103 substraction.forEach(item => intersection.delete(item));
104 return [...intersection];
105 }
106}
107</script>
108
109<style lang="scss">
110</style>