Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add searching by multiple tags #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class PinViewSet(viewsets.ModelViewSet):
def get_queryset(self):
query = Pin.objects.all()
request = self.request
tags = self.request.query_params.getlist('tags', None)
if tags is not None:
for tag in tags:
query = query.filter(tags__name=tag)
return filter_private_pin(request, query)


Expand Down
1 change: 1 addition & 0 deletions pinry-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"axios": "^0.21.2",
"buefy": "^0.8.20",
"core-js": "^3.3.2",
"qs": "^6.7.0",
"register-service-worker": "^1.6.2",
"vue": "^2.6.10",
"vue-masonry": "^0.11.8",
Expand Down
8 changes: 6 additions & 2 deletions pinry-spa/src/components/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import qs from 'qs';
import storage from './utils/storage';

const API_PREFIX = '/api/v2/';
Expand Down Expand Up @@ -119,11 +120,14 @@ function fetchPins(offset, tagFilter, userFilter) {
limit: 30,
offset,
};
if (tagFilter) queryArgs.tags__name = tagFilter;
if (tagFilter) queryArgs.tags = tagFilter;
if (userFilter) queryArgs.submitter__username = userFilter;
return axios.get(
url,
{ params: queryArgs },
{
params: queryArgs,
paramsSerializer: params => qs.stringify(params, { arrayFormat: 'repeat' }),
},
);
}

Expand Down
38 changes: 14 additions & 24 deletions pinry-spa/src/components/search/SearchPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
<option>Tag</option>
<option>Board</option>
</b-select>
<b-autocomplete
<b-taginput
v-show="filterType === 'Tag'"
class="search-input"
v-model="name"
:data="filteredDataArray"
:keep-first="true"
:data="filteredTags"
autocomplete
:open-on-focus="true"
placeholder="select a filter then type to filter"
icon="magnify"
@select="option => selected = option">
placeholder="select a filter then type to filter"
@input="option => selected = option"
@typing="filterTags">
<template slot="empty">No results found</template>
</b-autocomplete>
</b-taginput>
<template v-if="filterType === 'Board'">
<b-input
class="search-input"
Expand Down Expand Up @@ -46,21 +46,21 @@ export default {
data() {
return {
filterType: null,
selectedOption: [],
filteredTags: [],
options: {
Tag: [],
},
name: '',
name: [],
boardText: '',
selected: null,
};
},
methods: {
selectOption(filterName) {
this.name = '';
this.name = [];
this.boardText = '';
if (filterName === 'Tag') {
this.selectedOption = this.options.Tag;
this.filteredTags = this.options.Tag;
}
},
searchBoard() {
Expand All @@ -72,6 +72,9 @@ export default {
{ filterType: this.filterType, selected: this.boardText },
);
},
filterTags(text) {
this.filteredTags = this.options.Tag.filter(tag => tag.toLowerCase().includes(text.toLowerCase()));
},
},
watch: {
filterType(newVal) {
Expand All @@ -84,19 +87,6 @@ export default {
);
},
},
computed: {
filteredDataArray() {
return this.selectedOption.filter(
(option) => {
const ret = option
.toString()
.toLowerCase()
.indexOf(this.name.toLowerCase()) >= 0;
return ret;
},
);
},
},
created() {
api.Tag.fetchList().then(
(resp) => {
Expand Down