Add search bar for collections (#1260)
Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="row-wrapper">
|
<div class="row-wrapper">
|
||||||
<button class="icon" @click="toggleShowChildren">
|
<button class="icon" @click="toggleShowChildren">
|
||||||
<i class="material-icons" v-show="!showChildren">arrow_right</i>
|
<i class="material-icons" v-show="!showChildren && !isFiltered">arrow_right</i>
|
||||||
<i class="material-icons" v-show="showChildren">arrow_drop_down</i>
|
<i class="material-icons" v-show="showChildren || isFiltered">arrow_drop_down</i>
|
||||||
<folderIcon class="material-icons" />
|
<folderIcon class="material-icons" />
|
||||||
<span>{{ collection.name }}</span>
|
<span>{{ collection.name }}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-show="showChildren">
|
<div v-show="showChildren || isFiltered">
|
||||||
<ul class="flex-col">
|
<ul class="flex-col">
|
||||||
<li
|
<li
|
||||||
v-for="(folder, index) in collection.folders"
|
v-for="(folder, index) in collection.folders"
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
:folderIndex="index"
|
:folderIndex="index"
|
||||||
:collection-index="collectionIndex"
|
:collection-index="collectionIndex"
|
||||||
:doc="doc"
|
:doc="doc"
|
||||||
|
:isFiltered="isFiltered"
|
||||||
@edit-folder="editFolder(collectionIndex, folder, index)"
|
@edit-folder="editFolder(collectionIndex, folder, index)"
|
||||||
@edit-request="$emit('edit-request', $event)"
|
@edit-request="$emit('edit-request', $event)"
|
||||||
/>
|
/>
|
||||||
@@ -105,6 +106,7 @@ export default {
|
|||||||
collectionIndex: Number,
|
collectionIndex: Number,
|
||||||
collection: Object,
|
collection: Object,
|
||||||
doc: Boolean,
|
doc: Boolean,
|
||||||
|
isFiltered: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
<div class="row-wrapper">
|
<div class="row-wrapper">
|
||||||
<div>
|
<div>
|
||||||
<button class="icon" @click="toggleShowChildren">
|
<button class="icon" @click="toggleShowChildren">
|
||||||
<i class="material-icons" v-show="!showChildren">arrow_right</i>
|
<i class="material-icons" v-show="!showChildren && !isFiltered">arrow_right</i>
|
||||||
<i class="material-icons" v-show="showChildren">arrow_drop_down</i>
|
<i class="material-icons" v-show="showChildren || isFiltered">arrow_drop_down</i>
|
||||||
<i class="material-icons">folder_open</i>
|
<i class="material-icons">folder_open</i>
|
||||||
<span>{{ folder.name }}</span>
|
<span>{{ folder.name }}</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
</v-popover>
|
</v-popover>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-show="showChildren">
|
<div v-show="showChildren || isFiltered">
|
||||||
<ul class="flex-col">
|
<ul class="flex-col">
|
||||||
<li
|
<li
|
||||||
v-for="(request, index) in folder.requests"
|
v-for="(request, index) in folder.requests"
|
||||||
@@ -72,6 +72,7 @@ export default {
|
|||||||
collectionIndex: Number,
|
collectionIndex: Number,
|
||||||
folderIndex: Number,
|
folderIndex: Number,
|
||||||
doc: Boolean,
|
doc: Boolean,
|
||||||
|
isFiltered: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ TODO:
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<pw-section class="yellow" :label="$t('collections')" ref="collections">
|
<pw-section class="yellow" :label="$t('collections')" ref="collections">
|
||||||
|
<div class="show-on-large-screen">
|
||||||
|
<input aria-label="Search" type="search" :placeholder="$t('search')" v-model="filterText" />
|
||||||
|
<!-- <button class="icon">
|
||||||
|
<i class="material-icons">search</i>
|
||||||
|
</button> -->
|
||||||
|
</div>
|
||||||
<add-collection :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
|
<add-collection :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
|
||||||
<edit-collection
|
<edit-collection
|
||||||
:show="showModalEdit"
|
:show="showModalEdit"
|
||||||
@@ -66,11 +72,12 @@ TODO:
|
|||||||
</p>
|
</p>
|
||||||
<div class="virtual-list">
|
<div class="virtual-list">
|
||||||
<ul class="flex-col">
|
<ul class="flex-col">
|
||||||
<li v-for="(collection, index) in collections" :key="collection.name">
|
<li v-for="(collection, index) in filteredCollections" :key="collection.name">
|
||||||
<collection
|
<collection
|
||||||
:collection-index="index"
|
:collection-index="index"
|
||||||
:collection="collection"
|
:collection="collection"
|
||||||
:doc="doc"
|
:doc="doc"
|
||||||
|
:isFiltered="filterText.length > 0"
|
||||||
@edit-collection="editCollection(collection, index)"
|
@edit-collection="editCollection(collection, index)"
|
||||||
@add-folder="addFolder(collection, index)"
|
@add-folder="addFolder(collection, index)"
|
||||||
@edit-folder="editFolder($event)"
|
@edit-folder="editFolder($event)"
|
||||||
@@ -80,6 +87,11 @@ TODO:
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
<ul class="flex-col" v-if="filterText && filteredCollections.length === 0">
|
||||||
|
<li>
|
||||||
|
<label>{{ $t("nothing_found") }} "{{ filterText }}"</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</pw-section>
|
</pw-section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -110,6 +122,7 @@ export default {
|
|||||||
editingFolderIndex: undefined,
|
editingFolderIndex: undefined,
|
||||||
editingRequest: undefined,
|
editingRequest: undefined,
|
||||||
editingRequestIndex: undefined,
|
editingRequestIndex: undefined,
|
||||||
|
filterText: "",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -118,6 +131,45 @@ export default {
|
|||||||
? fb.currentCollections
|
? fb.currentCollections
|
||||||
: this.$store.state.postwoman.collections
|
: this.$store.state.postwoman.collections
|
||||||
},
|
},
|
||||||
|
filteredCollections() {
|
||||||
|
const collections =
|
||||||
|
fb.currentUser !== null ? fb.currentCollections : this.$store.state.postwoman.collections
|
||||||
|
|
||||||
|
if (!this.filterText) return collections
|
||||||
|
|
||||||
|
const filterText = this.filterText.toLowerCase()
|
||||||
|
const filteredCollections = []
|
||||||
|
|
||||||
|
for (let collection of collections) {
|
||||||
|
const filteredRequests = []
|
||||||
|
const filteredFolders = []
|
||||||
|
for (let request of collection.requests) {
|
||||||
|
console.log(request)
|
||||||
|
if (request.name.toLowerCase().includes(filterText)) filteredRequests.push(request)
|
||||||
|
}
|
||||||
|
for (let folder of collection.folders) {
|
||||||
|
const filteredFolderRequests = []
|
||||||
|
for (let request of folder.requests) {
|
||||||
|
if (request.name.toLowerCase().includes(filterText))
|
||||||
|
filteredFolderRequests.push(request)
|
||||||
|
}
|
||||||
|
if (filteredFolderRequests.length > 0) {
|
||||||
|
const filteredFolder = Object.assign({}, folder)
|
||||||
|
filteredFolder.requests = filteredFolderRequests
|
||||||
|
filteredFolders.push(filteredFolder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredRequests.length + filteredFolders.length > 0) {
|
||||||
|
const filteredCollection = Object.assign({}, collection)
|
||||||
|
filteredCollection.requests = filteredRequests
|
||||||
|
filteredCollection.folders = filteredFolders
|
||||||
|
filteredCollections.push(filteredCollection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredCollections
|
||||||
|
},
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
this._keyListener = function (e) {
|
this._keyListener = function (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user