mandalorian/scripts/planets.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2021-10-20 09:58:23 +00:00
import { api_call, API_URL, createPagination, api_call_array } from "./util";
2021-10-18 15:32:20 +00:00
2021-10-19 07:47:51 +00:00
2021-10-19 15:35:05 +00:00
const planetes = document.getElementById("resultats");
2021-10-18 15:32:20 +00:00
2021-10-19 13:23:08 +00:00
2021-10-19 14:04:18 +00:00
function remplissage(results) {
2021-10-19 08:31:51 +00:00
planetes.innerHTML = "";
2021-10-19 08:31:51 +00:00
const previousUrl = results.previous;
const nextUrl = results.next;
const tabResults = results.results;
2021-10-19 14:04:18 +00:00
for (resultPlanet of tabResults) {
2021-10-19 08:31:51 +00:00
const nom = resultPlanet.name;
const diametre = resultPlanet.diameter;
const climate = resultPlanet.climate;
const terrain = resultPlanet.terrain;
const population = resultPlanet.population;
const tabResidents = resultPlanet.residents;
2021-10-19 09:52:12 +00:00
const tabFilms = resultPlanet.films;
2021-10-19 08:31:51 +00:00
2021-10-19 14:04:18 +00:00
planetes.innerHTML +=
2021-10-19 20:23:22 +00:00
`<section class="resultat accordeon_item">
<h1 class="accordeon_item_header">${nom}</h1>
<div class="accordeon_item_body">
2021-10-20 08:37:54 +00:00
<div class="column1">
<p>${terrain}</p>
<p>${climate}</p>
<p>${diametre}Km</p>
</div>
2021-10-20 08:37:54 +00:00
<div class="column2">${tabResidents}</div>
<div class="column3">${tabFilms}</div>
</div>
</section>`;
2021-10-20 08:37:54 +00:00
2021-10-20 09:58:23 +00:00
const accordeonItemHeader = document.querySelectorAll(".accordeon_item_header");
item = accordeonItemHeader[accordeonItemHeader.length - 1];
item.addEventListener("click", event => {
2021-10-20 08:53:02 +00:00
accordeonItemHeader.classList.toggle("active");
2021-10-20 09:58:23 +00:00
api_call_array(tabResidents, fillDetails);
api_call_array(tabFilms, fillDetails);
2021-10-19 20:23:22 +00:00
});
2021-10-20 09:58:23 +00:00
//Pagination
createPagination(previousUrl, nextUrl, planetes, remplissage);
// const accordeonItemHeader = document.querySelectorAll(".accordeon_item_header");
// accordeonItemHeader.forEach(accordeonItemHeader => {
// accordeonItemHeader.addEventListener("click", event => {
// accordeonItemHeader.classList.toggle("active");
// api_call_array(tabResidents, fillDetails);
// api_call_array(tabFilms, fillDetails);
// });
// });
}
const fillResidents = (jsonResp) => {
console.log(jsonResp);
}
const fillFilms = (jsonResp) => {
console.log(jsonResp);
}
api_call(API_URL + "/planets", remplissage);
2021-10-19 15:35:05 +00:00
2021-10-20 09:58:23 +00:00
console.log('planet.js loaded');