equal
deleted
inserted
replaced
|
1 import _ from 'lodash'; |
|
2 |
|
3 import { |
|
4 RECEIVE_ANNOTATIONS, |
|
5 } from '../actions'; |
|
6 |
|
7 function documents( |
|
8 state = { |
|
9 documents: {}, |
|
10 }, |
|
11 action, |
|
12 ) { |
|
13 switch (action.type) { |
|
14 case RECEIVE_ANNOTATIONS: |
|
15 return Object.assign({}, state, { |
|
16 documents: _(action.annotations) |
|
17 .groupBy('uri') |
|
18 .map((annotList, url) => { |
|
19 const users = _(annotList).map(a => a.user).uniq().value(); |
|
20 const tagsCall = _(annotList) |
|
21 .reduce( |
|
22 (res, annot) => res.concat(annot.tags.filter(t => t.toLowerCase().startsWith('need:'))), |
|
23 [], |
|
24 ); |
|
25 const commentsNb = _(annotList).reduce((res, annot) => { |
|
26 let fres = res; |
|
27 if (annot.references && annot.references.length) { |
|
28 fres += 1; |
|
29 } |
|
30 return fres; |
|
31 }, 0); |
|
32 return [ |
|
33 url, |
|
34 { |
|
35 uri: url, |
|
36 annotations: annotList.length, |
|
37 users: users.length, |
|
38 calls: tagsCall.length, |
|
39 comments: commentsNb, |
|
40 updated: annotList[0].updated, |
|
41 }, |
|
42 ]; |
|
43 }).fromPairs() |
|
44 .value(), |
|
45 }); |
|
46 |
|
47 default: |
|
48 return state; |
|
49 } |
|
50 } |
|
51 |
|
52 export default documents; |