Skip to content

Commit

Permalink
[ML4SE-591] Added checkbox type, fixed borders in html. Deleted index…
Browse files Browse the repository at this point in the history
… from the database for survey table
  • Loading branch information
mikrise2 committed Apr 5, 2024
1 parent 7b72f18 commit 2baff3a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.serialization.Transient
* Radio button id and value
*/
@Serializable
data class RadioInfo(val id: String, val value: String)
data class ValueInfo(val id: String, val value: String)

/**
* This is a class that constructs an input field of a specified type in HTML.
Expand Down Expand Up @@ -102,7 +102,7 @@ data class RadioHtmlQuestion(
* **ElementId** here is radio button **name**!!!.
*/
override val elementId: String,
@SerialName("info") val infos: List<RadioInfo>
@SerialName("info") val infos: List<ValueInfo>
) : HtmlQuestion() {
override fun toHtml(): String = buildString {
append(htmlText())
Expand All @@ -114,6 +114,26 @@ data class RadioHtmlQuestion(
}
}

@Serializable
@SerialName("Checkbox")
data class CheckboxHtmlQuestion(
override val text: String,
/**
* **ElementId** here is checkbox button **name**!!!.
*/
override val elementId: String,
@SerialName("info") val infos: List<ValueInfo>
) : HtmlQuestion() {
override fun toHtml(): String = buildString {
append(htmlText())
infos.forEach { (id, value) ->
append("<label for=\"$id\"><input type=\"checkbox\" id=\"$id\" ${elementId.asParameter("name")} ")
append("value=\"$value\" ${isRequiredString()}>")
append("$value</label><br>")
}
}
}

@Serializable
@SerialName("Textarea")
data class TextAreaHtmlQuestion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class SurveyParser(private val mainWindow: MainPluginWindow, project: Project) :
is HtmlQuestionContainer -> item.subQuestions.forEach {
parseAndLog(it, id)
}
is CheckboxHtmlQuestion -> item.infos.forEach { info ->
val result = mainWindow.checkIfRadioButtonChecked(info.id).await()
surveyLogger.log(item.text, result.toString(), option = info.id, questionId = id)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
surveys:
- id: default
htmlQuestions:
- !<Textarea>
text: 1.How helpful was the hint in solving the problem?
- !<Radio>
text: 1.How helpful was the hint in solving the problem? Where 1 - not helpful at all, 5 - very helpful.
elementId: helpfulHint
required: true
rows: 5
cols: 50
- !<Radio>
info:
- id: helpfulHint1
value: 1
- id: helpfulHint2
value: 2
- id: helpfulHint3
value: 3
- id: helpfulHint4
value: 4
- id: helpfulHint5
value: 5
- !<Checkbox>
text: 2.Why did you decide to ask for a hint?
elementId: hintAsk
required: true
Expand All @@ -27,7 +36,7 @@ surveys:
elementId: hintAskOptional
rows: 5
cols: 50
- !<Radio>
- !<Checkbox>
text: 3.Which option did you prefer?
elementId: optionPrefer
required: true
Expand All @@ -49,7 +58,7 @@ surveys:
elementId: optionPreferOptional
rows: 5
cols: 50
- !<Radio>
- !<Checkbox>
text: 4.Have you ever used hints to quickly complete a task and move on?
elementId: quickComplete
required: true
Expand All @@ -69,7 +78,7 @@ surveys:
elementId: quickCompleteOptional
rows: 5
cols: 50
- !<Radio>
- !<Checkbox>
text: 5.Have there ever been situations when you didn't understand a hint? If yes what did you do?
elementId: understandHint
required: true
Expand All @@ -95,7 +104,7 @@ surveys:
elementId: understandHintOptional
rows: 5
cols: 50
- !<Radio>
- !<Checkbox>
text: 6.Would you like to continue using hints?
elementId: continueUse
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let fields = document.getElementsByName(fieldTemp.name);
fields.forEach(function (field) {
field.onclick = function () {
if (field.type === "radio") {
if (field.type === "radio" || field.type === "checkbox") {
defaultBorder(field.name)
} else {
defaultBorder(field.id)
Expand All @@ -22,10 +22,7 @@
function checkAllInputs() {
let checker = true
requiredFields.forEach(function (field) {
if (field.type === "checkbox" && !field.checked) {
redBorder(field.id)
checker = false
} else if (field.type === "radio") {
if (field.type === "radio" || field.type === "checkbox") {
let checked = document.querySelector(`input[name = ${field.name}]:checked`);
if (checked == null) {
redBorder(field.name)
Expand Down

0 comments on commit 2baff3a

Please sign in to comment.