diff --git a/lib/ui/api.ts b/lib/ui/api.ts index 15f5d0c..1f755c9 100644 --- a/lib/ui/api.ts +++ b/lib/ui/api.ts @@ -106,14 +106,23 @@ router.get(`/devices/:id.csv`, async (ctx) => { for (const k of Object.keys(res[0]).sort()) { const p = res[0][k]; + let value = ""; + let type = ""; + if (p.value) { + value = p.value[0]; + type = p.value[1]; + if (type === "xsd:dateTime" && typeof value === "number") + value = new Date(value).toJSON(); + } + const row = [ k, p.object, p.objectTimestamp, p.writable, p.writableTimestamp, - p.value != null ? `"${p.value[0].toString().replace(/"/g, '""')}"` : "", - p.value != null ? p.value[1] : "", + `"${value.toString().replace(/"/g, '""')}"`, + type, p.valueTimestamp, p.notification, p.notificationTimestamp, @@ -285,11 +294,21 @@ for (const [resource, flags] of Object.entries(resources)) { return tags.join(", "); } + if (e === exp) { + const p = obj[e[1]]; + if ( + p && + p.value && + p.value[1] === "xsd:dateTime" && + typeof p.value[0] === "number" + ) + return new Date(p.value[0]).toJSON(); + } } } else if (e[0] === "FUNC") { if (e[1] === "DATE_STRING") { if (e[2] && !Array.isArray(e[2])) - return new Date(e[2]).toISOString(); + return new Date(e[2]).toJSON(); } } } diff --git a/ui/components/parameter.ts b/ui/components/parameter.ts index 3d775f0..45ef733 100644 --- a/ui/components/parameter.ts +++ b/ui/components/parameter.ts @@ -62,6 +62,8 @@ const evaluateParam = memoize((exp, obj, now: number) => { timestamp = p.valueTimestamp; value = p.value[0]; parameter = exp[1]; + if (p.value[1] === "xsd:dateTime" && typeof value === "number") + value = new Date(value).toLocaleString(); } } diff --git a/ui/drawer-component.ts b/ui/drawer-component.ts index 1d1d76f..6076d01 100644 --- a/ui/drawer-component.ts +++ b/ui/drawer-component.ts @@ -76,13 +76,13 @@ function renderStagingSpv(task: StageTask, queueFunc, cancelFunc): Children { ] ); } else { + const type = task.parameterValues[0][2]; + let value = task.parameterValues[0][1]; + if (type === "xsd:dateTime" && typeof value === "number") + value = new Date(value).toJSON() || value; input = m("input", { - type: ["xsd:dateTime", "xsd:int", "xsd:unsignedInt"].includes( - task.parameterValues[0][2] - ) - ? "number" - : "text", - value: task.parameterValues[0][1], + type: ["xsd:int", "xsd:unsignedInt"].includes(type) ? "number" : "text", + value: value, oninput: (e) => { e.redraw = false; task.parameterValues[0][1] = input.dom.value;