author | Chloe Laisne <chloe.laisne@gmail.com> |
Mon, 30 May 2016 23:58:34 +0200 | |
changeset 176 | d1baf7ccecc8 |
parent 160 | c77f06ff3e54 |
permissions | -rw-r--r-- |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import ENV from 'app-client/config/environment'; |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
import _ from 'lodash/lodash'; |
127
5cd8c3065c38
extract common functionalities to common module. First application to lexvo name resolving
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
3 |
import * as constants from 'corpus-common-addon/utils/constants'; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
export default function() { |
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
7 |
this.namespace = ENV.baseURL.replace(/\/$/,'')+'/api/v1'; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
9 |
this.get('/documents'); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
10 |
this.get('/documents/:id', function(db, request) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
11 |
var docId = decodeURIComponent(request.params.id); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
13 |
return { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
14 |
'document': db.documents.find(docId) |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
15 |
}; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
16 |
}); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
18 |
this.get('/languages', function(db) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
19 |
var res = {}; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
20 |
_.each(db.languages, function(lang) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
21 |
res[lang.id] = lang.count; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
22 |
}); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
23 |
return res; |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
}); |
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
25 |
|
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
26 |
this.get('/themes', function(db) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
27 |
var res = {}; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
28 |
_.each(db.themes, function(theme) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
29 |
res[theme.id] = {'label': theme.label, 'count': theme.count}; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
30 |
}); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
31 |
return res; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
32 |
}); |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
|
160
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
34 |
this.get('/discourses', function(db) { |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
35 |
var res = {}; |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
36 |
_.each(db.discourses, function(discourse) { |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
37 |
res[discourse.id] = {'label': discourse.label, 'count': discourse.count}; |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
38 |
}); |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
39 |
return res; |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
40 |
}); |
c77f06ff3e54
add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
158
diff
changeset
|
41 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
42 |
this.get('/lexvo/:ids', function(db, request) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
43 |
var langIds = decodeURIComponent(request.params.ids); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
44 |
var resMap = _.reduce(langIds.split(','), function(res, id) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
45 |
var fullId = id; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
46 |
if(!_.startsWith(fullId, constants.LEXVO_BASE_URL)) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
47 |
fullId = constants.LEXVO_BASE_URL + id; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
48 |
} |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
49 |
var lexvoRes = db.lexvo.find(fullId); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
50 |
res[id] = lexvoRes?lexvoRes.name:null; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
51 |
return res; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
52 |
}, {}); |
127
5cd8c3065c38
extract common functionalities to common module. First application to lexvo name resolving
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
53 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
54 |
return { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
55 |
'lexvoids': resMap |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
56 |
}; |
127
5cd8c3065c38
extract common functionalities to common module. First application to lexvo name resolving
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
57 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
58 |
}); |
127
5cd8c3065c38
extract common functionalities to common module. First application to lexvo name resolving
ymh <ymh.work@gmail.com>
parents:
126
diff
changeset
|
59 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
60 |
this.get('/bnf/:ids', function(db, request) { |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
61 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
62 |
var bnfIds = decodeURIComponent(request.params.ids); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
63 |
var resMap = _.reduce(bnfIds.split(','), function(res, id) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
64 |
var fullId = id; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
65 |
if(_.startsWith(fullId, constants.BNF_BASE_URL)) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
66 |
fullId = fullId.slice(constants.BNF_BASE_URL.length); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
67 |
} else if (_.startsWith(fullId, constants.BNF_ARK_BASE_URL)) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
68 |
fullId = fullId.slice(constants.BNF_ARK_BASE_URL.length); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
69 |
} else if (!_.startsWith(fullId, constants.BNF_ARK_BASE_ID)) { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
70 |
fullId = constants.BNF_ARK_BASE_ID + fullId; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
71 |
} |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
72 |
var bnfRes = db.lexvo.find(fullId); |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
73 |
res[fullId] = bnfRes?bnfRes.label:null; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
74 |
return res; |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
75 |
}, {}); |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
76 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
77 |
return { |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
78 |
'bnfids': resMap |
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
79 |
}; |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
80 |
|
158
366509ae2f37
Add controller for themes count + upgrade ember for app-client
ymh <ymh.work@gmail.com>
parents:
134
diff
changeset
|
81 |
}); |
134
c06d08c8a1b8
add bnf resolver in common addon + applications
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
82 |
|
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
} |