From da955d84beda72e26ce641375bd6fc4159a4c9fc Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 25 Oct 2017 14:00:43 +0200 Subject: Prepare logview for error merging. --- components/kube/contents/ui/LogView.qml | 21 +++++++----- framework/qml/Notifications.qml | 28 ++++++++++++++++ framework/qmldir | 1 + framework/src/sinkfabric.cpp | 7 ++-- tests/tst_logview.qml | 58 +++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 framework/qml/Notifications.qml create mode 100644 tests/tst_logview.qml diff --git a/components/kube/contents/ui/LogView.qml b/components/kube/contents/ui/LogView.qml index 4475e318..246e1a18 100644 --- a/components/kube/contents/ui/LogView.qml +++ b/components/kube/contents/ui/LogView.qml @@ -42,8 +42,11 @@ Controls.SplitView { Kube.Listener { filter: Kube.Messages.notification onMessageReceived: { - root.pendingError = true - logModel.insert(0, {message: message.message, details: message.details, timestamp: new Date(), resource: message.resource}); + if (message.type == Kube.Notifications.error) { + root.pendingError = true + } + var error = {timestamp: new Date(), message: message.message, details: message.details, resource: message.resource} + logModel.insert(0, {type: message.type, errors: [error]}) } } @@ -64,14 +67,15 @@ Controls.SplitView { model: ListModel { id: logModel + objectName: "logModel" } onCurrentItemChanged: { if (!!currentItem.currentData.resource) { - details.resourceId = currentItem.currentData.resource + details.resourceId = currentItem.currentData.errors.get(0).resource } - details.message = currentItem.currentData.message + "\n" + currentItem.currentData.details - details.timestamp = currentItem.currentData.timestamp + details.message = currentItem.currentData.message + "\n" + currentItem.currentData.errors.get(0).details + details.timestamp = currentItem.currentData.errors.get(0).timestamp } delegate: Kube.ListDelegate { border.color: Kube.Colors.buttonColor @@ -86,7 +90,7 @@ Controls.SplitView { } height: Kube.Units.gridUnit width: parent.width - Kube.Units.largeSpacing * 2 - text: qsTr("Error") + text: model.type == Kube.Notifications.error ? qsTr("Error") : qsTr("Info") } Kube.Label { @@ -102,8 +106,7 @@ Controls.SplitView { maximumLineCount: 1 elide: Text.ElideRight color: Kube.Colors.disabledTextColor - - text: model.message + text: model.errors.get(0).message } Kube.Label { @@ -113,7 +116,7 @@ Controls.SplitView { right: parent.right bottom: parent.bottom } - text: Qt.formatDateTime(model.timestamp, " hh:mm:ss dd MMM yyyy") + text: Qt.formatDateTime(model.errors.get(0).timestamp, " hh:mm:ss dd MMM yyyy") font.italic: true color: Kube.Colors.disabledTextColor font.pointSize: Kube.Units.smallFontSize diff --git a/framework/qml/Notifications.qml b/framework/qml/Notifications.qml new file mode 100644 index 00000000..df1190d3 --- /dev/null +++ b/framework/qml/Notifications.qml @@ -0,0 +1,28 @@ +/* + Copyright (C) 2017 Michael Bohlender, + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +pragma Singleton + +import QtQuick 2.7 + +Item { + property string error: "error" + property string info: "info" + property string progress: "progress" +} + diff --git a/framework/qmldir b/framework/qmldir index 90d1c762..12eeb43d 100644 --- a/framework/qmldir +++ b/framework/qmldir @@ -47,6 +47,7 @@ GridView 1.0 GridView.qml ScrollHelper 1.0 ScrollHelper.qml ModelIndexRetriever 1.0 ModelIndexRetriever.qml singleton Messages 1.0 Messages.qml +singleton Notifications 1.0 Notifications.qml singleton Colors 1.0 Colors.qml singleton Icons 1.0 Icons.qml singleton Units 1.0 Units.qml diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp index 9768fa96..cdaa9a90 100644 --- a/framework/src/sinkfabric.cpp +++ b/framework/src/sinkfabric.cpp @@ -151,7 +151,7 @@ public: SinkLog() << "Received notification: " << notification; QVariantMap message; if (notification.type == Sink::Notification::Warning) { - message["type"] = Notification::Warning; + message["type"] = "warning"; if (notification.code == Sink::ApplicationDomain::TransmissionError) { message["message"] = QObject::tr("Failed to send message."); } else { @@ -160,7 +160,7 @@ public: } else if (notification.type == Sink::Notification::Status) { return; } else if (notification.type == Sink::Notification::Error) { - message["type"] = Notification::Warning; + message["type"] = "error"; message["resource"] = QString{notification.resource}; message["details"] = notification.message; switch(notification.code) { @@ -188,12 +188,13 @@ public: Fabric::Fabric{}.postMessage("errorNotification", message); } else if (notification.type == Sink::Notification::Info) { if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { - message["type"] = Notification::Info; + message["type"] = "info"; message["message"] = QObject::tr("A message has been sent."); } else { return; } } else if (notification.type == Sink::Notification::Progress) { + message["type"] = "progress"; message["progress"] = notification.progress; message["total"] = notification.total; if (!notification.entities.isEmpty()) { diff --git a/tests/tst_logview.qml b/tests/tst_logview.qml new file mode 100644 index 00000000..48e21734 --- /dev/null +++ b/tests/tst_logview.qml @@ -0,0 +1,58 @@ +/* + * Copyright 2017 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.0 +import QtQuick.Window 2.1 +import QtTest 1.0 +import org.kube.framework 1.0 as Kube +import "../components/kube/contents/ui/" as Components + + +TestCase { + id: logviewTestcase + width: 400 + height: 400 + name: "LogView" + + Components.LogView { + id: logView + } + + function test_logview() { + var listModel = findChild(logView, "logModel"); + verify(listModel) + compare(listModel.count, 0) + //ignore progress + Kube.Fabric.postMessage(Kube.Messages.progressNotification, {}) + compare(listModel.count, 0) + + Kube.Fabric.postMessage(Kube.Messages.notification, {type: Kube.Notifications.info, message: "foobar", resource: "resource"}) + compare(listModel.count, 1) + compare(logView.pendingError, false) + + Kube.Fabric.postMessage(Kube.Messages.notification, {"type": Kube.Notifications.error, message: "foobar", resource: "resource"}) + compare(listModel.count, 2) + compare(logView.pendingError, true) + compare(listModel.get(0).type, Kube.Notifications.error) + compare(listModel.get(0).errors.count, 1) + compare(listModel.get(0).errors.get(0).message, "foobar") + compare(listModel.get(0).errors.get(0).resource, "resource") + } +} -- cgit v1.2.3