client/src/actions/notesActions.js
changeset 129 d48946d164c6
parent 98 2e939d9cf193
child 132 906a6c7c7943
equal deleted inserted replaced
128:34a75bd8d0b9 129:d48946d164c6
     1 import uuidV1 from 'uuid/v1';
     1 import uuidV1 from 'uuid/v1';
     2 
     2 
     3 import * as types from '../constants/actionTypes';
     3 import * as types from '../constants/actionTypes';
     4 import WebAnnotationSerializer from '../api/WebAnnotationSerializer';
     4 // import WebAnnotationSerializer from '../api/WebAnnotationSerializer';
       
     5 import { ActionEnum } from '../constants';
     5 
     6 
     6 export const addNote = (session, data) => {
     7 export const addNote = (session, data) => {
     7   const noteId = uuidV1();
     8   const noteId = uuidV1();
     8   const note = {
     9   const note = {
     9     _id: noteId,
    10     _id: noteId,
    13     html: data.html,
    14     html: data.html,
    14     startedAt: data.startedAt,
    15     startedAt: data.startedAt,
    15     finishedAt: data.finishedAt,
    16     finishedAt: data.finishedAt,
    16     categories: data.categories,
    17     categories: data.categories,
    17     marginComment: data.marginComment,
    18     marginComment: data.marginComment,
       
    19     action: ActionEnum.CREATED
    18   };
    20   };
    19 
       
    20   const noteSrvr = {
       
    21     ext_id: noteId,
       
    22     session: session._id,
       
    23     raw: JSON.stringify(data.raw),
       
    24     plain: data.plain,
       
    25     html: data.html,
       
    26     tc_start: data.startedAt,
       
    27     tc_end: data.finishedAt,
       
    28     categorization: WebAnnotationSerializer.serialize(note),
       
    29     margin_note: data.marginComment,
       
    30   }
       
    31 
    21 
    32   return {
    22   return {
    33     type: types.ADD_NOTE,
    23     type: types.ADD_NOTE,
    34     note,
    24     note,
    35     meta: {
       
    36       offline: {
       
    37         effect: {
       
    38           url: `/api/notes/sessions/${session.get('_id')}/notes/`,
       
    39           method: 'POST',
       
    40           data: noteSrvr
       
    41         },
       
    42         commit: { type: types.NOOP },
       
    43         rollback: { type: types.NOOP }
       
    44       }
       
    45     }
       
    46   };
    25   };
    47 }
    26 }
    48 
    27 
    49 export const deleteNote = (note) => {
    28 export const deleteNote = (note) => {
    50   return {
    29   return {
    51     type: types.DELETE_NOTE,
    30     type: types.DELETE_NOTE,
    52     note,
    31     note,
    53     meta: {
       
    54       offline: {
       
    55         effect: {
       
    56           url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`,
       
    57           method: 'DELETE'
       
    58         },
       
    59         commit: { type: types.NOOP },
       
    60         rollback: { type: types.NOOP }
       
    61       }
       
    62     }
       
    63   };
    32   };
    64 }
    33 }
    65 
    34 
    66 export const updateNote = (note, data) => {
    35 export const updateNote = (note, data) => {
    67   const noteSrvr = {
       
    68     raw: JSON.stringify(data.raw),
       
    69     plain: data.plain,
       
    70     html: data.html,
       
    71     categorization: WebAnnotationSerializer.serialize(note),
       
    72     margin_note: data.marginComment,
       
    73   }
       
    74 
    36 
    75   return {
    37   return {
    76     type: types.UPDATE_NOTE,
    38     type: types.UPDATE_NOTE,
    77     note,
    39     note,
    78     data,
    40     data,
    79     meta: {
       
    80       offline: {
       
    81         effect: {
       
    82           url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`,
       
    83           method: 'PUT',
       
    84           data: noteSrvr
       
    85         },
       
    86         commit: { type: types.NOOP },
       
    87         rollback: { type: types.NOOP }
       
    88       }
       
    89     }
       
    90   };
    41   };
    91 }
    42 }
       
    43 
       
    44 export const doDeleteNote = (noteId) => {
       
    45   return { type: types.DO_DELETE_NOTE, noteId };
       
    46 }
       
    47 
       
    48 export const loadNote = (note) => {
       
    49   return { type: types.LOAD_NOTE, note };
       
    50 }
       
    51 
       
    52 export const resetActionNote = (note) => {
       
    53   return { type: types.RESET_ACTION_NOTE, note };
       
    54 }
       
    55