From 5a280f20286e34319414881d84d4f024d95fc3da Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 7 Apr 2022 15:31:55 +0800 Subject: Merge announcement/assignment views as ActivityView --- contents/ui/ActivityView.qml | 86 ++++++++++++++++++++++++++++++++++++++++ contents/ui/AnnouncementView.qml | 82 -------------------------------------- contents/ui/main.qml | 71 ++++++++++++++++++++++++++++----- 3 files changed, 148 insertions(+), 91 deletions(-) create mode 100644 contents/ui/ActivityView.qml delete mode 100644 contents/ui/AnnouncementView.qml (limited to 'contents/ui') diff --git a/contents/ui/ActivityView.qml b/contents/ui/ActivityView.qml new file mode 100644 index 0000000..9c4cc30 --- /dev/null +++ b/contents/ui/ActivityView.qml @@ -0,0 +1,86 @@ +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 +import org.kde.plasma.extras 2.0 as PlasmaExtras + +RowLayout { + id: activityView + width: parent.width + Layout.fillWidth: true + + RowLayout { + Layout.fillWidth: true + PlasmaComponents3.CheckBox { + id: activityCheckbox + onToggled: () => { + activityLabel.font.strikeout = (checkState == Qt.Checked) + } + } + + PlasmaComponents3.Label { + id: activityLabel + text: `[${course}] ${title}` + font.bold: important + color: important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor + elide: Text.ElideRight + Layout.fillWidth: true + + MouseArea { + anchors.fill: parent + onClicked: () => { + activityCheckbox.toggle() // toggle checkbox + activityCheckbox.toggled() // and trigger the onToggled effects + } + } + } + } + + RowLayout { + Layout.alignment: Qt.AlignRight + + PlasmaComponents3.ToolButton { + icon.name: "view-visible" + onClicked: () => { + Qt.openUrlExternally(url) + } + } + + PlasmaComponents3.ToolButton { + icon.name: "emblem-important-symbolic" + onClicked: () => { + important = !important + activityLabel.font.bold = important + activityLabel.color = important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor + let importantActivities = plasmoid.configuration.importantActivities + if (important) { + if (!importantActivities.includes(activityId)) { + importantActivities.push(activityId) + } + } else { + // remove activityId from list + importantActivities.splice(importantActivities.indexOf(activityId), 1) + } + // save config + plasmoid.configuration.importantActivities = importantActivities + } + } + + PlasmaComponents3.ToolButton { + icon.name: "delete" + onClicked: () => { + // 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/AnnouncementView.qml b/contents/ui/AnnouncementView.qml deleted file mode 100644 index 53c78be..0000000 --- a/contents/ui/AnnouncementView.qml +++ /dev/null @@ -1,82 +0,0 @@ -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 -import org.kde.plasma.extras 2.0 as PlasmaExtras - -RowLayout { - id: announcementView - width: parent.width - Layout.fillWidth: true - - RowLayout { - Layout.fillWidth: true - PlasmaComponents3.CheckBox { - id: announcementCheckbox - onToggled: () => { - announcementLabel.font.strikeout = (checkState == Qt.Checked) - } - } - - PlasmaComponents3.Label { - id: announcementLabel - text: `[${course}] ${title}` - font.bold: important - color: important ? PlasmaCore.Theme.negativeTextColor : PlasmaCore.Theme.textColor - elide: Text.ElideRight - Layout.fillWidth: true - - MouseArea { - anchors.fill: parent - onClicked: () => { - announcementCheckbox.toggle() // toggle checkbox - announcementCheckbox.toggled() // and trigger the onToggled effects - } - } - } - } - - RowLayout { - Layout.alignment: Qt.AlignRight - - PlasmaComponents3.ToolButton { - icon.name: "view-visible" - onClicked: () => { - Qt.openUrlExternally(url) - } - } - - PlasmaComponents3.ToolButton { - 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 - if (important) { - if (!importantAnnouncements.includes(announcementId)) { - importantAnnouncements.push(announcementId) - } - } else { - // remove announcementId from list - importantAnnouncements.splice(importantAnnouncements.indexOf(announcementId), 1) - } - // save config - plasmoid.configuration.importantAnnouncements = importantAnnouncements - } - } - - 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) - } - } - } -} 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") -- cgit v1.2.3