Tyler Scott | f08ab96 | 2015-06-30 16:31:29 -0600 | [diff] [blame] | 1 | //{@ @todo: this need to be configured before the document load |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 2 | var catalog = "/catalog/myUniqueName"; |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 3 | var config = { |
| 4 | host: "atmos-csu.research-lan.colostate.edu", |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 5 | port: 9696 |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 6 | }; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 7 | |
| 8 | // @} |
| 9 | |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 10 | var atmos = {}; //Comment this out if you don't want debug access. |
| 11 | |
| 12 | //Run when the document loads. |
| 13 | $(function () { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 14 | |
| 15 | //remove "atmos =" if you don't want debug access |
Tyler Scott | a1ac69d | 2015-07-02 17:42:03 -0600 | [diff] [blame] | 16 | atmos = new Atmos(catalog, config); |
Tyler Scott | f65b710 | 2015-06-30 18:40:14 -0600 | [diff] [blame] | 17 | |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 18 | }); |
| 19 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 20 | /* |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 21 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 22 | */ |
| 23 | |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 24 | /** |
| 25 | * Atmos |
| 26 | * @version 2.0 |
| 27 | * |
| 28 | * Configures an Atmos object. This manages the atmos interface. |
| 29 | * |
| 30 | * @constructor |
| 31 | * @param {string} catalog - NDN path |
| 32 | * @param {Object} config - Object of configuration options for a Face. |
| 33 | */ |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 34 | function Atmos(catalog, config){ |
| 35 | "use strict"; |
| 36 | //Internal variables. |
| 37 | this.results = [] |
| 38 | this.resultCount = 0; |
| 39 | this.page = 1; |
| 40 | this.totalPages = 1; |
| 41 | this.selectedSearch = {}; |
| 42 | this.dropdown = []; |
| 43 | this.state = {}; |
| 44 | this.currentViewIndex = 0; |
| 45 | |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 46 | this.catalog = catalog; |
| 47 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 48 | this.face = new Face(config); |
| 49 | this.categories = $('#side-menu'); |
| 50 | this.resultTable = $('#resultTable'); |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 51 | this.filters = $('#filters'); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 52 | |
| 53 | var scope = this; |
| 54 | |
| 55 | this.resultTable.on('click', '.interest-button', function(){ |
| 56 | var button = $(this); |
| 57 | |
| 58 | var name = button.parent().prev().text(); |
| 59 | var interest = new Interest(new Name('/retrieve' + name)); |
| 60 | scope.face.expressInterest(interest, function(){ |
| 61 | var message = $('<div class="success"><span class="glyphicon glyphicon-ok"></span> Success!</div>'); |
| 62 | message.insertAfter(button); |
| 63 | message.fadeOut(5000); |
| 64 | }, function(){ |
| 65 | var message = $('<div class="fail"><span class="glyphicon glyphicon-remove"></span> Failed!</div>'); |
| 66 | message.insertAfter(button); |
| 67 | message.fadeOut(5000); |
| 68 | }); |
| 69 | |
| 70 | }); |
| 71 | |
| 72 | $.getJSON("search_catagories.json").done(function (data) { |
| 73 | $.each(data, function (pageSection, contents) { |
| 74 | if (pageSection == "SearchCatagories") { |
| 75 | $.each(contents, function (search, searchOptions) { |
| 76 | var e = $('<li><a href="#">' + search.replace(/\_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>'); |
| 77 | |
| 78 | var sub = e.find('ul.subnav'); |
| 79 | $.each(searchOptions, function(index, name){ |
| 80 | var item = $('<li><a href="#">' + name + '</a></li>'); |
| 81 | sub.append(item); |
| 82 | item.click(function(){ |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 83 | scope.addFilter(name); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 84 | }); |
| 85 | }); |
| 86 | |
| 87 | //Toggle the menus. |
| 88 | e.click(function(){ |
| 89 | scope.categories.find('.subnav').slideUp(); |
| 90 | var t = $(this).find('.subnav'); |
| 91 | if ( !t.is(':visible')){ |
| 92 | t.slideDown().triggerHandler('focus'); //Cancel other animations and slide down. |
| 93 | } |
| 94 | }); |
| 95 | |
| 96 | scope.categories.append(e); |
| 97 | }); |
| 98 | } |
| 99 | }); |
| 100 | }); |
| 101 | |
| 102 | $('#searchBar').submit(function(e){ |
| 103 | e.preventDefault(); |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 104 | console.log("Search started!", $('#search')); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 105 | }) |
| 106 | |
| 107 | } |
| 108 | |
| 109 | Atmos.prototype.onData = function(data) { |
| 110 | var payloadStr = data.content.toString().split("\n")[0]; |
| 111 | |
| 112 | var queryResults = JSON.parse(payloadStr); |
| 113 | |
| 114 | var scope = this; |
| 115 | |
| 116 | $.each(this.queryResults, function (queryResult, field) { |
| 117 | |
| 118 | if (queryResult == "next") { |
| 119 | scope.populateAutocomplete(field); |
| 120 | } |
| 121 | |
| 122 | $.each(field, function (entryCount, name) { |
| 123 | scope.results.push(name); |
| 124 | }); |
| 125 | }); |
| 126 | |
| 127 | // Calculating the current page and the view |
| 128 | this.totalPages = Math.ceil(this.resultCount / 20); |
| 129 | this.populateResults(0); |
| 130 | } |
| 131 | |
| 132 | Atmos.prototype.query = function(prefix, parameters, callback, pipeline) { |
| 133 | this.results = []; |
| 134 | this.dropdown = []; |
| 135 | this.resultTable.empty(); |
| 136 | this.resultTable.append('<tr><th colspan="2">Results</th></tr>'); |
| 137 | |
| 138 | var queryPrefix = new Name(prefix); |
| 139 | queryPrefix.append("query"); |
| 140 | |
| 141 | var jsonString = JSON.stringify(parameters); |
| 142 | queryPrefix.append(jsonString); |
| 143 | |
| 144 | this.state = { |
| 145 | prefix: new Name(prefix), |
| 146 | userOnData: callback, |
| 147 | outstanding: {}, |
| 148 | nextSegment: 0, |
| 149 | }; |
| 150 | |
| 151 | /*if (state.hasOwnProperty("version")) { |
| 152 | console.log("state already has version"); |
| 153 | }*/ |
| 154 | |
| 155 | var queryInterest = new Interest(queryPrefix); |
| 156 | queryInterest.setInterestLifetimeMilliseconds(10000); |
| 157 | |
| 158 | var scope = this; |
| 159 | |
| 160 | this.face.expressInterest(queryInterest, |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 161 | function(interest, data){ |
| 162 | scope.onQueryData(interest, data); |
| 163 | }, function(interest){ |
| 164 | scope.onQueryTimeout(interest); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 165 | } |
| 166 | ); |
| 167 | |
| 168 | this.state["outstanding"][queryInterest.getName().toUri()] = 0; |
| 169 | } |
| 170 | |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 171 | /** |
| 172 | * @deprecated |
| 173 | * Use applyFilters/addFilters as appropriate. |
| 174 | */ |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 175 | Atmos.prototype.submitCatalogSearch = function(field) { |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 176 | console.warn("Use of deprecated function submitCatalogSearch! (Use applyFilters/addFilters as appropriate)"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | Atmos.prototype.expressNextInterest = function() { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 180 | // @todo pipelines |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 181 | var nextName = new Name(this.state["results"]); |
| 182 | nextName.appendSegment(this.state["nextSegment"]); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 183 | |
| 184 | var nextInterest = new Interest(nextName); |
| 185 | nextInterest.setInterestLifetimeMilliseconds(10000); |
| 186 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 187 | var scope = this; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 188 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 189 | this.face.expressInterest(nextInterest, |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 190 | function(interest, data){ |
| 191 | scope.onQueryResultsData(interest, data); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 192 | }, |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 193 | function(interest){ |
| 194 | scope.onQueryResultsTimeout(interest); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 195 | }); |
| 196 | |
| 197 | this.state["nextSegment"] ++; |
| 198 | this.state["outstanding"][nextName.toUri()] = 0; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 199 | } |
| 200 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 201 | Atmos.prototype.onQueryData = function(interest, data) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 202 | var name = data.getName(); |
| 203 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 204 | delete this.state["outstanding"][interest.getName().toUri()]; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 205 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 206 | this.state["version"] = name.get(this.state["prefix"].size() + 2).toVersion(); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 207 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 208 | this.state["results"] = new Name(this.state["prefix"]).append("query-results").appendVersion(this.state["version"]); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 209 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 210 | this.expressNextInterest(); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 211 | } |
| 212 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 213 | Atmos.prototype.onQueryResultsData = function(interest, data) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 214 | var name = data.getName(); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 215 | delete this.state["outstanding"][interest.getName().toUri()]; |
Tyler Scott | f08ab96 | 2015-06-30 16:31:29 -0600 | [diff] [blame] | 216 | if (!name.get(-1).equals(data.getMetaInfo().getFinalBlockId())) { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 217 | this.expressNextInterest(); |
Tyler Scott | f08ab96 | 2015-06-30 16:31:29 -0600 | [diff] [blame] | 218 | } //else { |
| 219 | //alert("found final block"); |
| 220 | //} |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 221 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 222 | this.state["userOnData"](data); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 223 | } |
| 224 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 225 | Atmos.prototype.onQueryTimeout = function(interest) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 226 | var uri = interest.getName().toUri(); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 227 | if (this.state["outstanding"][uri] < 1) { |
| 228 | this.state["outstanding"][uri] ++; |
| 229 | var scope = this; |
| 230 | this.face.expressInterest(interest, |
| 231 | function(){ |
| 232 | scope.onQueryData.apply(scope, arguments); |
| 233 | }, |
| 234 | function(){ |
| 235 | scope.onQueryTimeout.apply(scope, arguments); |
| 236 | }); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 237 | } else { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 238 | delete this.state["outstanding"][uri]; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 239 | |
| 240 | // We modify the autocomplete box here because we need to know |
| 241 | // we have all of the entries first. Fairly hacky. |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 242 | /* TODO FIXME |
| 243 | var autocompleteFullName = this.autocompleteText.value; |
| 244 | for (var i = 0; i < dropdown.length; ++i) { |
| 245 | if (this.dropdown[i].substr(0, dropdown[i].length - 1).toUpperCase === this.autocompleteText.value.toUpperCase || dropdown.length == 1) { |
| 246 | autocompleteText.value = dropdown[i]; |
| 247 | } |
| 248 | } |
| 249 | */ |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | Atmos.prototype.onQueryResultsTimeout = function(interest) { |
| 254 | var uri = interest.getName().toUri(); |
| 255 | if (this.state["outstanding"][uri] < 1) { |
| 256 | this.state["outstanding"][uri] ++; |
| 257 | var scope = this; |
| 258 | this.face.expressInterest(interest, |
| 259 | function(){ |
| 260 | scope.onQueryResultsData.apply(scope, arguments); |
| 261 | }, |
| 262 | function(){ |
| 263 | scope.onQueryResultsTimeout.apply(scope, arguments); |
| 264 | }); |
| 265 | } else { |
| 266 | delete this.state["outstanding"][uri]; |
| 267 | // We modify the autocomplete box here because we need to know |
| 268 | // we have all of the entries first. Fairly hacky. |
| 269 | /* TODO FIXME |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 270 | var autocompleteFullName = autocompleteText.value; |
| 271 | for (var i = 0; i < dropdown.length; ++i) { |
| 272 | if (dropdown[i].substr(0, dropdown[i].length - 1).toUpperCase === autocompleteText.value.toUpperCase || dropdown.length == 1) { |
| 273 | autocompleteText.value = dropdown[i]; |
| 274 | } |
| 275 | } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 276 | */ |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 280 | Atmos.prototype.populateResults = function(startIndex) { |
| 281 | this.resultTable.empty(); |
| 282 | this.resultTable.append('<tr><th colspan="2">Results</th></tr>'); |
| 283 | |
| 284 | |
| 285 | for (var i = startIndex; i < startIndex + 20 && i < this.results.length; ++i) { |
| 286 | resultTable.append('<tr><td>' + this.results[i] |
| 287 | + '</td><td><button class="interest-button btn btn-default btn-xs">Retrieve</button></td></tr>'); |
| 288 | } |
| 289 | |
| 290 | if (this.results.length <= 20) { |
| 291 | this.page = 1; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 292 | } else { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 293 | this.page = startIndex / 20 + 1; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 294 | } |
| 295 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 296 | this.totalPages = Math.ceil(this.results.length / 20); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 297 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 298 | //TODO Fix the page to fit the theme. |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 299 | var currentPage = $(".page"); |
| 300 | currentPage.empty(); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 301 | if (this.page != 1) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 302 | currentPage.append('<a href="#" onclick="getPage(this.id);" id="<"><</a>'); |
| 303 | } |
| 304 | // This section of code creates the paging for the results. |
| 305 | // To prevent it from having a 1000+ pages, it will only show the 5 pages before/after |
| 306 | // the current page and the total pages (expect users not to really jump around a lot). |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 307 | for (var i = 1; i <= this.totalPages; ++i) { |
| 308 | if (i == 1 || i == this.totalPages // Min or max |
| 309 | || (i <= this.page && i + 5 >= this.page) // in our current page range |
| 310 | || (i >= this.page && i - 5 <= this.page)) { // in our current page range |
| 311 | if (i != this.page) { |
Tyler Scott | f08ab96 | 2015-06-30 16:31:29 -0600 | [diff] [blame] | 312 | currentPage.append(' <a href="#" onclick="getPage(' + i + ');">' + i + '</a>') |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 313 | if (i == 1 && this.page > i + 5) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 314 | currentPage.append(' ... '); |
| 315 | } |
| 316 | } else { |
| 317 | currentPage.append(' ' + i); |
| 318 | } |
| 319 | } else { // Need to skip ahead |
| 320 | if (i == page + 6) { |
| 321 | currentPage.append(' ... '); |
| 322 | |
Tyler Scott | f08ab96 | 2015-06-30 16:31:29 -0600 | [diff] [blame] | 323 | currentPage.append(' <a href="#" onclick="getPage(this.id);" id=">">></a>') |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 324 | i = this.totalPages - 1; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 328 | currentPage.append(' ' + this.results.length + ' results'); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 329 | } |
| 330 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 331 | Atmos.prototype.getPage = function(clickedPage) { |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 332 | console.log(clickedPage); |
| 333 | |
| 334 | var nextPage = clickedPage; |
| 335 | if (clickedPage === "<") { |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 336 | nextPage = this.page - 5; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 337 | } else if (clickedPage === ">") { |
| 338 | console.log("> enabled"); |
| 339 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 340 | nextPage = this.page + 5; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | nextPage--; // Need to adjust for starting at 0 |
| 344 | |
| 345 | if (nextPage < 0 ) { |
| 346 | nextPage = 0; |
| 347 | console.log("0 enabled"); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 348 | } else if (nextPage > this.totalPages - 1) { |
| 349 | nextPage = this.totalPages - 1; |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 350 | console.log("total enabled"); |
| 351 | } |
| 352 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 353 | this.populateResults(nextPage * 20); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 357 | |
| 358 | Atmos.prototype.submitAutoComplete = function() { |
| 359 | /* FIXME TODO |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 360 | if (autocompleteText.value.length > 0) { |
| 361 | var selection = autocompleteText.value; |
| 362 | $.each(dropdown, function (i, dropdownEntry) { |
| 363 | if (dropdownEntry.substr(0, dropdownEntry.length - 1) == selection) { |
| 364 | selection = dropdownEntry; |
| 365 | } |
| 366 | }); |
| 367 | |
| 368 | selectedSearch["?"] = selection; |
| 369 | query(catalog, selectedSearch, onData, 1); |
| 370 | delete selectedSearch["?"]; |
| 371 | } |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 372 | */ |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 373 | } |
| 374 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 375 | Atmos.prototype.populateAutocomplete = function(fields) { |
| 376 | /* FIXME TODO |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 377 | var isAutocompleteFullName = (autocompleteText.value.charAt(autocompleteText.value.length - 1) === "/"); |
| 378 | var autocompleteFullName = autocompleteText.value; |
| 379 | for (var i = 0; i < fields.length; ++i) { |
| 380 | var fieldFullName = fields[i]; |
| 381 | var entry = autocompleteFullName; |
| 382 | var skipahead = ""; |
| 383 | |
| 384 | if (isAutocompleteFullName) { |
| 385 | skipahead = fieldFullName.substr(autocompleteText.value.length, fieldFullName.length); |
| 386 | } else { |
| 387 | if (fieldFullName.charAt(autocompleteText.value.length) === "/") { |
| 388 | entry += "/"; |
| 389 | skipahead = fieldFullName.substr(autocompleteText.value.length + 1, fieldFullName.length); |
| 390 | } else { |
| 391 | skipahead = fieldFullName.substr(autocompleteText.value.length, fieldFullName.length); |
| 392 | } |
| 393 | } |
| 394 | if (skipahead.indexOf("/") != -1) { |
| 395 | entry += skipahead.substr(0, skipahead.indexOf("/") + 1); |
| 396 | } else { |
| 397 | entry += skipahead; |
| 398 | } |
| 399 | |
| 400 | var added = false; |
| 401 | for (var j = 0; j < dropdown.length && !added; ++j) { |
| 402 | if (dropdown[j] === entry) { |
| 403 | added = true; |
| 404 | } else if (dropdown[j] > entry) { |
| 405 | dropdown.splice(j, 0, entry); |
| 406 | added = true; |
| 407 | } |
| 408 | } |
| 409 | if (!added) { |
| 410 | dropdown.push(entry); |
| 411 | } |
| 412 | |
| 413 | } |
| 414 | $("#autocompleteText").autocomplete({ |
| 415 | source: dropdown |
| 416 | }); |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 417 | */ |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 418 | } |
| 419 | |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 420 | /** |
| 421 | * Adds a filter to the list of filters. |
| 422 | * There is no need to remove the filter, it is done via ui clicks. |
| 423 | * |
| 424 | * @param {string} filter |
| 425 | */ |
| 426 | Atmos.prototype.addFilter = function(name){ |
| 427 | var existing = this.filters.find('span:contains(' + name + ')'); |
| 428 | if (existing.length){ |
| 429 | //If the category is clicked twice, then we delete it. |
| 430 | existing.remove(); |
| 431 | this.applyFilters(); |
| 432 | |
| 433 | } else { |
| 434 | |
| 435 | var filter = $('<span class="label label-default"></span>'); |
| 436 | filter.text(name); |
| 437 | |
| 438 | this.filters.append(filter); |
| 439 | |
| 440 | this.applyFilters(); |
| 441 | |
| 442 | var scope = this; |
| 443 | filter.click(function(){ |
| 444 | $(this).remove(); |
| 445 | scope.applyFilters(); |
| 446 | }); |
| 447 | |
| 448 | } |
| 449 | |
| 450 | } |
| 451 | |
| 452 | Atmos.prototype.applyFilters = function(){ |
| 453 | var filters = this.filters.children().toArray().map(function(obj, index){ |
| 454 | return $(obj).text(); |
| 455 | }, []); |
| 456 | console.log('Collected filters:', filters); |
| 457 | this.query(this.catalog, filters, function(data){ |
| 458 | scope.onData(data); |
| 459 | }, 1); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * @deprecated |
| 464 | * Use addFilter instead. |
| 465 | */ |
| 466 | Atmos.prototype.populateCurrentSelections = function() { |
| 467 | console.warn("Use of deprecated function populateCurrentSelections! (Use addFilter instead)"); |
| 468 | /* |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 469 | var currentSelection = $(".currentSelections"); |
| 470 | currentSelection.empty(); |
| 471 | |
| 472 | currentSelection.append("<p>Filtering on:"); |
| 473 | |
Tyler Scott | 7d076e2 | 2015-07-06 19:21:50 -0600 | [diff] [blame] | 474 | var scope = this; |
| 475 | |
| 476 | $.each(this.selectedSearch, function (searchMenuCatagory, selection) { |
| 477 | var e = $('<a href="#">[X] ' + searchMenuCatagory + ":" + selection + '</a>'); |
| 478 | e.onclick(function(){ |
| 479 | var searchFilter = $(this).text(); |
| 480 | |
| 481 | var search = ""; |
| 482 | for (var j = 0; j < searchFilter.length; ++j) { |
| 483 | search += searchFilter[j] + " "; |
| 484 | } |
| 485 | console.log("Split values: '" + search + "'"); |
| 486 | |
| 487 | delete this.selectedSearch[searchFilter[0]]; |
| 488 | this.query(catalog, selectedSearch, onData, 1); |
| 489 | populateCurrentSelections(); |
| 490 | }); |
| 491 | currentSelection.append(e); |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 492 | }); |
| 493 | |
| 494 | currentSelection.append("</p>"); |
Tyler Scott | e815d3e | 2015-07-09 16:56:17 -0600 | [diff] [blame^] | 495 | */ |
Tyler Scott | 3c17d5f | 2015-06-23 17:49:29 -0600 | [diff] [blame] | 496 | } |