Added filter and sort on my collection

This commit is contained in:
Damien Broqua 2022-02-16 09:55:12 +01:00
parent 68fa736a91
commit 99d2507248
3 changed files with 94 additions and 8 deletions

View file

@ -3,10 +3,53 @@
<thead>
<tr>
<th>Pochette</th>
<th>Artiste</th>
<th>
<div class="field">
<label class="label">
<span class="icon-text">
<span class="icon has-text-info">
<i v-if="sort !== 'artists_sort'" class="fa-solid fa-sort" @click="changeSort('artists_sort', 'asc')"></i>
<i v-if="sort === 'artists_sort' && order === 'desc'" class="fa-solid fa-sort-down" @click="changeSort('artists_sort', 'asc')"></i>
<i v-if="sort === 'artists_sort' && order === 'asc'" class="fa-solid fa-sort-up" @click="changeSort('artists_sort', 'desc')"></i>
</span>
<span>Artiste</span>
</span>
</label>
<div class="control">
<div class="select is-small">
<select v-model="artist" @change="fetch">
<option value="">Tous</option>
<%
for (let i = 0; i < page.artists.length; i += 1 ) {
__append(`<option value="${page.artists[i]}">${page.artists[i]}</option>`);
}
%>
</select>
</div>
</div>
</div>
</th>
<th>Titre</th>
<th>Année</th>
<th>Pays</th>
<th>
<span class="icon-text">
<span class="icon has-text-info">
<i v-if="sort !== 'year'" class="fa-solid fa-sort" @click="changeSort('year', 'asc')"></i>
<i v-if="sort === 'year' && order === 'desc'" class="fa-solid fa-sort-down" @click="changeSort('year', 'asc')"></i>
<i v-if="sort === 'year' && order === 'asc'" class="fa-solid fa-sort-up" @click="changeSort('year', 'desc')"></i>
</span>
<span>Année</span>
</span>
</th>
<th>
<span class="icon-text">
<span class="icon has-text-info">
<i v-if="sort !== 'country'" class="fa-solid fa-sort" @click="changeSort('country', 'asc')"></i>
<i v-if="sort === 'country' && order === 'desc'" class="fa-solid fa-sort-down" @click="changeSort('country', 'asc')"></i>
<i v-if="sort === 'country' && order === 'asc'" class="fa-solid fa-sort-up" @click="changeSort('country', 'desc')"></i>
</span>
<span>Pays</span>
</span>
</th>
<th>Format</th>
<th>Genres</th>
<th>Styles</th>
@ -85,6 +128,9 @@
page: 1,
totalPages: 1,
limit: 5,
artist: '',
sort: 'artists_sort',
order: 'asc',
}
},
created() {
@ -93,14 +139,13 @@
methods: {
fetch() {
this.loading = true;
axios.get(`/api/v1/albums?page=${this.page}&limit=${this.limit}`)
axios.get(`/api/v1/albums?page=${this.page}&limit=${this.limit}&artists_sort=${this.artist}&sort=${this.sort}&order=${this.order}`)
.then( response => {
this.items = response.data.rows;
this.total = response.data.count;
this.totalPages = parseInt(response.data.count / this.limit) + (response.data.count % this.limit > 0 ? 1 : 0);
console.log('total:', this.total, (this.page * this.limit));
})
.catch((err) => {
showToastr(err.response?.data?.message || "Impossible de charger votre collection");
@ -127,7 +172,14 @@
this.page = page;
this.fetch();
}
},
changeSort(sort, order) {
this.sort = sort;
this.order = order;
this.page = 1;
this.fetch();
},
}
}).mount('#app')
</script>