Verified Commit 42a2ffbf authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Fix #109: List pending requests by default, added a status filter for requests

parent f2d20e1b
import django_filters
from funkwhale_api.common import fields
from . import models
class ImportRequestFilter(django_filters.FilterSet):
q = fields.SearchFilter(search_fields=[
'artist_name',
'user__username',
'albums',
'comment',
])
class Meta:
model = models.ImportRequest
fields = {
......
......@@ -15,6 +15,7 @@ STATUS_CHOICES = [
('closed', 'closed'),
]
class ImportRequest(models.Model):
creation_date = models.DateTimeField(default=timezone.now)
imported_date = models.DateTimeField(null=True, blank=True)
......
List pending requests by default, added a status filter for requests (#109)
......@@ -6,7 +6,11 @@
<router-link class="ui item" to="/library/radios" exact><i18next path="Radios"/></router-link>
<router-link class="ui item" to="/library/playlists" exact><i18next path="Playlists"/></router-link>
<div class="ui secondary right menu">
<router-link v-if="$store.state.auth.authenticated" class="ui item" to="/library/requests/" exact>
<router-link
v-if="$store.state.auth.authenticated"
class="ui item"
:to="{name: 'library.requests', query: {status: 'pending' }}"
exact>
<i18next path="Requests"/>
<div class="ui teal label">{{ requestsCount }}</div>
</router-link>
......
......@@ -8,6 +8,16 @@
<label>{{ $t('Search') }}</label>
<input type="text" v-model="query" placeholder="Enter an artist name, a username..."/>
</div>
<div class="field">
<label>{{ $t('Status') }}</label>
<select class="ui dropdown" v-model="status">
<option :value="'any'">{{ $t('Any') }}</option>
<option :value="'pending'">{{ $t('Pending') }}</option>
<option :value="'accepted'">{{ $t('Accepted') }}</option>
<option :value="'imported'">{{ $t('Imported') }}</option>
<option :value="'closed'">{{ $t('Closed') }}</option>
</select>
</div>
<div class="field">
<label>{{ $t('Ordering') }}</label>
<select class="ui dropdown" v-model="ordering">
......@@ -81,7 +91,8 @@ const FETCH_URL = 'requests/import-requests/'
export default {
mixins: [OrderingMixin, PaginationMixin],
props: {
defaultQuery: {type: String, required: false, default: ''}
defaultQuery: {type: String, required: false, default: ''},
defaultStatus: {required: false, default: 'any'}
},
components: {
RequestCard,
......@@ -96,7 +107,8 @@ export default {
query: this.defaultQuery,
paginateBy: parseInt(this.defaultPaginateBy || 12),
orderingDirection: defaultOrdering.direction,
ordering: defaultOrdering.field
ordering: defaultOrdering.field,
status: this.defaultStatus || 'any'
}
},
created () {
......@@ -107,14 +119,18 @@ export default {
},
methods: {
updateQueryString: _.debounce(function () {
this.$router.replace({
let query = {
query: {
query: this.query,
page: this.page,
paginateBy: this.paginateBy,
ordering: this.getOrderingAsString()
}
})
}
if (this.status !== 'any') {
query.query.status = this.status
}
this.$router.replace(query)
}, 500),
fetchData: _.debounce(function () {
var self = this
......@@ -123,9 +139,12 @@ export default {
let params = {
page: this.page,
page_size: this.paginateBy,
search: this.query,
q: this.query,
ordering: this.getOrderingAsString()
}
if (this.status !== 'any') {
params.status = this.status
}
logger.default.debug('Fetching request...')
axios.get(url, {params: params}).then((response) => {
self.result = response.data
......@@ -165,6 +184,10 @@ export default {
query () {
this.updateQueryString()
this.fetchData()
},
status () {
this.updateQueryString()
this.fetchData()
}
}
}
......
......@@ -212,7 +212,7 @@ export default new Router({
defaultQuery: route.query.query,
defaultPaginateBy: route.query.paginateBy,
defaultPage: route.query.page,
defaultStatus: route.query.status || 'pending'
defaultStatus: route.query.status || 'any'
}),
children: [
]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment