added possibility to filter datas

This commit is contained in:
Matthis FAUVET 2024-06-21 19:35:58 +02:00
parent 98d8cc7bfd
commit edb214c459
2 changed files with 23 additions and 21 deletions

View File

@ -1,19 +0,0 @@
function execQuery(table, filter = "all", id = -1){
let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/"
let computeHttpRequest;
if(filter !== undefined){
switch(table){
case "songs":
computeHttpRequest = baseHttpRequest+table+"?title="+filter;
default :
computeHttpRequest = baseHttpRequest+table+"?name="+filter;
}
} else if(id !== undefined) {
computeHttpRequest = baseHttpRequest+table+"/"+id;
} else {
computeHttpRequest = baseHttpRequest+table;
}
return fetch(computeHttpRequest).then(response => {
return response.json();
});
};

View File

@ -65,7 +65,7 @@
this.update();
},
async fetchData(){
let data = await execQuery(this.state.search, this.state.filter, this.state.id);
let data = await this.execQuery(this.state.search, this.state.filter, this.state.id);
this.update({
items: data.results
});
@ -74,7 +74,7 @@
this.album_style = "isDeactivate";
this.artist_style = "isDeactivate";
this.song_style = "isDeactivate";
}
},
}
</script>
<style>
@ -92,4 +92,25 @@
width: 32%;
}
</style>
<script>
function execQuery(table, filter = "all", id = -1){
let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/"
let computeHttpRequest;
if(filter !== undefined){
switch(table){
case "songs":
computeHttpRequest = baseHttpRequest+table+"?title="+filter;
default :
computeHttpRequest = baseHttpRequest+table+"?name="+filter;
}
} else if(id !== undefined) {
computeHttpRequest = baseHttpRequest+table+"/"+id;
} else {
computeHttpRequest = baseHttpRequest+table;
}
return fetch(computeHttpRequest).then(response => {
return response.json();
});
};
</script>
</onzer>