feat(GODT-2788): Add JSON validator file.

This commit is contained in:
Romain Le Jeune
2023-08-01 12:47:16 +00:00
parent ae4705ba70
commit 9b88778c43
4 changed files with 232 additions and 28 deletions

View File

@ -23,6 +23,9 @@ Item {
Checkbox
}
property string _typeOpen: "open"
property string _typeChoice: "choice"
property string _typeMutlichoice: "multichoice"
property var colorScheme
property var _bottomMargin: 20
property var _lineHeight: 1
@ -32,26 +35,26 @@ Item {
property string tips: ""
property string label: ""
property bool mandatory: false
property var type: QuestionItem.InputType.TextInput
property var type: root._typeOpen
property var answerList: ListModel{}
property int maxChar: 150
property string answer:{
if (type === QuestionItem.InputType.TextInput) {
if (type === root._typeOpen) {
return textInput.text
} else if (type === QuestionItem.InputType.Radio) {
} else if (type === root._typeChoice) {
return selectionRadio.text
} else if (type === QuestionItem.InputType.Checkbox) {
} else if (type === root._typeMutlichoice) {
return selectionCheckBox.text
}
return ""
}
property bool error: {
if (root.type === QuestionItem.InputType.TextInput)
if (root.type === root._typeOpen)
return textInput.error;
if (root.type === QuestionItem.InputType.Radio)
if (root.type === root._typeChoice)
return selectionRadio.error;
if (root.type === QuestionItem.InputType.Checkbox)
if (root.type === root._typeMutlichoice)
return selectionCheckBox.error;
return false
}
@ -64,11 +67,11 @@ Item {
function validate() {
if (root.type === QuestionItem.InputType.TextInput)
if (root.type === root._typeOpen)
textInput.validate()
else if (root.type === QuestionItem.InputType.Radio)
else if (root.type === root._typeChoice)
selectionRadio.validate()
else if (root.type === QuestionItem.InputType.Checkbox)
else if (root.type === root._typeMutlichoice)
selectionCheckBox.validate()
}
@ -91,7 +94,7 @@ Item {
id: textInput
Layout.fillWidth: true
Layout.fillHeight: true
Layout.minimumHeight: root.type === QuestionItem.InputType.TextInput ? heightForLinesVisible(2) : 0
Layout.minimumHeight: root.type === root._typeOpen ? heightForLinesVisible(2) : 0
colorScheme: root.colorScheme
property int _maxLength: root.maxChar
@ -102,7 +105,7 @@ Item {
placeholderText: mandatory ? qsTr("%1... (min. %2 characters)").arg(root.text).arg(_minLength) : ""
function setDefaultValue(defaultValue) {
textInput.text = root.type === QuestionItem.InputType.TextInput ? defaultValue : ""
textInput.text = root.type === root._typeOpen ? defaultValue : ""
}
validator: function (text) {
@ -121,7 +124,7 @@ Item {
}
}
visible: root.type === QuestionItem.InputType.TextInput
visible: root.type === root._typeOpen
}
ButtonGroup {
@ -133,7 +136,7 @@ Item {
property bool error: root.mandatory
function setDefaultValue(defaultValue) {
const values = root.type === QuestionItem.InputType.Radio ? defaultValue : [];
const values = root.type === root._typeChoice ? defaultValue : [];
for (var i = 0; i < buttons.length; ++i) {
buttons[i].checked = values.includes(buttons[i].text);
}
@ -157,7 +160,7 @@ Item {
ButtonGroup.group: selectionRadio
colorScheme: root.colorScheme
text: modelData
visible: root.type === QuestionItem.InputType.Radio
visible: root.type === root._typeChoice
}
}
ButtonGroup {
@ -176,7 +179,7 @@ Item {
property bool error: root.mandatory
function setDefaultValue(defaultValue) {
const values = root.type === QuestionItem.InputType.Checkbox ? defaultValue.split(delimitor) : [];
const values = root.type === root._typeMutlichoice ? defaultValue.split(delimitor) : [];
for (var i = 0; i < buttons.length; ++i) {
buttons[i].checked = values.includes(buttons[i].text);
}
@ -201,7 +204,7 @@ Item {
ButtonGroup.group: selectionCheckBox
colorScheme: root.colorScheme
text: modelData
visible: root.type === QuestionItem.InputType.Checkbox
visible: root.type === root._typeMutlichoice
}
}
}

View File

@ -5,27 +5,22 @@
"data_v1.0.0": {
"categories": [
{
"id": 0,
"name": "I can't receive mail",
"questions": [0,1,2,3,4]
},
{
"id": 1,
"name": "I can't send mail",
"questions": [0,1,2,3,4]
},
{
"id": 2,
"name": "Bridge is not starting",
"questions": [0,1,2,3]
},
{
"id": 3,
"name": "Bridge is slow",
"questions": [0,1,2,3]
},
{
"id": 4,
"name": "None of the above",
"questions": [0,1,2,3]
}
@ -35,7 +30,7 @@
"id": 0,
"text": "What happened?",
"tips": "Expected behavior",
"type": 1,
"type": "open",
"mandatory": true,
"maxChar": 400
},
@ -43,7 +38,7 @@
"id": 1,
"text": "What did you want or expect to happen?",
"tips": "Result",
"type": 1,
"type": "open",
"mandatory": true,
"maxChar": 400
},
@ -51,19 +46,19 @@
"id": 2,
"text": "What were the step-by-step actions you took that led to this happening?",
"tips": "Steps to reproduce",
"type": 1,
"type": "open",
"maxChar": 400
},
{
"id": 3,
"text": "Can you reproduce this issue? (If you repeat the actions, the same thing happens.)",
"type": 2,
"type": "choice",
"answerList": ["Yes", "No", "I don't know"]
},
{
"id": 4,
"text": "Can you list the software you are running?",
"type": 3,
"type": "multichoice",
"answerList": ["VPN", "Antivirus", "Firewall", "Cache cleaner"]
}
]