summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-25 14:00:43 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-10-25 14:00:43 +0200
commitda955d84beda72e26ce641375bd6fc4159a4c9fc (patch)
tree9ced7c7fc2d1404a45728ea8fc64a14590fdb9d3
parent65d7fe39ccb3ae011f63ab6abbdcec5ee0c71055 (diff)
downloadkube-da955d84beda72e26ce641375bd6fc4159a4c9fc.tar.gz
kube-da955d84beda72e26ce641375bd6fc4159a4c9fc.zip
Prepare logview for error merging.
-rw-r--r--components/kube/contents/ui/LogView.qml21
-rw-r--r--framework/qml/Notifications.qml28
-rw-r--r--framework/qmldir1
-rw-r--r--framework/src/sinkfabric.cpp7
-rw-r--r--tests/tst_logview.qml58
5 files changed, 103 insertions, 12 deletions
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 {
42 Kube.Listener { 42 Kube.Listener {
43 filter: Kube.Messages.notification 43 filter: Kube.Messages.notification
44 onMessageReceived: { 44 onMessageReceived: {
45 root.pendingError = true 45 if (message.type == Kube.Notifications.error) {
46 logModel.insert(0, {message: message.message, details: message.details, timestamp: new Date(), resource: message.resource}); 46 root.pendingError = true
47 }
48 var error = {timestamp: new Date(), message: message.message, details: message.details, resource: message.resource}
49 logModel.insert(0, {type: message.type, errors: [error]})
47 } 50 }
48 } 51 }
49 52
@@ -64,14 +67,15 @@ Controls.SplitView {
64 67
65 model: ListModel { 68 model: ListModel {
66 id: logModel 69 id: logModel
70 objectName: "logModel"
67 } 71 }
68 72
69 onCurrentItemChanged: { 73 onCurrentItemChanged: {
70 if (!!currentItem.currentData.resource) { 74 if (!!currentItem.currentData.resource) {
71 details.resourceId = currentItem.currentData.resource 75 details.resourceId = currentItem.currentData.errors.get(0).resource
72 } 76 }
73 details.message = currentItem.currentData.message + "\n" + currentItem.currentData.details 77 details.message = currentItem.currentData.message + "\n" + currentItem.currentData.errors.get(0).details
74 details.timestamp = currentItem.currentData.timestamp 78 details.timestamp = currentItem.currentData.errors.get(0).timestamp
75 } 79 }
76 delegate: Kube.ListDelegate { 80 delegate: Kube.ListDelegate {
77 border.color: Kube.Colors.buttonColor 81 border.color: Kube.Colors.buttonColor
@@ -86,7 +90,7 @@ Controls.SplitView {
86 } 90 }
87 height: Kube.Units.gridUnit 91 height: Kube.Units.gridUnit
88 width: parent.width - Kube.Units.largeSpacing * 2 92 width: parent.width - Kube.Units.largeSpacing * 2
89 text: qsTr("Error") 93 text: model.type == Kube.Notifications.error ? qsTr("Error") : qsTr("Info")
90 } 94 }
91 95
92 Kube.Label { 96 Kube.Label {
@@ -102,8 +106,7 @@ Controls.SplitView {
102 maximumLineCount: 1 106 maximumLineCount: 1
103 elide: Text.ElideRight 107 elide: Text.ElideRight
104 color: Kube.Colors.disabledTextColor 108 color: Kube.Colors.disabledTextColor
105 109 text: model.errors.get(0).message
106 text: model.message
107 } 110 }
108 111
109 Kube.Label { 112 Kube.Label {
@@ -113,7 +116,7 @@ Controls.SplitView {
113 right: parent.right 116 right: parent.right
114 bottom: parent.bottom 117 bottom: parent.bottom
115 } 118 }
116 text: Qt.formatDateTime(model.timestamp, " hh:mm:ss dd MMM yyyy") 119 text: Qt.formatDateTime(model.errors.get(0).timestamp, " hh:mm:ss dd MMM yyyy")
117 font.italic: true 120 font.italic: true
118 color: Kube.Colors.disabledTextColor 121 color: Kube.Colors.disabledTextColor
119 font.pointSize: Kube.Units.smallFontSize 122 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 @@
1/*
2 Copyright (C) 2017 Michael Bohlender, <bohlender@kolabsys.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19pragma Singleton
20
21import QtQuick 2.7
22
23Item {
24 property string error: "error"
25 property string info: "info"
26 property string progress: "progress"
27}
28
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
47ScrollHelper 1.0 ScrollHelper.qml 47ScrollHelper 1.0 ScrollHelper.qml
48ModelIndexRetriever 1.0 ModelIndexRetriever.qml 48ModelIndexRetriever 1.0 ModelIndexRetriever.qml
49singleton Messages 1.0 Messages.qml 49singleton Messages 1.0 Messages.qml
50singleton Notifications 1.0 Notifications.qml
50singleton Colors 1.0 Colors.qml 51singleton Colors 1.0 Colors.qml
51singleton Icons 1.0 Icons.qml 52singleton Icons 1.0 Icons.qml
52singleton Units 1.0 Units.qml 53singleton 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:
151 SinkLog() << "Received notification: " << notification; 151 SinkLog() << "Received notification: " << notification;
152 QVariantMap message; 152 QVariantMap message;
153 if (notification.type == Sink::Notification::Warning) { 153 if (notification.type == Sink::Notification::Warning) {
154 message["type"] = Notification::Warning; 154 message["type"] = "warning";
155 if (notification.code == Sink::ApplicationDomain::TransmissionError) { 155 if (notification.code == Sink::ApplicationDomain::TransmissionError) {
156 message["message"] = QObject::tr("Failed to send message."); 156 message["message"] = QObject::tr("Failed to send message.");
157 } else { 157 } else {
@@ -160,7 +160,7 @@ public:
160 } else if (notification.type == Sink::Notification::Status) { 160 } else if (notification.type == Sink::Notification::Status) {
161 return; 161 return;
162 } else if (notification.type == Sink::Notification::Error) { 162 } else if (notification.type == Sink::Notification::Error) {
163 message["type"] = Notification::Warning; 163 message["type"] = "error";
164 message["resource"] = QString{notification.resource}; 164 message["resource"] = QString{notification.resource};
165 message["details"] = notification.message; 165 message["details"] = notification.message;
166 switch(notification.code) { 166 switch(notification.code) {
@@ -188,12 +188,13 @@ public:
188 Fabric::Fabric{}.postMessage("errorNotification", message); 188 Fabric::Fabric{}.postMessage("errorNotification", message);
189 } else if (notification.type == Sink::Notification::Info) { 189 } else if (notification.type == Sink::Notification::Info) {
190 if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { 190 if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) {
191 message["type"] = Notification::Info; 191 message["type"] = "info";
192 message["message"] = QObject::tr("A message has been sent."); 192 message["message"] = QObject::tr("A message has been sent.");
193 } else { 193 } else {
194 return; 194 return;
195 } 195 }
196 } else if (notification.type == Sink::Notification::Progress) { 196 } else if (notification.type == Sink::Notification::Progress) {
197 message["type"] = "progress";
197 message["progress"] = notification.progress; 198 message["progress"] = notification.progress;
198 message["total"] = notification.total; 199 message["total"] = notification.total;
199 if (!notification.entities.isEmpty()) { 200 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 @@
1/*
2 * Copyright 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick 2.7
21import QtQuick.Controls 2.0
22import QtQuick.Window 2.1
23import QtTest 1.0
24import org.kube.framework 1.0 as Kube
25import "../components/kube/contents/ui/" as Components
26
27
28TestCase {
29 id: logviewTestcase
30 width: 400
31 height: 400
32 name: "LogView"
33
34 Components.LogView {
35 id: logView
36 }
37
38 function test_logview() {
39 var listModel = findChild(logView, "logModel");
40 verify(listModel)
41 compare(listModel.count, 0)
42 //ignore progress
43 Kube.Fabric.postMessage(Kube.Messages.progressNotification, {})
44 compare(listModel.count, 0)
45
46 Kube.Fabric.postMessage(Kube.Messages.notification, {type: Kube.Notifications.info, message: "foobar", resource: "resource"})
47 compare(listModel.count, 1)
48 compare(logView.pendingError, false)
49
50 Kube.Fabric.postMessage(Kube.Messages.notification, {"type": Kube.Notifications.error, message: "foobar", resource: "resource"})
51 compare(listModel.count, 2)
52 compare(logView.pendingError, true)
53 compare(listModel.get(0).type, Kube.Notifications.error)
54 compare(listModel.get(0).errors.count, 1)
55 compare(listModel.get(0).errors.get(0).message, "foobar")
56 compare(listModel.get(0).errors.get(0).resource, "resource")
57 }
58}