summaryrefslogtreecommitdiff
path: root/contents/ui
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-04-07 15:31:55 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-04-07 15:31:55 +0800
commit5a280f20286e34319414881d84d4f024d95fc3da (patch)
tree9b47106b140447f965d1a8e2bba31c9d35af2150 /contents/ui
parentb026a7f1b2920b3b9639f9b9fe30f8dc8473461d (diff)
Merge announcement/assignment views as ActivityView
Diffstat (limited to 'contents/ui')
-rw-r--r--contents/ui/ActivityView.qml (renamed from contents/ui/AnnouncementView.qml)38
-rw-r--r--contents/ui/main.qml71
2 files changed, 83 insertions, 26 deletions
diff --git a/contents/ui/AnnouncementView.qml b/contents/ui/ActivityView.qml
index 53c78be..9c4cc30 100644
--- a/contents/ui/AnnouncementView.qml
+++ b/contents/ui/ActivityView.qml
@@ -9,21 +9,21 @@ import org.kde.plasma.components 3.0 as PlasmaComponents3
import org.kde.plasma.extras 2.0 as PlasmaExtras
RowLayout {
- id: announcementView
+ id: activityView
width: parent.width
Layout.fillWidth: true
RowLayout {
Layout.fillWidth: true
PlasmaComponents3.CheckBox {
- id: announcementCheckbox
+ id: activityCheckbox
onToggled: () => {
- announcementLabel.font.strikeout = (checkState == Qt.Checked)
+ activityLabel.font.strikeout = (checkState == Qt.Checked)
}
}
PlasmaComponents3.Label {
- id: announcementLabel
+ id: activityLabel
text: `[${course}] ${title}`
font.bold: important
color: important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
@@ -33,8 +33,8 @@ RowLayout {
MouseArea {
anchors.fill: parent
onClicked: () => {
- announcementCheckbox.toggle() // toggle checkbox
- announcementCheckbox.toggled() // and trigger the onToggled effects
+ activityCheckbox.toggle() // toggle checkbox
+ activityCheckbox.toggled() // and trigger the onToggled effects
}
}
}
@@ -54,28 +54,32 @@ RowLayout {
icon.name: "emblem-important-symbolic"
onClicked: () => {
important = !important
- announcementLabel.font.bold = important
- announcementLabel.color = important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
- let importantAnnouncements = plasmoid.configuration.importantAnnouncements
+ activityLabel.font.bold = important
+ activityLabel.color = important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor
+ let importantActivities = plasmoid.configuration.importantActivities
if (important) {
- if (!importantAnnouncements.includes(announcementId)) {
- importantAnnouncements.push(announcementId)
+ if (!importantActivities.includes(activityId)) {
+ importantActivities.push(activityId)
}
} else {
- // remove announcementId from list
- importantAnnouncements.splice(importantAnnouncements.indexOf(announcementId), 1)
+ // remove activityId from list
+ importantActivities.splice(importantActivities.indexOf(activityId), 1)
}
// save config
- plasmoid.configuration.importantAnnouncements = importantAnnouncements
+ plasmoid.configuration.importantActivities = importantActivities
}
}
PlasmaComponents3.ToolButton {
icon.name: "delete"
onClicked: () => {
- // avoid non-fatal TypeError due to announcementView.parent=null but .width=parent.width
- announcementView.width = 0
- announcementsModel.remove(index)
+ // avoid non-fatal TypeError due to activityView.parent=null but .width=parent.width
+ activityView.width = 0
+ if (type == "announcement") {
+ announcementsModel.remove(index)
+ } else {
+ assignmentsModel.remove(index)
+ }
}
}
}
diff --git a/contents/ui/main.qml b/contents/ui/main.qml
index 4872c3c..bc49207 100644
--- a/contents/ui/main.qml
+++ b/contents/ui/main.qml
@@ -47,22 +47,41 @@ Item {
)
announcementsModel.clear()
+ assignmentsModel.clear()
for (let course of courses) {
callApi(`/courses/${course[0]}/activity_stream`, 10, activityStream => {
// Get activity stream for each course
- activityStream.forEach((activity, index) => {
+ let announcementCount = 0
+ let assignmentCount = 0
+ activityStream.forEach(activity => {
if (activity.type == "Announcement") {
announcementsModel.append({
- index: index,
+ type: "announcement",
+ activityId: activity.id,
+ index: announcementCount,
course: course[1],
title: activity.title,
url: activity.html_url,
- important: plasmoid.configuration.importantAnnouncements.includes(
- activity.announcement_id.toString()
+ important: plasmoid.configuration.importantActivities.includes(
+ activity.id.toString()
),
- announcementId: activity.announcement_id
})
+ announcementCount++
+ } else if (activity.type == "Submission") {
+ assignmentsModel.append({
+ type: "assignment",
+ activityId: activity.id,
+ index: assignmentCount,
+ course: course[1],
+ title: activity.title,
+ due: activity.assignment.due_at,
+ url: activity.html_url,
+ important: plasmoid.configuration.importantActivities.includes(
+ activity.id.toString()
+ ),
+ })
+ assignmentCount++
}
})
})
@@ -93,11 +112,13 @@ Item {
ListModel {
id: announcementsModel
ListElement {
+ type: "announcement"
+ index: 0
course: "CS101"
- title: "Title of the announcement"
+ title: "Title"
url: "https://xkcd.com"
important: true
- announcementId: 0
+ activityId: 0
}
}
@@ -106,16 +127,48 @@ Item {
Layout.margins: PlasmaCore.Units.smallSpacing
Layout.fillWidth: true
Layout.fillHeight: true
-
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
ListView {
Layout.fillWidth: true
- delegate: AnnouncementView {}
+ delegate: ActivityView {}
model: announcementsModel
}
}
+ PlasmaExtras.Heading {
+ level: 2
+ text: "Assignments"
+ }
+
+ ListModel {
+ id: assignmentsModel
+ ListElement {
+ type: "assignment"
+ index: 0
+ course: "EE210"
+ title: "Title"
+ due: "2022-12-31T23:59:59Z"
+ url: "https://xkcd.com"
+ important: true
+ activityId: 1
+ }
+ }
+
+ ScrollView {
+ implicitHeight: PlasmaCore.Units.gridUnit * 20
+ Layout.margins: PlasmaCore.Units.smallSpacing
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
+
+ ListView {
+ Layout.fillWidth: true
+ delegate: ActivityView {}
+ model: assignmentsModel
+ }
+ }
+
PlasmaComponents3.Button {
icon.name: "view-refresh"
text: i18n("Refresh")