feat(GODT-2821): Display questions in one page.

This commit is contained in:
Romain LE JEUNE
2023-07-25 16:33:33 +02:00
committed by Romain Le Jeune
parent cbbab71f5c
commit 1a2783a63b
5 changed files with 70 additions and 135 deletions

View File

@ -22,7 +22,7 @@ SettingsView {
fillHeight: true fillHeight: true
property var categories: ["category 1", "category 2"] property var categories: Backend.bugCategories
Label { Label {
Layout.fillWidth: true Layout.fillWidth: true

View File

@ -18,38 +18,27 @@ import Proton
SettingsView { SettingsView {
id: root id: root
signal resume property var questions:Backend.bugQuestions
property var categoryId:0
property var questionSet:ListModel{}
signal questionAnswered signal questionAnswered
function setDefaultValue() { function setDefaultValue() {
} }
function next() { function setCategoryId(catId) {
root.categoryId = catId;
if (stackLayout.currentIndex >=(stackLayout.count - 1)) { }
function submit() {
root.questionAnswered(); root.questionAnswered();
} }
else
{
++stackLayout.currentIndex
root.setDefaultValue();
}
}
function previous() {
if (stackLayout.currentIndex === 0) {
root.resume()
}
else {
--stackLayout.currentIndex
root.setDefaultValue();
}
}
fillHeight: true fillHeight: true
onBack: { onCategoryIdChanged: {
root.previous(); root.questionSet = Backend.getQuestionSet(root.categoryId)
root.setDefaultValue();
} }
onVisibleChanged: { onVisibleChanged: {
@ -63,48 +52,22 @@ SettingsView {
type: Label.Heading type: Label.Heading
} }
Label { Repeater {
Layout.fillWidth: true model: root.questionSet
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"
}
QuestionItem { QuestionItem {
Layout.fillWidth: true Layout.fillWidth: true
implicitWidth: parent.implicitWidth
colorScheme: root.colorScheme colorScheme: root.colorScheme
showSeparator: index < (root.questionSet.length - 1)
text: "question 2" text: root.questions[modelData].text
type: QuestionItem.InputType.Radio tips: root.questions[modelData].tips ? root.questions[modelData].tips : ""
mandatory: true label: root.questions[modelData].label ? root.questions[modelData].label : ""
answerList: ["answer A", "answer B", "answer C","answer D"] type: root.questions[modelData].type
tips: "" answerList: root.questions[modelData].answerList ? root.questions[modelData].answerList : []
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"
} }
} }
// fill height so the footer label will always be attached to the bottom // fill height so the footer label will always be attached to the bottom
@ -118,10 +81,7 @@ SettingsView {
text: qsTr("Continue") text: qsTr("Continue")
onClicked: { onClicked: {
if (stackLayout.children[stackLayout.currentIndex].validate()) { submit();
next();
}
} }
} }
} }

View File

@ -27,6 +27,21 @@ Item {
signal back signal back
signal bugReportWasSent 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 { Rectangle {
anchors.fill: parent anchors.fill: parent
@ -37,16 +52,6 @@ Item {
StackLayout { StackLayout {
id: bugReportFlow id: bugReportFlow
function showBugCategory() {
bugReportFlow.currentIndex = 0;
}
function showBugQuestion() {
bugReportFlow.currentIndex = 1;
}
function showBugReport() {
bugReportFlow.currentIndex = 2;
}
anchors.fill: parent anchors.fill: parent
BugCategoryView { BugCategoryView {
@ -61,7 +66,7 @@ Item {
} }
onCategorySelected: function(categoryId){ onCategorySelected: function(categoryId){
root.categoryId = categoryId root.categoryId = categoryId
bugReportFlow.showBugQuestion(); root.showBugQuestion();
} }
} }
BugQuestionView { BugQuestionView {
@ -71,11 +76,11 @@ Item {
path: root.titles path: root.titles
currPath: 1 currPath: 1
onResume: { onBack: {
bugReportFlow.showBugCategory(); root.showBugCategory();
} }
onQuestionAnswered: { onQuestionAnswered: {
bugReportFlow.showBugReport(); root.showBugReport();
} }
} }
BugReportView { BugReportView {
@ -87,7 +92,7 @@ Item {
currPath: 2 currPath: 2
onBack: { onBack: {
bugReportFlow.showBugQuestion(); root.showBugQuestion();
} }
onBugReportWasSent: { onBugReportWasSent: {
root.bugReportWasSent(); root.bugReportWasSent();

View File

@ -24,13 +24,16 @@ Item {
} }
property var colorScheme property var colorScheme
property var _bottomMargin: 20
property var _lineHeight: 1
property bool showSeparator: true
property string text: "" property string text: ""
property string tips: "" property string tips: ""
property string errorString: "" property string label: ""
property bool error: false
property var type: QuestionItem.InputType.TextInput property var type: QuestionItem.InputType.TextInput
property bool mandatory: true
property var answerList: ListModel{} property var answerList: ListModel{}
property string answer:{ property string answer:{
if (type === QuestionItem.InputType.TextInput) { if (type === QuestionItem.InputType.TextInput) {
return textInput.text return textInput.text
@ -42,18 +45,6 @@ Item {
return "" 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 implicitHeight: children[0].implicitHeight + children[0].anchors.topMargin + children[0].anchors.bottomMargin
ColumnLayout { ColumnLayout {
@ -68,6 +59,7 @@ Item {
} }
ColumnLayout { ColumnLayout {
spacing: 16 spacing: 16
Layout.bottomMargin: root._bottomMargin
TextArea { TextArea {
id: textInput id: textInput
Layout.fillWidth: true Layout.fillWidth: true
@ -75,16 +67,9 @@ Item {
Layout.minimumHeight: root.type === QuestionItem.InputType.TextInput ? heightForLinesVisible(2) : 0 Layout.minimumHeight: root.type === QuestionItem.InputType.TextInput ? heightForLinesVisible(2) : 0
colorScheme: root.colorScheme colorScheme: root.colorScheme
label: qsTr("Your answer") label: qsTr(root.label)
placeholderText: qsTr(root.tips) placeholderText: qsTr(root.tips)
validator: function (str) {
if (root.mandatory && str.length === 0) {
return root.errorStr;
}
return;
}
visible: root.type === QuestionItem.InputType.TextInput visible: root.type === QuestionItem.InputType.TextInput
} }
@ -93,10 +78,6 @@ Item {
property string text: { property string text: {
return checkedButton ? checkedButton.text : ""; return checkedButton ? checkedButton.text : "";
} }
function validate() {
root.error = false
}
} }
Repeater { Repeater {
model: root.answerList model: root.answerList
@ -120,10 +101,6 @@ Item {
} }
return str; return str;
} }
function validate() {
root.error = false
}
} }
Repeater { Repeater {
model: root.answerList model: root.answerList
@ -137,14 +114,13 @@ Item {
} }
} }
} }
Label { Rectangle {
id: errorText anchors.bottom: root.bottom
Layout.fillWidth: true anchors.left: root.left
visible: root.error anchors.right: root.right
color: root.colorScheme.signal_danger color: colorScheme.border_weak
colorScheme: root.colorScheme height: root._lineHeight
text: root.errorString visible: root.showSeparator
type: Label.LabelType.Caption_semibold
} }
// fill height so the footer label will always be attached to the bottom // fill height so the footer label will always be attached to the bottom
Item { Item {

View File

@ -7,46 +7,46 @@
{ {
"id": 0, "id": 0,
"name": "I can't receive mail", "name": "I can't receive mail",
"questions": [0,1,2,3,4,5] "questions": [0,1,2,3,4]
}, },
{ {
"id": 1, "id": 1,
"name": "I can't send mail", "name": "I can't send mail",
"questions": [0,1,2,3,4,5] "questions": [0,1,2,3,4]
}, },
{ {
"id": 2, "id": 2,
"name": "Bridge is not starting", "name": "Bridge is not starting",
"questions": [0,1,2,3,4,5] "questions": [0,1,2,3]
}, },
{ {
"id": 3, "id": 3,
"name": "Bridge is slow", "name": "Bridge is slow",
"questions": [0,1,2,3,4,5] "questions": [0,1,2,3]
}, },
{ {
"id": 4, "id": 4,
"name": "None of the above", "name": "None of the above",
"questions": [0,1,2,3,4,5] "questions": [0,1,2,3]
} }
], ],
"questions": [ "questions": [
{ {
"id": 0, "id": 0,
"text": "Expected behavior", "text": "What did you expect to happen?",
"tips": "What did you expect to happen?", "tips": "Expected behavior",
"type": 1 "type": 1
}, },
{ {
"id": 1, "id": 1,
"text": "Result", "text": "What happened instead?",
"tips": "What happened instead?", "tips": "Result",
"type": 1 "type": 1
}, },
{ {
"id": 2, "id": 2,
"text": "Steps to reproduce", "text": "What were the step-by-step actions you took that led to this happening?",
"tips": "What were the step-by-step actions you took that led to this happening?", "tips": "Steps to reproduce",
"type": 1 "type": 1
}, },
{ {
@ -60,12 +60,6 @@
"text": "Do you have such software running?", "text": "Do you have such software running?",
"type": 3, "type": 3,
"answerList": ["VPN", "anti-virus", "firewall", "cache cleaner", "None of this"] "answerList": ["VPN", "anti-virus", "firewall", "cache cleaner", "None of this"]
},
{
"id": 5,
"text": "Do want to share something more?",
"tips": "Type here...",
"type": 1
} }
] ]
} }