author | ymh <ymh.work@gmail.com> |
Sun, 04 Dec 2016 13:49:44 +0100 | |
changeset 466 | a8effb60ccb6 |
parent 447 | 38d5789e30d0 |
child 467 | 762fc0eb4946 |
permissions | -rw-r--r-- |
173 | 1 |
import ENV from 'app-client/config/environment'; |
2 |
import _ from 'lodash/lodash'; |
|
3 |
import * as constants from 'corpus-common-addon/utils/constants'; |
|
466
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
4 |
import Collection from 'ember-cli-mirage/orm/collection'; |
173 | 5 |
|
6 |
export default function() { |
|
7 |
||
8 |
// These comments are here to help you get started. Feel free to delete them. |
|
9 |
||
10 |
/* |
|
11 |
Config (with defaults). |
|
12 |
||
13 |
Note: these only affect routes defined *after* them! |
|
14 |
*/ |
|
15 |
// this.urlPrefix = ''; // make this `http://localhost:8080`, for example, if your API is on a different server |
|
16 |
// this.namespace = ''; // make this `api`, for example, if your API is namespaced |
|
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
17 |
this.namespace = (ENV.APP.backRootURL || ENV.rootURL).replace(/\/$/,'')+'/api/v1'; |
173 | 18 |
// this.timing = 400; // delay for each request, automatically set to 0 during testing |
19 |
||
20 |
this.get('/documents', function({ documents }) { |
|
21 |
return this.serialize(documents.all(), 'sparse-document'); |
|
22 |
}); |
|
245
c9dd78a43b07
Transcript model and erializer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
173
diff
changeset
|
23 |
|
173 | 24 |
this.get('/documents/:id', ({documents}, request) => { |
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
25 |
let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
173 | 26 |
return documents.find(id); |
27 |
}); |
|
28 |
||
29 |
this.get('/documents/:id/transcript', ({transcripts}, request) => { |
|
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
318
diff
changeset
|
30 |
let id = decodeURIComponent(decodeURIComponent(request.params.id)); |
173 | 31 |
return transcripts.find(id).transcript; |
32 |
}); |
|
33 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
34 |
this.get('/stats/languages', 'languages'); |
173 | 35 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
36 |
this.get('/stats/geostats', 'geostats'); |
274
53a6985443f8
geostats endpoint + mapvar
Chloe Laisne <chloe.laisne@gmail.com>
parents:
261
diff
changeset
|
37 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
38 |
this.get('/stats/themes', 'themes'); |
173 | 39 |
|
466
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
40 |
this.get('/stats/discourses', ({discourses}, request) => { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
41 |
console.log("DISCOURSES", request.queryParams, discourses.all(), discourses.all().models); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
42 |
|
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
43 |
if(request.queryParams['discourse']) { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
44 |
var res = []; |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
45 |
request.queryParams.discourse.forEach( did => { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
46 |
let d = discourses.find(did); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
47 |
if(d) { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
48 |
res.push(d); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
49 |
} |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
50 |
}); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
51 |
let allDiscourses = discourses.all().models; |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
52 |
let i=0; |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
53 |
while(i<allDiscourses.length && res.length < (allDiscourses.length/2)) { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
54 |
let d = allDiscourses[i++]; |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
55 |
if(!_.contains(request.queryParams.discourse, d.id)) { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
56 |
d.count = Math.floor(d.count / 2); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
57 |
res.push(d); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
58 |
} |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
59 |
} |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
60 |
console.log("DISCOURSES", request.queryParams, { modelName: "discourse", models: res }); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
61 |
//return discourses.all(); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
62 |
return new Collection('discourse', res); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
63 |
} else { |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
64 |
return discourses.all(); |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
65 |
} |
a8effb60ccb6
correct discourse display and update
ymh <ymh.work@gmail.com>
parents:
447
diff
changeset
|
66 |
}); |
173 | 67 |
|
307 | 68 |
this.get('/stats/datestats', 'datestats'); |
69 |
||
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
329
diff
changeset
|
70 |
this.get('/stats/dateminmax', 'dateminmax'); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
329
diff
changeset
|
71 |
|
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
72 |
this.get('/resolvers/lexvo/:ids', ({lexvos}, request) => { |
173 | 73 |
var langIds = decodeURIComponent(request.params.ids); |
74 |
var resMap = _.reduce(langIds.split(','), function(res, id) { |
|
75 |
var fullId = id; |
|
329
0a2c2ad49d75
Improvce language visualization. Generalize language node selection, change language query parameters, add resolution of node name (corpus-) to lexvo controler
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
76 |
if(!_.startsWith(fullId, constants.LEXVO_BASE_URL) && !_.startsWith(fullId, constants.LANGUAGES_NODE_PREFIX)) { |
173 | 77 |
fullId = constants.LEXVO_BASE_URL + id; |
78 |
} |
|
79 |
var lexvoRes = lexvos.find(fullId); |
|
80 |
res[id] = lexvoRes?lexvoRes.name:null; |
|
81 |
return res; |
|
82 |
}, {}); |
|
83 |
return { |
|
84 |
'lexvoids': resMap |
|
85 |
}; |
|
86 |
}); |
|
87 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
88 |
this.get('/resolvers/bnf/:ids', ({ bnfs }, request) => { |
173 | 89 |
var bnfIds = decodeURIComponent(request.params.ids); |
90 |
var resMap = _.reduce(bnfIds.split(','), function(res, id) { |
|
91 |
var fullId = id; |
|
92 |
if(_.startsWith(fullId, constants.BNF_BASE_URL)) { |
|
93 |
fullId = fullId.slice(constants.BNF_BASE_URL.length); |
|
94 |
} else if (_.startsWith(fullId, constants.BNF_ARK_BASE_URL)) { |
|
95 |
fullId = fullId.slice(constants.BNF_ARK_BASE_URL.length); |
|
96 |
} else if (!_.startsWith(fullId, constants.BNF_ARK_BASE_ID)) { |
|
97 |
fullId = constants.BNF_ARK_BASE_ID + fullId; |
|
98 |
} |
|
99 |
var bnfRes = bnfs.find(fullId); |
|
100 |
res[id] = bnfRes?bnfRes.label:null; |
|
101 |
return res; |
|
102 |
}, {}); |
|
103 |
return { |
|
104 |
'bnfids': resMap |
|
105 |
}; |
|
106 |
}); |
|
107 |
||
305
ff6cf3fc5f40
api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents:
304
diff
changeset
|
108 |
this.get('/resolvers/geonames/:ids', ({ geonames }, request) => { |
304
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
109 |
var geonamesIds = decodeURIComponent(request.params.ids); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
110 |
var resMap = _.reduce(geonamesIds.split(','), function(res, id) { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
111 |
var code = id; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
112 |
var m = code.match(constants.GEONAMES_BASE_URLS); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
113 |
if(m) { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
114 |
code = code.slice(m[0].length); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
115 |
} |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
116 |
code = code.replace(/\/+$/, ''); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
117 |
var geonamesRes = geonames.find(code); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
118 |
res[id] = geonamesRes?geonamesRes.label:null; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
119 |
return res; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
120 |
}, {}); |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
121 |
return { |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
122 |
'geonamesids': resMap |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
123 |
}; |
20071981ba2a
add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
278
diff
changeset
|
124 |
}); |
173 | 125 |
|
447
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
126 |
this.get('/resolvers/viaf/:ids', ({viafs}, request) => { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
127 |
var viafIds = decodeURIComponent(request.params.ids); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
128 |
var resMap = _.reduce(viafIds.split(','), function(res, id) { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
129 |
var fullId = id; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
130 |
if(!_.startsWith(fullId, constants.VIAF_BASE_URL)) { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
131 |
fullId = constants.VIAF_BASE_URL + id; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
132 |
} |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
133 |
var viafRes = viafs.find(fullId); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
134 |
res[id] = viafRes?viafRes.name:null; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
135 |
return res; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
136 |
}, {}); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
137 |
return { |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
138 |
'viafids': resMap |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
139 |
}; |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
140 |
}); |
38d5789e30d0
Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents:
424
diff
changeset
|
141 |
|
173 | 142 |
} |