2022-02-15 16:45:14 +01:00
|
|
|
<div class="container" id="app">
|
2022-02-15 11:03:20 +01:00
|
|
|
<form @submit="search">
|
2022-02-15 16:45:14 +01:00
|
|
|
<div class="field has-addons">
|
|
|
|
<div class="control">
|
|
|
|
<input class="input" type="text" name="q" v-model="q" placeholder="Nom de l'album ou code barre (ex : Hybrid Theory">
|
|
|
|
</div>
|
|
|
|
<div class="control">
|
|
|
|
<button class="button is-link" :disabled="loading">
|
|
|
|
<span class="icon">
|
|
|
|
<i class="fas fa-search"></i>
|
|
|
|
</span>
|
|
|
|
</button>
|
2022-02-15 11:03:20 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
2022-02-15 16:45:14 +01:00
|
|
|
<table class="table is-striped is-hoverable is-fullwidth">
|
2022-02-15 11:03:20 +01:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Pochette</th>
|
|
|
|
<th>Titre</th>
|
|
|
|
<th>Pays</th>
|
|
|
|
<th>Année</th>
|
|
|
|
<th>Format</th>
|
|
|
|
<th>Genres</th>
|
|
|
|
<th>Styles</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2022-02-15 16:45:14 +01:00
|
|
|
<tr v-if="loading">
|
|
|
|
<td colspan="7">
|
|
|
|
Chargement en cours…
|
|
|
|
</td>
|
|
|
|
</tr>
|
2022-02-15 11:03:20 +01:00
|
|
|
<tr v-for="item in items">
|
|
|
|
<td>
|
|
|
|
<img :src="item.thumb" :alt="item.title" style="max-width: 120px;"/>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<a :href="'/ajouter-un-album/' + item.id">{{ item.title }}</a>
|
|
|
|
</td>
|
|
|
|
<td>{{ item.year }}</td>
|
|
|
|
<td>{{ item.country }}</td>
|
|
|
|
<td>
|
|
|
|
<ul>
|
|
|
|
<li v-for="format in item.format">{{ format }}</li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<ul>
|
|
|
|
<li v-for="genre in item.genre">{{ genre }}</li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<ul>
|
|
|
|
<li v-for="style in item.style">{{ style }}</li>
|
|
|
|
</ul>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
Vue.createApp({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
q: '',
|
2022-02-15 16:45:14 +01:00
|
|
|
loading: false,
|
2022-02-15 11:03:20 +01:00
|
|
|
items: [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
search(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2022-02-15 16:45:14 +01:00
|
|
|
if ( this.loading ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
2022-02-15 11:03:20 +01:00
|
|
|
axios.get(`/api/v1/search?q=${this.q}`)
|
|
|
|
.then( response => {
|
|
|
|
const {
|
|
|
|
results,
|
|
|
|
} = response.data;
|
|
|
|
let items = [];
|
|
|
|
|
|
|
|
for (let i = 0 ; i < results.length ; i += 1 ) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
thumb,
|
|
|
|
year,
|
|
|
|
country,
|
|
|
|
format,
|
|
|
|
genre,
|
|
|
|
style,
|
|
|
|
} = results[i];
|
|
|
|
items.push({
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
thumb,
|
|
|
|
year,
|
|
|
|
country,
|
|
|
|
format,
|
|
|
|
genre,
|
|
|
|
style,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this.items = items;
|
|
|
|
})
|
2022-02-15 16:45:14 +01:00
|
|
|
.catch((err) => {
|
|
|
|
showToastr(err.response?.data?.message || "Aucun résultat trouvé :/");
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.loading = false;
|
2022-02-15 11:03:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).mount('#app')
|
|
|
|
</script>
|
|
|
|
|