forked from sjcporter/CapabilityMaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelastic_cap.js
63 lines (51 loc) · 1.79 KB
/
elastic_cap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//@ sourceURL=elastic_cap.js
(function($){
'use strict';
console.log('ready elastic_cap 1');
// The JSON list url
var esurl = "https://vivo.colorado.edu/es/fis/person/_search?callback=?&source=";
var esdsl = {
"size": 0,
"aggs" : {
"researchAreas" : {
"terms" : {"field" : "researchArea.name.exact", "size": 0}
}
}
}
var esdslreq = "source=" + JSON.stringify(esdsl);
function createList(rtopics) {
// get the datalist element
var datalist = $("#rtopiclist select");
// $('<select>').appendTo(datalist)
// Fill it with the rtopics array
for(var i=0; i < rtopics.length; i++){
$('<option value="'+rtopics[i]+'">' +rtopics[i]+'</option>').appendTo(datalist);
}
// $('</select>').appendTo(datalist)
}
function loadDatas( callback ){
// Make the ajax call
$.getJSON(esurl, esdslreq, function(list){
// create the rtopics array
var rtopics =[];
var rbuckets=list.aggregations.researchAreas.buckets;
for(var i=0; i < rbuckets.length; i++){
rtopics.push(rbuckets[i].key);
}
// Call the function that will create the options
// But sort the array first (for better user experience)
callback(rtopics.sort());
});
}
// jQuery OnLoad ...
$(function(){
loadDatas( createList );
console.log('ready elastic_cap 2');
/*
var availableTags = $('#rtopiclist').find('option').map(function () {
return this.value;
}).get();
$('#query').autocomplete({ source: availableTags });
*/
});
})(jQuery);