summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contents/config/config.qml6
-rw-r--r--contents/config/main.xml5
-rw-r--r--contents/ui/configCanvas.qml73
-rw-r--r--contents/ui/configGeneral.qml67
-rw-r--r--contents/ui/main.qml12
5 files changed, 96 insertions, 67 deletions
diff --git a/contents/config/config.qml b/contents/config/config.qml
index 39eaa5c..be675e4 100644
--- a/contents/config/config.qml
+++ b/contents/config/config.qml
@@ -7,4 +7,10 @@ ConfigModel {
icon: "configure"
source: "configGeneral.qml"
}
+
+ ConfigCategory {
+ name: i18n("Canvas")
+ icon: "applications-internet"
+ source: "configCanvas.qml"
+ }
}
diff --git a/contents/config/main.xml b/contents/config/main.xml
index 6d743c8..923dc15 100644
--- a/contents/config/main.xml
+++ b/contents/config/main.xml
@@ -2,6 +2,11 @@
<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="showSubmittedAssignments" type="Bool">
+ <default>true</default>
+ </entry>
+ </group>
+ <group name="Canvas">
<entry name="canvasUrl" type="String">
<default>https://</default>
</entry>
diff --git a/contents/ui/configCanvas.qml b/contents/ui/configCanvas.qml
new file mode 100644
index 0000000..fc64389
--- /dev/null
+++ b/contents/ui/configCanvas.qml
@@ -0,0 +1,73 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+import org.kde.kirigami 2.5 as Kirigami
+
+Kirigami.FormLayout {
+ property alias cfg_canvasUrl: canvasUrl.text
+ property alias cfg_oauth2Token: oauth2Token.text
+ property alias cfg_courses: courses.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("Generate in Canvas web interface")
+ }
+
+ function fetchCourses() {
+ courses.clear()
+ fetchCoursesStatus.text = i18n("Fetching…")
+ let xhr = new XMLHttpRequest()
+ xhr.open("GET", `${canvasUrl.text.replace(/\/$/, "")}/api/v1/courses?per_page=100`)
+ xhr.setRequestHeader("Authorization", `Bearer ${oauth2Token.text}`)
+ xhr.onload = () => {
+ if (xhr.status == 200) {
+ try {
+ let json = JSON.parse(xhr.responseText)
+ for (let c of json) {
+ courses.append(`${c.id} ${c.course_code}`)
+ }
+ fetchCoursesStatus.text = i18n(
+ "Done! You can remove courses you don't wish to see on your desktop from the list."
+ )
+ } catch (e) {
+ if (e instanceof SyntaxError) {
+ console.error(`Cannot parse response for ${path} as JSON:\n${xhr.responseText}`)
+ fetchgCoursesStatus.text = i18n("Cannot parse API response")
+ } else { throw e }
+ }
+ } else {
+ console.error(`XHR failed when retrieving /courses (status ${xhr.status}):\n${xhr.responseText}`)
+ fetchCoursesStatus.text = i18n("API call failed (HTTP status %1)", xhr.status)
+ }
+ }
+ xhr.send()
+ }
+
+ ScrollView {
+ Layout.fillWidth: true
+ Kirigami.FormData.label: i18n("Courses:")
+ TextArea {
+ Layout.fillWidth: true
+ id: courses
+ placeholderText: i18n("Click Fetch courses for a full list")
+ }
+ }
+
+ Button {
+ text: "Fetch courses"
+ onClicked: fetchCourses()
+ }
+
+ Label {
+ id: fetchCoursesStatus
+ text: ""
+ }
+}
+
diff --git a/contents/ui/configGeneral.qml b/contents/ui/configGeneral.qml
index fc64389..479b9e6 100644
--- a/contents/ui/configGeneral.qml
+++ b/contents/ui/configGeneral.qml
@@ -4,70 +4,11 @@ import QtQuick.Layouts 1.15
import org.kde.kirigami 2.5 as Kirigami
Kirigami.FormLayout {
- property alias cfg_canvasUrl: canvasUrl.text
- property alias cfg_oauth2Token: oauth2Token.text
- property alias cfg_courses: courses.text
+ property alias cfg_showSubmittedAssignments: showSubmittedAssignments.checked
- 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("Generate in Canvas web interface")
- }
-
- function fetchCourses() {
- courses.clear()
- fetchCoursesStatus.text = i18n("Fetching…")
- let xhr = new XMLHttpRequest()
- xhr.open("GET", `${canvasUrl.text.replace(/\/$/, "")}/api/v1/courses?per_page=100`)
- xhr.setRequestHeader("Authorization", `Bearer ${oauth2Token.text}`)
- xhr.onload = () => {
- if (xhr.status == 200) {
- try {
- let json = JSON.parse(xhr.responseText)
- for (let c of json) {
- courses.append(`${c.id} ${c.course_code}`)
- }
- fetchCoursesStatus.text = i18n(
- "Done! You can remove courses you don't wish to see on your desktop from the list."
- )
- } catch (e) {
- if (e instanceof SyntaxError) {
- console.error(`Cannot parse response for ${path} as JSON:\n${xhr.responseText}`)
- fetchgCoursesStatus.text = i18n("Cannot parse API response")
- } else { throw e }
- }
- } else {
- console.error(`XHR failed when retrieving /courses (status ${xhr.status}):\n${xhr.responseText}`)
- fetchCoursesStatus.text = i18n("API call failed (HTTP status %1)", xhr.status)
- }
- }
- xhr.send()
- }
-
- ScrollView {
- Layout.fillWidth: true
- Kirigami.FormData.label: i18n("Courses:")
- TextArea {
- Layout.fillWidth: true
- id: courses
- placeholderText: i18n("Click Fetch courses for a full list")
- }
- }
-
- Button {
- text: "Fetch courses"
- onClicked: fetchCourses()
- }
-
- Label {
- id: fetchCoursesStatus
- text: ""
+ CheckBox {
+ id: showSubmittedAssignments
+ text: i18n("Show submitted assignments")
}
}
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index 5593b8c..f42ed15 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -46,6 +46,8 @@ Item {
line => { return line.split(" ", 2) }
)
+ const showSubmittedAssignments = plasmoid.configuration.showSubmittedAssignments
+
announcementsModel.clear()
assignmentsModel.clear()
@@ -84,10 +86,12 @@ Item {
important: plasmoid.configuration.importantAssignments.includes(assignment.id.toString()),
}
- if (info.important) {
- assignmentsModel.insert(importantCount.assignments++, info)
- } else {
- assignmentsModel.append(info)
+ if (!info.submitted || showSubmittedAssignments) {
+ if (info.important) {
+ assignmentsModel.insert(importantCount.assignments++, info)
+ } else {
+ assignmentsModel.append(info)
+ }
}
})
})