285 lines
11 KiB
Text
285 lines
11 KiB
Text
<main class="layout-maxed collection" id="app">
|
|
<h1>
|
|
Collection de <%= page.username %>
|
|
</h1>
|
|
|
|
<div class="filters">
|
|
<div class="field">
|
|
<label for="artist">Artiste</label>
|
|
<select id="artist" v-model="artist" @change="changeFilter">
|
|
<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 class="field">
|
|
<label for="format">Format</label>
|
|
<select id="format" v-model="format" @change="changeFilter">
|
|
<option value="">Tous</option>
|
|
<%
|
|
for (let i = 0; i < page.formats.length; i += 1 ) {
|
|
__append(`<option value="${page.formats[i]}">${page.formats[i]}</option>`);
|
|
}
|
|
%>
|
|
</select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="sortOrder">Trier par</label>
|
|
<select id="sortOrder" v-model="sortOrder" @change="changeSort">
|
|
<option value="artists_sort-asc">Artiste (A-Z)</option>
|
|
<option value="artists_sort-desc">Artiste (Z-A)</option>
|
|
<option value="year-asc">Année (A-Z)</option>
|
|
<option value="year-desc">Année (Z-A)</option>
|
|
<option value="country-asc">Pays (A-Z)</option>
|
|
<option value="country-desc">Pays (Z-A)</option>
|
|
<option value="formats.name-asc">Format (A-Z)</option>
|
|
<option value="formats.name-desc">Format (Z-A)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="filters" v-if="moreFilters">
|
|
<div class="field">
|
|
<label for="format">Année</label>
|
|
<select id="format" v-model="year" @change="changeFilter">
|
|
<option value="">Toutes</option>
|
|
<%
|
|
for (let i = 0; i < page.years.length; i += 1 ) {
|
|
__append(`<option value="${page.years[i]}">${page.years[i]}</option>`);
|
|
}
|
|
%>
|
|
</select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="genre">Genre</label>
|
|
<select id="genre" v-model="genre" @change="changeFilter">
|
|
<option value="">Tous</option>
|
|
<%
|
|
for (let i = 0; i < page.genres.length; i += 1 ) {
|
|
__append(`<option value="${page.genres[i]}">${page.genres[i]}</option>`);
|
|
}
|
|
%>
|
|
</select>
|
|
</div>
|
|
<div class="field">
|
|
<label for="style">Style</label>
|
|
<select id="style" v-model="style" @change="changeFilter">
|
|
<option value="">Tous</option>
|
|
<%
|
|
for (let i = 0; i < page.styles.length; i += 1 ) {
|
|
__append(`<option value="${page.styles[i]}">${page.styles[i]}</option>`);
|
|
}
|
|
%>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<span @click="showMoreFilters" class="showMoreFilters">
|
|
<template v-if="!moreFilters">Voir plus de filtres</template>
|
|
<template v-if="moreFilters">Voir moins de filtres</template>
|
|
<i class="icon-left-open down" v-if="!moreFilters"></i>
|
|
<i class="icon-left-open up" v-if="moreFilters"></i>
|
|
</span>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 list">
|
|
<div class="loader" v-if="loading">
|
|
<div class="animation"></div>
|
|
<div>
|
|
Chargement des données en cours…
|
|
</div>
|
|
</div>
|
|
<div class="item" v-if="!loading" v-for="item in items">
|
|
<span class="title">
|
|
{{ item.artists_sort}} - {{ item.title }}
|
|
</span>
|
|
<div class="grid grid-cols-2 md:grid-cols-4">
|
|
<div>
|
|
<img :src="item.thumb" :alt="item.title" />
|
|
</div>
|
|
<div class="md:col-span-3">
|
|
<span><strong>Année :</strong> {{ item.year }}</span>
|
|
<br />
|
|
<span><strong>Pays :</strong> {{ item.country }}</span>
|
|
<br />
|
|
<span>
|
|
<strong>Format : </strong>
|
|
<span v-for="(format, index) in item.formats">
|
|
{{ format.name }}
|
|
<template v-if="format.descriptions">
|
|
(<template v-for="(description, j) in format.descriptions">
|
|
{{description}}<template v-if="j < format.descriptions.length - 1">, </template>
|
|
</template>)
|
|
</template>
|
|
<template v-if="index < item.formats.length - 1">, </template>
|
|
</span>
|
|
</span>
|
|
<br />
|
|
<span><strong>Genre :</strong> <template v-for="(genre, index) in item.genres">{{ genre }}<template v-if="index < item.genres.length - 1">, </template></template></span>
|
|
<br />
|
|
<span><strong>Style :</strong> <template v-for="(style, index) in item.styles">{{ style }}<template v-if="index < item.styles.length - 1">, </template></template></span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="total">
|
|
<strong>Nombre total d'éléments : </strong>{{total}}
|
|
</div>
|
|
<nav class="pagination" role="navigation" aria-label="Pagination">
|
|
<ul class="pagination-list">
|
|
<template v-for="p in Array.from({length: totalPages}, (v, i) => (i+1))">
|
|
<template v-if="p < 2 || p > (totalPages - 1) || (page - 1) <= p && page + 1 >= p">
|
|
<li>
|
|
<a class="pagination-link" :class="{'is-current': p === page}" @click="goTo(p)" aria-label="Aller à la page {{p}}">{{ p }}</a>
|
|
</li>
|
|
</template>
|
|
<template v-if="(page - 3 === p && page - 2 > 1) || (page + 2 === p && page + 2 < totalPages - 1)">
|
|
<li>
|
|
<a class="pagination-link is-disabled">…</a>
|
|
</li>
|
|
</template>
|
|
</template>
|
|
</ul>
|
|
</nav>
|
|
</main>
|
|
|
|
<script>
|
|
const {
|
|
protocol,
|
|
host
|
|
} = window.location;
|
|
|
|
Vue.createApp({
|
|
data() {
|
|
return {
|
|
loading: false,
|
|
moreFilters: false,
|
|
items: [],
|
|
total: 0,
|
|
page: 1,
|
|
totalPages: 1,
|
|
limit: 16,
|
|
artist: '',
|
|
format: '',
|
|
year: '',
|
|
genre: '',
|
|
style: '',
|
|
sortOrder: 'artists_sort-asc',
|
|
sort: 'artists_sort',
|
|
order: 'asc',
|
|
userId: "<%= params.userId %>",
|
|
}
|
|
},
|
|
created() {
|
|
this.fetch();
|
|
},
|
|
methods: {
|
|
fetch() {
|
|
this.loading = true;
|
|
this.total = 0;
|
|
|
|
const queryString = window.location.search;
|
|
const urlParams = new URLSearchParams(queryString);
|
|
const entries = urlParams.entries();
|
|
|
|
for(const entry of entries) {
|
|
switch(entry[0]) {
|
|
case 'artists_sort':
|
|
this.artist = entry[1];
|
|
break;
|
|
default:
|
|
this[entry[0]] = entry[1];
|
|
}
|
|
}
|
|
|
|
let url = `/api/v1/albums?userId=${this.userId}&page=${this.page}&limit=${this.limit}&sort=${this.sort}&order=${this.order}`;
|
|
if ( this.artist ) {
|
|
url += `&artists_sort=${this.artist.replace('&', '%26')}`;
|
|
}
|
|
if ( this.format ) {
|
|
url += `&format=${this.format.replace('&', '%26')}`;
|
|
}
|
|
if ( this.year ) {
|
|
url += `&year=${this.year}`;
|
|
}
|
|
if ( this.genre ) {
|
|
url += `&genre=${this.genre.replace('&', '%26')}`;
|
|
}
|
|
if ( this.style ) {
|
|
url += `&style=${this.style.replace('&', '%26')}`;
|
|
}
|
|
|
|
axios.get(url)
|
|
.then( response => {
|
|
this.items = response.data.rows;
|
|
this.total = response.data.count || 0;
|
|
this.totalPages = parseInt(response.data.count / this.limit) + (response.data.count % this.limit > 0 ? 1 : 0);
|
|
|
|
})
|
|
.catch((err) => {
|
|
showToastr(err.response?.data?.message || "Impossible de charger cette collection");
|
|
})
|
|
.finally(() => {
|
|
this.loading = false;
|
|
});
|
|
},
|
|
changeUrl() {
|
|
let url = `?page=${this.page}&limit=${this.limit}&sort=${this.sort}&order=${this.order}`;
|
|
if ( this.artist ) {
|
|
url += `&artists_sort=${this.artist.replace('&', '%26')}`;
|
|
}
|
|
if ( this.format ) {
|
|
url += `&format=${this.format.replace('&', '%26')}`;
|
|
}
|
|
if ( this.year ) {
|
|
url += `&year=${this.year}`;
|
|
}
|
|
if ( this.genre ) {
|
|
url += `&genre=${this.genre.replace('&', '%26')}`;
|
|
}
|
|
if ( this.style ) {
|
|
url += `&style=${this.style.replace('&', '%26')}`;
|
|
}
|
|
|
|
location.href = url;
|
|
},
|
|
next(event) {
|
|
event.preventDefault();
|
|
|
|
this.page += 1;
|
|
|
|
this.changeUrl();
|
|
},
|
|
previous(event) {
|
|
event.preventDefault();
|
|
|
|
this.page -= 1;
|
|
|
|
this.changeUrl();
|
|
},
|
|
goTo(page) {
|
|
this.page = page;
|
|
|
|
this.changeUrl();
|
|
},
|
|
changeSort() {
|
|
const [sort,order] = this.sortOrder.split('-');
|
|
this.sort = sort;
|
|
this.order = order;
|
|
this.page = 1;
|
|
|
|
this.changeUrl();
|
|
},
|
|
changeFilter() {
|
|
this.page = 1;
|
|
|
|
this.changeUrl();
|
|
},
|
|
showMoreFilters() {
|
|
this.moreFilters = !this.moreFilters;
|
|
}
|
|
}
|
|
}).mount('#app');
|
|
</script>
|