From 1a2783a63b8967f90d7d4420294f2085a48385ba Mon Sep 17 00:00:00 2001 From: Romain LE JEUNE Date: Tue, 25 Jul 2023 16:33:33 +0200 Subject: [PATCH] feat(GODT-2821): Display questions in one page. --- .../bridge-gui/qml/BugCategoryView.qml | 2 +- .../bridge-gui/qml/BugQuestionView.qml | 86 +++++-------------- .../bridge-gui/qml/BugReportFlow.qml | 35 ++++---- .../bridge-gui/qml/QuestionItem.qml | 54 ++++-------- .../qml/Resources/bug_report_flow.json | 28 +++--- 5 files changed, 70 insertions(+), 135 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml index 343aaea1..e4e1451d 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugCategoryView.qml @@ -22,7 +22,7 @@ SettingsView { fillHeight: true - property var categories: ["category 1", "category 2"] + property var categories: Backend.bugCategories Label { Layout.fillWidth: true diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml index 3a18f03b..cc76bd75 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugQuestionView.qml @@ -18,38 +18,27 @@ import Proton SettingsView { id: root - signal resume + property var questions:Backend.bugQuestions + property var categoryId:0 + property var questionSet:ListModel{} + signal questionAnswered function setDefaultValue() { } - function next() { - - if (stackLayout.currentIndex >=(stackLayout.count - 1)) { - root.questionAnswered(); - } - else - { - ++stackLayout.currentIndex - root.setDefaultValue(); - } + function setCategoryId(catId) { + root.categoryId = catId; } - - function previous() { - if (stackLayout.currentIndex === 0) { - root.resume() - } - else { - --stackLayout.currentIndex - root.setDefaultValue(); - } + function submit() { + root.questionAnswered(); } fillHeight: true - onBack: { - root.previous(); + onCategoryIdChanged: { + root.questionSet = Backend.getQuestionSet(root.categoryId) + root.setDefaultValue(); } onVisibleChanged: { @@ -63,48 +52,22 @@ SettingsView { type: Label.Heading } - Label { - Layout.fillWidth: true - colorScheme: root.colorScheme - text: qsTr("Step " + (stackLayout.currentIndex + 1) + " of " + stackLayout.count ) - type: Label.Caption - } - - StackLayout { - id: stackLayout - QuestionItem { - Layout.fillWidth: true - colorScheme: root.colorScheme - - text: "question 1" - type: QuestionItem.InputType.TextInput - mandatory: true - tips: "" - errorString: "please answer the question" - } + Repeater { + model: root.questionSet QuestionItem { Layout.fillWidth: true + + implicitWidth: parent.implicitWidth + colorScheme: root.colorScheme + showSeparator: index < (root.questionSet.length - 1) - text: "question 2" - type: QuestionItem.InputType.Radio - mandatory: true - answerList: ["answer A", "answer B", "answer C","answer D"] - tips: "" - errorString: "please answer the question" - } - - QuestionItem { - Layout.fillWidth: true - colorScheme: root.colorScheme - - text: "question 3" - type: QuestionItem.InputType.Checkbox - mandatory: true - answerList: ["answer 1", "answer 2", "answer 3","answer 4"] - tips: "" - errorString: "please answer the question" + text: root.questions[modelData].text + tips: root.questions[modelData].tips ? root.questions[modelData].tips : "" + label: root.questions[modelData].label ? root.questions[modelData].label : "" + type: root.questions[modelData].type + answerList: root.questions[modelData].answerList ? root.questions[modelData].answerList : [] } } // fill height so the footer label will always be attached to the bottom @@ -118,10 +81,7 @@ SettingsView { text: qsTr("Continue") onClicked: { - if (stackLayout.children[stackLayout.currentIndex].validate()) { - next(); - } - + submit(); } } } \ No newline at end of file diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml b/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml index 21f0b911..57207055 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/BugReportFlow.qml @@ -27,6 +27,21 @@ Item { signal back signal bugReportWasSent + onVisibleChanged: { + root.showBugCategory(); + } + + function showBugCategory() { + bugReportFlow.currentIndex = 0; + } + function showBugQuestion() { + bugReportFlow.currentIndex = 1; + bugQuestion.setCategoryId(root.categoryId); + } + function showBugReport() { + bugReportFlow.currentIndex = 2; + } + Rectangle { anchors.fill: parent @@ -37,16 +52,6 @@ Item { StackLayout { id: bugReportFlow - function showBugCategory() { - bugReportFlow.currentIndex = 0; - } - function showBugQuestion() { - bugReportFlow.currentIndex = 1; - } - function showBugReport() { - bugReportFlow.currentIndex = 2; - } - anchors.fill: parent BugCategoryView { @@ -61,7 +66,7 @@ Item { } onCategorySelected: function(categoryId){ root.categoryId = categoryId - bugReportFlow.showBugQuestion(); + root.showBugQuestion(); } } BugQuestionView { @@ -71,11 +76,11 @@ Item { path: root.titles currPath: 1 - onResume: { - bugReportFlow.showBugCategory(); + onBack: { + root.showBugCategory(); } onQuestionAnswered: { - bugReportFlow.showBugReport(); + root.showBugReport(); } } BugReportView { @@ -87,7 +92,7 @@ Item { currPath: 2 onBack: { - bugReportFlow.showBugQuestion(); + root.showBugQuestion(); } onBugReportWasSent: { root.bugReportWasSent(); diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/QuestionItem.qml b/internal/frontend/bridge-gui/bridge-gui/qml/QuestionItem.qml index 712284f9..92a7d114 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/QuestionItem.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/QuestionItem.qml @@ -24,13 +24,16 @@ Item { } property var colorScheme + property var _bottomMargin: 20 + property var _lineHeight: 1 + property bool showSeparator: true + property string text: "" property string tips: "" - property string errorString: "" - property bool error: false + property string label: "" property var type: QuestionItem.InputType.TextInput - property bool mandatory: true property var answerList: ListModel{} + property string answer:{ if (type === QuestionItem.InputType.TextInput) { return textInput.text @@ -42,18 +45,6 @@ Item { return "" } - function validate() { - if (type === QuestionItem.InputType.TextInput) { - textInput.validate() - root.error = textInput.error - } else if (type === QuestionItem.InputType.Radio) { - selectionRadio.validate() - } else if (type === QuestionItem.InputType.Checkbox) { - selectionCheckBox.validate() - } - return !root.error - } - implicitHeight: children[0].implicitHeight + children[0].anchors.topMargin + children[0].anchors.bottomMargin ColumnLayout { @@ -68,6 +59,7 @@ Item { } ColumnLayout { spacing: 16 + Layout.bottomMargin: root._bottomMargin TextArea { id: textInput Layout.fillWidth: true @@ -75,16 +67,9 @@ Item { Layout.minimumHeight: root.type === QuestionItem.InputType.TextInput ? heightForLinesVisible(2) : 0 colorScheme: root.colorScheme - label: qsTr("Your answer") + label: qsTr(root.label) placeholderText: qsTr(root.tips) - validator: function (str) { - if (root.mandatory && str.length === 0) { - return root.errorStr; - } - return; - } - visible: root.type === QuestionItem.InputType.TextInput } @@ -93,10 +78,6 @@ Item { property string text: { return checkedButton ? checkedButton.text : ""; } - - function validate() { - root.error = false - } } Repeater { model: root.answerList @@ -120,10 +101,6 @@ Item { } return str; } - - function validate() { - root.error = false - } } Repeater { model: root.answerList @@ -137,14 +114,13 @@ Item { } } } - Label { - id: errorText - Layout.fillWidth: true - visible: root.error - color: root.colorScheme.signal_danger - colorScheme: root.colorScheme - text: root.errorString - type: Label.LabelType.Caption_semibold + Rectangle { + anchors.bottom: root.bottom + anchors.left: root.left + anchors.right: root.right + color: colorScheme.border_weak + height: root._lineHeight + visible: root.showSeparator } // fill height so the footer label will always be attached to the bottom Item { 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 index 109caa36..7d9820eb 100644 --- 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 @@ -7,46 +7,46 @@ { "id": 0, "name": "I can't receive mail", - "questions": [0,1,2,3,4,5] + "questions": [0,1,2,3,4] }, { "id": 1, "name": "I can't send mail", - "questions": [0,1,2,3,4,5] + "questions": [0,1,2,3,4] }, { "id": 2, "name": "Bridge is not starting", - "questions": [0,1,2,3,4,5] + "questions": [0,1,2,3] }, { "id": 3, "name": "Bridge is slow", - "questions": [0,1,2,3,4,5] + "questions": [0,1,2,3] }, { "id": 4, "name": "None of the above", - "questions": [0,1,2,3,4,5] + "questions": [0,1,2,3] } ], "questions": [ { "id": 0, - "text": "Expected behavior", - "tips": "What did you expect to happen?", + "text": "What did you expect to happen?", + "tips": "Expected behavior", "type": 1 }, { "id": 1, - "text": "Result", - "tips": "What happened instead?", + "text": "What happened instead?", + "tips": "Result", "type": 1 }, { "id": 2, - "text": "Steps to reproduce", - "tips": "What were the step-by-step actions you took that led to this happening?", + "text": "What were the step-by-step actions you took that led to this happening?", + "tips": "Steps to reproduce", "type": 1 }, { @@ -60,12 +60,6 @@ "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 } ] }