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 |
| 17 | * |
| 18 | * Configures an Atmos object. This manages the atmos interface. |
| 19 | * |
| 20 | * @constructor |
| 21 | * @param {string} catalog - NDN path |
| 22 | * @param {Object} config - Object of configuration options for a Face. |
| 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 | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 29 | this.page = 1; |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 30 | this.itemsPerPage = 25; |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame] | 31 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 32 | this.catalog = catalog; |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 33 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 34 | this.face = new Face(config); |
| 35 | this.categories = $('#side-menu'); |
| 36 | this.resultTable = $('#resultTable'); |
| 37 | this.filters = $('#filters'); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 38 | this.searchInput = $('#search'); |
| 39 | this.searchBar = $('#searchBar'); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 40 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 41 | var scope = this; |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 42 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 43 | this.resultTable.on('click', '.interest-button', function(){ |
| 44 | var button = $(this); |
Tyler Scott | 087aef7 | 2015-07-14 14:11:59 -0600 | [diff] [blame] | 45 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 46 | if (button.is(':disabled')){ |
| 47 | console.warn("Attempt to request again!"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 48 | } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 49 | |
| 50 | var name = button.parent().prev().text(); |
| 51 | var interest = new Interest(new Name('/retrieve' + name)); |
| 52 | scope.face.expressInterest(interest, function(){}, function(){}); |
| 53 | |
| 54 | button.text("Requested!") |
| 55 | .removeClass('btn-primary') |
| 56 | .addClass('btn-default') |
| 57 | .addClass('disabled') |
| 58 | .prop('disabled', true); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 59 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 60 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 61 | //Filter setup |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 62 | $.getJSON("search_catagories.json").done(function (data) { |
| 63 | $.each(data, function (pageSection, contents) { |
| 64 | if (pageSection == "SearchCatagories") { |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 65 | $.each(contents, function (category, searchOptions) { |
| 66 | //Create the category |
| 67 | 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] | 68 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 69 | var sub = e.find('ul.subnav'); |
| 70 | $.each(searchOptions, function(index, name){ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 71 | //Create the filter list inside the category |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 72 | var item = $('<li><a href="#">' + name + '</a></li>'); |
| 73 | sub.append(item); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 74 | item.click(function(){ //Click on the side menu filters |
| 75 | if (item.hasClass('active')){ //Does the filter already exist? |
| 76 | item.removeClass('active'); |
| 77 | scope.filters.find(':contains(' + category + ':' + name + ')').remove(); |
| 78 | } else { //Add a filter |
| 79 | item.addClass('active'); |
| 80 | var filter = $('<span class="label label-default"></span>'); |
| 81 | filter.text(category + ':' + name); |
| 82 | |
| 83 | scope.filters.append(filter); |
| 84 | |
| 85 | filter.click(function(){ //Click on a filter |
| 86 | filter.remove(); |
| 87 | item.removeClass('active'); |
| 88 | }); |
| 89 | } |
| 90 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 91 | }); |
| 92 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 93 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 94 | //Toggle the menus. (Only respond when the immediate tab is clicked.) |
| 95 | e.find('> a').click(function(){ |
| 96 | scope.categories.find('.subnav').slideUp(); |
| 97 | var t = $(this).siblings('.subnav'); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 98 | if ( !t.is(':visible') ){ //If the sub menu is not visible |
| 99 | t.slideDown(function(){ |
| 100 | t.triggerHandler('focus'); |
| 101 | }); //Make it visible and look at it. |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 102 | } |
| 103 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 104 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 105 | scope.categories.append(e); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 106 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 107 | }); |
| 108 | } |
| 109 | }); |
| 110 | }); |
| 111 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 112 | this.searchBar.submit(function(e){ |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 113 | e.preventDefault(); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 114 | scope.search(); |
| 115 | }); |
| 116 | |
| 117 | this.searchInput.autoComplete(function(field, callback){ |
| 118 | scope.autoComplete(field, callback); |
| 119 | }); |
| 120 | |
| 121 | } |
| 122 | |
| 123 | Atmos.prototype.search = function(){ |
| 124 | var filters = this.getFilters(); |
| 125 | |
| 126 | if (this.searchInput.val().length === 0 && !filters.hasOwnProperty()){ |
| 127 | if (!this.searchBar.hasClass('has-error')){ |
| 128 | this.searchBar.addClass('has-error').append('<span class="help-block">A filter or search value is required!</span>'); |
| 129 | } |
| 130 | return; |
| 131 | } else { |
| 132 | this.searchBar.removeClass('has-error').find('.help-block').fadeOut(function(){$(this).remove()}); |
| 133 | } |
| 134 | |
| 135 | console.log("Search started!", this.searchInput.val(), filters); |
| 136 | |
| 137 | console.log("Initiating query"); |
| 138 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 139 | var scope = this; |
| 140 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 141 | this.query(this.catalog, filters, |
| 142 | function(interest, data){ //Response function |
| 143 | console.log("Query Response:", interest, data); |
| 144 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 145 | var parameters = JSON.stringify(filters); |
| 146 | |
| 147 | var ack = data.getName(); |
| 148 | |
| 149 | var name = new Name(scope.catalog).append("query-results").append(parameters) |
| 150 | .append(ack.get(ack.getComponentCount() - 3)).append(ack.getComponent(ack.getComponentCount() - 2)) |
| 151 | |
| 152 | var first = new Name(name).appendSegment(0); |
| 153 | |
| 154 | console.log("Next request:", first.toUri()); |
| 155 | |
| 156 | scope.face.expressInterest(new Interest(first).setInterestLifetimeMilliseconds(10000), |
| 157 | function(interest, data){ //Response |
| 158 | |
| 159 | var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g,"")); |
| 160 | |
| 161 | var results = scope.results[0] = content.results; |
| 162 | scope.resultCount = content.resultCount; |
| 163 | |
| 164 | console.log("Got results:", results); |
| 165 | |
| 166 | }, |
| 167 | function(interest){ //Timeout |
| 168 | console.error("Failed to retrieve results: timeout"); |
| 169 | } |
| 170 | ); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 171 | |
| 172 | |
| 173 | }, function(interest){ //Timeout function |
| 174 | console.error("Request failed! Timeout"); |
| 175 | }); |
| 176 | |
| 177 | } |
| 178 | |
| 179 | Atmos.prototype.autoComplete = function(field, callback){ |
| 180 | console.log("Autocomplete triggered"); |
| 181 | |
| 182 | var filters = this.getFilters(); |
| 183 | |
| 184 | filters["?"] = this.searchInput.val(); |
| 185 | |
| 186 | this.query(this.catalog, filters, |
| 187 | function(interest, data){ |
| 188 | console.log(interest, data); |
| 189 | }, function(interest){ |
| 190 | console.error("Request failed! Timeout"); |
| 191 | }); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 192 | |
Tyler Scott | 424ee10 | 2015-07-14 16:50:41 -0600 | [diff] [blame] | 193 | } |
| 194 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 195 | // Atmos.prototype.onData = function(data) { |
| 196 | // console.log("Recieved data", data); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 197 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 198 | // var payloadStr = data.content.toString().split("\n")[0]; |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 199 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 200 | // if (!payloadStr || payloadStr.length === 0){ |
| 201 | // this.populateResults(); |
| 202 | // return; //No results were returned. |
| 203 | // } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 204 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 205 | // var queryResults = JSON.parse(payloadStr); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 206 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 207 | // var scope = this; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 208 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 209 | // $.each(queryResults, function (queryResult, field) { |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 210 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 211 | // if (queryResult == "next") { |
| 212 | // scope.populateAutocomplete(field); |
| 213 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 214 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 215 | // if (queryResult == "results" && field == null){ |
| 216 | // return; //Sometimes the results are null. (We should skip this.) |
| 217 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 218 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 219 | // $.each(field, function (entryCount, name) { |
| 220 | // scope.results.push(name); |
| 221 | // }); |
| 222 | // });http://stackoverflow.com/questions/26334964/json-parse-unexpected-token-error |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 223 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 224 | // // Calculating the current page and the view |
| 225 | // this.populateResults(); |
Tyler Scott | 424ee10 | 2015-07-14 16:50:41 -0600 | [diff] [blame] | 226 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 227 | // } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 228 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 229 | Atmos.prototype.query = function(prefix, parameters, callback, timeout) { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 230 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 231 | var queryPrefix = new Name(prefix); |
| 232 | queryPrefix.append("query"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 233 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 234 | var jsonString = JSON.stringify(parameters); |
| 235 | queryPrefix.append(jsonString); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 236 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 237 | var queryInterest = new Interest(queryPrefix); |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 238 | queryInterest.setInterestLifetimeMilliseconds(4000); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 239 | |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 240 | this.face.expressInterest(queryInterest, callback, timeout); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 241 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 242 | } |
| 243 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 244 | // Atmos.prototype.expressNextInterest = function() { |
| 245 | // // @todo pipelines |
| 246 | // var nextName = new Name(this.state["results"]); |
| 247 | // nextName.appendSegment(this.state["nextSegment"]); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 248 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 249 | // var nextInterest = new Interest(nextName); |
| 250 | // nextInterest.setInterestLifetimeMilliseconds(10000); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 251 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 252 | // var scope = this; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 253 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 254 | // this.face.expressInterest(nextInterest, |
| 255 | // function(interest, data){ |
| 256 | // scope.onQueryResultsData(interest, data); |
| 257 | // }, |
| 258 | // function(interest){ |
| 259 | // scope.onQueryResultsTimeout(interest); |
| 260 | // }); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 261 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 262 | // this.state["nextSegment"] ++; |
| 263 | // this.state["outstanding"][nextName.toUri()] = 0; |
| 264 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 265 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 266 | // Atmos.prototype.onQueryData = function(interest, data) { |
| 267 | // var name = data.getName(); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 268 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 269 | // delete this.state["outstanding"][interest.getName().toUri()]; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 270 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 271 | // this.state["version"] = name.get(this.state["prefix"].size() + 2).toVersion(); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 272 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 273 | // this.state["results"] = new Name(this.state["prefix"]).append("query-results").append(this.state['parameters']) |
| 274 | // .appendVersion(this.state["version"]).append(name.getComponent(name.getComponentCount() - 2)); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 275 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 276 | // console.log("Requested URI", this.state.results.toUri()); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 277 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 278 | // this.expressNextInterest(); |
| 279 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 280 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 281 | // Atmos.prototype.onQueryResultsData = function(interest, data) { |
| 282 | // var name = data.getName(); |
| 283 | // delete this.state["outstanding"][interest.getName().toUri()]; |
| 284 | // if (!name.get(-1).equals(data.getMetaInfo().getFinalBlockId())) { |
| 285 | // this.expressNextInterest(); |
| 286 | // } //else { |
| 287 | // //alert("found final block"); |
| 288 | // //} |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 289 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 290 | // this.state["userOnData"](data); |
| 291 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 292 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 293 | // Atmos.prototype.onQueryTimeout = function(interest) { |
| 294 | // var uri = interest.getName().toUri(); |
| 295 | // if (this.state["outstanding"][uri] < 1) { |
| 296 | // this.state["outstanding"][uri] ++; |
| 297 | // var scope = this; |
| 298 | // this.face.expressInterest(interest, |
| 299 | // function(interest, data){ |
| 300 | // scope.onQueryData(interest, data); |
| 301 | // }, |
| 302 | // function(interest){ |
| 303 | // scope.onQueryTimeout(interest); |
| 304 | // }); |
| 305 | // } else { |
| 306 | // delete this.state["outstanding"][uri]; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 307 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 308 | // // We modify the autocomplete box here because we need to know |
| 309 | // // we have all of the entries first. Fairly hacky. |
| 310 | // /* TODO FIXME |
| 311 | // var autocompleteFullName = this.autocompleteText.value; |
| 312 | // for (var i = 0; i < dropdown.length; ++i) { |
| 313 | // if (this.dropdown[i].substr(0, dropdown[i].length - 1).toUpperCase === this.autocompleteText.value.toUpperCase || dropdown.length == 1) { |
| 314 | // autocompleteText.value = dropdown[i]; |
| 315 | // } |
| 316 | // } |
| 317 | // */ |
| 318 | // } |
| 319 | // } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 320 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 321 | // Atmos.prototype.onQueryResultsTimeout = function(interest) { |
| 322 | // var uri = interest.getName().toUri(); |
| 323 | // if (this.state["outstanding"][uri] < 1) { |
| 324 | // this.state["outstanding"][uri] ++; |
| 325 | // var scope = this; |
| 326 | // this.face.expressInterest(interest, |
| 327 | // function(){ |
| 328 | // scope.onQueryResultsData.apply(scope, arguments); |
| 329 | // }, |
| 330 | // function(){ |
| 331 | // scope.onQueryResultsTimeout.apply(scope, arguments); |
| 332 | // }); |
| 333 | // } else { |
| 334 | // delete this.state["outstanding"][uri]; |
| 335 | // // We modify the autocomplete box here because we need to know |
| 336 | // // we have all of the entries first. Fairly hacky. |
| 337 | // /* TODO FIXME |
| 338 | // var autocompleteFullName = autocompleteText.value; |
| 339 | // for (var i = 0; i < dropdown.length; ++i) { |
| 340 | // if (dropdown[i].substr(0, dropdown[i].length - 1).toUpperCase === autocompleteText.value.toUpperCase || dropdown.length == 1) { |
| 341 | // autocompleteText.value = dropdown[i]; |
| 342 | // } |
| 343 | // } |
| 344 | // */ |
| 345 | // } |
| 346 | // } |
| 347 | // **/ |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 348 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 349 | // Atmos.prototype.populateResults = function() { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 350 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 351 | // //TODO Check only for page changes and result length |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 352 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 353 | // this.resultTable.empty(); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 354 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 355 | // for (var i = startIndex; i < startIndex + 20 && i < this.results.length; ++i) { |
| 356 | // this.resultTable.append('<tr><td>' + this.results[i] |
| 357 | // + '</td><td><button class="interest-button btn btn-primary btn-xs">Retrieve</button></td></tr>'); |
| 358 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 359 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 360 | // if (this.results.length <= 20) { |
| 361 | // this.page = 1; |
| 362 | // } else { |
| 363 | // this.page = startIndex / 20 + 1; |
| 364 | // } |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 365 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 366 | // this.totalPages = Math.ceil(this.results.length / 20); |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 367 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 368 | // //TODO Fix the page to fit the theme. |
| 369 | // var currentPage = $(".page"); |
| 370 | // currentPage.empty(); |
| 371 | // if (this.page != 1) { |
| 372 | // currentPage.append('<a href="#" onclick="getPage(this.id);" id="<"><</a>'); |
| 373 | // } |
| 374 | // // This section of code creates the paging for the results. |
| 375 | // // To prevent it from having a 1000+ pages, it will only show the 5 pages before/after |
| 376 | // // the current page and the total pages (expect users not to really jump around a lot). |
| 377 | // for (var i = 1; i <= this.totalPages; ++i) { |
| 378 | // if (i == 1 || i == this.totalPages // Min or max |
| 379 | // || (i <= this.page && i + 5 >= this.page) // in our current page range |
| 380 | // || (i >= this.page && i - 5 <= this.page)) { // in our current page range |
| 381 | // if (i != this.page) { |
| 382 | // currentPage.append(' <a href="#" onclick="getPage(' + i + ');">' + i + '</a>'); |
| 383 | // if (i == 1 && this.page > i + 5) { |
| 384 | // currentPage.append(' ... '); |
| 385 | // } |
| 386 | // } else { |
| 387 | // currentPage.append(' ' + i); |
| 388 | // } |
| 389 | // } else { // Need to skip ahead |
| 390 | // if (i == this.page + 6) { |
| 391 | // currentPage.append(' ... '); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 392 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 393 | // currentPage.append(' <a href="#" onclick="getPage(this.id);" id=">">></a>') |
| 394 | // i = this.totalPages - 1; |
| 395 | // } |
| 396 | // } |
| 397 | // } |
| 398 | // currentPage.append(' ' + this.results.length + ' results'); |
| 399 | // } |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 400 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 401 | // Atmos.prototype.getPage = function(clickedPage) { |
| 402 | // console.log(clickedPage); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 403 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 404 | // var nextPage = clickedPage; |
| 405 | // if (clickedPage === "<") { |
| 406 | // nextPage = this.page - 5; |
| 407 | // } else if (clickedPage === ">") { |
| 408 | // console.log("> enabled"); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 409 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 410 | // nextPage = this.page + 5; |
| 411 | // } |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 412 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 413 | // nextPage--; // Need to adjust for starting at 0 |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 414 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 415 | // if (nextPage < 0 ) { |
| 416 | // nextPage = 0; |
| 417 | // console.log("0 enabled"); |
| 418 | // } else if (nextPage > this.totalPages - 1) { |
| 419 | // nextPage = this.totalPages - 1; |
| 420 | // console.log("total enabled"); |
| 421 | // } |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 422 | |
Tyler Scott | d90f84e | 2015-07-27 12:43:04 -0600 | [diff] [blame^] | 423 | // this.populateResults(nextPage * 20); |
| 424 | // return false; |
| 425 | // } |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 426 | |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 427 | /** |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 428 | * This function returns a map of all the categories active filters. |
| 429 | * @return {Object<string, string>} |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 430 | */ |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 431 | Atmos.prototype.getFilters = function(){ |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 432 | var filters = this.filters.children().toArray().reduce(function(prev, current){ |
Tyler Scott | 575c61b | 2015-07-13 13:42:16 -0600 | [diff] [blame] | 433 | var data = $(current).text().split(/:/); |
| 434 | prev[data[0]] = data[1]; |
| 435 | return prev; |
Tyler Scott | a153005 | 2015-07-24 00:13:28 -0600 | [diff] [blame] | 436 | }, {}); //Collect a map<category, filter>. |
| 437 | //TODO Make the return value map<category, Array<filter>> |
| 438 | return filters; |
Tyler Scott | 93cae87 | 2015-07-21 14:58:23 -0600 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | return Atmos; |
| 442 | |
| 443 | })(); |
| 444 | |
| 445 | |