Skip to content

Commit

Permalink
avniproject/avni-webapp#1354 - default value is calendar for date pic…
Browse files Browse the repository at this point in the history
…ker mode. create default values for track location and enable beneficiary mode instead of null.
  • Loading branch information
petmongrels committed Oct 4, 2024
1 parent 26d87dd commit 08fa682
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.avni.server.domain;

import org.avni.server.util.CollectionUtil;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
Expand All @@ -12,16 +13,29 @@ public class UserSettings {
public static final String LOCALE = "locale";
public static final String ENABLE_BENEFICIARY_MODE = "showBeneficiaryMode";
public static final String TRACK_LOCATION = "trackLocation";
public static final List<String> DATE_PICKER_MODE_OPTIONS = Arrays.asList("calendar", "spinner");
public static final String DEFAULT_DATE_PICKER_MODE = "calendar";
public static final String SPINNER_DATE_PICKER_MODE = "spinner";
public static final List<String> DATE_PICKER_MODE_OPTIONS = Arrays.asList(DEFAULT_DATE_PICKER_MODE, SPINNER_DATE_PICKER_MODE);

public UserSettings(JsonObject jsonObject) {
this.jsonObject = jsonObject;
}

public static String createDatePickerMode(String datePickerMode) {
if (StringUtils.isEmpty(datePickerMode)) {
return DEFAULT_DATE_PICKER_MODE;
}
return CollectionUtil.findMatchingIgnoreCase(DATE_PICKER_MODE_OPTIONS, datePickerMode);
}

public static Boolean createTrackLocation(Boolean trackLocation) {
return trackLocation != null && trackLocation;
}

public static Boolean createEnableBeneficiaryMode(Boolean enableBeneficiaryMode) {
return enableBeneficiaryMode != null && enableBeneficiaryMode;
}

public String getIdPrefix() {
return UserSettings.getIdPrefix(this.jsonObject);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ private void write(Row row) throws IDPException {

user.setSettings(new JsonObject()
.with(UserSettings.LOCALE, locale)
.with(UserSettings.TRACK_LOCATION, trackLocation)
.with(UserSettings.TRACK_LOCATION, UserSettings.createTrackLocation(trackLocation))
.withEmptyCheckAndTrim(UserSettings.DATE_PICKER_MODE, UserSettings.createDatePickerMode(datePickerMode))
.with(UserSettings.ENABLE_BENEFICIARY_MODE, beneficiaryMode)
.with(UserSettings.ENABLE_BENEFICIARY_MODE, UserSettings.createEnableBeneficiaryMode(beneficiaryMode))
.withEmptyCheckAndTrim(UserSettings.ID_PREFIX, idPrefix));

user.setOrganisationId(organisation.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public void shouldCreateUpdate() throws IDPException {
dataRow(" Bihar, District1, Block11", " Catchment 6", " username8@example", " User 8", " [email protected] ", " 9455509147 ", "Answer 1"),
catchmentCreated(false),
userCreatedDetails(true));
userCreatedDetails(user("username8@example"), datePickerMode("calendar"), language("en"), trackLocation(false), enableBeneficiaryMode(false), userGroup("Everyone"));

// wrong - username, email, phone number, language, track location, date picker mode, enable beneficiary mode
failure(
Expand Down

0 comments on commit 08fa682

Please sign in to comment.