diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-25 14:00:43 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-25 14:00:43 +0200 |
commit | da955d84beda72e26ce641375bd6fc4159a4c9fc (patch) | |
tree | 9ced7c7fc2d1404a45728ea8fc64a14590fdb9d3 | |
parent | 65d7fe39ccb3ae011f63ab6abbdcec5ee0c71055 (diff) | |
download | kube-da955d84beda72e26ce641375bd6fc4159a4c9fc.tar.gz kube-da955d84beda72e26ce641375bd6fc4159a4c9fc.zip |
Prepare logview for error merging.
-rw-r--r-- | components/kube/contents/ui/LogView.qml | 21 | ||||
-rw-r--r-- | framework/qml/Notifications.qml | 28 | ||||
-rw-r--r-- | framework/qmldir | 1 | ||||
-rw-r--r-- | framework/src/sinkfabric.cpp | 7 | ||||
-rw-r--r-- | tests/tst_logview.qml | 58 |
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 | |||
19 | pragma Singleton | ||
20 | |||
21 | import QtQuick 2.7 | ||
22 | |||
23 | Item { | ||
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 | |||
47 | ScrollHelper 1.0 ScrollHelper.qml | 47 | ScrollHelper 1.0 ScrollHelper.qml |
48 | ModelIndexRetriever 1.0 ModelIndexRetriever.qml | 48 | ModelIndexRetriever 1.0 ModelIndexRetriever.qml |
49 | singleton Messages 1.0 Messages.qml | 49 | singleton Messages 1.0 Messages.qml |
50 | singleton Notifications 1.0 Notifications.qml | ||
50 | singleton Colors 1.0 Colors.qml | 51 | singleton Colors 1.0 Colors.qml |
51 | singleton Icons 1.0 Icons.qml | 52 | singleton Icons 1.0 Icons.qml |
52 | singleton Units 1.0 Units.qml | 53 | 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: | |||
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 | |||
20 | import QtQuick 2.7 | ||
21 | import QtQuick.Controls 2.0 | ||
22 | import QtQuick.Window 2.1 | ||
23 | import QtTest 1.0 | ||
24 | import org.kube.framework 1.0 as Kube | ||
25 | import "../components/kube/contents/ui/" as Components | ||
26 | |||
27 | |||
28 | TestCase { | ||
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 | } | ||