blob: e66e2163b7f7ede16d224d7f5146064fbe9ea0e7 [file] [log] [blame]
avm999634f7c03c2020-09-29 00:08:12 +02001<!DOCTYPE html>
2
3<html lang="ca">
4 <head>
delefmeefcc0302020-09-30 09:26:12 +02005 <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
avm999634f7c03c2020-09-29 00:08:12 +020017 <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 Huguet898768a2020-09-29 00:30:23 +020019 <link rel="stylesheet" href="./css/bulma-adjustments.css">
avm999634f7c03c2020-09-29 00:08:12 +020020 </head>
21 <body>
avm999634f7c03c2020-09-29 00:08:12 +020022 <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
avm99963c041bae2020-09-30 10:57:33 +020044 document.getElementById('subject-final').textContent = final_JSON.class.friendly_name || final_JSON.class.calendar_name;
avm999634f7c03c2020-09-29 00:08:12 +020045 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 = "";
avm999634f7c03c2020-09-29 00:08:12 +020088 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 => {
avm99963154e51a2020-10-01 01:16:38 +0200137 if (data.payload.classes.length == 0) {
138 document.getElementById('no-subjects').classList.remove('hidden');
139 }
140
141
avm999634f7c03c2020-09-29 00:08:12 +0200142 for (var classe of data.payload.classes) {
143 console.log(classe);
144
145 var hora_inici = formatDate(new Date(parseInt(classe.begins)*1000));
146 var hora_final = formatDate(new Date(parseInt(classe.ends)*1000));
147
148 var classeDiv = document.createElement('div');
149 classeDiv.classList.add('message', 'complex-button');
150 classeDiv.id = 'subject-' + classe.subject_id + '-' + classe.room;
151 classeDiv.setAttribute('data-class', JSON.stringify(classe));
152
153 var header = document.createElement('div');
154 header.classList.add('message-header');
delefme20d025b2020-09-30 12:00:37 +0200155 header.textContent = classe.friendly_name || classe.calendar_name;
avm999634f7c03c2020-09-29 00:08:12 +0200156
157 var body = document.createElement('div');
158 body.classList.add('message-body');
159
160 var div1 = document.createElement('div');
161 var span = document.createElement('span');
162 span.textContent = classe.room;
163
164 div1.textContent = 'Aula ';
165 div1.appendChild(span);
166
167 var div2 = document.createElement('div');
168 div2.textContent = hora_inici + ' - ' + hora_final;
169
170 body.appendChild(div1);
171 body.appendChild(div2);
172
173 classeDiv.appendChild(header);
174 classeDiv.appendChild(body);
175
176 document.getElementById("subject-container").appendChild(classeDiv);
177 }
178
179 var elements = document.getElementsByClassName("button");
180 Array.from(elements).forEach(function(element) {
181 element.addEventListener('click', clickButton);
182 element.parent = element.parentNode.id;
183 });
184 var elements = document.getElementsByClassName("complex-button");
185 Array.from(elements).forEach(function(element) {
186 element.addEventListener('click', clickButton);
187 element.parent = element.parentNode.id;
188 });
189 });
190 });
191 </script>
192
193 <span id="dev-mode" class="hidden">Dev mode</span>
194
195 <nav class="navbar is-link">
196 <div class="navbar-brand">
197 <div class="navbar-item has-text-weight-bold">Traçabilitat DAFME</div>
198 </div>
199 </nav>
200
201 <section id="section-1" class="section">
202 <!--
203 <div class="field has-addons">
204 <p class="control">
205 <button class="button">&lt;</button>
206 </p>
207 <p class="control">
208 <input type="date" class="button">
209 </p>
210 <p class="control">
211 <button class="button">&gt;</button>
212 </p>
213 </div>
214 <div class="field has-addons">
215 <p class="control">
216 <button class="button">&lt;</button>
217 </p>
218 <p class="control">
219 <input type="button" class="button" value="08:00 - 08:30">
220 </p>
221 <p class="control">
222 <button class="button">&gt;</button>
223 </p>
224 </div><br>
225 -->
226 <div id="subject-container" class="grid buttons"></div><br>
avm99963154e51a2020-10-01 01:16:38 +0200227 <div id="no-subjects" class="hidden">No s'està impartint cap classe en aquests moments.</div>
avm999634f7c03c2020-09-29 00:08:12 +0200228
229 </section>
230
231 <section id="section-2" class="section" style="display: none;">
232 <button class="button is-link is-light" onclick="switchSection('section-1')">Torna enrere (Classe)</button>
233
234 <div id="letter-container" class="buttons grid">
235 <button class="button" id="letter-A" data-letter="A">A</button>
236 <button class="button" id="letter-B" data-letter="B">B</button>
237 <button class="button" id="letter-C" data-letter="C">C</button>
238 <button class="button" id="letter-D" data-letter="D">D</button>
239 <button class="button" id="letter-E" data-letter="E">E</button>
240 <button class="button" id="letter-F" data-letter="F">F</button>
241 <button class="button" id="letter-G" data-letter="G">G</button>
242 <button class="button" id="letter-H" data-letter="H">H</button>
243 <button class="button" id="letter-I" data-letter="I">I</button>
244 <button class="button" id="letter-J" data-letter="J">J</button>
245 <button class="button" id="letter-K" data-letter="K">K</button>
246 <button class="button" id="letter-L" data-letter="L">L</button>
247 </div>
248 </section>
249
250 <section id="section-3" class="section" style="display: none;">
251 <button class="button is-link is-light" onclick="switchSection('section-2')">Torna enrere (Lletra)</button>
252
253 <div id="number-container" class="buttons grid">
254 <button class="button" id="number-1" data-number="1">1</button>
255 <button class="button" id="number-2" data-number="2">2</button>
256 <button class="button" id="number-3" data-number="3">3</button>
257 <button class="button" id="number-4" data-number="4">4</button>
258 <button class="button" id="number-5" data-number="5">5</button>
259 <button class="button" id="number-6" data-number="6">6</button>
260 <button class="button" id="number-7" data-number="7">7</button>
261 <button class="button" id="number-8" data-number="8">8</button>
262 <button class="button" id="number-9" data-number="9">9</button>
263 <button class="button" id="number-10" data-number="10">10</button>
264 </div>
265 </section>
266 <section id="section-send" class="section" style="display: none;">
267 <button class="button is-link is-light" onclick="switchSection('section-3')">Torna enrere (Número)</button>
268 <br/><br/>
269 <span class="has-text-weight-bold">Assignatura:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200270 <span id="subject-final">ASSIGNATURA ESCOLLIDA</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200271 <span class="has-text-weight-bold">Aula:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200272 <span id="classroom-final">AULA ESCOLLIDA</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200273 <span class="has-text-weight-bold">Data:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200274 <span id="date-final">DD/MM/YYYY</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200275 <span class="has-text-weight-bold">Hora:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200276 <span id="time-final">HH:MM - HH:MM</span><br>
avm999634f7c03c2020-09-29 00:08:12 +0200277 <span class="has-text-weight-bold">Posició:</span>
Andreu Huguet898768a2020-09-29 00:30:23 +0200278 <span id="letter-final">A</span><span id="number-final">1</span><br><br>
avm999634f7c03c2020-09-29 00:08:12 +0200279
280 <button id="send-button" class="button is-link is-large">Omple el formulari</button><br><br>
281
282 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>
flopgui53b67b42020-09-30 11:48:34 +0200283
flopgui0a80b592020-09-30 11:52:12 +0200284 <br><br><article class="message is-warning">
flopgui53b67b42020-09-30 11:48:34 +0200285 <div class="message-body">
avm99963a6e546a2020-09-30 20:46:59 +0200286 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>.
flopgui53b67b42020-09-30 11:48:34 +0200287 </div>
288 </article>
Ferran López6759ecf2020-09-30 11:32:44 +0200289 </section>
avm999634f7c03c2020-09-29 00:08:12 +0200290 <script>
291 var current_section = "section-1";
292
293 function toggleVisibility(id) {
294 var x = document.getElementById(id);
295 if (x.style.display === "none") {
296 x.style.display = "block";
297 } else {
298 x.style.display = "none";
299 }
300 }
301
302 function switchSection(s) {
303 setTimeout(function(){
304 toggleVisibility(current_section);
305 toggleVisibility(s);
306 current_section = s;
307 }, 75);
308 }
309
310 const idsFormulari = {
311 room: "1063142948",
312 day: "2115504093",
313 begins: "1749141911",
314 ends: "1827359679",
315 rows: {
316 A: "208184485",
317 B: "1077148310",
318 C: "642851281",
319 D: "1686039024",
320 E: "697835787",
321 F: "1511799646",
322 G: "809853432",
323 H: "182597499",
324 I: "1890539481",
325 J: "529159478",
326 K: "1615241874",
327 L: "1334263875"
328 },
329 notes: "1600275159"
330 };
331 const formBaseUrl = "https://docs.google.com/forms/d/e/1FAIpQLSfT9o287VqLyhwR8LPdloAQWhuqCgA3NfdhgP5vb9_sVQHL-g/viewform";
332
333 function sendForm() {
334 // Add subject to user
335 fetch(api_url + "addUserSubject", {
336 "method": "POST",
337 "body": JSON.stringify({
338 subject: final_JSON.class.subject_id
339 }),
340 "mode": "cors",
341 "credentials": "include"
342 })
343 .then(res => res.json())
344 .then(json => {
345 console.log("Subject added to user: ", json);
346
347 var begins = new Date(parseInt(final_JSON.class.begins)*1000);
348 var ends = new Date(parseInt(final_JSON.class.ends)*1000);
349
350 var params = new URLSearchParams();
351 params.append("entry." + idsFormulari.room, final_JSON.class.room); // class, number, letter
352 params.append("entry." + idsFormulari.day, begins.getFullYear().toString() + '-' + (begins.getMonth() + 1).toString().padStart(2, "0") + '-' + begins.getDate().toString().padStart(2, "0"));
353 params.append("entry." + idsFormulari.begins, formatDate(begins));
354 params.append("entry." + idsFormulari.ends, formatDate(ends));
355 params.append("entry." + idsFormulari.rows[final_JSON.letter], 'Columna ' + final_JSON.number);
avm99963c041bae2020-09-30 10:57:33 +0200356 // params.append("entry." + idsFormulari.notes, '[Autogenerat per delefme/covid-tracability -- Assignatura seleccionada: ' + (final_JSON.class.friendly_name || final_JSON.class.calendar_name) + ']');
avm999634f7c03c2020-09-29 00:08:12 +0200357
avm99963dbdc9652020-09-29 01:09:25 +0200358 var formulari_link = formBaseUrl + '?' + params.toString() + '#i1';
avm999634f7c03c2020-09-29 00:08:12 +0200359 window.location.href = formulari_link;
360 });
361 }
362
363 document.getElementById("send-button").addEventListener('click', function (el) {
364 document.getElementById('send-button').classList.add('is-loading');
365
366 sendForm();
367 });
368 </script>
369 </body>
370</html>