summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contents/config/config.qml10
-rw-r--r--contents/config/main.xml12
-rw-r--r--contents/ui/configGeneral.qml23
-rw-r--r--contents/ui/main.qml33
4 files changed, 75 insertions, 3 deletions
diff --git a/contents/config/config.qml b/contents/config/config.qml
new file mode 100644
index 0000000..39eaa5c
--- /dev/null
+++ b/contents/config/config.qml
@@ -0,0 +1,10 @@
+import QtQuick 2.0
+import org.kde.plasma.configuration 2.0
+
+ConfigModel {
+ ConfigCategory {
+ name: i18n("General")
+ icon: "configure"
+ source: "configGeneral.qml"
+ }
+}
diff --git a/contents/config/main.xml b/contents/config/main.xml
new file mode 100644
index 0000000..7b86809
--- /dev/null
+++ b/contents/config/main.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0 http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
+ <kcfgfile name=""/>
+ <group name="General">
+ <entry name="canvasUrl" type="String">
+ <default>https://</default>
+ </entry>
+ <entry name="oauth2Token" type="String">
+ <default></default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/contents/ui/configGeneral.qml b/contents/ui/configGeneral.qml
new file mode 100644
index 0000000..c13b5ea
--- /dev/null
+++ b/contents/ui/configGeneral.qml
@@ -0,0 +1,23 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.kde.kirigami 2.5 as Kirigami
+
+Kirigami.FormLayout {
+ id: page
+ property alias cfg_canvasUrl: canvasUrl.text
+ property alias cfg_oauth2Token: oauth2Token.text
+
+ TextField {
+ id: canvasUrl
+ Kirigami.FormData.label: i18n("Canvas URL:")
+ placeholderText: i18n("https://your.canvas.url/")
+ }
+
+ TextField {
+ id: oauth2Token
+ Kirigami.FormData.label: i18n("OAuth2 Token:")
+ placeholderText: i18n("")
+ }
+}
+
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index c78ba5e..33c12b6 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -2,6 +2,7 @@ import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
+import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.components 3.0 as PlasmaComponents3
@@ -11,11 +12,31 @@ Item {
width: PlasmaCore.Units.gridUnit * 20
height: PlasmaCore.Units.gridUnit * 40
+ readonly property string canvasUrl: plasmoid.configuration.canvasUrl
+ readonly property string apiEndpoint: `${canvasUrl.replace(/\/$/, "")}/api/v1`
+ readonly property string oauth2Token: plasmoid.configuration.oauth2Token
+ readonly property string authHeader: `Bearer ${oauth2Token}`
+
function syncCanvas() {
- // TODO: networking
- for (let i = 0; i < 8; i++) {
- announcementsModel.append({course: `VZ${i}01`, title: "Something"})
+ let xhr = new XMLHttpRequest()
+ xhr.open("GET", `${apiEndpoint}/courses`)
+ xhr.setRequestHeader("Authorization", authHeader)
+ xhr.onload = function () {
+ if (xhr.status == 200) {
+ try {
+ let courses = JSON.parse(xhr.responseText)
+ for (let c of courses) {
+ announcementsModel.append({course: c.name, title: ""})
+ }
+ } catch (e) {
+ if (e instanceof SyntaxError) { console.error("Cannot parse JSON:") }
+ else { throw e }
+ }
+ } else {
+ console.error("XHR failed")
+ }
}
+ xhr.send()
}
Timer {
@@ -25,9 +46,15 @@ Item {
onTriggered: syncCanvas();
}
+ Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
+
+ Plasmoid.fullRepresentation: main
+
ColumnLayout {
id: main
anchors.fill: parent
+ width: PlasmaCore.Units.gridUnit * 20
+ height: PlasmaCore.Units.gridUnit * 40
PlasmaExtras.Heading {
level: 1