Base
This commit is contained in:
59
nginx/static/scripts/main.js
Normal file
59
nginx/static/scripts/main.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { initRouter } from './router.js';
|
||||
import { initNavigation } from './navigation.js';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
initRouter();
|
||||
initNavigation();
|
||||
|
||||
document.getElementById('download-archive').addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
console.log('Téléchargement de l\'archive');
|
||||
});
|
||||
});
|
||||
|
||||
async function loadTemplate(templateName) {
|
||||
const response = await fetch(`/templates/${templateName}.html`);
|
||||
return await response.text();
|
||||
}
|
||||
|
||||
export async function displayHome() {
|
||||
const content = document.getElementById('content');
|
||||
content.innerHTML = await loadTemplate('home');
|
||||
}
|
||||
|
||||
export async function displaySources(sources) {
|
||||
const content = document.getElementById('content');
|
||||
content.innerHTML = await loadTemplate('sources');
|
||||
|
||||
const sourcesList = document.getElementById('sourcesList');
|
||||
sourcesList.innerHTML = sources.map(source => `
|
||||
<li class="source-item">
|
||||
<h3>${source.title}</h3>
|
||||
<p>${source.description}</p>
|
||||
<p class="category">Catégorie: ${source.category}</p>
|
||||
<a href="${source.archiveUrl}" target="_blank">Lien archivé</a>
|
||||
</li>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
export async function displaySuggestionForm() {
|
||||
const content = document.getElementById('content');
|
||||
content.innerHTML = await loadTemplate('suggest');
|
||||
|
||||
document.getElementById('suggestionForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
// Logique pour traiter la soumission du formulaire
|
||||
console.log('Formulaire de suggestion soumis');
|
||||
});
|
||||
}
|
||||
|
||||
export async function displaySearchForm() {
|
||||
const content = document.getElementById('content');
|
||||
content.innerHTML = await loadTemplate('search');
|
||||
|
||||
document.getElementById('searchForm').addEventListener('submit', (e) => {
|
||||
e.preventDefault();
|
||||
// Logique pour traiter la recherche
|
||||
console.log('Recherche soumise');
|
||||
});
|
||||
}
|
||||
17
nginx/static/scripts/navigation.js
Normal file
17
nginx/static/scripts/navigation.js
Normal file
@ -0,0 +1,17 @@
|
||||
export function initNavigation() {
|
||||
document.getElementById('home-button').addEventListener('click', () => {
|
||||
window.location.hash = '#/';
|
||||
});
|
||||
|
||||
document.getElementById('sources-button').addEventListener('click', () => {
|
||||
window.location.hash = '#/sources';
|
||||
});
|
||||
|
||||
document.getElementById('suggest-button').addEventListener('click', () => {
|
||||
window.location.hash = '#/suggest';
|
||||
});
|
||||
|
||||
document.getElementById('search-button').addEventListener('click', () => {
|
||||
window.location.hash = '#/search';
|
||||
});
|
||||
}
|
||||
26
nginx/static/scripts/router.js
Normal file
26
nginx/static/scripts/router.js
Normal file
@ -0,0 +1,26 @@
|
||||
import { displayHome, displaySources, displaySuggestionForm, displaySearchForm } from './main.js';
|
||||
|
||||
const routes = {
|
||||
'/': displayHome,
|
||||
'/sources': () => {
|
||||
// Simulons des données pour l'exemple
|
||||
const sources = [
|
||||
{ title: 'Source 1', description: 'Description 1', category: 'Médical', archiveUrl: '#' },
|
||||
{ title: 'Source 2', description: 'Description 2', category: 'Scientifique', archiveUrl: '#' },
|
||||
];
|
||||
displaySources(sources);
|
||||
},
|
||||
'/suggest': displaySuggestionForm,
|
||||
'/search': displaySearchForm
|
||||
};
|
||||
|
||||
export function initRouter() {
|
||||
async function router() {
|
||||
const path = window.location.hash.slice(1) || '/';
|
||||
const route = routes[path] || routes['/'];
|
||||
await route();
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', router);
|
||||
window.addEventListener('load', router);
|
||||
}
|
||||
Reference in New Issue
Block a user