laradb

script pour établir une bdd Ãà partir d'un tsv avec différent format - retour accueil

git clone git://bebou.netlib.re/laradb
Log | Files | Refs |

script.js (7241B)


      1 const filter = () => {
      2 	// textarea qui filtre les tr qui match la string :not(.match){display:none}
      3 }
      4 const body = document.querySelector('body')
      5 
      6 
      7 const sortTimeline = () => {
      8 
      9 const rows = Array.from(document.querySelectorAll('#TIMELINE tbody tr'));
     10 
     11 
     12 
     13 rows.sort((a, b) => {
     14 	const rectA = a.querySelector('.rectangle div');
     15 	const rectB = b.querySelector('.rectangle div');
     16 	//console.log(rectA, rectB)
     17 
     18 	if (!rectA || !rectB) {
     19 		return 0
     20 	}
     21 
     22 // sort by shortest to longest lifetime
     23 //	const widthA = parseFloat(window.getComputedStyle(rectA).width) || 0;
     24 //	const widthB = parseFloat(window.getComputedStyle(rectB).width) || 0;
     25 
     26 // sort by oldest to newest start date
     27 	const widthA = parseFloat(window.getComputedStyle(rectA).left) || 0;
     28 	const widthB = parseFloat(window.getComputedStyle(rectB).left) || 0;
     29 
     30 	return widthA - widthB;
     31 });
     32 
     33 	const parent = rows[0].parentNode;
     34 
     35 	rows.forEach(row => parent.appendChild(row));
     36 }
     37 
     38 const setFrequency = () => {
     39 const rows = Array.from(document.querySelectorAll('#TIMELINE tbody tr .rectangle div'));
     40 const verticalBar = document.createElement('div')
     41 verticalBar.setAttribute("id","vertical-bar")
     42 
     43 document.querySelector('#TIMELINE').addEventListener('mousemove', (event) => {
     44     verticalBar.style.left = `${event.clientX}px`;
     45 });
     46 const graduation = document.createElement('div')
     47 graduation.setAttribute("id","graduation")
     48 const numbers = document.querySelector('#TIMELINE .numbers')
     49 for(let i = 1970; i < 1990; i++){
     50     const number = document.createElement('div')
     51 	number.classList.add("number")
     52     number.innerHTML = i
     53     numbers.appendChild(number)
     54 }
     55 numbers.appendChild(graduation)
     56 body.appendChild(verticalBar)
     57 console.log(numbers)
     58 rows.forEach((r) => {
     59     const noi = r.getAttribute("data-number-of-issues")
     60     r.style.backgroundImage = `repeating-linear-gradient(90deg,
     61             var(--noir) 0px,
     62             var(--noir) calc(${100 / noi}% - var(--noi-width) - 1px),
     63             var(--accent) calc(${100 / noi}% - var(--noi-width)),
     64             var(--accent) ${100 / noi}%)`
     65 })
     66 
     67 function handleResize() {
     68 	console.log("Window resized or loaded.");
     69 
     70 let years = 20
     71 graduation.style.backgroundImage = `repeating-linear-gradient(90deg,
     72             transparent calc(${100 / years}% / 2 * -1),
     73             transparent calc(${100 / years}% - var(--grad-width) - 1px + ${100 / years}% / 2 * -1),
     74             var(--accent) calc(${100 / years}% - var(--grad-width) + ${100 / years}% / 2 * -1),
     75             var(--accent) calc(${100 / years}% + ${100 / years}% / 2 * -1) )`
     76 	
     77 	numbers
     78 	const width = window.innerWidth;
     79 	const height = window.innerHeight;
     80 	console.log(`Width: ${width}, Height: ${height}`);
     81 	if (width < 1200 && width > 770){
     82 years = 10
     83 graduation.style.backgroundImage = `repeating-linear-gradient(90deg,
     84             transparent calc(${100 / years}% / 2 * -1),
     85             transparent calc(${100 / years}% - var(--grad-width) - 1px + ${100 / years}% / 2 * -1),
     86             var(--accent) calc(${100 / years}% - var(--grad-width) + ${100 / years}% / 2 * -1),
     87             var(--accent) calc(${100 / years}% + ${100 / years}% / 2 * -1) )`
     88 	numbers.classList.add("numbers-1-of-2")
     89 	}
     90 	else if (width < 770){
     91 	numbers.classList.remove("numbers-1-of-2")
     92 	numbers.classList.add("numbers-1-of-4")
     93 years = 5
     94 graduation.style.backgroundImage = `repeating-linear-gradient(90deg,
     95             transparent calc(${100 / years}% / 2 * -1),
     96             transparent calc(${100 / years}% - var(--grad-width) - 1px + ${100 / years}% / 2 * -1),
     97             var(--accent) calc(${100 / years}% - var(--grad-width) + ${100 / years}% / 2 * -1),
     98             var(--accent) calc(${100 / years}% + ${100 / years}% / 2 * -1) )`
     99 
    100 	}
    101 	else if (width > 1200) {
    102 let years = 20
    103 graduation.style.backgroundImage = `repeating-linear-gradient(90deg,
    104             transparent calc(${100 / years}% / 2 * -1),
    105             transparent calc(${100 / years}% - var(--grad-width) - 1px + ${100 / years}% / 2 * -1),
    106             var(--accent) calc(${100 / years}% - var(--grad-width) + ${100 / years}% / 2 * -1),
    107             var(--accent) calc(${100 / years}% + ${100 / years}% / 2 * -1) )`
    108 	numbers.classList.remove("numbers-1-of-2")
    109 	numbers.classList.remove("numbers-1-of-4")
    110 
    111 }
    112 
    113 }
    114 
    115 window.addEventListener('load', handleResize);
    116 
    117 window.addEventListener('resize', handleResize);
    118 }
    119 
    120 
    121 const onClickTable = () => {
    122 const rows = document.querySelectorAll('#TABLEAU tbody tr');
    123 
    124 rows.forEach(row => {
    125 	row.addEventListener('click', () => {
    126 		//row.querySelectorAll('td.hidden').forEach(td => {td.classList.toggle('show')})
    127         row.classList.toggle('show')
    128 })
    129 });
    130 }
    131 
    132 let sortDirection = "asc";
    133 
    134 function sortTable(n) {
    135 	n = n - 1;
    136 
    137 	const table = document.querySelector("table");
    138 	const rows = Array.from(table.rows).slice(1); 
    139 	
    140 	const headers = document.querySelectorAll('table thead td')
    141 	headers.forEach((h) => {
    142 		h.classList.remove('asc','desc')
    143 	})
    144 
    145 	console.log(n);
    146 
    147 	rows.sort((rowA, rowB) => {
    148 		let cellA, cellB;
    149 
    150 		if (n === 1 || n === 2) {
    151 			cellA = rowA.cells[n].getAttribute('data-date');
    152 			cellB = rowB.cells[n].getAttribute('data-date');
    153 		} else if (n === 3) {
    154 			cellA = parseInt(rowA.cells[n].textContent) || 0;
    155 			cellB = parseInt(rowB.cells[n].textContent) || 0;
    156 		} else {
    157 			cellA = rowA.cells[n].textContent.trim().toLowerCase();
    158 			cellB = rowB.cells[n].textContent.trim().toLowerCase();
    159 		}
    160 
    161 		if (cellA < cellB) {
    162 			return sortDirection === "asc" ? -1 : 1;
    163 		}
    164 		if (cellA > cellB) {
    165 			return sortDirection === "asc" ? 1 : -1;
    166 		}
    167 		return 0;
    168 	});
    169 
    170 	sortDirection = sortDirection === "asc" ? "desc" : "asc";
    171 	headers[n].classList.add(sortDirection)
    172 
    173 	rows.forEach(row => table.appendChild(row));
    174 }
    175 
    176 function convertDate(dateInput) {
    177 	if (/^\d{4}-\d{2}-\d{2}$/.test(dateInput)) {
    178 		const [year, month, day] = dateInput.split("-");
    179 		return [`${year}${month}${day}`, `${day}.${month}.${year}`];
    180 
    181 	} else if (/^\d{4}-\d{2}$/.test(dateInput)) {
    182 		const [year, month] = dateInput.split("-");
    183 		return [`${year}${month}00`, `${month}.${year}`];
    184 
    185 	} else if (/^\d{4}$/.test(dateInput)) {
    186 		return [dateInput + "0000", dateInput];
    187 
    188 	} else {
    189 		return [dateInput, dateInput];
    190 	}
    191 }
    192 
    193 const formatDate = () => {
    194 
    195     document.querySelectorAll('.start-date, .end-date').forEach((e) => {
    196 	if (e.children.length > 0){
    197 	let span = e.querySelector('span')
    198 	e.setAttribute('data-date',convertDate(span.innerText)[0])
    199     span.innerText = convertDate(span.innerText)[1]
    200 }
    201 	else {
    202 	e.setAttribute('data-date',convertDate(e.innerText)[0])
    203     e.innerText = convertDate(e.innerText)[1]
    204 
    205 }
    206     })
    207 }
    208 
    209 const path = window.location.pathname;
    210 
    211 function findCurrentNavLinks() {
    212     const links = document.querySelectorAll("nav a");
    213 	let activeLinks = []
    214 
    215     for (let link of links) {
    216 			console.log("/" + link.href.split('/').splice(-1)[0] == path)
    217         if ("/" + link.href.split('/').splice(-1)[0] == path) {
    218 			activeLinks = [...activeLinks, link]
    219         }
    220     }
    221     return activeLinks 
    222 }
    223 
    224 const currentLinks = findCurrentNavLinks();
    225 currentLinks.forEach((e) => {
    226 e.setAttribute("id","active"); 
    227 })
    228 
    229 
    230 switch (path) {
    231   case '/table.html':
    232 	onClickTable()
    233 	formatDate()
    234     break;
    235 
    236   case '/timeline.html':
    237 	setFrequency()
    238 	sortTimeline()
    239     break;
    240 
    241   case '/map.html':
    242     break;
    243 
    244   default:
    245     break;
    246 }