Skip to content

Commit

Permalink
Correctly shows options value when code or name include special chara…
Browse files Browse the repository at this point in the history
…cters
  • Loading branch information
ferdyrod committed Jul 12, 2024
1 parent 03497ce commit 6e84e8f
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.dhis2.composetable.model.DropdownOption;

import java.util.List;

public abstract class FieldViewModel {
Expand Down Expand Up @@ -59,6 +61,9 @@ public abstract class FieldViewModel {
@NonNull
public abstract List<String> options();

@NonNull
public abstract List<DropdownOption> optionsList();

@NonNull
public abstract String storeBy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.dhis2.composetable.model.DropdownOption;
import org.hisp.dhis.android.core.common.ValueType;
import org.hisp.dhis.android.core.program.SectionRenderingType;

Expand All @@ -28,5 +29,6 @@ FieldViewModel create(@NonNull String id,
@Nullable int row,
@Nullable int column,
@Nullable String categoryOptionCombo,
@Nullable String catCombo);
@Nullable String catCombo,
@Nullable List<DropdownOption> options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.dhis2.composetable.model.DropdownOption;
import org.dhis2.data.forms.dataentry.tablefields.age.AgeViewModel;
import org.dhis2.data.forms.dataentry.tablefields.coordinate.CoordinateViewModel;
import org.dhis2.data.forms.dataentry.tablefields.datetime.DateTimeViewModel;
Expand Down Expand Up @@ -42,19 +43,19 @@ public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull
@NonNull Boolean mandatory, @Nullable String optionSet, @Nullable String value,
@Nullable String section, @Nullable Boolean allowFutureDates, @NonNull Boolean editable, @Nullable SectionRenderingType renderingType,
@Nullable String description, @Nullable String dataElement, @Nullable List<String> listCategoryOption, @Nullable String storeBy,
@Nullable int row, @Nullable int column, @Nullable String categoryOptionCombo, String catCombo) {
@Nullable int row, @Nullable int column, @Nullable String categoryOptionCombo, String catCombo, @Nullable List<DropdownOption> options) {
isNull(type, "type must be supplied");

if (!isEmpty(optionSet)) {
if (renderingType == null || renderingType == SectionRenderingType.LISTING)
return SpinnerViewModel.create(id, label, hintFilterOptions, mandatory, optionSet, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return SpinnerViewModel.create(id, label, hintFilterOptions, mandatory, optionSet, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
else
return ImageViewModel.create(id, label, optionSet, value, section, editable, mandatory, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo); //transforms option set into image option selector
return ImageViewModel.create(id, label, optionSet, value, section, editable, mandatory, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo,options); //transforms option set into image option selector
}

switch (type) {
case AGE:
return AgeViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return AgeViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
case TEXT:
case EMAIL:
case LETTER:
Expand All @@ -68,24 +69,24 @@ public FieldViewModel create(@NonNull String id, @NonNull String label, @NonNull
case INTEGER_ZERO_OR_POSITIVE:
case UNIT_INTERVAL:
case URL:
return EditTextViewModel.create(id, label, mandatory, value, hintEnterText, 1, type, section, editable, description, dataElement, listCategoryOption, storeBy, row, column, categoryOptionCombo, catCombo);
return EditTextViewModel.create(id, label, mandatory, value, hintEnterText, 1, type, section, editable, description, dataElement, listCategoryOption, storeBy, row, column, categoryOptionCombo, catCombo, options);
case TIME:
case DATE:
case DATETIME:
return DateTimeViewModel.create(id, label, mandatory, type, value, section, allowFutureDates, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return DateTimeViewModel.create(id, label, mandatory, type, value, section, allowFutureDates, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
case COORDINATE:
return CoordinateViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return CoordinateViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
case BOOLEAN:
case TRUE_ONLY:
return RadioButtonViewModel.fromRawValue(id, label, type, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return RadioButtonViewModel.fromRawValue(id, label, type, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
case ORGANISATION_UNIT:
//return OrgUnitViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
case IMAGE:
case TRACKER_ASSOCIATE:
case USERNAME:
return UnsupportedViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo);
return UnsupportedViewModel.create(id, label, mandatory, value, section, editable, description,dataElement,listCategoryOption,storeBy, row, column, categoryOptionCombo, catCombo, options);
default:
return EditTextViewModel.create(id, label, mandatory, value, hintEnterText, 1, type, section, editable, description, dataElement, listCategoryOption, storeBy, row, column, categoryOptionCombo, catCombo);
return EditTextViewModel.create(id, label, mandatory, value, hintEnterText, 1, type, section, editable, description, dataElement, listCategoryOption, storeBy, row, column, categoryOptionCombo, catCombo, options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.google.auto.value.AutoValue;

import org.dhis2.composetable.model.DropdownOption;
import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel;

import java.util.List;
Expand All @@ -15,43 +16,43 @@
*/

@AutoValue
public abstract class AgeViewModel extends FieldViewModel {
public abstract class AgeViewModel extends FieldViewModel {

@NonNull
public abstract Boolean mandatory();

@Nullable
public abstract String value();

public static FieldViewModel create(String id, String label, Boolean mandatory, String value, String section, Boolean editable, String description, @NonNull String dataElement, @NonNull List<String> listCategoryOption, @NonNull String storeBy, @Nullable int row, @Nullable int column, @Nullable String categoryOptionCombo, String catCombo) {
return new AutoValue_AgeViewModel(id, label, section, null, editable, null, null, null, description,dataElement, listCategoryOption, storeBy , row, column, categoryOptionCombo, catCombo, mandatory, value);
public static FieldViewModel create(String id, String label, Boolean mandatory, String value, String section, Boolean editable, String description, @NonNull String dataElement, @NonNull List<String> listCategoryOption, @NonNull String storeBy, @Nullable int row, @Nullable int column, @Nullable String categoryOptionCombo, String catCombo, @Nullable List<DropdownOption> options) {
return new AutoValue_AgeViewModel(id, label, section, null, editable, null, null, null, description,dataElement, listCategoryOption, options, storeBy , row, column, categoryOptionCombo, catCombo, mandatory, value);
}

@Override
public FieldViewModel setMandatory() {
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(), catCombo(), true, value());
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(), catCombo(), true, value());
}

@Override
public FieldViewModel setValue(String value) {
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(), catCombo(), mandatory(), value);
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(), catCombo(), mandatory(), value);
}

@NonNull
@Override
public FieldViewModel withError(@NonNull String error) {
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error, description(), dataElement(), options(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), value());
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error, description(), dataElement(), options(), optionsList(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), value());
}

@NonNull
@Override
public FieldViewModel withWarning(@NonNull String warning) {
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning, error(), description(), dataElement(), options(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), value());
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning, error(), description(), dataElement(), options(), optionsList(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), value());
}

@NonNull
@Override
public FieldViewModel withValue(String data) {
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), data);
return new AutoValue_AgeViewModel(uid(), label(), programStageSection(), allowFutureDate(), editable(), optionSet(), warning(), error(), description(), dataElement(), options(), optionsList(), storeBy(),row(), column(), categoryOptionCombo(),catCombo(), mandatory(), data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.google.auto.value.AutoValue;

import org.dhis2.composetable.model.DropdownOption;
import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel;

import java.util.List;
Expand All @@ -15,35 +16,35 @@

@AutoValue
public abstract class CoordinateViewModel extends FieldViewModel {
public static FieldViewModel create(String id, String label, Boolean mandatory, String value, String section, Boolean editable, String description, @NonNull String dataElement, @NonNull List<String> listCategoryOption, @NonNull String storeBy, @Nullable int row, @Nullable int column, String categoryOptionCombo, String catCombo) {
return new AutoValue_CoordinateViewModel(id, label, mandatory, value, section, null, editable, null, null, null,description,dataElement, listCategoryOption, storeBy, row, column, categoryOptionCombo, catCombo);
public static FieldViewModel create(String id, String label, Boolean mandatory, String value, String section, Boolean editable, String description, @NonNull String dataElement, @NonNull List<String> listCategoryOption, @NonNull String storeBy, @Nullable int row, @Nullable int column, String categoryOptionCombo, String catCombo, @NonNull List<DropdownOption> options) {
return new AutoValue_CoordinateViewModel(id, label, mandatory, value, section, null, editable, null, null, null,description,dataElement, listCategoryOption, options, storeBy, row, column, categoryOptionCombo, catCombo);
}

@Override
public FieldViewModel setMandatory() {
return new AutoValue_CoordinateViewModel(uid(), label(), true, value(), programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(),catCombo());
return new AutoValue_CoordinateViewModel(uid(), label(), true, value(), programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(),catCombo());
}

@Override
public FieldViewModel setValue(String value) {
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value, programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(),catCombo());
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value, programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(),catCombo());
}

@NonNull
@Override
public FieldViewModel withWarning(@NonNull String warning) {
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value(), programStageSection(), null, editable(), null, warning, error(),description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value(), programStageSection(), null, editable(), null, warning, error(),description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
}

@NonNull
@Override
public FieldViewModel withError(@NonNull String error) {
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value(), programStageSection(), null, editable(), null, warning(), error,description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), value(), programStageSection(), null, editable(), null, warning(), error,description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
}

@NonNull
@Override
public FieldViewModel withValue(String data) {
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), data, programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
return new AutoValue_CoordinateViewModel(uid(), label(), mandatory(), data, programStageSection(), null, editable(), null, warning(), error(),description(), dataElement(), options(), optionsList(), storeBy(), row(), column(), categoryOptionCombo(), catCombo());
}
}
Loading

0 comments on commit 6e84e8f

Please sign in to comment.