1 import { select } from 'redux-saga/effects' |
1 import { select } from 'redux-saga/effects' |
2 import { getCreatedNotes, getUpdatedNotes, getDeletedNotes } from '../selectors/coreSelectors'; |
2 import { getCreatedNotes, getUpdatedNotes, getDeletedNotes } from '../selectors/coreSelectors'; |
3 import NoteRecord from '../store/noteRecord'; |
3 import NoteRecord from '../store/noteRecord'; |
4 import { doDeleteNote, loadNote, resetActionNote } from '../actions/notesActions'; |
4 import { doDeleteNote, loadNote, resetActionNote } from '../actions/notesActions'; |
5 import Immutable from 'immutable'; |
|
6 import SyncMixin from './BaseSyncronizer'; |
5 import SyncMixin from './BaseSyncronizer'; |
7 import WebAnnotationSerializer from '../api/WebAnnotationSerializer'; |
6 import WebAnnotationSerializer from '../api/WebAnnotationSerializer'; |
8 |
7 |
|
8 import * as R from 'ramda'; |
|
9 |
9 class NoteSyncBase { |
10 class NoteSyncBase { |
10 |
11 |
11 // local diffs (immutable) |
|
12 * getLocalDiffs() { |
12 * getLocalDiffs() { |
13 return Immutable.Map({ |
13 return { |
14 created: yield select(getCreatedNotes), |
14 created: yield select(getCreatedNotes), |
15 updated: yield select(getUpdatedNotes), |
15 updated: yield select(getUpdatedNotes), |
16 deleted: yield select(getDeletedNotes) |
16 deleted: yield select(getDeletedNotes) |
17 }) |
17 } |
18 } |
18 } |
19 |
19 |
20 // remote urls |
20 // remote urls |
21 getRemoteLoadUrl() { |
21 getRemoteLoadUrl() { |
22 return "/api/notes/notes/"; |
22 return "/api/notes/notes/"; |
23 } |
23 } |
24 |
24 |
25 getRemoteDeleteUrl(localObjInst) { |
25 getRemoteDeleteUrl(localObjInst) { |
26 return `/api/notes/sessions/${localObjInst.get('session')}/notes/${localObjInst.get('_id')}/`; |
26 return `/api/notes/sessions/${R.prop('session',localObjInst)}/notes/${R.prop('_id',localObjInst)}/`; |
27 } |
27 } |
28 |
28 |
29 getRemoteCreateUrl(localObjInst) { |
29 getRemoteCreateUrl(localObjInst) { |
30 return `/api/notes/sessions/${localObjInst.get('session')}/notes/`; |
30 return `/api/notes/sessions/${R.prop('session',localObjInst)}/notes/`; |
31 } |
31 } |
32 |
32 |
33 getRemoteUpdateUrl(localObjInst) { |
33 getRemoteUpdateUrl(localObjInst) { |
34 return `/api/notes/sessions/${localObjInst.get('session')}/notes/${localObjInst.get('_id')}/`; |
34 return `/api/notes/sessions/${R.prop('session',localObjInst)}/notes/${R.prop('_id',localObjInst)}/`; |
35 } |
35 } |
36 |
36 |
37 // build remote json message |
37 // build remote json message |
38 getRemoteData(localObjInst) { |
38 getRemoteData(localObjInst) { |
39 |
39 |
40 return { |
40 return { |
41 ext_id: localObjInst.get('_id'), |
41 ext_id: R.prop('_id',localObjInst), |
42 session: localObjInst.get('session'), |
42 session: R.prop('session',localObjInst), |
43 raw: JSON.stringify(localObjInst.get('raw')), |
43 raw: JSON.stringify(R.prop('raw',localObjInst)), |
44 plain: localObjInst.get('plain'), |
44 plain: R.prop('plain',localObjInst), |
45 html: localObjInst.get('html'), |
45 html: R.prop('html',localObjInst), |
46 tc_start: localObjInst.get('startedAt'), |
46 tc_start: R.prop('startedAt',localObjInst), |
47 tc_end: localObjInst.get('finishedAt'), |
47 tc_end: R.prop('finishedAt',localObjInst), |
48 categorization: JSON.stringify(WebAnnotationSerializer.serialize(localObjInst)), |
48 categorization: JSON.stringify(WebAnnotationSerializer.serialize(localObjInst)), |
49 margin_note: localObjInst.get('marginComment'), |
49 margin_note: R.prop('marginComment',localObjInst), |
50 } |
50 } |
51 |
51 |
52 } |
52 } |
53 |
53 |
54 getLocalRecord(remoteObj) { |
54 getLocalRecord(remoteObj) { |
55 return new NoteRecord({ |
55 return NoteRecord({ |
56 _id: remoteObj.ext_id, |
56 _id: remoteObj.ext_id, |
57 session: remoteObj.session, |
57 session: remoteObj.session, |
58 raw: JSON.parse(remoteObj.raw), |
58 raw: JSON.parse(remoteObj.raw), |
59 plain: remoteObj.plain, |
59 plain: remoteObj.plain, |
60 html: remoteObj.html, |
60 html: remoteObj.html, |