client/src/api/WebAnnotationSerializer.js
changeset 98 2e939d9cf193
child 100 6fd752d98933
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/api/WebAnnotationSerializer.js	Tue Jun 27 13:12:19 2017 +0200
@@ -0,0 +1,47 @@
+import Note from '../store/noteRecord';
+
+class WebAnnotationSerializer {
+
+  static serialize = (note) => {
+
+    const categories = note.categories;
+
+    const baseAnnotation = {
+      '@context': "http://www.w3.org/ns/anno.jsonld",
+      "type":     "Annotation",
+    }
+
+    const source = "/session/" + note.session + "/notes/" + note._id;
+
+    return categories.map((category, index) => {
+
+      let annotation = Object.assign({}, baseAnnotation, {
+        id: index
+      });
+
+      if (category.hasOwnProperty('hasComment') && category.hasComment) {
+        const body = {
+          "type": "TextualBody",
+          "value": category.comment,
+          "format": "text/plain"
+        };
+
+        annotation = Object.assign({}, annotation, { body })
+      }
+
+      return Object.assign({}, annotation, {
+        "target": {
+          "source": source,
+          "selector": {
+            "type": "TextQuoteSelector",
+            "exact": category.text,
+          }
+        }
+      })
+    });
+
+  }
+
+}
+
+export default WebAnnotationSerializer