client/src/api/WebAnnotationSerializer.js
changeset 98 2e939d9cf193
child 100 6fd752d98933
equal deleted inserted replaced
97:69eaef18b01b 98:2e939d9cf193
       
     1 import Note from '../store/noteRecord';
       
     2 
       
     3 class WebAnnotationSerializer {
       
     4 
       
     5   static serialize = (note) => {
       
     6 
       
     7     const categories = note.categories;
       
     8 
       
     9     const baseAnnotation = {
       
    10       '@context': "http://www.w3.org/ns/anno.jsonld",
       
    11       "type":     "Annotation",
       
    12     }
       
    13 
       
    14     const source = "/session/" + note.session + "/notes/" + note._id;
       
    15 
       
    16     return categories.map((category, index) => {
       
    17 
       
    18       let annotation = Object.assign({}, baseAnnotation, {
       
    19         id: index
       
    20       });
       
    21 
       
    22       if (category.hasOwnProperty('hasComment') && category.hasComment) {
       
    23         const body = {
       
    24           "type": "TextualBody",
       
    25           "value": category.comment,
       
    26           "format": "text/plain"
       
    27         };
       
    28 
       
    29         annotation = Object.assign({}, annotation, { body })
       
    30       }
       
    31 
       
    32       return Object.assign({}, annotation, {
       
    33         "target": {
       
    34           "source": source,
       
    35           "selector": {
       
    36             "type": "TextQuoteSelector",
       
    37             "exact": category.text,
       
    38           }
       
    39         }
       
    40       })
       
    41     });
       
    42 
       
    43   }
       
    44 
       
    45 }
       
    46 
       
    47 export default WebAnnotationSerializer