async function startApp() { await printPage(); } async function printPage(){ // Load data console.log("___printPage()___"); // Print HTML let html = ""; html += "
Schedule Volvo rechanging
\n"; html += "How much there is battery left in the car?
"; html += "\n"; html += "| Schedule date | Energy price | Total cost (cents) |
|---|---|---|
| No schedules found | ||
| " + scheduleDate + " | "; scheduleTableHtml += "" + energyPrice + " | "; scheduleTableHtml += "" + calculatedPrice.toFixed(3) + " | "; scheduleTableHtml += "
| " + hours + " h " + minutes + " min | " + totalCost + " € | |
There is total of " + hours + " hours and " + minutes + " minutes of changing! Total cost for charging is " + totalCost + " €
"; if (totalCount > 0) { html += "\n"; } html += scheduleTableHtml; document.getElementById('volvoschedules').innerHTML = html; } async function scheduleWithBatteryChargePercentage() { let element = document.getElementById('batteryleftpercentageelement'); let readyTime = document.getElementById('readytimeelement'); console.log("Scheduling Volvo per battery percentage left " + element.value + " and to be ready at " + readyTime.value + "..."); let response = await createVolvoScheduleByLeftPercentage(element.value, readyTime.value, true); console.log("Response : " + response.message); alert(response.message); await updateVolvoSchedules(); return false; } async function deleteSchedules() { console.log("Deleting Volvo schedules..."); let response = await deleteVolvoSchedules(); console.log("Response : " + response.message); await updateVolvoSchedules(); return false; } async function readVolvoSchedules() { const response = await fetch("/schedule/read/volvo"); const data = await response.json(); console.log("==> fetchSchedules: " + JSON.stringify(data)); return data; } async function createVolvoScheduleByLeftPercentage(leftPercentage, readyTime, activateScheduling) { const response = await fetch('/schedule/create/volvo/leftpercentage', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({leftPercentage: leftPercentage, readyTime: readyTime, activateScheduling: activateScheduling}) }); const data = await response.json(); console.log("==> createVolvoScheduleByLeftPercentage: " + JSON.stringify(data)); return data; } async function deleteVolvoSchedules() { const response = await fetch('/schedule/delete/volvo', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({delete: true}) }); const data = await response.json(); console.log("==> deleteVolvoSchedules: " + JSON.stringify(data)); return data; }