Skip to content

Commit

Permalink
Merge pull request #3 from romainfb/Feat/mainPage
Browse files Browse the repository at this point in the history
This commit implements the main data page
  • Loading branch information
romainfb authored Nov 17, 2023
2 parents 650cdc2 + 9fbe0b4 commit 11c8cac
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 33 deletions.
50 changes: 39 additions & 11 deletions assets/js/fetchOpenData.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,50 @@ async function getWCDataTypeAmount(type) {
* @autor : Romain
*/

let dataTypeAmountUrinal;
let dataTypeAmountAutomatic;
let dataTypeAmountCottage;

async function fetchData() {
try {
dataTypeAmountUrinal = await getWCDataTypeAmount("URINOIR");
dataTypeAmountAutomatic = await getWCDataTypeAmount("SANITAIRE_AUTOMATIQUE");
dataTypeAmountCottage = await getWCDataTypeAmount("CHALET_DE_NECESSITE");

// Set the variable to true when all data is loaded
dataLoaded = true;
let urinalData = await getWCDataTypeAmount("URINOIR");
let wCDataTypeAmount = await getWCDataTypeAmount("SANITAIRE_AUTOMATIQUE");
let cottageData = await getWCDataTypeAmount("CHALET_DE_NECESSITE");

let totalData = urinalData + wCDataTypeAmount + cottageData;

updateCounter("urinalData", urinalData);
updateCounter("wcAutoData", wCDataTypeAmount);
updateCounter("cottageData", cottageData);
updateCounter("totalData", totalData);

} catch (error) {
console.error('There was an error fetching data:', error);
}
}

let dataLoaded = false;
fetchData();
fetchData();

/*
* Print data in HTML
* @function updateCounter
* @param {string} elementId
* @param {integer} finalAmount
* @autor : Romain
*/

async function updateCounter(elementId, finalAmount) {
const element = document.getElementById(elementId);
const duration = 2000; // 2 secondes
const interval = 50; // 50 millisecondes
const iterations = duration / interval;
const increment = finalAmount / iterations;

let currentAmount = 0;

const counterInterval = setInterval(() => {
currentAmount += increment;
element.innerHTML = Math.round(currentAmount);

if (currentAmount >= finalAmount) {
clearInterval(counterInterval);
}
}, interval);
}
46 changes: 26 additions & 20 deletions assets/js/header.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
document.addEventListener('DOMContentLoaded', function () {
var headerHTML = `
<header class="bg-[#181823] shadow-lg">
<div class="container mx-auto px-8 py-8 flex justify-center scale-110"> <!-- Agrandissement du conteneur -->
<nav>
<ul class="flex space-x-6"> <!-- Agrandissement de l'espace entre les éléments -->
<li>
<a href="#data" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Data</a> <!-- Texte plus grand et padding augmenté -->
</li>
<li>
<a href="#information" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Information</a>
</li>
<li>
<a href="#autre" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Autre</a>
</li>
</ul>
</nav>
</div>
</header>`;
var headerHTML = `
<div class="w-full bg-[#181823] h-fit shadow-lg px-8 py-8 flex justify-center"> <!-- Agrandissement du conteneur -->
<nav>
<ul class="flex space-x-6"> <!-- Agrandissement de l'espace entre les éléments -->
<li>
<a href="#data" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Data</a> <!-- Texte plus grand et padding augmenté -->
</li>
<li>
<a href="#information" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Information</a>
</li>
<li>
<a href="#autre" class="text-xl px-5 py-3 bg-mainColor text-white font-semibold rounded-lg shadow-md transition duration-300 hover:bg-white hover:text-black">Autre</a>
</li>
</ul>
</nav>
</div>`;

document.body.insertAdjacentHTML('afterbegin', headerHTML);
});
// Trouver la div avec l'id mainContainer
var mainContainer = document.getElementById('mainContainer');

// Insérer le code HTML dans la div mainContainer
if (mainContainer) {
mainContainer.insertAdjacentHTML('afterbegin', headerHTML);
} else {
console.error("La div avec l'id mainContainer n'a pas été trouvée.");
}
});
82 changes: 82 additions & 0 deletions assets/js/libs/scrollifyReveal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
class ScrollifyReveal {
constructor() {
// Default options for scrolling animations
this.defaultOptions = {
delay: 0, // Deadline before start of animation
distance: '0px', // Vertical travel distance
duration: '500ms', // Animation duration
easing: 'cubic-bezier(0.5, 0, 0, 1)', // Timer function (speed curve)
zoom: 0.8, // Zoom on appear
hideOnExit: true, // Enable or disable disappearance when out of view
opacity: 1, // Final opacity
};
}

reveal(selector, options) {
// Selects all items corresponding to the selector
const elements = document.querySelectorAll(selector);

// Merges default options with supplied options
options = { ...this.defaultOptions, ...options };

// Creates an intersection observer to detect the visibility of elements
const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;

// Checks if the item has not already been revealed
if (!target.classList.contains('revealed')) {
setTimeout(() => {
// Applies appearance animation
target.style.opacity = `${options.opacity}`;
target.style.transform = 'scale(1)';
target.style.transition = `opacity ${options.duration} ${options.easing}, transform ${options.duration} ${options.easing}`;
target.style.transitionDelay = `${options.delay}ms, ${options.delay}ms`;

// Marks element as revealed
target.classList.add('revealed');

// Add a transitionend event listener to remove the scale transform
target.addEventListener('transitionend', () => {
target.style.transform = '';
target.style.transition = '';
target.style.transitionDelay = '';
}, { once: true });
}, options.delay);
}
} else if (options.hideOnExit) {
const target = entry.target;

// Checks if the item has been previously revealed
if (target.classList.contains('revealed')) {
// Applies disappearing animation
target.style.opacity = '0';

// Defines the transformation according to options.zoom
target.style.transform = `translateY(${options.distance}) scale(${options.zoom})`;

target.style.transition = `opacity ${options.duration} ${options.easing}, transform ${options.duration} ${options.easing}`;
target.style.transitionDelay = '0s, 0s';

// Marks element as not revealed
target.classList.remove('revealed');
}
}
});
});

