Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 1 | //Run when the document loads AND we have the config loaded. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 2 | (function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 3 | "use strict"; |
| 4 | var config; |
| 5 | Promise.all([ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 6 | new Promise(function(resolve, reject) { |
| 7 | $.ajax('../config.json').done(function(data) { |
| 8 | config = data; |
| 9 | resolve(); |
| 10 | }).fail(function() { |
| 11 | console.error("Failed to get config."); |
| 12 | ga('send', 'event', 'error', 'config'); |
| 13 | reject(); |
| 14 | }); |
| 15 | } |
| 16 | ), |
| 17 | new Promise(function(resolve, reject) { |
| 18 | var timeout = setTimeout(function() { |
| 19 | console.error("Document never loaded? Something bad has happened!"); |
| 20 | reject(); |
| 21 | }, 10000); |
| 22 | $(function() { |
| 23 | clearTimeout(timeout); |
| 24 | resolve(); |
| 25 | }); |
| 26 | } |
| 27 | ) |
| 28 | ]).then(function() { |
Tyler Scott | 2118a41 | 2015-10-29 15:17:05 -0600 | [diff] [blame] | 29 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 30 | var getParameterByName = function(name) { |
| 31 | name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); |
| 32 | var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"); |
| 33 | var results = regex.exec(location.search); |
| 34 | return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); |
| 35 | } |
Tyler Scott | 2118a41 | 2015-10-29 15:17:05 -0600 | [diff] [blame] | 36 | |
| 37 | //Overwrite config if present. Any failure will just cause this to be skipped. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 38 | try { |
Tyler Scott | 2118a41 | 2015-10-29 15:17:05 -0600 | [diff] [blame] | 39 | var configParam = JSON.parse(getParameterByName('config')); |
| 40 | config = jQuery.extend(true, config, configParam); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 41 | } catch (e) { |
Tyler Scott | 2118a41 | 2015-10-29 15:17:05 -0600 | [diff] [blame] | 42 | console.warn("Failure in config overwrite, skipping.", e); |
| 43 | } |
| 44 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 45 | new Atmos(config); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 46 | }, function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 47 | console.error("Failed to initialize!"); |
| 48 | ga('send', 'event', 'error', 'init'); |
| 49 | }); |
| 50 | })(); |
| 51 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 52 | var Atmos = (function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 53 | "use strict"; |
| 54 | |
| 55 | var closeButton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>'; |
| 56 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 57 | var guid = function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 58 | var d = new Date().getTime(); |
| 59 | var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 60 | var r = (d + Math.random() * 16) % 16 | 0; |
| 61 | d = Math.floor(d / 16); |
| 62 | return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 63 | }); |
| 64 | return uuid; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 65 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Atmos |
| 69 | * @version 2.0 |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 70 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 71 | * Configures an Atmos object. This manages the atmos interface. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 72 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 73 | * @constructor |
| 74 | * @param {string} catalog - NDN path |
| 75 | * @param {Object} config - Object of configuration options for a Face. |
| 76 | */ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 77 | var Atmos = function(config) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 78 | |
| 79 | //Internal variables. |
| 80 | this.results = []; |
| 81 | this.resultCount = Infinity; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 82 | this.name = null ; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 83 | this.page = 0; |
| 84 | this.resultsPerPage = 25; |
| 85 | this.retrievedSegments = 0; |
| 86 | |
| 87 | //Config/init |
| 88 | this.config = config; |
| 89 | |
| 90 | this.catalog = config['global']['catalogPrefix']; |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 91 | this.catalogPrefix = new Name(this.catalog); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 92 | |
| 93 | this.face = new Face(config['global']['faceConfig']); |
| 94 | |
| 95 | //Easy access dom variables |
| 96 | this.categories = $('#side-menu'); |
| 97 | this.resultTable = $('#resultTable'); |
| 98 | this.filters = $('#filters'); |
| 99 | this.searchInput = $('#search'); |
| 100 | this.searchBar = $('#searchBar'); |
| 101 | this.searchButton = $('#searchButton'); |
| 102 | this.resultMenu = $('.resultMenu'); |
| 103 | this.alerts = $('#alerts'); |
| 104 | this.requestForm = $('#requestForm'); |
| 105 | |
| 106 | var scope = this; |
| 107 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 108 | $('.requestSelectedButton').click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 109 | ga('send', 'event', 'button', 'click', 'request'); |
| 110 | scope.request(scope.resultTable.find('.resultSelector:checked:not([disabled])').parent().parent()); |
| 111 | }); |
| 112 | |
| 113 | this.filterSetup(); |
| 114 | |
| 115 | //Init autocomplete |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 116 | this.searchInput.autoComplete(function(field, callback) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 117 | ga('send', 'event', 'search', 'autocomplete'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 118 | scope.autoComplete(field, function(data) { |
Tyler Scott | 9445899 | 2015-09-24 14:16:28 -0700 | [diff] [blame] | 119 | var list = data.next; |
| 120 | var last = data.lastComponent === true; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 121 | callback(list.map(function(element) { |
| 122 | return field + element + (last ? "/" : ""); |
| 123 | //Don't add trailing slash for last component. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 124 | })); |
| 125 | }); |
| 126 | }); |
| 127 | |
| 128 | //Handle search |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 129 | this.searchBar.submit(function(e) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 130 | ga('send', 'event', 'search', 'submit'); |
| 131 | e.preventDefault(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 132 | if (scope.searchInput.val().length === 0) { |
| 133 | if (!scope.searchBar.hasClass('has-error')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 134 | scope.searchBar.addClass('has-error').append('<span class="help-block">Search path is required!</span>'); |
| 135 | } |
| 136 | return; |
| 137 | } else { |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 138 | scope.searchBar.removeClass('has-error').find('.help-block').fadeOut(function() { |
| 139 | $(this).remove() |
| 140 | }); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 141 | } |
| 142 | scope.pathSearch(); |
| 143 | }); |
| 144 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 145 | this.searchButton.click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 146 | console.log("Search Button Pressed"); |
| 147 | ga('send', 'event', 'button', 'click', 'search'); |
| 148 | scope.search(); |
| 149 | }); |
| 150 | |
| 151 | //Result navigation handlers |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 152 | this.resultMenu.find('.next').click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 153 | ga('send', 'event', 'button', 'click', 'next'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 154 | if (!$(this).hasClass('disabled')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 155 | scope.getResults(scope.page + 1); |
| 156 | } |
| 157 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 158 | this.resultMenu.find('.previous').click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 159 | ga('send', 'event', 'button', 'click', 'previous'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 160 | if (!$(this).hasClass('disabled')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 161 | scope.getResults(scope.page - 1); |
| 162 | } |
| 163 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 164 | this.resultMenu.find('.clearResults').click(function() { |
Tyler Scott | e8dac70 | 2015-10-13 14:33:25 -0600 | [diff] [blame] | 165 | ga('send', 'event', 'button', 'click', 'resultClear'); |
| 166 | scope.clearResults(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 167 | $('#results').fadeOut(function() { |
Tyler Scott | e8dac70 | 2015-10-13 14:33:25 -0600 | [diff] [blame] | 168 | $(this).addClass('hidden'); |
| 169 | }); |
| 170 | }); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 171 | |
| 172 | //Change the number of results per page handler |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 173 | var rpps = $('.resultsPerPageSelector').click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 174 | |
| 175 | var t = $(this); |
| 176 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 177 | if (t.hasClass('active')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
| 181 | rpps.find('.active').removeClass('active'); |
| 182 | t.addClass('active'); |
| 183 | scope.resultsPerPage = Number(t.text()); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 184 | scope.getResults(0); |
| 185 | //Force return to page 1; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 186 | |
| 187 | }); |
| 188 | |
| 189 | //Init tree search |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 190 | $('#treeSearch div').treeExplorer(function(path, callback) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 191 | console.log("Tree Explorer request", path); |
| 192 | ga('send', 'event', 'tree', 'request'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 193 | scope.autoComplete(path, function(data) { |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 194 | var list = data.next; |
| 195 | var last = (data.lastComponent === true); |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 196 | |
| 197 | if (last) { |
| 198 | console.log("Redirecting last element request to a search."); |
| 199 | scope.clearResults(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 200 | scope.query(scope.catalog, { |
| 201 | '??': path |
| 202 | }, |
| 203 | function(interest, data) { |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 204 | console.log("Search response", interest, data); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 205 | scope.name = interest.getName(); |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 206 | scope.getResults(0); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 207 | }, function(interest) { |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 208 | console.warn("Failed to retrieve final component.", interest, path); |
| 209 | scope.createAlert("Failed to request final component. " + path + " See console for details."); |
| 210 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 211 | return; |
| 212 | //Don't call the callback |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 213 | } |
| 214 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 215 | console.log("Autocomplete response", list); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 216 | callback(list.map(function(element) { |
| 217 | return (path == "/" ? "/" : "") + element + "/"; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 218 | })); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 219 | }); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 220 | }); |
| 221 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 222 | $('#treeSearch').on('click', '.treeSearch', function() { |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 223 | var t = $(this); |
| 224 | |
| 225 | scope.clearResults(); |
| 226 | |
| 227 | var path = t.parent().parent().attr('id'); |
| 228 | |
Tyler Scott | bb42ed2 | 2015-10-21 17:02:56 -0600 | [diff] [blame] | 229 | console.log("Tree search:", path); |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 230 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 231 | scope.query(scope.catalog, { |
| 232 | '??': path |
| 233 | }, |
| 234 | function(interest, data) { |
| 235 | //Success |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 236 | console.log("Tree search response", interest, data); |
| 237 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 238 | scope.name = interest.getName(); |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 239 | |
| 240 | scope.getResults(0); |
| 241 | }, |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 242 | function(interest) { |
| 243 | //Failure |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 244 | console.warn("Request failed! Timeout", interest); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 245 | scope.createAlert("Request timed out.\"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 246 | }); |
| 247 | |
| 248 | }); |
| 249 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 250 | this.setupRequestForm(); |
| 251 | |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 252 | this.resultTable.popover({ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 253 | selector: ".metaDataLink", |
| 254 | content: function() { |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 255 | return scope.getMetaData(this); |
| 256 | }, |
| 257 | title: "Metadata", |
| 258 | html: true, |
| 259 | trigger: 'click', |
| 260 | placement: 'bottom' |
| 261 | }); |
| 262 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 263 | this.resultTable.on('click', '.metaDataLink', function(e) { |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 264 | //This prevents the page from scrolling when you click on a name. |
| 265 | e.preventDefault(); |
| 266 | }); |
| 267 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 268 | this.resultTable.on('click', '.subsetButton', function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 269 | var metaData = $(this).siblings('pre').text(); |
| 270 | var exp = /netcdf ([\w-]+)/; |
| 271 | var match = exp.exec(metaData); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 272 | var filename = match[0].replace(/netcdf /, '') + '.nc'; |
| 273 | scope.request(null , filename); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 274 | }); |
| 275 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 276 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 277 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 278 | Atmos.prototype.clearResults = function() { |
| 279 | this.results = []; |
| 280 | //Drop any old results. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 281 | this.retrievedSegments = 0; |
| 282 | this.resultCount = Infinity; |
| 283 | this.page = 0; |
| 284 | this.resultTable.empty(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 285 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 286 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 287 | Atmos.prototype.pathSearch = function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 288 | var value = this.searchInput.val(); |
| 289 | |
| 290 | this.clearResults(); |
| 291 | |
| 292 | var scope = this; |
| 293 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 294 | this.query(this.catalog, { |
| 295 | "??": value |
| 296 | }, |
| 297 | function(interest, data) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 298 | console.log("Query response:", interest, data); |
| 299 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 300 | scope.name = interest.getName(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 301 | |
| 302 | scope.getResults(0); |
| 303 | |
| 304 | }, |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 305 | function(interest) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 306 | console.warn("Request failed! Timeout", interest); |
| 307 | scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details."); |
| 308 | }); |
| 309 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 310 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 311 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 312 | Atmos.prototype.search = function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 313 | |
| 314 | var filters = this.getFilters(); |
| 315 | |
| 316 | console.log("Search started!", this.searchInput.val(), filters); |
| 317 | |
| 318 | console.log("Initiating query"); |
| 319 | |
| 320 | this.clearResults(); |
| 321 | |
| 322 | var scope = this; |
| 323 | |
| 324 | this.query(this.catalog, filters, |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 325 | function(interest, data) { |
| 326 | //Response function |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 327 | console.log("Query Response:", interest, data); |
| 328 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 329 | scope.name = interest.getName(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 330 | |
| 331 | scope.getResults(0); |
| 332 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 333 | }, function(interest) { |
| 334 | //Timeout function |
Tyler Scott | d980a29 | 2015-10-13 15:16:34 -0600 | [diff] [blame] | 335 | console.warn("Request failed after 3 attempts!", interest); |
| 336 | scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details."); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 337 | }); |
| 338 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 339 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 340 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 341 | Atmos.prototype.autoComplete = function(field, callback) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 342 | |
| 343 | var scope = this; |
| 344 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 345 | var result = {}; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 346 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 347 | const getAll = function(interest, data) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 348 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 349 | if (data.getContent().length !== 0) { |
| 350 | var resp = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")); |
| 351 | if (result.next) { |
| 352 | result.next = result.next.concat(resp.next); |
| 353 | } else { |
| 354 | result = resp; |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 355 | } |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 356 | } else { |
| 357 | callback(result); |
| 358 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 359 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 360 | var name = data.getName(); |
| 361 | var segment = name.components[name.getComponentCount() - 1]; |
| 362 | if (segment.toSegment() !== data.getMetaInfo().getFinalBlockId().toSegment()){ |
| 363 | name = name.getPrefix(-1); //Remove segment |
| 364 | name.appendSegment(segment.toSegment() + 1); |
| 365 | scope.expressInterest(name, getAll, function() { |
| 366 | console.warn("Autocomplete timed out, results may be incomplete."); |
| 367 | callback(result); |
| 368 | //Return if we get a timeout. |
| 369 | }); |
| 370 | } else { |
| 371 | callback(result); |
| 372 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 373 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 374 | } |
| 375 | |
| 376 | this.query(this.catalog, { |
| 377 | "?": field |
| 378 | }, getAll); |
| 379 | |
| 380 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 381 | |
| 382 | Atmos.prototype.showResults = function(resultIndex) { |
| 383 | |
| 384 | var results = this.results.slice(this.resultsPerPage * resultIndex, this.resultsPerPage * (resultIndex + 1)); |
| 385 | |
| 386 | var resultDOM = $( |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 387 | results.reduce(function(prev, current) { |
| 388 | prev.push('<tr><td><input class="resultSelector" type="checkbox"></td><td class="popover-container"><a href="#" class="metaDataLink">'); |
| 389 | prev.push(current); |
| 390 | prev.push('</a></td></tr>'); |
| 391 | return prev; |
| 392 | }, ['<tr><th><input id="resultSelectAll" type="checkbox" title="Select All"> Select</th><th>Name</th></tr>']).join('') |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 393 | ); |
| 394 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 395 | resultDOM.find('#resultSelectAll').click(function() { |
| 396 | if ($(this).is(':checked')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 397 | resultDOM.find('.resultSelector:not([disabled])').prop('checked', true); |
| 398 | } else { |
| 399 | resultDOM.find('.resultSelector:not([disabled])').prop('checked', false); |
| 400 | } |
| 401 | }); |
| 402 | |
| 403 | this.resultTable.hide().empty().append(resultDOM).slideDown('slow'); |
| 404 | |
| 405 | this.resultMenu.find('.pageNumber').text(resultIndex + 1); |
| 406 | this.resultMenu.find('.pageLength').text(this.resultsPerPage * resultIndex + results.length); |
| 407 | |
| 408 | if (this.resultsPerPage * (resultIndex + 1) >= this.resultCount) { |
| 409 | this.resultMenu.find('.next').addClass('disabled'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 410 | } else if (resultIndex === 0) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 411 | this.resultMenu.find('.next').removeClass('disabled'); |
| 412 | } |
| 413 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 414 | if (resultIndex === 0) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 415 | this.resultMenu.find('.previous').addClass('disabled'); |
| 416 | } else if (resultIndex === 1) { |
| 417 | this.resultMenu.find('.previous').removeClass('disabled'); |
| 418 | } |
| 419 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 420 | $.scrollTo("#results", 500, { |
| 421 | interrupt: true |
| 422 | }); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 423 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 424 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 425 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 426 | Atmos.prototype.getResults = function(index) { |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 427 | var scope = this; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 428 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 429 | if ($('#results').hasClass('hidden')) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 430 | $('#results').removeClass('hidden').slideDown(); |
| 431 | } |
| 432 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 433 | if ((scope.results.length === scope.resultCount) || (scope.resultsPerPage * (index + 1) < scope.results.length)) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 434 | //console.log("We already have index", index); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 435 | scope.page = index; |
| 436 | scope.showResults(index); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 437 | return; |
| 438 | } |
| 439 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 440 | if (scope.name === null ) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 441 | console.error("This shouldn't be reached! We are getting results before a search has occured!"); |
| 442 | throw new Error("Illegal State"); |
| 443 | } |
| 444 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 445 | var interestName = new Name(scope.name); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 446 | |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 447 | // Interest name should be /<catalog-prefix>/query/<query-param>/<version>/<#seq> |
| 448 | if (scope.name.size() === (scope.catalogPrefix.size() + 3)) { |
| 449 | interestName = interestName.appendSegment(scope.retrievedSegments++); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 450 | //console.log("Requesting data index: (", scope.retrievedSegments - 1, ") at ", interestName.toUri()); |
Chengyu Fan | 7b978f8 | 2015-12-09 17:03:23 -0700 | [diff] [blame] | 451 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 452 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 453 | this.expressInterest(interestName, |
| 454 | function(interest, data) { |
| 455 | //Response |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 456 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 457 | if (data.getContent().length === 0) { |
| 458 | scope.resultMenu.find('.totalResults').text(0); |
| 459 | scope.resultMenu.find('.pageNumber').text(0); |
| 460 | scope.resultMenu.find('.pageLength').text(0); |
| 461 | console.log("Empty response."); |
| 462 | scope.resultTable.html("<tr><td>Empty response. This usually means no results.</td></tr>"); |
| 463 | return; |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 464 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 465 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 466 | var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")); |
| 467 | |
| 468 | if (!content.results) { |
| 469 | scope.resultMenu.find('.totalResults').text(0); |
| 470 | scope.resultMenu.find('.pageNumber').text(0); |
| 471 | scope.resultMenu.find('.pageLength').text(0); |
| 472 | console.log("No results were found!"); |
| 473 | scope.resultTable.html("<tr><td>No Results</td></tr>"); |
| 474 | return; |
| 475 | } |
| 476 | |
| 477 | scope.results = scope.results.concat(content.results); |
| 478 | |
| 479 | scope.resultCount = content.resultCount; |
| 480 | |
| 481 | scope.resultMenu.find('.totalResults').text(scope.resultCount); |
| 482 | |
| 483 | scope.page = index; |
| 484 | |
| 485 | // reset scope.name |
| 486 | scope.name = new Name(data.getName().getPrefix(scope.catalogPrefix.size() + 3)); |
| 487 | |
| 488 | scope.getResults(index); |
| 489 | //Keep calling this until we have enough data. |
| 490 | |
| 491 | }, function() {}//Ignore failure |
| 492 | ); |
| 493 | |
| 494 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 495 | |
| 496 | Atmos.prototype.query = function(prefix, parameters, callback, timeout) { |
| 497 | |
| 498 | var queryPrefix = new Name(prefix); |
| 499 | queryPrefix.append("query"); |
| 500 | |
| 501 | var jsonString = JSON.stringify(parameters); |
| 502 | queryPrefix.append(jsonString); |
| 503 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 504 | this.expressInterest(queryPrefix, callback, timeout); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 505 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 506 | } |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 507 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 508 | |
| 509 | Atmos.prototype.expressInterest = function(name, success, failure) { |
| 510 | |
| 511 | var interest = new Interest(name); |
| 512 | interest.setInterestLifetimeMilliseconds(1500); |
| 513 | interest.setMustBeFresh(true); |
| 514 | |
| 515 | const face = this.face; |
| 516 | |
| 517 | async.retry(4, function(done) { |
| 518 | face.expressInterest(interest, function(interest, data) { |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 519 | done(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 520 | success(interest, data); |
| 521 | }, function(interest) { |
| 522 | done("Interest timed out 4 times.", interest); |
| 523 | }); |
| 524 | }, function(err, interest) { |
| 525 | if (err) { |
| 526 | console.log(err, interest); |
| 527 | failure(interest); |
Tyler Scott | 8724e42 | 2015-10-13 17:59:07 -0600 | [diff] [blame] | 528 | } |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 529 | }); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 530 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 531 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 532 | |
| 533 | /** |
| 534 | * This function returns a map of all the categories active filters. |
| 535 | * @return {Object<string, string>} |
| 536 | */ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 537 | Atmos.prototype.getFilters = function() { |
| 538 | var filters = this.filters.children().toArray().reduce(function(prev, current) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 539 | var data = $(current).text().split(/:/); |
| 540 | prev[data[0]] = data[1]; |
| 541 | return prev; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 542 | }, {}); |
| 543 | //Collect a map<category, filter>. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 544 | //TODO Make the return value map<category, Array<filter>> |
| 545 | return filters; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 546 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 547 | |
| 548 | /** |
| 549 | * Creates a closable alert for the user. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 550 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 551 | * @param {string} message |
| 552 | * @param {string} type - Override the alert type. |
| 553 | */ |
| 554 | Atmos.prototype.createAlert = function(message, type) { |
| 555 | |
| 556 | var alert = $('<div class="alert"><div>'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 557 | alert.addClass(type ? type : 'alert-info'); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 558 | alert.text(message); |
| 559 | alert.append(closeButton); |
| 560 | |
| 561 | this.alerts.append(alert); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 562 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Requests all of the names represented by the buttons in the elements list. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 566 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 567 | * @param elements {Array<jQuery>} A list of the table row elements |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 568 | * @param subsetFileName {String} If present then do a subsetting request instead. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 569 | */ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 570 | Atmos.prototype.request = function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 571 | |
| 572 | //Pseudo globals. |
| 573 | var keyChain; |
| 574 | var certificateName; |
| 575 | var keyAdded = false; |
| 576 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 577 | return function(elements, subsetFilename) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 578 | |
| 579 | var names = []; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 580 | $(elements).find('.metaDataLink').each(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 581 | var name = $(this).text(); |
| 582 | names.push(name); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 583 | }); |
| 584 | |
| 585 | var subset = false; |
| 586 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 587 | if (!subsetFilename) { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 588 | $('#subsetting').hide(); |
| 589 | } else { |
| 590 | $('#subsetting').show(); |
| 591 | subset = true; |
| 592 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 593 | |
| 594 | var scope = this; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 595 | this.requestForm.on('submit', function(e) { |
| 596 | //This will be registered for the next submit from the form. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 597 | e.preventDefault(); |
| 598 | |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 599 | $('#request .alert').remove(); |
| 600 | |
| 601 | var variables = []; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 602 | if (subset) { |
| 603 | $('#subsetVariables .row').each(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 604 | var t = $(this); |
| 605 | var values = {}; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 606 | t.find('.values input').each(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 607 | var t = $(this); |
| 608 | values[t.attr('name')] = t.val(); |
| 609 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 610 | variables.push({ |
| 611 | variable: t.find('.variable').val(), |
| 612 | values: values |
| 613 | }); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 614 | }); |
| 615 | } |
| 616 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 617 | //Form checking |
| 618 | var dest = scope.requestForm.find('#requestDest .active'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 619 | if (dest.length !== 1) { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 620 | var alert = $('<div class="alert alert-warning">A destination is required!' + closeButton + '<div>'); |
| 621 | $('#request > .panel-body').append(alert); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 622 | return; |
| 623 | } |
| 624 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 625 | $('#request').modal('hide'); |
| 626 | //Initial params are ok. We can close the form. |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 627 | |
| 628 | scope.cleanRequestForm(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 629 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 630 | $(this).off(e); |
| 631 | //Don't fire this again, the request must be regenerated |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 632 | |
| 633 | //Key setup |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 634 | if (!keyAdded) { |
| 635 | if (!scope.config.retrieval.demoKey || !scope.config.retrieval.demoKey.pub || !scope.config.retrieval.demoKey.priv) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 636 | scope.createAlert("This host was not configured to handle retrieval! See console for details.", 'alert-danger'); |
| 637 | console.error("Missing/invalid key! This must be configured in the config on the server.", scope.config.demoKey); |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | //FIXME base64 may or may not exist in other browsers. Need a new polyfill. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 642 | var pub = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.pub)); |
| 643 | //MUST be a Buffer (Buffer != Uint8Array) |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 644 | var priv = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.priv)); |
| 645 | |
| 646 | var identityStorage = new MemoryIdentityStorage(); |
| 647 | var privateKeyStorage = new MemoryPrivateKeyStorage(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 648 | keyChain = new KeyChain(new IdentityManager(identityStorage,privateKeyStorage), |
| 649 | new SelfVerifyPolicyManager(identityStorage)); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 650 | |
| 651 | var keyName = new Name("/retrieve/DSK-123"); |
| 652 | certificateName = keyName.getSubName(0, keyName.size() - 1) |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 653 | .append("KEY").append(keyName.get(-1)) |
| 654 | .append("ID-CERT").append("0"); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 655 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 656 | identityStorage.addKey(keyName, KeyType.RSA, new Blob(pub,false)); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 657 | privateKeyStorage.setKeyPairForKeyName(keyName, KeyType.RSA, pub, priv); |
| 658 | |
| 659 | scope.face.setCommandSigningInfo(keyChain, certificateName); |
| 660 | |
| 661 | keyAdded = true; |
| 662 | |
| 663 | } |
| 664 | |
| 665 | //Retrieval |
| 666 | var retrievePrefix = new Name("/catalog/ui/" + guid()); |
| 667 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 668 | scope.face.registerPrefix(retrievePrefix, |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 669 | function(prefix, interest, face, interestFilterId, filter) { |
| 670 | //On Interest |
| 671 | //This function will exist until the page exits but will likely only be used once. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 672 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 673 | var data = new Data(interest.getName()); |
| 674 | var content; |
| 675 | if (subset) { |
| 676 | content = JSON.stringify({ |
| 677 | name: subsetFilename, |
| 678 | subset: variables |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 679 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 680 | } else { |
| 681 | content = JSON.stringify(names); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 682 | } |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 683 | //Blob breaks the data! Don't use it |
| 684 | data.setContent(content); |
| 685 | //TODO Packetize this. |
| 686 | keyChain.sign(data, certificateName); |
| 687 | |
| 688 | try { |
| 689 | face.putData(data); |
| 690 | console.log("Responded for", interest.getName().toUri(), data); |
| 691 | scope.createAlert("Data retrieval has initiated.", "alert-success"); |
| 692 | } catch (e) { |
| 693 | console.error("Failed to respond to", interest.getName().toUri(), data); |
| 694 | scope.createAlert("Data retrieval failed."); |
| 695 | } |
| 696 | |
| 697 | }, function(prefix) { |
| 698 | //On fail |
| 699 | scope.createAlert("Failed to register the retrieval URI! See console for details.", "alert-danger"); |
| 700 | console.error("Failed to register URI:", prefix.toUri(), prefix); |
| 701 | }, function(prefix, registeredPrefixId) { |
| 702 | //On success |
| 703 | var name = new Name(dest.text()); |
| 704 | name.append(prefix); |
| 705 | |
| 706 | scope.expressInterest(name, |
| 707 | function(interest, data) { |
| 708 | //Success |
| 709 | console.log("Request for", name.toUri(), "succeeded.", interest, data); |
| 710 | }, |
| 711 | function() { |
| 712 | console.warn("Failed to request from retrieve agent."); |
| 713 | } |
| 714 | ); |
| 715 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 716 | ); |
| 717 | |
| 718 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 719 | $('#request').modal(); |
| 720 | //This forces the form to be the only option. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 721 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 722 | } |
| 723 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 724 | }(); |
| 725 | |
| 726 | Atmos.prototype.filterSetup = function() { |
| 727 | //Filter setup |
| 728 | |
| 729 | var prefix = new Name(this.catalog).append("filters-initialization"); |
| 730 | |
| 731 | var scope = this; |
| 732 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 733 | this.getAll(prefix, function(data) { |
| 734 | //Success |
| 735 | var raw = JSON.parse(data.replace(/[\n\0]/g, '')); |
| 736 | //Remove null byte and parse |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 737 | |
| 738 | console.log("Filter categories:", raw); |
| 739 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 740 | $.each(raw, function(index, object) { |
| 741 | //Unpack list of objects |
| 742 | $.each(object, function(category, searchOptions) { |
| 743 | //Unpack category from object (We don't know what it is called) |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 744 | //Create the category |
| 745 | var e = $('<li><a href="#">' + category.replace(/_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>'); |
| 746 | |
| 747 | var sub = e.find('ul.subnav'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 748 | $.each(searchOptions, function(index, name) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 749 | //Create the filter list inside the category |
| 750 | var item = $('<li><a href="#">' + name + '</a></li>'); |
| 751 | sub.append(item); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 752 | item.click(function() { |
| 753 | //Click on the side menu filters |
| 754 | if (item.hasClass('active')) { |
| 755 | //Does the filter already exist? |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 756 | item.removeClass('active'); |
| 757 | scope.filters.find(':contains(' + category + ':' + name + ')').remove(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 758 | } else { |
| 759 | //Add a filter |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 760 | item.addClass('active'); |
| 761 | var filter = $('<span class="label label-default"></span>'); |
| 762 | filter.text(category + ':' + name); |
| 763 | |
| 764 | scope.filters.append(filter); |
| 765 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 766 | filter.click(function() { |
| 767 | //Click on a filter |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 768 | filter.remove(); |
| 769 | item.removeClass('active'); |
| 770 | }); |
| 771 | } |
| 772 | |
| 773 | }); |
| 774 | }); |
| 775 | |
| 776 | //Toggle the menus. (Only respond when the immediate tab is clicked.) |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 777 | e.find('> a').click(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 778 | scope.categories.find('.subnav').slideUp(); |
| 779 | var t = $(this).siblings('.subnav'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 780 | if (!t.is(':visible')) { |
| 781 | //If the sub menu is not visible |
| 782 | t.slideDown(function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 783 | t.triggerHandler('focus'); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 784 | }); |
| 785 | //Make it visible and look at it. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 786 | } |
| 787 | }); |
| 788 | |
| 789 | scope.categories.append(e); |
| 790 | |
| 791 | }); |
| 792 | }); |
| 793 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 794 | }, function(interest) { |
| 795 | //Timeout |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 796 | scope.createAlert("Failed to initialize the filters!", "alert-danger"); |
| 797 | console.error("Failed to initialize filters!", interest); |
| 798 | ga('send', 'event', 'error', 'filters'); |
| 799 | }); |
| 800 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 801 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 802 | |
| 803 | /** |
| 804 | * This function retrieves all segments in order until it knows it has reached the last one. |
| 805 | * It then returns the final joined result. |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 806 | |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 807 | * @param prefix {String|Name} The ndn name we are retrieving. |
| 808 | * @param callback {function(String)} if successful, will call the callback with a string of data. |
| 809 | * @param failure {function(Interest)} if unsuccessful, will call failure with the last failed interest. |
| 810 | * @param stop {boolean} stop if no finalBlock. |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 811 | */ |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 812 | Atmos.prototype.getAll = function(prefix, callback, failure, stop) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 813 | |
| 814 | var scope = this; |
| 815 | var d = []; |
| 816 | |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 817 | var name = new Name(prefix); |
| 818 | var segment = 0; |
Tyler Scott | 8724e42 | 2015-10-13 17:59:07 -0600 | [diff] [blame] | 819 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 820 | var request = function() { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 821 | |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 822 | var n2 = new Name(name); |
| 823 | n2.appendSegment(segment); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 824 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 825 | scope.expressInterest(n2, handleData, function() {}); |
| 826 | //Forward to handleData and ignore error |
| 827 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 828 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 829 | var handleData = function(interest, data) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 830 | |
| 831 | d.push(data.getContent().toString()); |
| 832 | |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 833 | var hasFinalBlock = data.getMetaInfo().getFinalBlockId().value.length === 0; |
| 834 | var finalBlockStop = hasFinalBlock && stop; |
| 835 | |
| 836 | if (finalBlockStop || |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 837 | (!hasFinalBlock && interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment())) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 838 | callback(d.join("")); |
| 839 | } else { |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 840 | segment++; |
| 841 | request(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 842 | } |
| 843 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 844 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 845 | |
Tyler Scott | d61bf83 | 2015-11-30 16:36:17 -0700 | [diff] [blame] | 846 | request(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 847 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 848 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 849 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 850 | Atmos.prototype.cleanRequestForm = function() { |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 851 | $('#requestDest').prev().removeClass('btn-success').addClass('btn-default'); |
| 852 | $('#requestDropText').text('Destination'); |
| 853 | $('#requestDest .active').removeClass('active'); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 854 | $('#subsetMenu').attr('class', 'collapse'); |
| 855 | $('#subsetVariables').empty(); |
| 856 | $('#request .alert').alert('close').remove(); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 857 | } |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 858 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 859 | Atmos.prototype.setupRequestForm = function() { |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 860 | |
| 861 | var scope = this; |
| 862 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 863 | this.requestForm.find('#requestCancel').click(function() { |
| 864 | $('#request').unbind('submit')//Removes all event handlers. |
| 865 | .modal('hide'); |
| 866 | //Hides the form. |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 867 | scope.cleanRequestForm(); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 868 | }); |
| 869 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 870 | var dests = $(this.config['retrieval']['destinations'].reduce(function(prev, current) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 871 | prev.push('<li><a href="#">'); |
| 872 | prev.push(current); |
| 873 | prev.push("</a></li>"); |
| 874 | return prev; |
| 875 | }, []).join("")); |
| 876 | |
| 877 | this.requestForm.find('#requestDest').append(dests) |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 878 | .on('click', 'a', function(e) { |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 879 | $('#requestDest .active').removeClass('active'); |
Tyler Scott | b59e6de | 2015-09-18 14:46:30 -0600 | [diff] [blame] | 880 | var t = $(this); |
| 881 | t.parent().addClass('active'); |
| 882 | $('#requestDropText').text(t.text()); |
| 883 | $('#requestDest').prev().removeClass('btn-default').addClass('btn-success'); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 884 | }); |
| 885 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 886 | var addVariable = function(selector) { |
| 887 | var ele = $(selector).clone().attr('id', ''); |
| 888 | ele.find('.close').click(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 889 | ele.remove(); |
| 890 | }); |
| 891 | $('#subsetVariables').append(ele); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 892 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 893 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 894 | $('#subsetAddVariableBtn').click(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 895 | addVariable('#customTemplate'); |
| 896 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 897 | $('#subsetAddTimeVariable').click(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 898 | addVariable('#timeTemplate'); |
| 899 | }); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 900 | $('#subsetAddLocVariable').click(function() { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 901 | addVariable('#locationTemplate'); |
| 902 | }); |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 903 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 904 | } |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 905 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 906 | Atmos.prototype.getMetaData = (function() { |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 907 | |
| 908 | var cache = {}; |
| 909 | |
| 910 | return function(element) { |
| 911 | var name = $(element).text(); |
| 912 | |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 913 | ga('send', 'event', 'request', 'metaData'); |
| 914 | |
| 915 | var subsetButton = '<button class="btn btn-default subsetButton" type="button">Subset</button>'; |
| 916 | |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 917 | if (cache[name]) { |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 918 | return [subsetButton, '<pre class="metaData">', cache[name], '</pre>'].join(''); |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | var prefix = new Name(name).append("metadata"); |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 922 | var id = guid(); |
| 923 | //We need an id because the return MUST be a string. |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 924 | var ret = '<div id="' + id + '"><span class="fa fa-spinner fa-spin"></span></div>'; |
| 925 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 926 | this.getAll(prefix, function(data) { |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 927 | var el = $('<pre class="metaData"></pre>'); |
| 928 | el.text(data); |
Tyler Scott | f355e45 | 2015-11-06 21:35:14 -0700 | [diff] [blame] | 929 | var container = $('<div></div>'); |
| 930 | container.append($(subsetButton)); |
| 931 | container.append(el); |
| 932 | $('#' + id).empty().append(container); |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 933 | cache[name] = data; |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 934 | }, function(interest) { |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 935 | $('#' + id).text("The metadata is unavailable for this name."); |
| 936 | console.log("Data is unavailable for " + name); |
| 937 | }); |
| 938 | |
| 939 | return ret; |
| 940 | |
Tyler Scott | 66a965d | 2016-02-29 15:41:33 -0700 | [diff] [blame^] | 941 | } |
Tyler Scott | 48f92cd | 2015-10-16 18:31:20 -0600 | [diff] [blame] | 942 | })(); |
| 943 | |
Tyler Scott | cdfcde8 | 2015-09-14 16:13:29 -0600 | [diff] [blame] | 944 | return Atmos; |
| 945 | |
| 946 | })(); |