blob: 347366ea4550338e2a50bf29535c3936516c2814 [file] [log] [blame]
Tyler Scott696d38f2015-08-04 22:41:22 -06001//Run when the document loads AND we have the config loaded.
2(function(){
3 var catalog = null;
4 var config = null;
5 Promise.all([
6 new Promise(function(resolve, reject){
7 $.ajax('config.json').done(function(data){
8 catalog = data.catalogPrefix;
9 config = data.faceConfig;
10 resolve();
11 }).fail(function(){
12 console.error("Failed to get config.");
13 reject()
14 });
15 }),
16 new Promise(function(resolve, reject){
17 var timeout = setTimeout(function(){
18 console.error("Document never loaded? Something bad has happened!");
19 reject();
20 }, 10000);
21 $(function () {
22 clearTimeout(timeout);
23 resolve();
24 });
25 })
26 ]).then(function(){
27 new Atmos(catalog, config);
28 }, function(){
29 console.error("Failed to initialize!");
30 })
31})();
Tyler Scott3c17d5f2015-06-23 17:49:29 -060032
Tyler Scott93cae872015-07-21 14:58:23 -060033var Atmos = (function(){
Tyler Scott7d076e22015-07-06 19:21:50 -060034 "use strict";
Tyler Scott93cae872015-07-21 14:58:23 -060035 /**
36 * Atmos
37 * @version 2.0
Tyler Scott4d951222015-07-31 14:38:27 -060038 *
Tyler Scott93cae872015-07-21 14:58:23 -060039 * Configures an Atmos object. This manages the atmos interface.
Tyler Scott4d951222015-07-31 14:38:27 -060040 *
41 * @constructor
Tyler Scott93cae872015-07-21 14:58:23 -060042 * @param {string} catalog - NDN path
Tyler Scott4d951222015-07-31 14:38:27 -060043 * @param {Object} config - Object of configuration options for a Face.
Tyler Scott93cae872015-07-21 14:58:23 -060044 */
45 function Atmos(catalog, config){
Tyler Scott7d076e22015-07-06 19:21:50 -060046
Tyler Scott93cae872015-07-21 14:58:23 -060047 //Internal variables.
48 this.results = [];
Tyler Scott4e4865a2015-08-06 14:23:21 -060049 this.resultCount = Infinity;
Tyler Scottc55879f2015-07-28 14:56:37 -060050 this.name = null;
51 this.page = 0;
Tyler Scott4e4865a2015-08-06 14:23:21 -060052 this.resultsPerPage = 25;
53 this.retrievedSegments = 0;
Tyler Scotte815d3e2015-07-09 16:56:17 -060054
Tyler Scott93cae872015-07-21 14:58:23 -060055 this.catalog = catalog;
Tyler Scott7d076e22015-07-06 19:21:50 -060056
Tyler Scott93cae872015-07-21 14:58:23 -060057 this.face = new Face(config);
Tyler Scott696d38f2015-08-04 22:41:22 -060058
Tyler Scott93cae872015-07-21 14:58:23 -060059 this.categories = $('#side-menu');
60 this.resultTable = $('#resultTable');
61 this.filters = $('#filters');
Tyler Scotta1530052015-07-24 00:13:28 -060062 this.searchInput = $('#search');
63 this.searchBar = $('#searchBar');
Tyler Scottc55879f2015-07-28 14:56:37 -060064 this.searchButton = $('#searchButton');
Tyler Scott3fc05272015-08-17 18:02:35 -060065 this.resultMenu = $('.resultMenu');
Tyler Scott4d951222015-07-31 14:38:27 -060066 this.alerts = $('#alerts');
Tyler Scott7d076e22015-07-06 19:21:50 -060067
Tyler Scott93cae872015-07-21 14:58:23 -060068 var scope = this;
Tyler Scott7d076e22015-07-06 19:21:50 -060069
Tyler Scott93cae872015-07-21 14:58:23 -060070 this.resultTable.on('click', '.interest-button', function(){
Tyler Scott3fc05272015-08-17 18:02:35 -060071 scope.request(this);
Tyler Scott7d076e22015-07-06 19:21:50 -060072 });
Tyler Scott7d076e22015-07-06 19:21:50 -060073
Tyler Scott3fc05272015-08-17 18:02:35 -060074 $('.requestSelectedButton').click(function(){
75 scope.request(
76 scope.resultTable.find('.resultSelector:checked:not([disabled])')
77 .parent().next().find('.interest-button')
78 );
Tyler Scott93cae872015-07-21 14:58:23 -060079 });
80
Tyler Scott3fc05272015-08-17 18:02:35 -060081 this.filterSetup();
82
Tyler Scottc55879f2015-07-28 14:56:37 -060083 this.searchInput.autoComplete(function(field, callback){
84 scope.autoComplete(field, callback);
85 });
86
Tyler Scotta1530052015-07-24 00:13:28 -060087 this.searchBar.submit(function(e){
Tyler Scott93cae872015-07-21 14:58:23 -060088 e.preventDefault();
Tyler Scott6b810812015-08-11 18:20:05 -060089 scope.pathSearch();
Tyler Scottc55879f2015-07-28 14:56:37 -060090 });
91
92 this.searchButton.click(function(){
93 console.log("Search Button Pressed");
Tyler Scotta1530052015-07-24 00:13:28 -060094 scope.search();
95 });
96
Tyler Scott3fc05272015-08-17 18:02:35 -060097 this.resultMenu.find('.next').click(function(){
Tyler Scottc55879f2015-07-28 14:56:37 -060098 if (!$(this).hasClass('disabled')){
99 scope.getResults(scope.page + 1);
100 }
101 });
Tyler Scott3fc05272015-08-17 18:02:35 -0600102 this.resultMenu.find('.previous').click(function(){
Tyler Scottc55879f2015-07-28 14:56:37 -0600103 if (!$(this).hasClass('disabled')){
104 scope.getResults(scope.page - 1);
105 }
Tyler Scotta1530052015-07-24 00:13:28 -0600106 });
Tyler Scott3fc05272015-08-17 18:02:35 -0600107
108 var rpps = $('.resultsPerPageSelector').click(function(){
109
110 var t = $(this);
111
112 if (t.hasClass('active')){
113 return;
114 }
115
116 rpps.find('.active').removeClass('active');
117 t.addClass('active');
118 scope.resultsPerPage = Number(t.text());
119 scope.getResults(0); //Force return to page 1;
120
Tyler Scott4e4865a2015-08-06 14:23:21 -0600121 });
Tyler Scotta1530052015-07-24 00:13:28 -0600122
123 }
124
Tyler Scott6b810812015-08-11 18:20:05 -0600125 Atmos.prototype.clearResults = function(){
126 this.results = []; //Drop any old results.
127 this.retrievedSegments = 0;
128 this.resultCount = Infinity;
129 this.page = 0;
130 this.resultTable.empty();
131 }
132
133 Atmos.prototype.pathSearch = function(){
134 var value = this.searchInput.val();
135
136 this.clearResults();
137
138 var scope = this;
139
140 this.query(this.catalog, {"??": value},
141 function(interest, data){
142 console.log("Query response:", interest, data);
143
Chengyu Fanf4c747a2015-08-18 13:56:01 -0600144 scope.name = data.getContent().toString().replace(/[\n\0]/g,"");
Tyler Scott6b810812015-08-11 18:20:05 -0600145
146 scope.getResults(0);
147
148 },
149 function(interest){
150 console.warn("Request failed! Timeout", interest);
151 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
152 });
153
154 }
155
Tyler Scotta1530052015-07-24 00:13:28 -0600156 Atmos.prototype.search = function(){
Tyler Scotta1530052015-07-24 00:13:28 -0600157
Tyler Scottc55879f2015-07-28 14:56:37 -0600158 var filters = this.getFilters();
Tyler Scotta1530052015-07-24 00:13:28 -0600159
160 console.log("Search started!", this.searchInput.val(), filters);
161
Tyler Scott4d951222015-07-31 14:38:27 -0600162 console.log("Initiating query");
Tyler Scotta1530052015-07-24 00:13:28 -0600163
Tyler Scott6b810812015-08-11 18:20:05 -0600164 this.clearResults();
Tyler Scottc55879f2015-07-28 14:56:37 -0600165
Tyler Scottd90f84e2015-07-27 12:43:04 -0600166 var scope = this;
167
Tyler Scott4d951222015-07-31 14:38:27 -0600168 this.query(this.catalog, filters,
Tyler Scotta1530052015-07-24 00:13:28 -0600169 function(interest, data){ //Response function
170 console.log("Query Response:", interest, data);
171
Chengyu Fanf4c747a2015-08-18 13:56:01 -0600172 scope.name = data.getContent().toString().replace(/[\n\0]/g,"");
Tyler Scottd90f84e2015-07-27 12:43:04 -0600173
Tyler Scottc55879f2015-07-28 14:56:37 -0600174 scope.getResults(0);
Tyler Scotta1530052015-07-24 00:13:28 -0600175
176 }, function(interest){ //Timeout function
Tyler Scottb6e329f2015-07-28 16:08:33 -0600177 console.warn("Request failed! Timeout");
Tyler Scott4d951222015-07-31 14:38:27 -0600178 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
Tyler Scotta1530052015-07-24 00:13:28 -0600179 });
180
181 }
182
183 Atmos.prototype.autoComplete = function(field, callback){
Tyler Scotta1530052015-07-24 00:13:28 -0600184
Tyler Scottc55879f2015-07-28 14:56:37 -0600185 if (this.searchInput.val().length === 0 && !filters.hasOwnProperty()){
186 if (!this.searchBar.hasClass('has-error')){
187 this.searchBar.addClass('has-error').append('<span class="help-block">A filter or search value is required!</span>');
188 }
189 return;
190 } else {
191 this.searchBar.removeClass('has-error').find('.help-block').fadeOut(function(){$(this).remove()});
192 }
193
Tyler Scottb6e329f2015-07-28 16:08:33 -0600194 var scope = this;
195
Tyler Scott4d951222015-07-31 14:38:27 -0600196 this.query(this.catalog, {"?": field},
Tyler Scotta1530052015-07-24 00:13:28 -0600197 function(interest, data){
Tyler Scottb6e329f2015-07-28 16:08:33 -0600198
Chengyu Fanf4c747a2015-08-18 13:56:01 -0600199 var name = new Name(data.getContent().toString().replace(/[\n\0]/g,""));
Tyler Scottb6e329f2015-07-28 16:08:33 -0600200
Tyler Scottab822fe2015-08-10 14:38:49 -0600201 var interest = new Interest(name);
202 interest.setInterestLifetimeMilliseconds(5000);
203 interest.setMustBeFresh(true);
204
205 scope.face.expressInterest(interest,
Tyler Scottb6e329f2015-07-28 16:08:33 -0600206 function(interest, data){
Tyler Scott4d951222015-07-31 14:38:27 -0600207
Tyler Scottfe8e4932015-07-28 17:45:45 -0600208 if (data.getContent().length !== 0){
209 var options = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")).next.map(function(element){
Tyler Scottfc990392015-08-10 13:48:03 -0600210 return field + element + "/";
Tyler Scottfe8e4932015-07-28 17:45:45 -0600211 });
212 callback(options);
213 }
214
Tyler Scottb6e329f2015-07-28 16:08:33 -0600215 }, function(interest){
216 console.warn("Interest timed out!", interest);
Tyler Scott4d951222015-07-31 14:38:27 -0600217 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
Tyler Scottb6e329f2015-07-28 16:08:33 -0600218 });
219
Tyler Scotta1530052015-07-24 00:13:28 -0600220 }, function(interest){
Tyler Scottb6e329f2015-07-28 16:08:33 -0600221 console.error("Request failed! Timeout", interest);
Tyler Scott4d951222015-07-31 14:38:27 -0600222 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
Tyler Scotta1530052015-07-24 00:13:28 -0600223 });
Tyler Scott93cae872015-07-21 14:58:23 -0600224
Tyler Scott424ee102015-07-14 16:50:41 -0600225 }
226
Tyler Scottc55879f2015-07-28 14:56:37 -0600227 Atmos.prototype.showResults = function(resultIndex) {
Tyler Scott7d076e22015-07-06 19:21:50 -0600228
Tyler Scott3fc05272015-08-17 18:02:35 -0600229 if ($('#results').hasClass('hidden')){
230 $('#results').removeClass('hidden').slideDown();
231 }
232
Tyler Scott4e4865a2015-08-06 14:23:21 -0600233 var results = this.results.slice(this.resultsPerPage * resultIndex, this.resultsPerPage * (resultIndex + 1));
234
Tyler Scott3fc05272015-08-17 18:02:35 -0600235 var resultDOM = $(
236 results.reduce(function(prev, current){
237 prev.push('<tr><td><input class="resultSelector" type="checkbox"></td><td>');
238 prev.push(current);
239 prev.push('</td></tr>');
240 return prev;
241 }, ['<tr><th><input id="resultSelectAll" type="checkbox" title="Select All"> Select</th><th>Name</th></tr>']).join('')
242 );
Tyler Scott7d076e22015-07-06 19:21:50 -0600243
Tyler Scott3fc05272015-08-17 18:02:35 -0600244 resultDOM.find('#resultSelectAll').click(function(){
245 if ($(this).is(':checked')){
246 resultDOM.find('.resultSelector:not([disabled])').prop('checked', true);
247 } else {
248 resultDOM.find('.resultSelector:not([disabled])').prop('checked', false);
249 }
250 });
Tyler Scott7d076e22015-07-06 19:21:50 -0600251
Tyler Scott3fc05272015-08-17 18:02:35 -0600252 this.resultTable.empty().append(resultDOM).slideDown();
253 if (this.resultMenu.hasClass('hidden')){
254 this.resultMenu.removeClass('hidden').slideDown();
255 }
256
257 this.resultMenu.find('.pageNumber').text(resultIndex + 1);
258 this.resultMenu.find('.pageLength').text(this.resultsPerPage * (resultIndex + 1));
Tyler Scott7d076e22015-07-06 19:21:50 -0600259
Tyler Scott4e4865a2015-08-06 14:23:21 -0600260 if (this.resultsPerPage * (resultIndex + 1) >= this.resultCount) {
Tyler Scott3fc05272015-08-17 18:02:35 -0600261 this.resultMenu.find('.next').addClass('disabled');
Tyler Scott4e4865a2015-08-06 14:23:21 -0600262 } else if (resultIndex === 0){
Tyler Scott3fc05272015-08-17 18:02:35 -0600263 this.resultMenu.find('.next').removeClass('disabled');
Tyler Scottc55879f2015-07-28 14:56:37 -0600264 }
Tyler Scott93cae872015-07-21 14:58:23 -0600265
Tyler Scottc55879f2015-07-28 14:56:37 -0600266 if (resultIndex === 0){
Tyler Scott3fc05272015-08-17 18:02:35 -0600267 this.resultMenu.find('.previous').addClass('disabled');
Tyler Scottc55879f2015-07-28 14:56:37 -0600268 } else if (resultIndex === 1) {
Tyler Scott3fc05272015-08-17 18:02:35 -0600269 this.resultMenu.find('.previous').removeClass('disabled');
Tyler Scottc55879f2015-07-28 14:56:37 -0600270 }
Tyler Scott93cae872015-07-21 14:58:23 -0600271
Tyler Scottc55879f2015-07-28 14:56:37 -0600272 }
Tyler Scott93cae872015-07-21 14:58:23 -0600273
Tyler Scottc55879f2015-07-28 14:56:37 -0600274 Atmos.prototype.getResults = function(index){
Tyler Scott93cae872015-07-21 14:58:23 -0600275
Tyler Scott4e4865a2015-08-06 14:23:21 -0600276 if ((this.results.length === this.resultCount) || (this.resultsPerPage * (index + 1) < this.results.length)){
Tyler Scottc55879f2015-07-28 14:56:37 -0600277 //console.log("We already have index", index);
278 this.page = index;
279 this.showResults(index);
280 return;
281 }
Tyler Scott7d076e22015-07-06 19:21:50 -0600282
Tyler Scottc55879f2015-07-28 14:56:37 -0600283 if (this.name === null) {
284 console.error("This shouldn't be reached! We are getting results before a search has occured!");
285 throw new Error("Illegal State");
286 }
Tyler Scott424ee102015-07-14 16:50:41 -0600287
Tyler Scott4e4865a2015-08-06 14:23:21 -0600288 var first = new Name(this.name).appendSegment(this.retrievedSegments++);
Tyler Scottc55879f2015-07-28 14:56:37 -0600289
Tyler Scott4e4865a2015-08-06 14:23:21 -0600290 console.log("Requesting data index: (", this.retrievedSegments - 1, ") at ", first.toUri());
Tyler Scottc55879f2015-07-28 14:56:37 -0600291
292 var scope = this;
293
Tyler Scottab822fe2015-08-10 14:38:49 -0600294 var interest = new Interest(first)
295 interest.setInterestLifetimeMilliseconds(5000);
296 interest.setMustBeFresh(true);
297
298 this.face.expressInterest(interest,
Tyler Scottc55879f2015-07-28 14:56:37 -0600299 function(interest, data){ //Response
300
301 if (data.getContent().length === 0){
Tyler Scott3fc05272015-08-17 18:02:35 -0600302 scope.resultMenu.find('.totalResults').text(0);
303 scope.resultMenu.find('.pageNumber').text(0);
Tyler Scottc55879f2015-07-28 14:56:37 -0600304 console.log("Empty response.");
305 return;
306 }
307
Tyler Scottc55879f2015-07-28 14:56:37 -0600308 var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g,""));
309
Tyler Scott4e4865a2015-08-06 14:23:21 -0600310 if (!content.results){
Tyler Scott3fc05272015-08-17 18:02:35 -0600311 scope.resultMenu.find('.totalResults').text(0);
312 scope.resultMenu.find('.pageNumber').text(0);
Tyler Scottc55879f2015-07-28 14:56:37 -0600313 console.log("No results were found!");
314 return;
315 }
316
Tyler Scott4e4865a2015-08-06 14:23:21 -0600317 scope.results = scope.results.concat(content.results);
318
319 scope.resultCount = content.resultCount;
320
Tyler Scott3fc05272015-08-17 18:02:35 -0600321 scope.resultMenu.find('.totalResults').text(scope.resultCount);
Tyler Scott4e4865a2015-08-06 14:23:21 -0600322
323 scope.page = index;
324
325 scope.getResults(index); //Keep calling this until we have enough data.
Tyler Scottc55879f2015-07-28 14:56:37 -0600326
327 },
328 function(interest){ //Timeout
Tyler Scott4d951222015-07-31 14:38:27 -0600329 console.error("Failed to retrieve results: timeout", interest);
330 scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
Tyler Scottc55879f2015-07-28 14:56:37 -0600331 }
332 );
333
334 }
Tyler Scott7d076e22015-07-06 19:21:50 -0600335
Tyler Scotta1530052015-07-24 00:13:28 -0600336 Atmos.prototype.query = function(prefix, parameters, callback, timeout) {
Tyler Scott7d076e22015-07-06 19:21:50 -0600337
Tyler Scott93cae872015-07-21 14:58:23 -0600338 var queryPrefix = new Name(prefix);
339 queryPrefix.append("query");
Tyler Scott7d076e22015-07-06 19:21:50 -0600340
Tyler Scott93cae872015-07-21 14:58:23 -0600341 var jsonString = JSON.stringify(parameters);
342 queryPrefix.append(jsonString);
Tyler Scott7d076e22015-07-06 19:21:50 -0600343
Tyler Scott93cae872015-07-21 14:58:23 -0600344 var queryInterest = new Interest(queryPrefix);
Tyler Scotta1530052015-07-24 00:13:28 -0600345 queryInterest.setInterestLifetimeMilliseconds(4000);
Tyler Scottab822fe2015-08-10 14:38:49 -0600346 queryInterest.setMustBeFresh(true);
Tyler Scott7d076e22015-07-06 19:21:50 -0600347
Tyler Scotta1530052015-07-24 00:13:28 -0600348 this.face.expressInterest(queryInterest, callback, timeout);
Tyler Scott93cae872015-07-21 14:58:23 -0600349
Tyler Scott93cae872015-07-21 14:58:23 -0600350 }
351
Tyler Scott93cae872015-07-21 14:58:23 -0600352 /**
Tyler Scotta1530052015-07-24 00:13:28 -0600353 * This function returns a map of all the categories active filters.
354 * @return {Object<string, string>}
Tyler Scott93cae872015-07-21 14:58:23 -0600355 */
Tyler Scotta1530052015-07-24 00:13:28 -0600356 Atmos.prototype.getFilters = function(){
Tyler Scott93cae872015-07-21 14:58:23 -0600357 var filters = this.filters.children().toArray().reduce(function(prev, current){
Tyler Scott575c61b2015-07-13 13:42:16 -0600358 var data = $(current).text().split(/:/);
359 prev[data[0]] = data[1];
360 return prev;
Tyler Scotta1530052015-07-24 00:13:28 -0600361 }, {}); //Collect a map<category, filter>.
362 //TODO Make the return value map<category, Array<filter>>
363 return filters;
Tyler Scott93cae872015-07-21 14:58:23 -0600364 }
365
Tyler Scott4d951222015-07-31 14:38:27 -0600366 /**
367 * Creates a closable alert for the user.
368 *
369 * @param {string} message
370 * @param {string} type - Override the alert type.
371 */
372 Atmos.prototype.createAlert = function(message, type) {
373
374 var alert = $('<div class="alert"><div>');
375 alert.addClass(type?type:'alert-info');
376 alert.text(message);
377 alert.append(Atmos.closeButton);
378
379 this.alerts.append(alert);
380 }
Tyler Scott3fc05272015-08-17 18:02:35 -0600381
382 /**
383 * Requests all of the names represented by the buttons in the elements list.
384 *
385 * @param elements {Array<jQuery>} A list of the interestButton elements
386 */
387 Atmos.prototype.request = function(elements){
388
389 var scope = this;
390 $(elements).filter(':not(.disabled)').each(function(){
391 var button = $(this);
392
393 if (button.hasClass('disabled')){
394 console.warn("An attempt to request a disabled element has occured");
395 return;
396 }
397
398 var name = button.text();
399 var interest = new Interest(new Name('/retrieve' + name));
400 scope.face.expressInterest(interest, function(){}, function(){});
401
402 })
403 .append('<span class="badge">Requested!</span>')
404 .addClass('disabled')
405 .addClass('label-success')
406 .parent().prev().find('.resultSelector').prop('disabled', true).prop('checked', false);
407
408 }
409
410 Atmos.prototype.filterSetup = function() {
411 //Filter setup
412
413 var prefix = new Name(this.catalog).append("filters-initialization");
414
415 var scope = this;
416
417 this.getAll(prefix, function(data) { //Success
418 var raw = JSON.parse(data.replace(/[\n\0]/g, '')); //Remove null byte and parse
419
420 console.log("Filter categories:", raw);
421
422 $.each(raw, function(index, object){ //Unpack list of objects
423 $.each(object, function(category, searchOptions) { //Unpack category from object (We don't know what it is called)
424 //Create the category
425 var e = $('<li><a href="#">' + category.replace(/\_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>');
426
427 var sub = e.find('ul.subnav');
428 $.each(searchOptions, function(index, name){
429 //Create the filter list inside the category
430 var item = $('<li><a href="#">' + name + '</a></li>');
431 sub.append(item);
432 item.click(function(){ //Click on the side menu filters
433 if (item.hasClass('active')){ //Does the filter already exist?
434 item.removeClass('active');
435 scope.filters.find(':contains(' + category + ':' + name + ')').remove();
436 } else { //Add a filter
437 item.addClass('active');
438 var filter = $('<span class="label label-default"></span>');
439 filter.text(category + ':' + name);
440
441 scope.filters.append(filter);
442
443 filter.click(function(){ //Click on a filter
444 filter.remove();
445 item.removeClass('active');
446 });
447 }
448
449 });
450 });
451
452 //Toggle the menus. (Only respond when the immediate tab is clicked.)
453 e.find('> a').click(function(){
454 scope.categories.find('.subnav').slideUp();
455 var t = $(this).siblings('.subnav');
456 if ( !t.is(':visible') ){ //If the sub menu is not visible
457 t.slideDown(function(){
458 t.triggerHandler('focus');
459 }); //Make it visible and look at it.
460 }
461 });
462
463 scope.categories.append(e);
464
465 });
466 });
467
468 }, function(interest){ //Timeout
469 scope.createAlert("Failed to initialize the filters!", "alert-danger");
470 console.error("Failed to initialize filters!", interest);
471 });
472
473 }
474
475 Atmos.prototype.getAll = function(prefix, callback, timeout){
476
477 var scope = this;
478 var d = [];
479
480 var request = function(segment){
481
482 var name = new Name(prefix);
483 name.appendSegment(segment);
484
485 var interest = new Interest(name);
486 interest.setInterestLifetimeMilliseconds(1000);
487 interest.setMustBeFresh(true); //Is this needed?
488
489 scope.face.expressInterest(interest, handleData, timeout);
490
491 }
492
493
494 var handleData = function(interest, data){
495
496 d.push(data.getContent().toString());
497
498 if (interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment()){
499 callback(d.join(""));
500 } else {
501 request(interest.getName().toSegment()++);
502 }
503
504 }
505
506 request(0);
507
508
509 }
510
Tyler Scott4d951222015-07-31 14:38:27 -0600511 Atmos.closeButton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
512
Tyler Scott93cae872015-07-21 14:58:23 -0600513 return Atmos;
514
515})();