From cbbab71f5c1d3c32c590f8e4238fb03ddedd8406 Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Tue, 25 Jul 2023 10:01:42 +0200 Subject: [PATCH] feat(GODT-2786): Init bug report flow description file. --- .../bridge-gui/bridge-gui/QMLBackend.cpp | 77 +++++++++++++++++++ .../bridge-gui/bridge-gui/QMLBackend.h | 14 ++++ .../bridge-gui/bridge-gui/Resources.qrc | 3 +- .../qml/Resources/bug_report_flow.json | 72 +++++++++++++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp index 2690600d..35c47953 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp @@ -89,6 +89,7 @@ void QMLBackend::init(GRPCConfig const &serviceConfig) { this->setUseSSLForIMAP(sslForIMAP); this->setUseSSLForSMTP(sslForSMTP); this->retrieveUserList(); + this->retrieveBugReportFlow(); } @@ -210,6 +211,42 @@ bool QMLBackend::areSameFileOrFolder(QUrl const &lhs, QUrl const &rhs) const { } +//**************************************************************************************************************************************************** +/// \param[in] categoryId The id of the bug category. +/// \return Set of question for this category. +//**************************************************************************************************************************************************** +QVariantList QMLBackend::getQuestionSet(quint8 categoryId) const { + return questionsSet_[categoryId]; +}; + + +//**************************************************************************************************************************************************** +/// \param[in] questionId The id of the question. +/// \param[in] answer The answer to that question. +//**************************************************************************************************************************************************** +void QMLBackend::setQuestionAnswer(quint8 questionId, QString const &answer) { + this->answers_[questionId] = answer; +} + + +//**************************************************************************************************************************************************** +/// \param[in] categoryId The id of the question set. +/// \return concatenate answers for set of questions. +//**************************************************************************************************************************************************** +QString QMLBackend::collectAnswer(quint8 categoryId) const { + QString answers; + QVariantList sets = this->getQuestionSet(categoryId); + foreach(const QVariant& var, sets) { + answers += " - "; + answers += questions_[var.toInt()].toMap()["text"].toString(); + answers += " "; + answers += answers_[var.toInt()]; + answers += "\n\r"; + } + return answers; +} + + //**************************************************************************************************************************************************** /// \return The value for the 'showOnStartup' property. //**************************************************************************************************************************************************** @@ -581,6 +618,21 @@ QStringList QMLBackend::availableKeychain() const { } +//**************************************************************************************************************************************************** +/// \return The value for the 'bugCategories' property. +//**************************************************************************************************************************************************** +QStringList QMLBackend::bugCategories() const { + return categories_; +} + +//**************************************************************************************************************************************************** +/// \return The value for the 'bugQuestions' property. +//**************************************************************************************************************************************************** +QVariantList QMLBackend::bugQuestions() const { + return questions_; +} + + //**************************************************************************************************************************************************** /// \return The value for the 'currentKeychain' property. //**************************************************************************************************************************************************** @@ -1169,6 +1221,31 @@ void QMLBackend::retrieveUserList() { } +//**************************************************************************************************************************************************** +// +//**************************************************************************************************************************************************** +void QMLBackend::retrieveBugReportFlow() { + categories_.clear(); + questions_.clear(); + questionsSet_.clear(); + QString val; + QFile file; + file.setFileName(":qml/Resources/bug_report_flow.json"); + file.open(QIODevice::ReadOnly | QIODevice::Text); + val = file.readAll(); + file.close(); + QJsonDocument d = QJsonDocument::fromJson(val.toUtf8()); + QJsonObject root = d.object(); + QJsonObject data = root.value(QString("data_v1.0.0")).toObject(); + QJsonArray categoriesJson = data.value(QString("categories")).toArray(); + foreach (const QJsonValue & v, categoriesJson) { + categories_.append(v.toObject()["name"].toString()); + questionsSet_.append(v.toObject()["questions"].toArray().toVariantList()); + } + questions_ = data.value(QString("questions")).toArray().toVariantList(); +} + + //**************************************************************************************************************************************************** // //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h index 5fb05d64..119a30bc 100644 --- a/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h +++ b/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h @@ -57,6 +57,9 @@ public: // member functions. Q_INVOKABLE bool isPortFree(int port) const; ///< Check if a given network port is available. Q_INVOKABLE QString nativePath(QUrl const &url) const; ///< Retrieve the native path of a local URL. Q_INVOKABLE bool areSameFileOrFolder(QUrl const &lhs, QUrl const &rhs) const; ///< Check if two local URL point to the same file. + Q_INVOKABLE QVariantList getQuestionSet(quint8 categoryId) const; ///< Retrieve the set of question for a given bug category. + Q_INVOKABLE void setQuestionAnswer(quint8 questionId, QString const &answer); ///< Feed an answer for a given question. + Q_INVOKABLE QString collectAnswer(quint8 categoryId) const; ///< Collect answer for a given set of questions. public: // Qt/QML properties. Note that the NOTIFY-er signal is required even for read-only properties (QML warning otherwise) Q_PROPERTY(bool showOnStartup READ showOnStartup NOTIFY showOnStartupChanged) @@ -87,6 +90,8 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo Q_PROPERTY(QString currentEmailClient READ currentEmailClient NOTIFY currentEmailClientChanged) Q_PROPERTY(QStringList availableKeychain READ availableKeychain NOTIFY availableKeychainChanged) Q_PROPERTY(QString currentKeychain READ currentKeychain NOTIFY currentKeychainChanged) + Q_PROPERTY(QStringList bugCategories READ bugCategories NOTIFY bugCategoriesChanged) + Q_PROPERTY(QVariantList bugQuestions READ bugQuestions NOTIFY bugQuestionsChanged) Q_PROPERTY(UserList *users MEMBER users_ NOTIFY usersChanged) Q_PROPERTY(bool dockIconVisible READ dockIconVisible WRITE setDockIconVisible NOTIFY dockIconVisibleChanged) @@ -124,6 +129,8 @@ public: // Qt/QML properties. Note that the NOTIFY-er signal is required even fo QString currentEmailClient() const; ///< Getter for the 'currentEmail' property. QStringList availableKeychain() const; ///< Getter for the 'availableKeychain' property. QString currentKeychain() const; ///< Getter for the 'currentKeychain' property. + QStringList bugCategories() const; ///< Getter for the 'bugCategories' property. + QVariantList bugQuestions() const; ///< Getter for the 'bugQuestions' property. void setDockIconVisible(bool visible); ///< Setter for the 'dockIconVisible' property. bool dockIconVisible() const;; ///< Getter for the 'dockIconVisible' property. @@ -153,6 +160,8 @@ signals: // Signal used by the Qt property system. Many of them are unused but r void tagChanged(QString const &tag); /// badEventDisplayQueue_; ///< THe queue for displaying 'bad event feedback request dialog'. std::unique_ptr trayIcon_; ///< The tray icon for the application. + QStringList categories_; ///< The list of Bug Category parsed from the description file. + QVariantList questions_; ///< The list of Questions parsed from the description file. + QList questionsSet_; ///< Sets of questions per bug category. + QMap answers_; ///< Map of QuestionId/Answer for the bug form. friend class AppController; }; diff --git a/internal/frontend/bridge-gui/bridge-gui/Resources.qrc b/internal/frontend/bridge-gui/bridge-gui/Resources.qrc index a3d0ec7b..9b404a8c 100644 --- a/internal/frontend/bridge-gui/bridge-gui/Resources.qrc +++ b/internal/frontend/bridge-gui/bridge-gui/Resources.qrc @@ -100,6 +100,7 @@ qml/Proton/TextField.qml qml/Proton/Toggle.qml qml/QuestionItem.qml + qml/Resources/bug_report_flow.json qml/SettingsItem.qml qml/SettingsView.qml qml/SetupGuide.qml @@ -109,4 +110,4 @@ qml/Status.qml qml/WelcomeGuide.qml - \ No newline at end of file + diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json b/internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json new file mode 100644 index 00000000..109caa36 --- /dev/null +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Resources/bug_report_flow.json @@ -0,0 +1,72 @@ +{ + "metadata": { + "version": "1.0.0" + }, + "data_v1.0.0": { + "categories": [ + { + "id": 0, + "name": "I can't receive mail", + "questions": [0,1,2,3,4,5] + }, + { + "id": 1, + "name": "I can't send mail", + "questions": [0,1,2,3,4,5] + }, + { + "id": 2, + "name": "Bridge is not starting", + "questions": [0,1,2,3,4,5] + }, + { + "id": 3, + "name": "Bridge is slow", + "questions": [0,1,2,3,4,5] + }, + { + "id": 4, + "name": "None of the above", + "questions": [0,1,2,3,4,5] + } + ], + "questions": [ + { + "id": 0, + "text": "Expected behavior", + "tips": "What did you expect to happen?", + "type": 1 + }, + { + "id": 1, + "text": "Result", + "tips": "What happened instead?", + "type": 1 + }, + { + "id": 2, + "text": "Steps to reproduce", + "tips": "What were the step-by-step actions you took that led to this happening?", + "type": 1 + }, + { + "id": 3, + "text": "Can you reproduce your issue?", + "type": 2, + "answerList": ["yes", "no", "I don't know"] + }, + { + "id": 4, + "text": "Do you have such software running?", + "type": 3, + "answerList": ["VPN", "anti-virus", "firewall", "cache cleaner", "None of this"] + }, + { + "id": 5, + "text": "Do want to share something more?", + "tips": "Type here...", + "type": 1 + } + ] + } +} \ No newline at end of file