create new branch
This commit is contained in:
parent
9570e3d1ae
commit
4c9af83342
12
index.html
12
index.html
@ -13,18 +13,18 @@
|
||||
<script src="https://unpkg.com/riot@9/riot+compiler.min.js"></script>
|
||||
|
||||
<script type="riot" src="./onzer.riot"></script>
|
||||
<script type="javascript" src="./onzer.riot"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
function fetch_data(){
|
||||
async function fetch_data() {
|
||||
return fetch("https://dwarves.iut-fbleau.fr/~fauvet/api/albums").then(response => {
|
||||
return response.json();
|
||||
} )
|
||||
});
|
||||
}
|
||||
|
||||
riot.compile().then(() => {
|
||||
riot.mount('onzer', {items: fetch_data()});
|
||||
})
|
||||
riot.compile().then(async () => {
|
||||
const data = await fetch_data();
|
||||
riot.mount('onzer', { items: data });
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
99
onzer.riot
99
onzer.riot
@ -11,7 +11,7 @@
|
||||
|
||||
<form onsubmit={add}>
|
||||
<div class="flex flex-row items-baseline">
|
||||
<input class="flex-grow-1 border-solid border bg-emerald-100 w-half rounded-lg border-emerald-300 border h-20 pl-6 grow"
|
||||
<input class="flex-grow-1 border-solid border bg-emerald-100 w-half rounded-lg border-emerald-300 h-20 pl-6 grow"
|
||||
placeholder={state.placeholder} onkeyup={edit} />
|
||||
<input type="button" value="Playlists"
|
||||
class="ml-2 border-solid bg-emerald-300 border rounded-lg border-emerald-600 mb-4 h-20 w-48 mt-2" />
|
||||
@ -27,78 +27,75 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
async onBeforeMount(props){
|
||||
let data = await props.items;
|
||||
this.state = {
|
||||
state: {
|
||||
placeholder: "Rechercher dans les albums",
|
||||
items: data.results,
|
||||
items: [],
|
||||
search: "albums",
|
||||
filter: undefined,
|
||||
id: undefined
|
||||
};
|
||||
this.paintButton();
|
||||
this.album_style = "isActivate";
|
||||
this.update();
|
||||
},
|
||||
onBeforeMount(props) {
|
||||
this.loadData(props.items);
|
||||
},
|
||||
async loadData(items) {
|
||||
const data = await items;
|
||||
this.update({
|
||||
state: {
|
||||
...this.state,
|
||||
items: data.results
|
||||
},
|
||||
album_style: "isActivate",
|
||||
artist_style: "isDeactivate",
|
||||
song_style: "isDeactivate"
|
||||
});
|
||||
},
|
||||
edit(e) {
|
||||
this.state.filter = e.target.value;
|
||||
console.log(this.state.filter);
|
||||
this.update({
|
||||
state: {
|
||||
...this.state,
|
||||
filter: e.target.value
|
||||
}
|
||||
});
|
||||
this.fetchData();
|
||||
this.update();
|
||||
},
|
||||
click(e) {
|
||||
e.preventDefault();
|
||||
this.paintButton();
|
||||
switch(e.target.value){
|
||||
case "Albums":
|
||||
this.state.placeholder = "Rechercher dans les albums";
|
||||
this.album_style = "isActivate";
|
||||
this.state.search = "albums";
|
||||
break;
|
||||
case "Artists":
|
||||
this.state.placeholder = "Rechercher dans les artists";
|
||||
this.artist_style = "isActivate";
|
||||
this.state.search = "artists";
|
||||
break;
|
||||
default:
|
||||
this.state.placeholder = "Rechercher dans les songs";
|
||||
this.song_style = "isActivate";
|
||||
this.state.search = "songs";
|
||||
}
|
||||
this.fetchData()
|
||||
this.update();
|
||||
const newState = {
|
||||
...this.state,
|
||||
placeholder: `Rechercher dans les ${e.target.value.toLowerCase()}`,
|
||||
search: e.target.value.toLowerCase(),
|
||||
filter: undefined
|
||||
};
|
||||
this.update({
|
||||
state: newState,
|
||||
album_style: e.target.value === "Albums" ? "isActivate" : "isDeactivate",
|
||||
artist_style: e.target.value === "Artists" ? "isActivate" : "isDeactivate",
|
||||
song_style: e.target.value === "Songs" ? "isActivate" : "isDeactivate"
|
||||
});
|
||||
this.fetchData();
|
||||
},
|
||||
async fetchData() {
|
||||
let data = await this.execQuery(this.state.search, this.state.filter, this.state.id);
|
||||
const data = await this.execQuery(this.state.search, this.state.filter, this.state.id);
|
||||
this.update({
|
||||
state: {
|
||||
...this.state,
|
||||
items: data.results
|
||||
}
|
||||
});
|
||||
},
|
||||
paintButton(){
|
||||
this.album_style = "isDeactivate";
|
||||
this.artist_style = "isDeactivate";
|
||||
this.song_style = "isDeactivate";
|
||||
},
|
||||
execQuery(table, filter = undefined, id = undefined) {
|
||||
console.log("CCACA");
|
||||
let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/"
|
||||
let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/";
|
||||
let computeHttpRequest;
|
||||
if (filter !== undefined) {
|
||||
switch(table){
|
||||
case "songs":
|
||||
computeHttpRequest = baseHttpRequest+table+"?title="+filter;
|
||||
break;
|
||||
default :
|
||||
computeHttpRequest = baseHttpRequest+table+"?name="+filter;
|
||||
}
|
||||
computeHttpRequest = table === "songs" ?
|
||||
`${baseHttpRequest}${table}?title=${filter}` :
|
||||
`${baseHttpRequest}${table}?name=${filter}`;
|
||||
} else if (id !== undefined) {
|
||||
computeHttpRequest = baseHttpRequest+table+"/"+id;
|
||||
computeHttpRequest = `${baseHttpRequest}${table}/${id}`;
|
||||
} else {
|
||||
computeHttpRequest = baseHttpRequest+table;
|
||||
computeHttpRequest = `${baseHttpRequest}${table}`;
|
||||
}
|
||||
return fetch(computeHttpRequest).then(response => {
|
||||
return response.json();
|
||||
});
|
||||
return fetch(computeHttpRequest).then(response => response.json());
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user