Skip to content

Commit

Permalink
Date range feature (#174)
Browse files Browse the repository at this point in the history
* - date addaed range selection feature added

* duplicate class removed from search.html

* Search title customized
  • Loading branch information
satyamrai12 authored Nov 27, 2023
1 parent 29ada0f commit 1b055c2
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

this.ckan.module('daterange', function ($) {
return {
initialize: function () {


const searchParams = new URLSearchParams(window.location.search);
const query = searchParams.get('q')
if(query) {
const hasDateAdded = query.search('date_added')

if(hasDateAdded >= 0) {
const closingPosition = query.indexOf(']', hasDateAdded + 11)
const dateRange = query.substring(hasDateAdded + 12, closingPosition).replaceAll('"', '').split(' TO ')

$('#startrange').val(dateRange[0]);
$('#endrange').val(dateRange[1]);

let message = document.querySelector("#search_title").innerHTML

message = message.split('"date_added')[0]

message = `${message} "${dateRange[0]}" To "${dateRange[1]}"`

document.querySelector("#search_title").innerHTML = message
}
} else {
$('#startrange').val('');
$('#endrange').val('');
}


this._onClick = jQuery.proxy(this._onClick, this);
this.el.on("click", this._onClick);
},
_onClick: async function() {
const start = $("#startrange").val()
const end = $("#endrange").val()
var link = document.createElement("a"); // Create with DOM
link.href = `/dataset?q=date_added:[%22${start}%22%20TO%20%22${end}%22]`;
link.click()
}
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ data_catalog_510-js:
filter: rjsmin
output: ckanext-data_catalog_510/%(version)s-resource.js
contents:
- js/data_catalog_510-daterange.js
- js/main.js
- js/polyfills.js
- js/data_catalog_510-common.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
{% ckan_extends %}
{% block secondary_content %}
{% block secondary_content %}
{% snippet "spatial/snippets/spatial_query.html", default_extent="{ \"type\": \"Polygon\",
\"coordinates\": [[[7.2274985, 50.7295671],[7.2274985, 53.7253321], [1.9193492, 53.7253321], [1.9193492, 50.7295671], [7.2274985, 50.7295671]]]}" %}
{{ super() }}
\"coordinates\": [[[7.2274985, 50.7295671],[7.2274985, 53.7253321], [1.9193492, 53.7253321], [1.9193492, 50.7295671], [7.2274985, 50.7295671]]]}" %}
<!-- {{ super() }} -->

{% for facet in facet_titles %}
{% if facet == 'date_added' %}
<section class="module module-narrow module-shallow">

<h2 class="module-heading">
<i class="fa fa-filter"></i>
Date Added
</h2>
<div class="module-content">
<input type="date" id="startrange" name="date_from" />
<input type="date" id="endrange" name="date_to" />
<button class="btn btn-primary mt-2" data-module="daterange">SEARCH</button>
</div>
</section>
{% else %}
{{ h.snippet('snippets/facet_list.html', title=facet_titles[facet], name=facet, search_facets=search_facets) }}
{% endif %}
{% endfor %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% ckan_extends %}

{% block search_title %}
{% if not error %}
<h1 id="search_title">{% snippet 'snippets/search_result_text.html', query=query, count=count, type=type %}</h1>
{% else %}
<h2>Error</h2>
{% endif %}
{% endblock %}

0 comments on commit 1b055c2

Please sign in to comment.