summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contents/ui/main.qml41
1 files changed, 27 insertions, 14 deletions
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index 33c12b6..e9529cf 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -17,28 +17,42 @@ Item {
readonly property string oauth2Token: plasmoid.configuration.oauth2Token
readonly property string authHeader: `Bearer ${oauth2Token}`
- function syncCanvas() {
+ function callApi(path, amount, callback) {
let xhr = new XMLHttpRequest()
- xhr.open("GET", `${apiEndpoint}/courses`)
+ xhr.open("GET", `${apiEndpoint}${path}` + (amount ? `?per_page=${amount}` : ""))
xhr.setRequestHeader("Authorization", authHeader)
- xhr.onload = function () {
+ xhr.onload = () => {
if (xhr.status == 200) {
try {
- let courses = JSON.parse(xhr.responseText)
- for (let c of courses) {
- announcementsModel.append({course: c.name, title: ""})
- }
+ let json = JSON.parse(xhr.responseText)
+ if (callback) { callback(json) }
} catch (e) {
- if (e instanceof SyntaxError) { console.error("Cannot parse JSON:") }
- else { throw e }
+ if (e instanceof SyntaxError) {
+ console.error(`Cannot parse response for ${path} as JSON:\n${xhr.responseText}`)
+ } else { throw e }
}
} else {
- console.error("XHR failed")
+ console.error(`XHR failed when retrieving ${path} (status ${xhr.status}):\n${xhr.responseText}`)
}
}
xhr.send()
}
+ function syncCanvas() {
+ // Get all courses
+ callApi("/courses", 20, courses => {
+ for (let course of courses) {
+ callApi(`/courses/${course.id}/activity_stream`, 10, activityStream => {
+ for (let activity of activityStream) {
+ if (activity.type == "Announcement") {
+ announcementsModel.append({course: course.course_code, title: activity.title})
+ }
+ }
+ })
+ }
+ })
+ }
+
Timer {
interval: 60 * 1000
running: true;
@@ -46,10 +60,6 @@ Item {
onTriggered: syncCanvas();
}
- Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
-
- Plasmoid.fullRepresentation: main
-
ColumnLayout {
id: main
anchors.fill: parent
@@ -75,6 +85,9 @@ Item {
Layout.margins: PlasmaCore.Units.smallSpacing
Layout.fillWidth: true
Layout.fillHeight: true
+
+ ScrollBar.horizontal.policy: ScollBar.AlwaysOff
+
ListView {
Layout.fillWidth: true
delegate: Text {