|
1 |
| -var footprints_layer_style = { |
| 1 | +"use strict"; |
| 2 | + |
| 3 | +let footprints_layer_style = { |
2 | 4 | "color": "#0000ff",
|
3 | 5 | "weight": 1,
|
4 | 6 | "opacity": 0.9,
|
5 | 7 | "fillOpacity": 0.1,
|
6 | 8 | };
|
7 | 9 |
|
8 |
| -var polygons = {}; |
| 10 | +let polygons = {}; |
| 11 | + |
| 12 | +function display_page(page) { |
| 13 | + // clear existing contents |
| 14 | + let datasets_table = document.getElementById("datasets_table"); |
| 15 | + // add the current page of datasets to the table |
| 16 | + if(page.results){ |
| 17 | + datasets_table.querySelectorAll("tbody > tr").forEach((row) => {row.remove()}); |
| 18 | + let newRow; |
| 19 | + let newCell; |
| 20 | + for(let dataset of page.results) { |
| 21 | + newRow = datasets_table.querySelector('tbody').insertRow(); |
| 22 | + newCell = newRow.insertCell(); |
| 23 | + newCell.appendChild(document.createTextNode(dataset.entry_id)); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + // deal with cursor pagination |
| 28 | + let previous_button = document.getElementById("datasets_previous_button"); |
| 29 | + let next_button = document.getElementById("datasets_next_button"); |
| 30 | + if(page.previous) { |
| 31 | + let previous_url = new URL(page.previous); |
| 32 | + previous_button.setAttribute("data-cursor", previous_url.searchParams.get('cursor')); |
| 33 | + previous_button.disabled = false; |
| 34 | + } else { |
| 35 | + previous_button.disabled = true; |
| 36 | + } |
| 37 | + if(page.next) { |
| 38 | + let next_url = new URL(page.next); |
| 39 | + next_button.setAttribute("data-cursor", next_url.searchParams.get('cursor')); |
| 40 | + next_button.disabled = false; |
| 41 | + } else { |
| 42 | + next_button.disabled = true; |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +function get_datasets(url, request_parameters) { |
| 47 | + let full_request_parameters = { |
| 48 | + ...request_parameters, |
| 49 | + }; |
| 50 | + let time_coverage_start = document.getElementById("id_time_coverage_start").value; |
| 51 | + let time_coverage_end = document.getElementById("id_time_coverage_end").value; |
| 52 | + let tags = document.getElementById("id_tags").value; |
| 53 | + let keywords = document.getElementById("id_keywords").value; |
| 54 | + let full_text = document.getElementById("id_full_text").value; |
| 55 | + let parameters = document.getElementById("id_parameters").value; |
| 56 | + |
| 57 | + if(time_coverage_start) {full_request_parameters.time_coverage_end__gte = time_coverage_start;} |
| 58 | + if(time_coverage_end) {full_request_parameters.time_coverage_start__lte = time_coverage_end;} |
9 | 59 |
|
10 |
| -$(document).ready(function(){ |
11 |
| - $(".dataset_row").each(function(){ |
12 |
| - polygons[$(this).attr("ajax_url")] = new L.GeoJSON.AJAX( |
13 |
| - $(this).attr("ajax_url"), |
14 |
| - {style: footprints_layer_style}).addTo(window.maps[0]); |
| 60 | + |
| 61 | + fetch(`${url}?` + new URLSearchParams(full_request_parameters).toString()) |
| 62 | + .then(response => response.json()) |
| 63 | + .then(page => display_page(page)) |
| 64 | + .catch(error => console.log(`${error}: Failed to get datasets`)); |
| 65 | +} |
| 66 | + |
| 67 | +document.addEventListener("DOMContentLoaded", function() { |
| 68 | + // add listeners to trigger datasets search |
| 69 | + let host = `${window.location.protocol}//${window.location.host}` |
| 70 | + document.querySelectorAll( |
| 71 | + "#dataset_search_button, #datasets_previous_button, #datasets_next_button" |
| 72 | + ).forEach((element) => element.addEventListener( |
| 73 | + "click", |
| 74 | + function() { |
| 75 | + let parameters = {page_size: document.getElementById("datasets_page_size").value}; |
| 76 | + let cursor = this.getAttribute('data-cursor'); |
| 77 | + if(cursor) {parameters.cursor = cursor;} |
| 78 | + get_datasets(`${host}${this.getAttribute('data-path')}`, parameters); |
| 79 | + } |
| 80 | + )); |
| 81 | + |
| 82 | + // trigger Search click if user presses enter on page size field |
| 83 | + document.getElementById("datasets_page_size").addEventListener("keypress", function(event) { |
| 84 | + if (event.key === "Enter") { |
| 85 | + event.preventDefault(); |
| 86 | + document.getElementById("dataset_search_button").click(); |
| 87 | + } |
15 | 88 | });
|
16 | 89 |
|
17 |
| - $(".dataset_row").hover( |
18 |
| - function(){ |
19 |
| - $(this).css("background-color", "#ffeeee"); |
20 |
| - polygons[$(this).attr("ajax_url")].setStyle({color: '#ff0000'}); |
21 |
| - }, |
22 |
| - function(){ |
23 |
| - $(this).css("background-color", "#ffffff"); |
24 |
| - polygons[$(this).attr("ajax_url")].setStyle({color: '#0000ff'}); |
25 |
| - }, |
26 |
| - ); |
| 90 | + |
| 91 | + // // highlights dataset coverage on the map |
| 92 | + // document.querySelectorAll(".dataset_row").forEach( |
| 93 | + // function(element) { |
| 94 | + // polygons[element.ajax_url] = new L.GeoJSON.AJAX( |
| 95 | + // element.ajax_url, |
| 96 | + // {style: footprints_layer_style}).addTo(window.maps[0]); |
| 97 | + // } |
| 98 | + // ); |
| 99 | + |
| 100 | + // $(".dataset_row").hover( |
| 101 | + // function(){ |
| 102 | + // $(this).css("background-color", "#ffeeee"); |
| 103 | + // polygons[$(this).attr("ajax_url")].setStyle({color: '#ff0000'}); |
| 104 | + // }, |
| 105 | + // function(){ |
| 106 | + // $(this).css("background-color", "#ffffff"); |
| 107 | + // polygons[$(this).attr("ajax_url")].setStyle({color: '#0000ff'}); |
| 108 | + // }, |
| 109 | + // ); |
27 | 110 | });
|
0 commit comments