From dc251fffc2998f1cf4f8e9631928c4b92ac0d90e Mon Sep 17 00:00:00 2001
From: Zero~Informatique
Date: Sun, 22 Dec 2019 07:40:55 +0100
Subject: viewer: Implemented the search by tags. Pushed the special urls to
 ENV.

---
 viewer/src/views/Gallery.vue | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

(limited to 'viewer/src/views/Gallery.vue')

diff --git a/viewer/src/views/Gallery.vue b/viewer/src/views/Gallery.vue
index 2020280..38199b9 100644
--- a/viewer/src/views/Gallery.vue
+++ b/viewer/src/views/Gallery.vue
@@ -1,17 +1,20 @@
 <template>
   <div>
-    <gallery-directory v-if="isDirectory" :directory="currentItem" />
-    <gallery-image v-if="isImage" :image="currentItem" />
+    <gallery-search v-if="$uiStore.isModeSearch" :items="currentSearch" />
+    <gallery-directory v-else-if="isDirectory" :directory="currentItem" />
+    <gallery-image v-else-if="isImage" :image="currentItem" />
   </div>
 </template>
 
 <script lang="ts">
 import { Component, Vue, Prop } from "vue-property-decorator";
+import GallerySearch from "./GallerySearch.vue";
 import GalleryDirectory from "./GalleryDirectory.vue";
 import GalleryImage from "./GalleryImage.vue";
+import GalleryStore from "../store/galleryStore";
 
 @Component({
-  components: { GalleryDirectory, GalleryImage },
+  components: { GallerySearch, GalleryDirectory, GalleryImage },
 })
 export default class Gallery extends Vue {
   @Prop(String) readonly pathMatch!: string;
@@ -24,25 +27,23 @@ export default class Gallery extends Vue {
     return this.checkType("image");
   }
 
+  // Results of the search (by tags)
+  get currentSearch(): Gallery.Item[] {
+    const currentTags = this.$uiStore.currentTags;
+    let items = new Set<Gallery.Item>();
+    currentTags.flatMap(tag => tag.items).forEach(item => items.add(item));
+    return [...items];
+  }
+
+  // Item pointed by the URL (navigation)
   get currentItem(): Gallery.Item | null {
     const galleryItemsRoot = this.$galleryStore.galleryItemsRoot;
-    if (galleryItemsRoot) return this.searchCurrentItem(galleryItemsRoot, this.pathMatch);
+    if (galleryItemsRoot) return GalleryStore.searchCurrentItem(galleryItemsRoot, this.pathMatch);
     return null;
   }
 
   // ---
 
-  private searchCurrentItem(item: Gallery.Item, currentPath: string): Gallery.Item | null {
-    if (currentPath === item.path) return item;
-    if (item.properties.type === "directory" && currentPath.startsWith(item.path)) {
-      const itemFound = item.properties.items
-        .map(item => this.searchCurrentItem(item, currentPath))
-        .find(item => Boolean(item));
-      return itemFound || null;
-    }
-    return null;
-  }
-
   private checkType(type: string): boolean {
     return (this.currentItem && this.currentItem.properties.type === type) || false;
   }
-- 
cgit v1.2.3

