diff --git a/challenger/src/main/resources/public/js/challengerui.js b/challenger/src/main/resources/public/js/challengerui.js index cd35cacf..36ef7326 100644 --- a/challenger/src/main/resources/public/js/challengerui.js +++ b/challenger/src/main/resources/public/js/challengerui.js @@ -60,4 +60,16 @@ function displayLocalGuids(){ // get challenger progress and save to local storage - // get challenger todos and save to local storage \ No newline at end of file + // 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)); + } +} \ No newline at end of file diff --git a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/definitions/field/instance/FieldValue.java b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/definitions/field/instance/FieldValue.java index a06fc7ed..f2155ea9 100644 --- a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/definitions/field/instance/FieldValue.java +++ b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/definitions/field/instance/FieldValue.java @@ -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("\"", "\\\"") + "\""; + } } diff --git a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/ERInstanceData.java b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/ERInstanceData.java index 97805adc..aa5b34e9 100644 --- a/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/ERInstanceData.java +++ b/ercoremodel/src/main/java/uk/co/compendiumdev/thingifier/core/domain/instances/ERInstanceData.java @@ -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())); } }