| author | ymh <ymh.work@gmail.com> |
| Fri, 23 Jun 2017 18:50:57 +0200 | |
| changeset 86 | fa8ef84a1780 |
| parent 83 | 76a4e4b11762 |
| child 98 | 2e939d9cf193 |
| 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'; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
| 15 | 5 |
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
|
6 |
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
|
7 |
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
|
8 |
_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
|
9 |
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
|
10 |
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
|
11 |
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
|
12 |
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
|
13 |
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
|
14 |
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
|
15 |
categories: data.categories, |
| 78 | 16 |
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
|
17 |
}; |
|
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 |
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
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
tc_end: 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
|
27 |
categorization: JSON.stringify(data.categories), |
| 86 | 28 |
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
|
29 |
} |
|
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 |
|
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
return { |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
}, |
|
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 |
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
|
42 |
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
|
43 |
} |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
} |
|
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 |
} |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
47 |
|
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
48 |
export const deleteNote = (note) => { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
49 |
return { |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
50 |
type: types.DELETE_NOTE, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
51 |
note, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
52 |
meta: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
53 |
offline: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
54 |
effect: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
55 |
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
|
56 |
method: 'DELETE' |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
57 |
}, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
58 |
commit: { type: types.NOOP }, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
59 |
rollback: { type: types.NOOP } |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
60 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
61 |
} |
|
79
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
62 |
}; |
|
772b73e31069
Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents:
78
diff
changeset
|
63 |
} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
64 |
|
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
65 |
export const updateNote = (note, data) => { |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
66 |
const noteSrvr = { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
67 |
raw: JSON.stringify(data.raw), |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
68 |
plain: data.plain, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
69 |
html: data.html, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
70 |
categorization: JSON.stringify(data.categories), |
| 86 | 71 |
margin_note: data.marginComment, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
72 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
73 |
|
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
74 |
return { |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
75 |
type: types.UPDATE_NOTE, |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
76 |
note, |
|
83
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
77 |
data, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
78 |
meta: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
79 |
offline: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
80 |
effect: { |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
81 |
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
|
82 |
method: 'PUT', |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
83 |
data: noteSrvr |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
84 |
}, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
85 |
commit: { type: types.NOOP }, |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
86 |
rollback: { type: types.NOOP } |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
87 |
} |
|
76a4e4b11762
add server request for note update and delete
ymh <ymh.work@gmail.com>
parents:
80
diff
changeset
|
88 |
} |
|
80
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
89 |
}; |
|
b3a02ea6d097
Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents:
79
diff
changeset
|
90 |
} |