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
property var categories: ["category 1", "category 2"]
property var categories: Backend.bugCategories
Label {
Layout.fillWidth: true

View File

@ -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)) {
function setCategoryId(catId) {
root.categoryId = catId;
}
function submit() {
root.questionAnswered();
}
else
{
++stackLayout.currentIndex
root.setDefaultValue();
}
}
function previous() {
if (stackLayout.currentIndex === 0) {
root.resume()
}
else {
--stackLayout.currentIndex
root.setDefaultValue();
}
}
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();
}
}
}

View File

@ -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();

View File

@ -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 {

View File

@ -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
}
]
}