avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | |
| 3 | <html lang="ca"> |
| 4 | <head> |
delefme | efcc030 | 2020-09-30 09:26:12 +0200 | [diff] [blame] | 5 | <meta charset="UTF-8"> |
| 6 | <title>Seients DAFME</title> |
| 7 | |
| 8 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 9 | <link rel="manifest" href="manifest.json"> |
| 10 | |
| 11 | <!-- Apple web app --> |
| 12 | <link rel="apple-touch-icon" href="./images/icon-64.png"> |
| 13 | <meta name="apple-mobile-web-app-title" content="Seients DAFME"> |
| 14 | <meta name="apple-mobile-web-app-capable" content="yes"> |
| 15 | <meta name="apple-mobile-web-app-status-bar-style" content="white"> |
| 16 | |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 17 | <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> |
| 18 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.0/css/bulma.min.css"> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 19 | <link rel="stylesheet" href="./css/bulma-adjustments.css"> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 20 | </head> |
| 21 | <body> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 22 | <script> |
| 23 | var elements = document.getElementsByClassName("button"); |
| 24 | Array.from(elements).forEach(function(element) { |
| 25 | element.addEventListener('click', clickButton); |
| 26 | element.parent = element.parentNode.id; |
| 27 | }); |
| 28 | var elements = document.getElementsByClassName("complex-button"); |
| 29 | Array.from(elements).forEach(function(element) { |
| 30 | element.addEventListener('click', clickButton); |
| 31 | element.parent = element.parentNode.id; |
| 32 | }); |
| 33 | |
| 34 | var final_JSON = { |
| 35 | "class": null, |
| 36 | "number": "", |
| 37 | "letter": "" |
| 38 | }; |
| 39 | |
| 40 | function fillInSummary() { |
| 41 | var begins = new Date(parseInt(final_JSON.class.begins)*1000); |
| 42 | var ends = new Date(parseInt(final_JSON.class.ends)*1000); |
| 43 | |
avm99963 | c041bae | 2020-09-30 10:57:33 +0200 | [diff] [blame] | 44 | document.getElementById('subject-final').textContent = final_JSON.class.friendly_name || final_JSON.class.calendar_name; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 45 | document.getElementById('classroom-final').textContent = final_JSON.class.room; |
| 46 | document.getElementById('date-final').textContent = begins.toLocaleDateString(); |
| 47 | document.getElementById('time-final').textContent = formatDate(begins) + ' - ' + formatDate(ends); |
| 48 | document.getElementById('letter-final').textContent = final_JSON.letter; |
| 49 | document.getElementById('number-final').textContent = final_JSON.number; |
| 50 | } |
| 51 | |
| 52 | function clickButton(element) { |
| 53 | var btn = element.currentTarget; |
| 54 | var parent = btn.parent; |
| 55 | |
| 56 | if (parent == "subject-container") { |
| 57 | // Canvi de background del button |
| 58 | var selectedClass = JSON.parse(btn.getAttribute('data-class')); |
| 59 | $("#subject-container .complex-button").removeClass("is-link") |
| 60 | btn.classList.add("is-link"); |
| 61 | // Canvi JSON |
| 62 | final_JSON["class"] = selectedClass; |
| 63 | // Anchor següent pregunta |
| 64 | switchSection("section-2"); |
| 65 | } else if (parent == "number-container") { |
| 66 | // Canvi de background del button |
| 67 | $("#number-container .button").removeClass("is-link is-light is-active") |
| 68 | btn.classList.add("is-link", "is-light", "is-active"); |
| 69 | // Canvi JSON |
| 70 | final_JSON["number"] = btn.getAttribute('data-number'); |
| 71 | // Introducció de totes les dades al resum final |
| 72 | fillInSummary(); |
| 73 | // Anchor següent pregunta |
| 74 | switchSection("section-send"); |
| 75 | } else if (parent == "letter-container") { |
| 76 | // Canvi de background del button |
| 77 | $("#letter-container .button").removeClass("is-link is-light is-active") |
| 78 | btn.classList.add("is-link", "is-light", "is-active"); |
| 79 | // Canvi JSON |
| 80 | final_JSON["letter"] = btn.getAttribute('data-letter'); |
| 81 | // Anchor següent pregunta |
| 82 | switchSection("section-3"); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | function formatDate(d) { |
| 87 | var str = ""; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 88 | str += d.getHours(); |
| 89 | str += ":"; |
| 90 | if (d.getMinutes() < 10) str += "0"; |
| 91 | str += d.getMinutes(); |
| 92 | return str; |
| 93 | } |
| 94 | |
| 95 | var api_url; |
| 96 | |
| 97 | window.addEventListener('load', _ => { |
| 98 | // Check if user is signed in |
| 99 | if (localStorage.getItem('devMode') == 'true') { |
| 100 | var banner = document.getElementById('dev-mode'); |
| 101 | banner.addEventListener('click', _ => { |
| 102 | localStorage.devMode = 'false'; |
| 103 | location.reload(); |
| 104 | }); |
| 105 | banner.classList.remove('hidden'); |
| 106 | api_url = localStorage.getItem('apiUrl') || 'https://covid-tracability-backend-dev.sandbox.avm99963.com/api/v1/' |
| 107 | } else { |
| 108 | api_url = "https://covid-tracability-backend-prod.sandbox.avm99963.com/api/v1/"; |
| 109 | } |
| 110 | fetch(api_url + "isSignedIn", { |
| 111 | "mode": "cors", |
| 112 | "credentials": "include" |
| 113 | }) |
| 114 | .then(response => response.json()) |
| 115 | .then(data => { |
| 116 | if (!data.payload.signedIn) { |
| 117 | console.log("Not signed in!"); |
| 118 | fetch(api_url + "getAuthUrl", { |
| 119 | "mode": "cors", |
| 120 | "credentials": "include" |
| 121 | }) |
| 122 | .then(response => response.json()) |
| 123 | .then(data => { |
| 124 | // TODO: redirect here |
| 125 | // location.href = data.payload.url; |
| 126 | console.warn('Log in here: ', data.payload.url); |
| 127 | }); |
| 128 | } |
| 129 | }); |
| 130 | |
| 131 | fetch(api_url + "getCurrentClasses", { |
| 132 | "mode": "cors", |
| 133 | "credentials": "include" |
| 134 | }) |
| 135 | .then(response => response.json()) |
| 136 | .then(data => { |
avm99963 | 154e51a | 2020-10-01 01:16:38 +0200 | [diff] [blame] | 137 | if (data.payload.classes.length == 0) { |
| 138 | document.getElementById('no-subjects').classList.remove('hidden'); |
avm99963 | 3c6f7fb | 2020-10-01 01:38:25 +0200 | [diff] [blame] | 139 | } else { |
| 140 | document.getElementById('fme-maps-container').classList.remove('hidden'); |
avm99963 | 154e51a | 2020-10-01 01:16:38 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Ferran López | 512bc1c | 2020-09-30 11:27:40 +0200 | [diff] [blame^] | 143 | for (var [i, classe] of data.payload.classes.entries()) { |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 144 | console.log(classe); |
| 145 | |
| 146 | var hora_inici = formatDate(new Date(parseInt(classe.begins)*1000)); |
| 147 | var hora_final = formatDate(new Date(parseInt(classe.ends)*1000)); |
| 148 | |
| 149 | var classeDiv = document.createElement('div'); |
| 150 | classeDiv.classList.add('message', 'complex-button'); |
| 151 | classeDiv.id = 'subject-' + classe.subject_id + '-' + classe.room; |
| 152 | classeDiv.setAttribute('data-class', JSON.stringify(classe)); |
| 153 | |
| 154 | var header = document.createElement('div'); |
| 155 | header.classList.add('message-header'); |
delefme | 20d025b | 2020-09-30 12:00:37 +0200 | [diff] [blame] | 156 | header.textContent = classe.friendly_name || classe.calendar_name; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 157 | |
| 158 | var body = document.createElement('div'); |
| 159 | body.classList.add('message-body'); |
| 160 | |
| 161 | var div1 = document.createElement('div'); |
| 162 | var span = document.createElement('span'); |
| 163 | span.textContent = classe.room; |
| 164 | |
Ferran López | 512bc1c | 2020-09-30 11:27:40 +0200 | [diff] [blame^] | 165 | if (i > 0 && data.payload.classes[i-1].friendly_name == classe.friendly_name) { |
| 166 | div1.classList.add('has-text-danger', 'has-text-weight-bold'); |
| 167 | } else if (data.payload.classes.length >= i && data.payload.classes[i+1].friendly_name == classe.friendly_name) { |
| 168 | div1.classList.add('has-text-danger', 'has-text-weight-bold'); |
| 169 | } |
| 170 | |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 171 | div1.textContent = 'Aula '; |
| 172 | div1.appendChild(span); |
| 173 | |
| 174 | var div2 = document.createElement('div'); |
| 175 | div2.textContent = hora_inici + ' - ' + hora_final; |
| 176 | |
| 177 | body.appendChild(div1); |
| 178 | body.appendChild(div2); |
| 179 | |
| 180 | classeDiv.appendChild(header); |
| 181 | classeDiv.appendChild(body); |
| 182 | |
| 183 | document.getElementById("subject-container").appendChild(classeDiv); |
| 184 | } |
| 185 | |
| 186 | var elements = document.getElementsByClassName("button"); |
| 187 | Array.from(elements).forEach(function(element) { |
| 188 | element.addEventListener('click', clickButton); |
| 189 | element.parent = element.parentNode.id; |
| 190 | }); |
| 191 | var elements = document.getElementsByClassName("complex-button"); |
| 192 | Array.from(elements).forEach(function(element) { |
| 193 | element.addEventListener('click', clickButton); |
| 194 | element.parent = element.parentNode.id; |
| 195 | }); |
| 196 | }); |
| 197 | }); |
| 198 | </script> |
| 199 | |
| 200 | <span id="dev-mode" class="hidden">Dev mode</span> |
| 201 | |
| 202 | <nav class="navbar is-link"> |
| 203 | <div class="navbar-brand"> |
| 204 | <div class="navbar-item has-text-weight-bold">Traçabilitat DAFME</div> |
| 205 | </div> |
| 206 | </nav> |
| 207 | |
| 208 | <section id="section-1" class="section"> |
| 209 | <!-- |
| 210 | <div class="field has-addons"> |
| 211 | <p class="control"> |
| 212 | <button class="button"><</button> |
| 213 | </p> |
| 214 | <p class="control"> |
| 215 | <input type="date" class="button"> |
| 216 | </p> |
| 217 | <p class="control"> |
| 218 | <button class="button">></button> |
| 219 | </p> |
| 220 | </div> |
| 221 | <div class="field has-addons"> |
| 222 | <p class="control"> |
| 223 | <button class="button"><</button> |
| 224 | </p> |
| 225 | <p class="control"> |
| 226 | <input type="button" class="button" value="08:00 - 08:30"> |
| 227 | </p> |
| 228 | <p class="control"> |
| 229 | <button class="button">></button> |
| 230 | </p> |
| 231 | </div><br> |
| 232 | --> |
avm99963 | 3c6f7fb | 2020-10-01 01:38:25 +0200 | [diff] [blame] | 233 | <div id="subject-container" class="grid buttons"></div> |
avm99963 | 154e51a | 2020-10-01 01:16:38 +0200 | [diff] [blame] | 234 | <div id="no-subjects" class="hidden">No s'està impartint cap classe en aquests moments.</div> |
avm99963 | 3c6f7fb | 2020-10-01 01:38:25 +0200 | [diff] [blame] | 235 | <div id="fme-maps-container" class="hidden"> |
| 236 | <h4>Mapes de les aules de l'FME</h4> |
| 237 | <div class="maps"> |
| 238 | <div class="map"> |
| 239 | <img src="img/ps.png"> |
| 240 | <div class="map--label">Planta <b>-1</b></div> |
| 241 | </div> |
| 242 | <div class="map"> |
| 243 | <img src="img/p0.png"> |
| 244 | <div class="map--label">Planta <b>0</b></div> |
| 245 | </div> |
| 246 | <div class="map"> |
| 247 | <img src="img/p1.png"> |
| 248 | <div class="map--label">Planta <b>1</b></div> |
| 249 | </div> |
| 250 | </div> |
| 251 | </div> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 252 | |
| 253 | </section> |
| 254 | |
| 255 | <section id="section-2" class="section" style="display: none;"> |
| 256 | <button class="button is-link is-light" onclick="switchSection('section-1')">Torna enrere (Classe)</button> |
| 257 | |
| 258 | <div id="letter-container" class="buttons grid"> |
| 259 | <button class="button" id="letter-A" data-letter="A">A</button> |
| 260 | <button class="button" id="letter-B" data-letter="B">B</button> |
| 261 | <button class="button" id="letter-C" data-letter="C">C</button> |
| 262 | <button class="button" id="letter-D" data-letter="D">D</button> |
| 263 | <button class="button" id="letter-E" data-letter="E">E</button> |
| 264 | <button class="button" id="letter-F" data-letter="F">F</button> |
| 265 | <button class="button" id="letter-G" data-letter="G">G</button> |
| 266 | <button class="button" id="letter-H" data-letter="H">H</button> |
| 267 | <button class="button" id="letter-I" data-letter="I">I</button> |
| 268 | <button class="button" id="letter-J" data-letter="J">J</button> |
| 269 | <button class="button" id="letter-K" data-letter="K">K</button> |
| 270 | <button class="button" id="letter-L" data-letter="L">L</button> |
| 271 | </div> |
| 272 | </section> |
| 273 | |
| 274 | <section id="section-3" class="section" style="display: none;"> |
| 275 | <button class="button is-link is-light" onclick="switchSection('section-2')">Torna enrere (Lletra)</button> |
| 276 | |
| 277 | <div id="number-container" class="buttons grid"> |
| 278 | <button class="button" id="number-1" data-number="1">1</button> |
| 279 | <button class="button" id="number-2" data-number="2">2</button> |
| 280 | <button class="button" id="number-3" data-number="3">3</button> |
| 281 | <button class="button" id="number-4" data-number="4">4</button> |
| 282 | <button class="button" id="number-5" data-number="5">5</button> |
| 283 | <button class="button" id="number-6" data-number="6">6</button> |
| 284 | <button class="button" id="number-7" data-number="7">7</button> |
| 285 | <button class="button" id="number-8" data-number="8">8</button> |
| 286 | <button class="button" id="number-9" data-number="9">9</button> |
| 287 | <button class="button" id="number-10" data-number="10">10</button> |
| 288 | </div> |
| 289 | </section> |
| 290 | <section id="section-send" class="section" style="display: none;"> |
| 291 | <button class="button is-link is-light" onclick="switchSection('section-3')">Torna enrere (Número)</button> |
| 292 | <br/><br/> |
| 293 | <span class="has-text-weight-bold">Assignatura:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 294 | <span id="subject-final">ASSIGNATURA ESCOLLIDA</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 295 | <span class="has-text-weight-bold">Aula:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 296 | <span id="classroom-final">AULA ESCOLLIDA</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 297 | <span class="has-text-weight-bold">Data:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 298 | <span id="date-final">DD/MM/YYYY</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 299 | <span class="has-text-weight-bold">Hora:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 300 | <span id="time-final">HH:MM - HH:MM</span><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 301 | <span class="has-text-weight-bold">Posició:</span> |
Andreu Huguet | 898768a | 2020-09-29 00:30:23 +0200 | [diff] [blame] | 302 | <span id="letter-final">A</span><span id="number-final">1</span><br><br> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 303 | |
| 304 | <button id="send-button" class="button is-link is-large">Omple el formulari</button><br><br> |
| 305 | |
| 306 | Hi ha errors? <br /><a class="button is-link is-light" href="https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform">Completa el formulari manualment</a> |
flopgui | 53b67b4 | 2020-09-30 11:48:34 +0200 | [diff] [blame] | 307 | |
flopgui | 0a80b59 | 2020-09-30 11:52:12 +0200 | [diff] [blame] | 308 | <br><br><article class="message is-warning"> |
flopgui | 53b67b4 | 2020-09-30 11:48:34 +0200 | [diff] [blame] | 309 | <div class="message-body"> |
avm99963 | a6e546a | 2020-09-30 20:46:59 +0200 | [diff] [blame] | 310 | Aquest primers dies estem de prova! Mireu bé la informació, si hi ha res malament <a href="https://docs.google.com/forms/d/e/1FAIpQLScZliauRiLzGCn7DrnKZCjGwiefNltI9N8-hUtO_Q0NGInHsg/viewform">envieu-nos un missatge</a>. |
flopgui | 53b67b4 | 2020-09-30 11:48:34 +0200 | [diff] [blame] | 311 | </div> |
| 312 | </article> |
Ferran López | 6759ecf | 2020-09-30 11:32:44 +0200 | [diff] [blame] | 313 | </section> |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 314 | <script> |
| 315 | var current_section = "section-1"; |
| 316 | |
| 317 | function toggleVisibility(id) { |
| 318 | var x = document.getElementById(id); |
Ferran López | 512bc1c | 2020-09-30 11:27:40 +0200 | [diff] [blame^] | 319 | if (x.style.display == "none") { |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 320 | x.style.display = "block"; |
| 321 | } else { |
| 322 | x.style.display = "none"; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | function switchSection(s) { |
| 327 | setTimeout(function(){ |
| 328 | toggleVisibility(current_section); |
| 329 | toggleVisibility(s); |
| 330 | current_section = s; |
| 331 | }, 75); |
| 332 | } |
| 333 | |
| 334 | const idsFormulari = { |
| 335 | room: "1063142948", |
| 336 | day: "2115504093", |
| 337 | begins: "1749141911", |
| 338 | ends: "1827359679", |
| 339 | rows: { |
| 340 | A: "208184485", |
| 341 | B: "1077148310", |
| 342 | C: "642851281", |
| 343 | D: "1686039024", |
| 344 | E: "697835787", |
| 345 | F: "1511799646", |
| 346 | G: "809853432", |
| 347 | H: "182597499", |
| 348 | I: "1890539481", |
| 349 | J: "529159478", |
| 350 | K: "1615241874", |
| 351 | L: "1334263875" |
| 352 | }, |
| 353 | notes: "1600275159" |
| 354 | }; |
| 355 | const formBaseUrl = "https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform"; |
| 356 | |
| 357 | function sendForm() { |
| 358 | // Add subject to user |
| 359 | fetch(api_url + "addUserSubject", { |
| 360 | "method": "POST", |
| 361 | "body": JSON.stringify({ |
| 362 | subject: final_JSON.class.subject_id |
| 363 | }), |
| 364 | "mode": "cors", |
| 365 | "credentials": "include" |
| 366 | }) |
| 367 | .then(res => res.json()) |
| 368 | .then(json => { |
| 369 | console.log("Subject added to user: ", json); |
| 370 | |
| 371 | var begins = new Date(parseInt(final_JSON.class.begins)*1000); |
| 372 | var ends = new Date(parseInt(final_JSON.class.ends)*1000); |
| 373 | |
| 374 | var params = new URLSearchParams(); |
| 375 | params.append("entry." + idsFormulari.room, final_JSON.class.room); // class, number, letter |
| 376 | params.append("entry." + idsFormulari.day, begins.getFullYear().toString() + '-' + (begins.getMonth() + 1).toString().padStart(2, "0") + '-' + begins.getDate().toString().padStart(2, "0")); |
| 377 | params.append("entry." + idsFormulari.begins, formatDate(begins)); |
| 378 | params.append("entry." + idsFormulari.ends, formatDate(ends)); |
| 379 | params.append("entry." + idsFormulari.rows[final_JSON.letter], 'Columna ' + final_JSON.number); |
avm99963 | c041bae | 2020-09-30 10:57:33 +0200 | [diff] [blame] | 380 | // params.append("entry." + idsFormulari.notes, '[Autogenerat per delefme/covid-tracability -- Assignatura seleccionada: ' + (final_JSON.class.friendly_name || final_JSON.class.calendar_name) + ']'); |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 381 | |
avm99963 | dbdc965 | 2020-09-29 01:09:25 +0200 | [diff] [blame] | 382 | var formulari_link = formBaseUrl + '?' + params.toString() + '#i1'; |
avm99963 | 4f7c03c | 2020-09-29 00:08:12 +0200 | [diff] [blame] | 383 | window.location.href = formulari_link; |
| 384 | }); |
| 385 | } |
| 386 | |
| 387 | document.getElementById("send-button").addEventListener('click', function (el) { |
| 388 | document.getElementById('send-button').classList.add('is-loading'); |
| 389 | |
| 390 | sendForm(); |
| 391 | }); |
| 392 | </script> |
| 393 | </body> |
| 394 | </html> |