Skip to content

Commit

Permalink
improved json output at field level and prototype save to localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Mar 1, 2024
1 parent b2706c4 commit 925a051
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
14 changes: 13 additions & 1 deletion challenger/src/main/resources/public/js/challengerui.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ function displayLocalGuids(){


// get challenger progress and save to local storage
// get challenger todos and save to local storage
// get challenger todos and save to local storage

function saveChallengerProgressToLocalStorage(aChallenger){
if(aChallenger && aChallenger.xChallenger){
localStorage.setItem(aChallenger.xChallenger + ".progress", JSON.stringify(aChallenger));
}
}

function saveChallengerTodosToLocalStorage(data, aChallenger){
if(data && aChallenger && aChallenger.xChallenger){
localStorage.setItem(aChallenger.xChallenger + ".data", JSON.stringify(data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,25 @@ public boolean asBoolean() {
public int asInteger() {
return Integer.valueOf(valueOfField);
}

public String asJsonValue() {
switch(forField.getType()) {
case BOOLEAN:
case FLOAT:
case AUTO_INCREMENT:
case INTEGER:
return valueOfField;
case AUTO_GUID:
case DATE:
case ENUM:
case STRING:
return quoted(valueOfField);
default:
return quoted(valueOfField);
}
}

private String quoted(String aString){
return "\"" + aString.replaceAll("\"", "\\\"") + "\"";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ public String asJson(){
Field aField = defn.getField(fieldName);
if(instance.hasInstantiatedFieldNamed(fieldName)){
dataArray.append(fieldSeparator);
// TODO: quote only if string
dataArray.append(quoted(aField.getName()) + ": " + quoted(instance.getFieldValue(fieldName).asString()));
dataArray.append(quoted(aField.getName()) + ": " + instance.getFieldValue(fieldName).asJsonValue());
}else {
if (aField.isMandatory()) {
dataArray.append(fieldSeparator);
// TODO: quote only if string
dataArray.append(quoted(aField.getName()) + ": " + quoted(aField.getDefaultValue().asString()));
dataArray.append(quoted(aField.getName()) + ": " + quoted(aField.getDefaultValue().asJsonValue()));
}
}

Expand Down

0 comments on commit 925a051

Please sign in to comment.