Implemented parsing for new datetime range picker
-// TODO: import detail-picker components here, not in create-post
-// TODO: each detail picker should know it's own rdf template
-// --> both for parsing to and from rdf
-// --> templates are used in need-builder (toRDF) and in parse-need (from RDF)
import {
get,
getIn,
@@ -370,22 +366,44 @@ export const details = {
icon: "#ico36_detail_datetime",
placeholder: undefined,
component: "won-datetime-range-picker",
- viewerComponent: "won-datetime-viewer",
+ viewerComponent: "won-datetime-viewer", // not used, values are read as fromDatetime and throughDatetime
parseToRDF: function({ value }) {
- console.log("TODO: implement parse to RDF for " + value);
- return undefined;
- },
- parseFromRDF: function(jsonLDImm) {
- console.log("TODO: implement parse from RDF for " + jsonLDImm.toJS());
- return undefined;
- },
- generateHumanReadable: function({ value, includeLabel }) {
- if (value || includeLabel) {
- // do nothing
+ if (value) {
+ const fromDatetime = parseDatetimeStrictly(value.fromDatetime);
+ const toDatetime = parseDatetimeStrictly(value.toDatetime);
+
+ let validFrom = undefined;
+ let validThrough = undefined;
+
+ if (isValidDate(fromDatetime)) {
+ const fromDatetimeString = toLocalISODateString(fromDatetime);
+ validFrom = {
+ "@value": fromDatetimeString,
+ "@type": "xsd:dateTime",
+ };
+ }
+
+ if (isValidDate(toDatetime)) {
+ const toDatetimeString = toLocalISODateString(toDatetime);
+ validThrough = {
+ "@value": toDatetimeString,
+ "@type": "xsd:dateTime",
+ };
+ }
+
+ return {
+ "s:validFrom": validFrom,
+ "s:validThrough": validThrough,
+ };
+ } else {
+ return {
+ "s:validFrom": undefined,
+ "s:validThrough": undefined,
+ };
}
- console.log("TODO: implement generate human readable for datetime range");
- return undefined;
},
+ parseFromRDF: function() {}, // RDF should be parsed by fromDatetime and throughDatetime
+ generateHumanReadable: function() {}, // should be generated by fromDatetime and troughDatetime
},
location: {
identifier: "location",
@@ -397,7 +415,6 @@ export const details = {
messageEnabled: true,
parseToRDF: function({ value, identifier, contentUri }) {
if (!value) {
- // TODO: this should happen in need-builder
return { "won:hasLocation": undefined };
}