// Initialize styles and observer for each element
elements.forEach(element => {
element.style.opacity = '0';
element.style.transform = `translateY(${options.distance}) scale(${options.zoom})`;
element.style.transition = `opacity ${options.duration} ${options.easing}, transform ${options.duration} ${options.easing}`;
element.style.transitionDelay = '0s, 0s';

// Observe element for visibility changes
observer.observe(element);
});
}
}

const scrollifyReveal = new ScrollifyReveal();
58 changes: 56 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<script src="./assets/js/fetchOpenData.js"></script>
<script src="./assets/js/libs/scrollifyReveal.js"></script>
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
<script>
tailwind.config = {
theme: {
Expand All @@ -21,10 +23,62 @@
</script>
</head>
<body class="h-screen w-screen bg-mainColor">
<script src="assets/js/header.js"></script>
<div class="flex h-full w-full">
<div id="mainContainer" class="flex h-full w-full flex-col">
<script src="assets/js/header.js"></script>

<div class="flex h-fit w-full justify-center pt-10 px-20 flex-col">

<h1 class="title text-white text-9xl font-black uppercase text-center pb-8">Bordeaux WC</h1>
<h2 class="subtitle text-white text-5xl font-bold uppercase text-center">Combien il y a t-il de toilettes sur Bordeaux ?</h1>

<div class="githubButton flex w-full h-fit justify-center pb-6 pt-10">

<a href="https://github.com/romainfb/bordeauxwc" class="text-mainColor bg-white px-6 py-2 rounded-xl font-bold text-2xl my-auto hover:scale-105 duration-300"><i class='bx bxl-github font-4xl'></i> Github</a>

</div>

</div>

<div class="numberDiv flex h-fit px-8 w-full flex-col">

<div class="flex flex-col h-fit w-full items-center pt-14 pb-6">
<span class="text-white text-8xl font-black uppercase text-center" id="totalData">0</span>
<span class="text-transparent text-4xl font-black uppercase text-center" style="-webkit-text-stroke-width: 2px; -webkit-text-stroke-color: white;">Au total</span>
</div>

<div class="flex flex-row h-fit w-full px-48">

<div class="flex flex-col w-full h-fit items-center pt-14">
<span class="text-white text-6xl font-black uppercase text-center" id="urinalData">0</span>
<span class="text-transparent text-2xl font-black uppercase text-center" style="-webkit-text-stroke-width: 1px; -webkit-text-stroke-color: white;">Urinoirs</span>
</div>

<div class="flex flex-col w-full items-center pt-14">
<span class="text-white text-6xl font-black uppercase text-center" id="wcAutoData">0</span>
<span class="text-transparent text-2xl font-black uppercase text-center" style="-webkit-text-stroke-width: 1px; -webkit-text-stroke-color: white;">WC automatiques</span>
</div>

<div class="flex flex-col w-full items-center pt-14">
<span class="text-white text-6xl font-black uppercase text-center" id="cottageData">0</span>
<span class="text-transparent text-2xl font-black uppercase text-center" style="-webkit-text-stroke-width: 1px; -webkit-text-stroke-color: white;">Châlet de nécessité</span>
</div>

</div>

</div>


</div>


</div>

<script>
scrollifyReveal.reveal('.title', {delay: 200});
scrollifyReveal.reveal('.subtitle', {delay: 300});
scrollifyReveal.reveal('.githubButton', {delay: 350});
scrollifyReveal.reveal('.numberDiv', {delay: 150});
</script>

</body>
</html>

0 comments on commit 11c8cac

Please sign in to comment.