Skip to content

Commit

Permalink
feat: orientation for radio and checkbox components (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsenave authored Jun 13, 2024
1 parent c5d8dcb commit ef06090
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>lunatic-model</artifactId>
<packaging>jar</packaging>

<version>3.9.2</version>
<version>3.10.0</version>
<name>Lunatic Model</name>
<description>Classes and converters for the Lunatic model</description>
<url>https://inseefr.github.io/Lunatic-Model/</url>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/BodyCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* TODO: remove this and do proper polymorphisme in tables instead. */
@JsonPropertyOrder({
"componentType",
"orientation",
"maxLength",
"min",
"max",
Expand All @@ -32,6 +33,9 @@
@Setter
public class BodyCell {

/** Orientation for radio / checkbox cells. */
protected Orientation orientation;

protected String value;
protected LabelType label;
protected String format;
Expand Down Expand Up @@ -63,4 +67,5 @@ public class BodyCell {
public BodyCell() {
this.options = new ArrayList<>();
}

}
15 changes: 11 additions & 4 deletions src/main/java/fr/insee/lunatic/model/flat/CheckboxGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@
import java.util.ArrayList;
import java.util.List;

/**
* Multiple choice response component with checkboxes.
*/
@Getter
@Setter
public class CheckboxGroup
extends ComponentType
implements ComponentMultipleResponseType
{
public class CheckboxGroup extends ComponentType implements ComponentMultipleResponseType {

/** Orientation of the checkbox modalities. */
protected Orientation orientation;

/** List of the modalities of the checkbox component. */
protected List<ResponsesCheckboxGroup> responses;

public CheckboxGroup() {
super();
this.componentType = ComponentTypeEnum.CHECKBOX_GROUP;
this.orientation = Orientation.VERTICAL;
this.responses = new ArrayList<>();
}

}
16 changes: 12 additions & 4 deletions src/main/java/fr/insee/lunatic/model/flat/CheckboxOne.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,28 @@
import java.util.ArrayList;
import java.util.List;

/**
* Unique choice response component with checkboxes.
*/
@Getter
@Setter
public class CheckboxOne
extends ComponentType
implements ComponentSimpleResponseType
{
public class CheckboxOne extends ComponentType implements ComponentSimpleResponseType {

/** Orientation of the checkbox modalities. */
protected Orientation orientation;

/** List of the modalities of the checkbox component. */
protected List<Options> options;

/** {@link ResponseType} */
@JsonProperty(required = true)
protected ResponseType response;

public CheckboxOne() {
super();
this.componentType = ComponentTypeEnum.CHECKBOX_ONE;
this.orientation = Orientation.VERTICAL;
this.options = new ArrayList<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"page",
"goToPage",
"maxLength",
"orientation",
"positioning",
"min",
"max",
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import lombok.Getter;
import lombok.Setter;

// TODO: this object class should be renamed to "Option" (singular), the current plural name is misleading.

/**
* Option / modality of a unique choice component (dropdown, radio, checkbox one).
*/
@JsonPropertyOrder({
"value",
"label"
Expand All @@ -13,10 +18,15 @@
@Setter
public class Options {

/** Response value associated to the modality. */
@JsonProperty(required = true)
protected String value;

/** Displayed label of the modality. */
@JsonProperty(required = true)
protected LabelType label;

/** {@link DetailResponse} */
protected DetailResponse detail;

}
14 changes: 14 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/Orientation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.insee.lunatic.model.flat;

/**
* Orientation of the response modalities of a radio or checkbox component.
*/
public enum Orientation {

/** Vertical orientation, which is the default. */
VERTICAL,

/** Horizontal orientation, to be used for radio or checkbox within a table for instance. */
HORIZONTAL

}
17 changes: 13 additions & 4 deletions src/main/java/fr/insee/lunatic/model/flat/Radio.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@
import java.util.ArrayList;
import java.util.List;

/**
* Unique choice response component with radio buttons.
*/
@Getter
@Setter
public class Radio
extends ComponentType
implements ComponentSimpleResponseType
{
public class Radio extends ComponentType implements ComponentSimpleResponseType {

/** Orientation of the radio modalities. */
protected Orientation orientation;

/** List of the modalities of the radio component. */
protected List<Options> options;

/** {@link ResponseType} */
@JsonProperty(required = true)
protected ResponseType response;

public Radio() {
super();
this.componentType = ComponentTypeEnum.RADIO;
this.orientation = Orientation.VERTICAL;
this.options = new ArrayList<>();
}

}
4 changes: 4 additions & 0 deletions src/main/java/fr/insee/lunatic/model/flat/ResponseType.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import lombok.Getter;
import lombok.Setter;

/** Collected response. */
@Getter
@Setter
public class ResponseType {

/** Name of the variable in which the reponse is collected. */
protected String name;

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void serializeCheckboxGroup() throws SerializationException, JSONException {
//
CheckboxGroup checkboxGroup = new CheckboxGroup();
checkboxGroup.setId("foo-id");
checkboxGroup.setComponentType(ComponentTypeEnum.CHECKBOX_GROUP);
//
ResponsesCheckboxGroup response1 = new ResponsesCheckboxGroup();
response1.setId("response1-id");
Expand Down Expand Up @@ -82,6 +81,7 @@ void serializeCheckboxGroup() throws SerializationException, JSONException {
{
"id": "foo-id",
"componentType": "CheckboxGroup",
"orientation": "VERTICAL",
"responses": [
{
"id": "response1-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void serializeCheckboxOne() throws SerializationException, JSONException {
//
CheckboxOne checkboxOne = new CheckboxOne();
checkboxOne.setId("foo-id");
checkboxOne.setComponentType(ComponentTypeEnum.CHECKBOX_ONE);
//
Options option1 = new Options();
option1.setLabel(new LabelType());
Expand Down Expand Up @@ -64,6 +63,7 @@ void serializeCheckboxOne() throws SerializationException, JSONException {
{
"id": "foo-id",
"componentType": "CheckboxOne",
"orientation": "VERTICAL",
"options": [
{
"value": "1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void serializeRadio() throws SerializationException, JSONException {
//
Radio radio = new Radio();
radio.setId("foo-id");
radio.setComponentType(ComponentTypeEnum.RADIO);
//
Options option1 = new Options();
option1.setLabel(new LabelType());
Expand Down Expand Up @@ -64,6 +63,7 @@ void serializeRadio() throws SerializationException, JSONException {
{
"id": "foo-id",
"componentType": "Radio",
"orientation": "VERTICAL",
"options": [
{
"value": "1",
Expand Down

0 comments on commit ef06090

Please sign in to comment.