diff --git a/evcharger-app/i18n/qml_de.ts b/evcharger-app/i18n/qml_de.ts index 54e9f5e..6d93e1f 100644 --- a/evcharger-app/i18n/qml_de.ts +++ b/evcharger-app/i18n/qml_de.ts @@ -1757,7 +1757,27 @@ Informationen - + + Idle + + + + + HEADERS_RECEIVED + + + + + LOADING + + + + + Request started... + + + + Download informations Informationen herunterladen diff --git a/evcharger-app/qml/InformationsTabPage.qml b/evcharger-app/qml/InformationsTabPage.qml index 0cac569..66102f1 100644 --- a/evcharger-app/qml/InformationsTabPage.qml +++ b/evcharger-app/qml/InformationsTabPage.qml @@ -15,6 +15,77 @@ ScrollableTabPage { text: qsTr("Informations") } + Text { + id: statusText + text: qsTr("Idle") + } + + ApiKeyValueHelper { + id: dataApiKeyValueHelper + deviceConnection: theDeviceConnection + apiKey: "data" + } + + QtObject { + property var xhr: undefined + property bool requestAgain: false + + property var parsed: typeof dataApiKeyValueHelper.value === 'string' || dataApiKeyValueHelper.value instanceof String ? + JSON.parse(dataApiKeyValueHelper.value) : undefined + property var url: parsed ? parsed.url + "&title=title&chartTitle=chartTitle&scale=1&width=" + (page.width-30) + "&app_id=1&&lang=de" : undefined + onUrlChanged: { + if (!url) + return; + + if (xhr) { + console.log('enqueued new request') + requestAgain = true + return + } + + console.log('started new request') + xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) { + statusText.text = qsTr("HEADERS_RECEIVED"); + } else if(xhr.readyState === XMLHttpRequest.LOADING) { + statusText.text = qsTr("LOADING"); + } else if(xhr.readyState === XMLHttpRequest.DONE) { + try { + var object = JSON.parse(xhr.responseText.toString()); + + imagesRepeater.model = object.images; + + statusText.text = qsTr("DONE!" + ('images' in object ? ' images' : '') + ('chartData' in object ? ' chartData' : '')); + } catch (e) { + statusText.text = qsTr("DONE, but exception: " + e); + } + + xhr = undefined + if (requestAgain) { + requestAgain = false + onUrlChanged() + } + } + } + statusText.text = qsTr("Request started..."); + xhr.open("GET", url); + xhr.send(); + } + } + + Repeater { + id: imagesRepeater + visible: false + Layout.fillWidth: true + + Image { + Layout.fillWidth: true + x: -30 + source: "data:image/svg+xml;utf8," + modelData + } + } + Repeater { model: 5