| author | Alexandre Segura <mex.zktk@gmail.com> |
| Tue, 27 Jun 2017 13:12:19 +0200 | |
| changeset 98 | 2e939d9cf193 |
| parent 86 | fa8ef84a1780 |
| child 129 | d48946d164c6 |
| permissions | -rw-r--r-- |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import uuidV1 from 'uuid/v1'; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import * as types from '../constants/actionTypes'; |
|
98
2e939d9cf193
Introduce WebAnnotationSerializer.
Alexandre Segura <mex.zktk@gmail.com>
parents:
86
diff
changeset
|
4 |
import WebAnnotationSerializer from '../api/WebAnnotationSerializer'; |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
|
| 15 | 6 |
export const addNote = (session, data) => { |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
7 |
const noteId = uuidV1(); |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
8 |
const note = { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
9 |
_id: noteId, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
10 |
session: session._id, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
11 |
raw: data.raw, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
12 |
plain: data.plain, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
13 |
html: data.html, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
14 |
startedAt: data.startedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
15 |
finishedAt: data.finishedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
16 |
categories: data.categories, |
| 78 | 17 |
marginComment: data.marginComment, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
18 |
}; |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
19 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
20 |
const noteSrvr = { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
21 |
ext_id: noteId, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
22 |
session: session._id, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
23 |
raw: JSON.stringify(data.raw), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
24 |
plain: data.plain, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
25 |
html: data.html, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
26 |
tc_start: data.startedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
27 |
tc_end: data.finishedAt, |
|
98
2e939d9cf193
Introduce WebAnnotationSerializer.
Alexandre Segura <mex.zktk@gmail.com>
parents:
86
diff
changeset
|
28 |
categorization: WebAnnotationSerializer.serialize(note), |
| 86 | 29 |
margin_note: data.marginComment, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
30 |
} |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
31 |
|
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
return { |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
33 |
type: types.ADD_NOTE, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
34 |
note, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
35 |
meta: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
36 |
offline: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
37 |
effect: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
38 |
url: `/api/notes/sessions/${session.get('_id')}/notes/`, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
39 |
method: 'POST', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
40 |
data: noteSrvr |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
41 |
}, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
42 |
commit: { type: types.NOOP }, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
43 |
rollback: { type: types.NOOP } |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
44 |
} |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
} |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
}; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
} |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
48 |
|
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
49 |
export const deleteNote = (note) => { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
50 |
return { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
51 |
type: types.DELETE_NOTE, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
52 |
note, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
53 |
meta: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
54 |
offline: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
55 |
effect: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
56 |
url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
57 |
method: 'DELETE' |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
58 |
}, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
59 |
commit: { type: types.NOOP }, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
60 |
rollback: { type: types.NOOP } |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
61 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
62 |
} |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
63 |
}; |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
64 |
} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
65 |
|
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
66 |
export const updateNote = (note, data) => { |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
67 |
const noteSrvr = { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
68 |
raw: JSON.stringify(data.raw), |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
69 |
plain: data.plain, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
70 |
html: data.html, |
|
98
2e939d9cf193
Introduce WebAnnotationSerializer.
Alexandre Segura <mex.zktk@gmail.com>
parents:
86
diff
changeset
|
71 |
categorization: WebAnnotationSerializer.serialize(note), |
| 86 | 72 |
margin_note: data.marginComment, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
73 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
74 |
|
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
75 |
return { |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
76 |
type: types.UPDATE_NOTE, |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
77 |
note, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
78 |
data, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
79 |
meta: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
80 |
offline: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
81 |
effect: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
82 |
url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
83 |
method: 'PUT', |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
84 |
data: noteSrvr |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
85 |
}, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
86 |
commit: { type: types.NOOP }, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
87 |
rollback: { type: types.NOOP } |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
88 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
89 |
} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
90 |
}; |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
91 |
} |