This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
powersync-app/nymea-app/ui/devicepages/NotificationsDevicePage.qml

150 lines
4.8 KiB
QML

import QtQuick 2.5
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
import Nymea 1.0
import "../components"
import "../customviews"
DevicePageBase {
id: root
property bool inputVisible: false
ColumnLayout {
anchors.fill: parent
Item {
Layout.fillWidth: true
Layout.preferredHeight: root.inputVisible ? inputColumn.implicitHeight : 0
Behavior on Layout.preferredHeight { NumberAnimation { duration: 130; easing.type: Easing.InOutQuad } }
ColumnLayout {
id: inputColumn
anchors { left: parent.left; bottom: parent.bottom; right: parent.right }
TextField {
id: titleTextField
Layout.fillWidth: true
Layout.topMargin: app.margins
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins
placeholderText: qsTr("Title")
}
TextArea {
id: bodyTextField
Layout.fillWidth: true
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins
placeholderText: qsTr("Text")
wrapMode: Text.WordWrap
}
}
}
Button {
Layout.fillWidth: true
Layout.margins: app.margins
text: !root.inputVisible ?
qsTr("Send a notification")
: titleTextField.displayText.length > 0 ?
qsTr("Send now")
: qsTr("Cancel")
onClicked: {
if (root.inputVisible && titleTextField.displayText.length > 0) {
var actionType = root.deviceClass.actionTypes.findByName("notify")
var params = []
var titleParam = {}
titleParam["paramTypeId"] = actionType.paramTypes.findByName("title").id
titleParam["value"] = titleTextField.displayText
params.push(titleParam)
var bodyParam = {}
bodyParam["paramTypeId"] = actionType.paramTypes.findByName("body").id
bodyParam["value"] = bodyTextField.text
params.push(bodyParam)
Engine.deviceManager.executeAction(root.device.id, actionType.id, params)
}
root.inputVisible = !root.inputVisible
}
}
ThinDivider {}
GenericTypeLogView {
Layout.fillHeight: true
Layout.fillWidth: true
text: qsTr("%1 notifications sent to this device in the last 24 hours.")
logsModel: LogsModel {
deviceId: root.device.id
live: true
Component.onCompleted: update()
typeIds: [root.deviceClass.actionTypes.findByName("notify").id];
}
delegate: MeaListItemDelegate {
width: parent.width
iconName: "../images/notification.svg"
text: model.value.trim()
subText: Qt.formatDateTime(model.timestamp)
progressive: false
onClicked: {
print("a", model.value.trim())
var parts = model.value.trim().split(', ')
print("b", parts)
var popup = detailsPopup.createObject(root, {timestamp: model.timestamp, notificationTitle: parts[1], notificationBody: parts[0]});
popup.open();
}
}
}
}
Component {
id: detailsPopup
MeaDialog {
id: detailsDialog
property string timestamp
property string notificationTitle
property string notificationBody
title: qsTr("Notification details")
Label {
Layout.fillWidth: true
text: qsTr("Date sent")
font.bold: true
}
Label {
Layout.fillWidth: true
text: Qt.formatDateTime(detailsDialog.timestamp)
}
Label {
Layout.topMargin: app.margins
Layout.fillWidth: true
text: qsTr("Title")
font.bold: true
}
Label {
Layout.fillWidth: true
text: detailsDialog.notificationTitle
wrapMode: Text.WordWrap
}
Label {
Layout.topMargin: app.margins
Layout.fillWidth: true
text: qsTr("Text")
font.bold: true
}
Label {
Layout.fillWidth: true
text: detailsDialog.notificationBody
wrapMode: Text.WordWrap
}
}
}
}