Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 1 | var catalog = "/catalog/myUniqueName"; |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 2 | var config = { |
Tyler Scott | 087aef7 | 2015-07-14 14:11:59 -0600 | [diff] [blame] | 3 | host: "atmos-csu.research-lan.colostate.edu", |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 4 | port: 9696 |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 5 | }; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 6 | |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 7 | //Run when the document loads. |
| 8 | $(function () { |
Tyler Scott | bb01356 | 2015-07-16 15:52:40 -0600 | [diff] [blame] | 9 | new Atmos(catalog, config); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 10 | }); |
| 11 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 12 | var Atmos = (function(){ |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 13 | "use strict"; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 14 | /** |
| 15 | * Atmos |
| 16 | * @version 2.0 |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 17 | * |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 18 | * Configures an Atmos object. This manages the atmos interface. |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 19 | * |
| 20 | * @constructor |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 21 | * @param {string} catalog - NDN path |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 22 | * @param {Object} config - Object of configuration options for a Face. |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 23 | */ |
| 24 | function Atmos(catalog, config){ |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 25 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 26 | //Internal variables. |
| 27 | this.results = []; |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 28 | this.resultCount = 0; |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 29 | this.name = null; |
| 30 | this.page = 0; |
| 31 | this.lastPage = -1; |
| 32 | //this.itemsPerPage = 25; //TODO |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame] | 33 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 34 | this.catalog = catalog; |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 35 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 36 | this.face = new Face(config); |
| 37 | this.categories = $('#side-menu'); |
| 38 | this.resultTable = $('#resultTable'); |
| 39 | this.filters = $('#filters'); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 40 | this.searchInput = $('#search'); |
| 41 | this.searchBar = $('#searchBar'); |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 42 | this.searchButton = $('#searchButton'); |
| 43 | this.pagers = $('.pager'); |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 44 | this.alerts = $('#alerts'); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 45 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 46 | var scope = this; |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 47 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 48 | this.resultTable.on('click', '.interest-button', function(){ |
| 49 | var button = $(this); |
Tyler Scott | 087aef7 | 2015-07-14 14:11:59 -0600 | [diff] [blame] | 50 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 51 | if (button.is(':disabled')){ |
| 52 | console.warn("Attempt to request again!"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 53 | } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 54 | |
| 55 | var name = button.parent().prev().text(); |
| 56 | var interest = new Interest(new Name('/retrieve' + name)); |
| 57 | scope.face.expressInterest(interest, function(){}, function(){}); |
| 58 | |
| 59 | button.text("Requested!") |
| 60 | .removeClass('btn-primary') |
| 61 | .addClass('btn-default') |
| 62 | .addClass('disabled') |
| 63 | .prop('disabled', true); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 64 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 65 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 66 | //Filter setup |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 67 | $.getJSON("search_catagories.json").done(function (data) { |
| 68 | $.each(data, function (pageSection, contents) { |
| 69 | if (pageSection == "SearchCatagories") { |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 70 | $.each(contents, function (category, searchOptions) { |
| 71 | //Create the category |
| 72 | var e = $('<li><a href="#">' + category.replace(/\_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>'); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 73 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 74 | var sub = e.find('ul.subnav'); |
| 75 | $.each(searchOptions, function(index, name){ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 76 | //Create the filter list inside the category |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 77 | var item = $('<li><a href="#">' + name + '</a></li>'); |
| 78 | sub.append(item); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 79 | item.click(function(){ //Click on the side menu filters |
| 80 | if (item.hasClass('active')){ //Does the filter already exist? |
| 81 | item.removeClass('active'); |
| 82 | scope.filters.find(':contains(' + category + ':' + name + ')').remove(); |
| 83 | } else { //Add a filter |
| 84 | item.addClass('active'); |
| 85 | var filter = $('<span class="label label-default"></span>'); |
| 86 | filter.text(category + ':' + name); |
| 87 | |
| 88 | scope.filters.append(filter); |
| 89 | |
| 90 | filter.click(function(){ //Click on a filter |
| 91 | filter.remove(); |
| 92 | item.removeClass('active'); |
| 93 | }); |
| 94 | } |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 95 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 96 | }); |
| 97 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 98 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 99 | //Toggle the menus. (Only respond when the immediate tab is clicked.) |
| 100 | e.find('> a').click(function(){ |
| 101 | scope.categories.find('.subnav').slideUp(); |
| 102 | var t = $(this).siblings('.subnav'); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 103 | if ( !t.is(':visible') ){ //If the sub menu is not visible |
| 104 | t.slideDown(function(){ |
| 105 | t.triggerHandler('focus'); |
| 106 | }); //Make it visible and look at it. |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 107 | } |
| 108 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 109 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 110 | scope.categories.append(e); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 111 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 112 | }); |
| 113 | } |
| 114 | }); |
| 115 | }); |
| 116 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 117 | this.searchInput.autoComplete(function(field, callback){ |
| 118 | scope.autoComplete(field, callback); |
| 119 | }); |
| 120 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 121 | this.searchBar.submit(function(e){ |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 122 | e.preventDefault(); |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 123 | console.warn("This feature is incomplete."); |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 124 | }); |
| 125 | |
| 126 | this.searchButton.click(function(){ |
| 127 | console.log("Search Button Pressed"); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 128 | scope.search(); |
| 129 | }); |
| 130 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 131 | this.pagers.find('.next').click(function(){ |
| 132 | if (!$(this).hasClass('disabled')){ |
| 133 | scope.getResults(scope.page + 1); |
| 134 | } |
| 135 | }); |
| 136 | this.pagers.find('.previous').click(function(){ |
| 137 | if (!$(this).hasClass('disabled')){ |
| 138 | scope.getResults(scope.page - 1); |
| 139 | } |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 140 | }); |
| 141 | |
| 142 | } |
| 143 | |
| 144 | Atmos.prototype.search = function(){ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 145 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 146 | var filters = this.getFilters(); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 147 | |
| 148 | console.log("Search started!", this.searchInput.val(), filters); |
| 149 | |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 150 | console.log("Initiating query"); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 151 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 152 | this.results = []; //Drop any old results. |
| 153 | this.resultTable.empty(); |
| 154 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame] | 155 | var scope = this; |
| 156 | |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 157 | this.query(this.catalog, filters, |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 158 | function(interest, data){ //Response function |
| 159 | console.log("Query Response:", interest, data); |
| 160 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame] | 161 | var parameters = JSON.stringify(filters); |
| 162 | |
| 163 | var ack = data.getName(); |
| 164 | |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 165 | scope.name = new Name(scope.catalog).append("query-results").append(parameters).append(ack.get(-3)).append(ack.get(-2)); |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame] | 166 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 167 | scope.getResults(0); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 168 | |
| 169 | }, function(interest){ //Timeout function |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 170 | console.warn("Request failed! Timeout"); |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 171 | scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 172 | }); |
| 173 | |
| 174 | } |
| 175 | |
| 176 | Atmos.prototype.autoComplete = function(field, callback){ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 177 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 178 | if (this.searchInput.val().length === 0 && !filters.hasOwnProperty()){ |
| 179 | if (!this.searchBar.hasClass('has-error')){ |
| 180 | this.searchBar.addClass('has-error').append('<span class="help-block">A filter or search value is required!</span>'); |
| 181 | } |
| 182 | return; |
| 183 | } else { |
| 184 | this.searchBar.removeClass('has-error').find('.help-block').fadeOut(function(){$(this).remove()}); |
| 185 | } |
| 186 | |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 187 | var scope = this; |
| 188 | |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 189 | this.query(this.catalog, {"?": field}, |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 190 | function(interest, data){ |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 191 | |
| 192 | var ack = data.getName(); |
| 193 | |
Tyler Scott | 9eb6abd | 2015-08-04 14:48:23 -0600 | [diff] [blame^] | 194 | var name = new Name(scope.catalog).append('query-results').append(JSON.stringify({"?": field})).append(ack.get(-3)).append(ack.get(-2)); |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 195 | |
| 196 | scope.face.expressInterest(new Interest(name).setInterestLifetimeMilliseconds(5000), |
| 197 | function(interest, data){ |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 198 | |
Tyler Scott | fe8e493 | 2015-07-28 17:45:45 -0600 | [diff] [blame] | 199 | if (data.getContent().length !== 0){ |
| 200 | var options = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")).next.map(function(element){ |
| 201 | return field + element; |
| 202 | }); |
| 203 | callback(options); |
| 204 | } |
| 205 | |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 206 | }, function(interest){ |
| 207 | console.warn("Interest timed out!", interest); |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 208 | scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 209 | }); |
| 210 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 211 | }, function(interest){ |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 212 | console.error("Request failed! Timeout", interest); |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 213 | scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 214 | }); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 215 | |
Tyler Scott | 424ee10 | 2015-07-14 16:50:41 -0600 | [diff] [blame] | 216 | } |
| 217 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 218 | Atmos.prototype.showResults = function(resultIndex) { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 219 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 220 | var results = $('<tr><td>' + this.results[resultIndex].join('</td><td><button class="interest-button btn btn-primary btn-sm">Retrieve</button></td></tr><tr><td>') + |
| 221 | '</td><td><button class="interest-button btn btn-primary btn-sm">Retrieve</button></td></tr>'); //Fastest way to generate the table. |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 222 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 223 | this.resultTable.empty().append(results); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 224 | |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 225 | this.pagers.find('.totalResults').text('(Page' + (resultIndex + 1) + ') Showing ' + this.results[resultIndex].length + ' of ' + this.resultCount + ' results'); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 226 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 227 | if (resultIndex === this.lastPage) { |
| 228 | this.pagers.find('.next').addClass('disabled'); |
| 229 | } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 230 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 231 | if (resultIndex === 0){ |
| 232 | this.pagers.find('.next').removeClass('disabled'); |
| 233 | this.pagers.find('.previous').addClass('disabled'); |
| 234 | } else if (resultIndex === 1) { |
| 235 | this.pagers.find('.previous').removeClass('disabled'); |
| 236 | } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 237 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 238 | } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 239 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 240 | Atmos.prototype.getResults = function(index){ |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 241 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 242 | if (this.results[index]){ |
| 243 | //console.log("We already have index", index); |
| 244 | this.page = index; |
| 245 | this.showResults(index); |
| 246 | return; |
| 247 | } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 248 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 249 | if (this.name === null) { |
| 250 | console.error("This shouldn't be reached! We are getting results before a search has occured!"); |
| 251 | throw new Error("Illegal State"); |
| 252 | } |
Tyler Scott | 424ee10 | 2015-07-14 16:50:41 -0600 | [diff] [blame] | 253 | |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 254 | var first = new Name(this.name).appendSegment(index); |
| 255 | |
Tyler Scott | b6e329f | 2015-07-28 16:08:33 -0600 | [diff] [blame] | 256 | console.log("Requesting data index: (", index, ") at ", first.toUri()); |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 257 | |
| 258 | var scope = this; |
| 259 | |
| 260 | this.face.expressInterest(new Interest(first).setInterestLifetimeMilliseconds(5000), |
| 261 | function(interest, data){ //Response |
| 262 | |
| 263 | if (data.getContent().length === 0){ |
| 264 | console.log("Empty response."); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | if (data.getName().get(-1).equals(data.getMetaInfo().getFinalBlockId())) { //Final page. |
| 269 | scope.lastPage = index; |
| 270 | //The next buttons will be disabled by showResults. |
| 271 | } |
| 272 | |
| 273 | var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g,"")); |
| 274 | |
| 275 | var results = scope.results[index] = content.results; |
| 276 | |
| 277 | scope.resultCount = content.resultCount; |
| 278 | |
| 279 | scope.pagers.find('.totalResults').text(scope.resultCount + " Results"); |
| 280 | |
| 281 | //console.log("Got results:", results); |
| 282 | |
| 283 | scope.page = index; |
| 284 | |
| 285 | if (!results){ |
| 286 | console.log("No results were found!"); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | scope.showResults(index); |
| 291 | |
| 292 | }, |
| 293 | function(interest){ //Timeout |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 294 | console.error("Failed to retrieve results: timeout", interest); |
| 295 | scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | c55879f | 2015-07-28 14:56:37 -0600 | [diff] [blame] | 296 | } |
| 297 | ); |
| 298 | |
| 299 | } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 300 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 301 | Atmos.prototype.query = function(prefix, parameters, callback, timeout) { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 302 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 303 | var queryPrefix = new Name(prefix); |
| 304 | queryPrefix.append("query"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 305 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 306 | var jsonString = JSON.stringify(parameters); |
| 307 | queryPrefix.append(jsonString); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 308 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 309 | var queryInterest = new Interest(queryPrefix); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 310 | queryInterest.setInterestLifetimeMilliseconds(4000); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 311 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 312 | this.face.expressInterest(queryInterest, callback, timeout); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 313 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 314 | } |
| 315 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 316 | /** |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 317 | * This function returns a map of all the categories active filters. |
| 318 | * @return {Object<string, string>} |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 319 | */ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 320 | Atmos.prototype.getFilters = function(){ |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 321 | var filters = this.filters.children().toArray().reduce(function(prev, current){ |
Tyler Scott | 575c61b | 2015-07-13 13:42:16 -0600 | [diff] [blame] | 322 | var data = $(current).text().split(/:/); |
| 323 | prev[data[0]] = data[1]; |
| 324 | return prev; |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 325 | }, {}); //Collect a map<category, filter>. |
| 326 | //TODO Make the return value map<category, Array<filter>> |
| 327 | return filters; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 328 | } |
| 329 | |
Tyler Scott | 4d95122 | 2015-07-31 14:38:27 -0600 | [diff] [blame] | 330 | /** |
| 331 | * Creates a closable alert for the user. |
| 332 | * |
| 333 | * @param {string} message |
| 334 | * @param {string} type - Override the alert type. |
| 335 | */ |
| 336 | Atmos.prototype.createAlert = function(message, type) { |
| 337 | |
| 338 | var alert = $('<div class="alert"><div>'); |
| 339 | alert.addClass(type?type:'alert-info'); |
| 340 | alert.text(message); |
| 341 | alert.append(Atmos.closeButton); |
| 342 | |
| 343 | this.alerts.append(alert); |
| 344 | } |
| 345 | Atmos.closeButton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'; |
| 346 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 347 | return Atmos; |
| 348 | |
| 349 | })(); |
| 350 | |
| 351 | |