Loading css/style.css +0 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ button{ margin-right: auto; width: 25%; font-size: large; display: none; } #villeListe{ Loading index.html +17 −3 Original line number Diff line number Diff line Loading @@ -10,13 +10,27 @@ <h1 id="instantWeather">Instant Weather</h1> <input type="search" id="codePostalInput" placeholder="Entrez votre code postal" aria-label="code postal"><button id="recherche" >Rechercher</button> <br> <select id="villeListe" aria-label="ville"> <select id="villeListe" class="cache" aria-label="ville"> <option>--Sélectionner une ville--</option> </select> <div class="resultat" > <div class="resultat cache" id="resultat"> <div class="weatherCard" id="weatherCard"> <p>Ville : <span id="WCVille"></span></p> <p>Temps <span id="WCBref"></span></p> <p>Température min : <span id="WCTemperatureMin"></span></p> <p>Température max : <span id="WCTemperatureMax"></span></p> <p>Probabilité de pluie : <span id="WCPluie"></span></p> <p>Temps d'ensoleillements : <span id="WCEnsoleillement"></span> heures.</p> <p>(valeurs de test)</p> </div> </div> <script src="js/Token.js"></script> <script src="js/WeatherCard.js"></script> <script src ="js/script.js"></script> <script src="js/arriere-plan.js"></script> <script src ="js/interface.js"></script> </body> </html> No newline at end of file js/script.js→js/arriere-plan.js +4 −7 Original line number Diff line number Diff line let titre = document.getElementById("instantWeather") let fond = document.getElementById("fond") let recherche = document.getElementById("recherche") recherche.addEventListener("click", ()=>{ let typetemps = weather.determineWeather()/*methode Victor*/ //console.log(typetemps); function actualiserArrierePlan(weatherCard){ let typetemps = weatherCard.determineWeather()//methode Victor console.log(typetemps); if(typetemps == 'soleil'){ fond.style.background = 'url("../image/theme_clair.jpg") no-repeat fixed' fond.style.backgroundSize = 'cover' Loading Loading @@ -46,5 +44,4 @@ recherche.addEventListener("click", ()=>{ fond.style.backgroundSize = 'cover' titre.classList.add('sombre') } }) } No newline at end of file js/fetchUtility.jsdeleted 100644 → 0 +0 −48 Original line number Diff line number Diff line /** * Parses the JSON returned by a network request * * @param {object} response A response from a network request * * @return {object} The parsed JSON from the request */ function parseJSON(response) { return response.json(); } /** * Checks if a network request came back fine, and throws an error if not * * @param {object} response A response from a network request * * @return {object|undefined} Returns either the response, or throws an error */ function checkStatus(response) { if (response.ok) { return response; } const error = new Error(response.statusText); error.response = response; throw error; } /** * Requests a URL, returning a promise * * @param {string} url The URL we want to request * @param {object} [options] The options we want to pass to "fetch" * * @return {object} The response data */ function request(url, options) { return fetch(url, options) .then(checkStatus) .then(parseJSON) .catch((error) => { console.log(error); }) } js/interface.js 0 → 100644 +107 −0 Original line number Diff line number Diff line // Éléments du DOM // Interface const barreRechercheCodePostal = document.getElementById("codePostalInput"); const boutonRechercheCodePostal = document.getElementById("recherche"); const listeDeroulanteVilles = document.getElementById("villeListe"); boutonRechercheCodePostal.addEventListener("click", onRechercher); listeDeroulanteVilles.addEventListener("change", onSelectionneVille); // Zones d'affichage const zoneResultats = document.getElementById("resultat"); const labelVille = document.getElementById("WCVille"); const labelBref = document.getElementById("WCBref"); // décrit brièvement le temps (clair, nuageux...) const labelTemperatureMin = document.getElementById("WCTemperatureMin"); const labelTemperatureMax = document.getElementById("WCTemperatureMax"); const labelPluie = document.getElementById("WCPluie"); // Probabilité de pluie const labelEnsoleillement = document.getElementById("WCEnsoleillement"); // Nombres d'heures d'ensoleillement let villes_insee = new Map(); function onRechercher(){ let codePostalS = barreRechercheCodePostal.value; let codePostalN = Number.parseInt(codePostalS); if(isNaN(codePostalN)){ onErreurSaisieCodePostal("Le code postal contient des caractères non numériques."); return; } if(codePostalS.length != 5){ onErreurSaisieCodePostal("Le code postal doit contenir 5 caractères."); return; } setVilles(codePostalN).then(listeVille); } function onErreurSaisieCodePostal(message){ alert(message); listeDeroulanteVilles.classList.add("cache"); zoneResultats.classList.add("cache"); } function listeVille(){ listeDeroulanteVilles.innerHTML = `<option value="placeholder">--Sélectionner une ville--</option>`; villes_insee.forEach((ville, codeInsee) => { listeDeroulanteVilles.innerHTML += `\n<option value="${codeInsee}">${ville}</option>` }); listeDeroulanteVilles.classList.remove("cache"); } const setVilles = async codepostal => { return fetch("https://geo.api.gouv.fr/communes?codePostal="+codepostal) .then(res =>{ if(!res.ok){ throw new Error("erreur") } return res.json(); }) .then(data =>{ villes_insee = new Map() for(i = 0; i < data.length; i++){ villes_insee[i] = data[i].nom; villes_insee.set( data[i].code, data[i].nom) } }) } function onSelectionneVille(){ let codeInsee = listeDeroulanteVilles.value; if(codeInsee === "placeholder"){ zoneResultats.classList.add("cache"); return; } const weatherCard = new WeatherCard(codeInsee); weatherCard.fetchData().then(() =>{ afficherMeteo(weatherCard); }) } function afficherMeteo(weatherCard){ labelVille.textContent = weatherCard.Ville(); //TODO remplir cette ligne //labelBref.textContent = "ensoleillé"; labelTemperatureMin.textContent = `${weatherCard.TempMin()} °C`; labelTemperatureMax.textContent = `${weatherCard.TempMax()} °C`; //TODO probabilité de pluie // labelPluie.textContent = weatherCard.; labelEnsoleillement.textContent = `${weatherCard.Sunhour()} heures`; actualiserArrierePlan(weatherCard); zoneResultats.classList.remove("cache"); } const getVilles = () => { return villes; } No newline at end of file Loading
css/style.css +0 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,6 @@ button{ margin-right: auto; width: 25%; font-size: large; display: none; } #villeListe{ Loading
index.html +17 −3 Original line number Diff line number Diff line Loading @@ -10,13 +10,27 @@ <h1 id="instantWeather">Instant Weather</h1> <input type="search" id="codePostalInput" placeholder="Entrez votre code postal" aria-label="code postal"><button id="recherche" >Rechercher</button> <br> <select id="villeListe" aria-label="ville"> <select id="villeListe" class="cache" aria-label="ville"> <option>--Sélectionner une ville--</option> </select> <div class="resultat" > <div class="resultat cache" id="resultat"> <div class="weatherCard" id="weatherCard"> <p>Ville : <span id="WCVille"></span></p> <p>Temps <span id="WCBref"></span></p> <p>Température min : <span id="WCTemperatureMin"></span></p> <p>Température max : <span id="WCTemperatureMax"></span></p> <p>Probabilité de pluie : <span id="WCPluie"></span></p> <p>Temps d'ensoleillements : <span id="WCEnsoleillement"></span> heures.</p> <p>(valeurs de test)</p> </div> </div> <script src="js/Token.js"></script> <script src="js/WeatherCard.js"></script> <script src ="js/script.js"></script> <script src="js/arriere-plan.js"></script> <script src ="js/interface.js"></script> </body> </html> No newline at end of file
js/script.js→js/arriere-plan.js +4 −7 Original line number Diff line number Diff line let titre = document.getElementById("instantWeather") let fond = document.getElementById("fond") let recherche = document.getElementById("recherche") recherche.addEventListener("click", ()=>{ let typetemps = weather.determineWeather()/*methode Victor*/ //console.log(typetemps); function actualiserArrierePlan(weatherCard){ let typetemps = weatherCard.determineWeather()//methode Victor console.log(typetemps); if(typetemps == 'soleil'){ fond.style.background = 'url("../image/theme_clair.jpg") no-repeat fixed' fond.style.backgroundSize = 'cover' Loading Loading @@ -46,5 +44,4 @@ recherche.addEventListener("click", ()=>{ fond.style.backgroundSize = 'cover' titre.classList.add('sombre') } }) } No newline at end of file
js/fetchUtility.jsdeleted 100644 → 0 +0 −48 Original line number Diff line number Diff line /** * Parses the JSON returned by a network request * * @param {object} response A response from a network request * * @return {object} The parsed JSON from the request */ function parseJSON(response) { return response.json(); } /** * Checks if a network request came back fine, and throws an error if not * * @param {object} response A response from a network request * * @return {object|undefined} Returns either the response, or throws an error */ function checkStatus(response) { if (response.ok) { return response; } const error = new Error(response.statusText); error.response = response; throw error; } /** * Requests a URL, returning a promise * * @param {string} url The URL we want to request * @param {object} [options] The options we want to pass to "fetch" * * @return {object} The response data */ function request(url, options) { return fetch(url, options) .then(checkStatus) .then(parseJSON) .catch((error) => { console.log(error); }) }
js/interface.js 0 → 100644 +107 −0 Original line number Diff line number Diff line // Éléments du DOM // Interface const barreRechercheCodePostal = document.getElementById("codePostalInput"); const boutonRechercheCodePostal = document.getElementById("recherche"); const listeDeroulanteVilles = document.getElementById("villeListe"); boutonRechercheCodePostal.addEventListener("click", onRechercher); listeDeroulanteVilles.addEventListener("change", onSelectionneVille); // Zones d'affichage const zoneResultats = document.getElementById("resultat"); const labelVille = document.getElementById("WCVille"); const labelBref = document.getElementById("WCBref"); // décrit brièvement le temps (clair, nuageux...) const labelTemperatureMin = document.getElementById("WCTemperatureMin"); const labelTemperatureMax = document.getElementById("WCTemperatureMax"); const labelPluie = document.getElementById("WCPluie"); // Probabilité de pluie const labelEnsoleillement = document.getElementById("WCEnsoleillement"); // Nombres d'heures d'ensoleillement let villes_insee = new Map(); function onRechercher(){ let codePostalS = barreRechercheCodePostal.value; let codePostalN = Number.parseInt(codePostalS); if(isNaN(codePostalN)){ onErreurSaisieCodePostal("Le code postal contient des caractères non numériques."); return; } if(codePostalS.length != 5){ onErreurSaisieCodePostal("Le code postal doit contenir 5 caractères."); return; } setVilles(codePostalN).then(listeVille); } function onErreurSaisieCodePostal(message){ alert(message); listeDeroulanteVilles.classList.add("cache"); zoneResultats.classList.add("cache"); } function listeVille(){ listeDeroulanteVilles.innerHTML = `<option value="placeholder">--Sélectionner une ville--</option>`; villes_insee.forEach((ville, codeInsee) => { listeDeroulanteVilles.innerHTML += `\n<option value="${codeInsee}">${ville}</option>` }); listeDeroulanteVilles.classList.remove("cache"); } const setVilles = async codepostal => { return fetch("https://geo.api.gouv.fr/communes?codePostal="+codepostal) .then(res =>{ if(!res.ok){ throw new Error("erreur") } return res.json(); }) .then(data =>{ villes_insee = new Map() for(i = 0; i < data.length; i++){ villes_insee[i] = data[i].nom; villes_insee.set( data[i].code, data[i].nom) } }) } function onSelectionneVille(){ let codeInsee = listeDeroulanteVilles.value; if(codeInsee === "placeholder"){ zoneResultats.classList.add("cache"); return; } const weatherCard = new WeatherCard(codeInsee); weatherCard.fetchData().then(() =>{ afficherMeteo(weatherCard); }) } function afficherMeteo(weatherCard){ labelVille.textContent = weatherCard.Ville(); //TODO remplir cette ligne //labelBref.textContent = "ensoleillé"; labelTemperatureMin.textContent = `${weatherCard.TempMin()} °C`; labelTemperatureMax.textContent = `${weatherCard.TempMax()} °C`; //TODO probabilité de pluie // labelPluie.textContent = weatherCard.; labelEnsoleillement.textContent = `${weatherCard.Sunhour()} heures`; actualiserArrierePlan(weatherCard); zoneResultats.classList.remove("cache"); } const getVilles = () => { return villes; } No newline at end of file