Skip to content

Commit

Permalink
smartsearch changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Jun 23, 2023
1 parent 91d6fc9 commit 1578024
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 69 deletions.
4 changes: 4 additions & 0 deletions css/arche.css
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,7 @@ table.dataTable.root-table td {
padding: 15px 15px !important;
}

.searchInElement {
padding: 10px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
Binary file modified inst/sites/default/files/.ht.sqlite
Binary file not shown.
77 changes: 52 additions & 25 deletions js/smartsearch.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
jQuery(function ($) {

"use strict";
$(document).ready(function () {
// update the breadcrumb!!!!
});


/********************** EVENTS *************************************/


// let metaValueField = $("input[name='metavalue']").val().replace(/[^a-z0-9öüäéáűúőóüöíß:./-\s]/gi, '').replace(/[\s]/g, '+');
$(document).delegate("#sks-form-front", "submit", function (e) {
e.preventDefault();

let searchParam = $('#q').val();

$('#block-mainpagecontent').html('<div class="container">' +
'<div class="row">' +
'<div class="col-12 mt-5">' +
Expand All @@ -24,44 +18,75 @@ jQuery(function ($) {
window.location.href = '/browser/search/?q=' + searchParam;
});

function countSearchIn() {
var count = $('.searchInElement').length;
$(".searchOnlyInBtn").html('Search only in ( ' + count + ' ) ');
}

$(document).delegate(".remove_search_only_in", "click", function (e) {
e.preventDefault();
var id = $(this).attr("data-removeid");
// #in17722
$('#searchIn #in' + id).remove();
countSearchIn();
});

$(document).delegate(".smartSearchInAdd", "click", function (e) {
e.preventDefault();
var id = $(this).attr("data-resourceid");
if ($('#in' + id).length === 1) {
return;
}

var element = $('#res' + id).clone();
element.find('div:first-child').remove();
element.find('div:last-child').children('div').remove();
console.log('element');
console.log(element);
element.find('div:first-child').html('<a data-removeid="' + id + '" href="#" class="remove_search_only_in">Remove</a>');
//element.find('div:last-child').children('div').remove();
var btn = element.find('button');
btn.text('-');
btn.attr('onclick', '$(this).parent().parent().parent().remove();');
element.attr('id', 'in' + id);
element.attr('class', 'searchInElement');
element.addClass('row');
$('#searchIn').append(element);
countSearchIn();
});

$(document).delegate(".resetSmartSearch", "click", function (e) {
console.log('clicked');
e.preventDefault();
$('#block-smartsearchblock input[type="text"]').val('');
$('#block-smartsearchblock input[type="search"]').val('');
$('#block-smartsearchblock input[type="checkbox"]').prop('checked', false);
$('#block-smartsearchblock textarea').val('');
$('#block-smartsearchblock select').val('');
});

//main search block
$(document).delegate(".smartsearch-btn", "click", function (e) {
console.log("search clicked");
$('.arche-smartsearch-page-div').show();
$('#block-mainpagecontent').html('<div class="container">' +
'<div class="row">' +
'<div class="col-12 mt-5">' +
'<img class="mx-auto d-block" src="/browser/modules/contrib/arche-gui/images/arche_logo_flip_47px.gif">' +
' </div>' +
'</div>');
search();

e.preventDefault();
});

if (window.location.href.indexOf("browser/search/") >= 0) {
let searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('q')) {
$('#block-mainpagecontent').html('<div class="container">' +
'<div class="row">' +
'<div class="col-12 mt-5">' +
'<img class="mx-auto d-block" src="/browser/modules/contrib/arche-gui/images/arche_logo_flip_47px.gif">' +
' </div>' +
'</div>');
'<div class="row">' +
'<div class="col-12 mt-5">' +
'<img class="mx-auto d-block" src="/browser/modules/contrib/arche-gui/images/arche_logo_flip_47px.gif">' +
' </div>' +
'</div>');
let param = searchParams.get('q');
$('#q').val(param);
//we have to wait 2 secs to download all facets
Expand Down Expand Up @@ -99,7 +124,7 @@ jQuery(function ($) {
url: '/browser/api/searchDateFacet',
success: function (data) {
data = jQuery.parseJSON(data);

$.each(data, function (k, v) {
var facet = '<div class="mt-2">' +
'<label class="mt-2 font-weight-bold" >' + v.label + '</label><br/>' +
Expand All @@ -118,6 +143,7 @@ jQuery(function ($) {
}
});
}

$(document).ready(function () {

fetchFacet();
Expand All @@ -140,7 +166,7 @@ jQuery(function ($) {
}
});
data.unshift({text: 'No filter', value: ''});

resolve(data);
});
} else {
Expand Down Expand Up @@ -198,7 +224,7 @@ jQuery(function ($) {
if (!searchStr) {
searchStr = $('#q').val();
}

var param = {
url: '/browser/api/smartsearch',
method: 'get',
Expand All @@ -222,7 +248,7 @@ jQuery(function ($) {
}
param.data.facets[prop].push(val);
});

$('input.facet-min').each(function (n, facet) {
var prop = $(facet).attr('data-value');
var val = $(facet).val();
Expand All @@ -233,7 +259,7 @@ jQuery(function ($) {
param.data.facets[prop].min = val;
}
});

$('input.facet-max').each(function (n, facet) {
var prop = $(facet).attr('data-value');
var val = $(facet).val();
Expand All @@ -244,33 +270,33 @@ jQuery(function ($) {
param.data.facets[prop].max = val;
}
});

$('input.range:checked').each(function (n, facet) {
var prop = $(facet).attr('data-value');
if (!(prop in param.data.facets)) {
param.data.facets[prop] = {};
}
param.data.facets[prop].distribution = 1;
});

$('input.distribution:checked').each(function (n, facet) {
var prop = $(facet).attr('data-value');
if (!(prop in param.data.facets)) {
param.data.facets[prop] = {};
}
param.data.facets[prop].distribution = (param.data.facets[prop].distribution || 0) + 2;
});

if ($('#searchInChb:checked').length === 1) {
$('#searchIn > div').each(function (n, el) {
param.data.searchIn.push($(el).attr('data-value'));
});
}

if (bbox !== '') {
param.data.facets['bbox'] = bbox;
}

var t0 = new Date();

param.success = function (x) {
Expand All @@ -290,7 +316,8 @@ jQuery(function ($) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
};

console.log("param: ");
console.log(param);
$.ajax(param);
}

Expand All @@ -305,7 +332,7 @@ jQuery(function ($) {
function showResults(data, param, t0) {
t0 = (new Date() - t0) / 1000;
data = jQuery.parseJSON(data);

var pages = $('#page').get(0);
var pageCount = Math.ceil(data.totalCount / data.pageSize);
$('#pageCount').text('/ ' + pageCount);
Expand Down
70 changes: 26 additions & 44 deletions templates/arche-smart-search-view.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3>Search</h3>
<h3>{{ "Search"|trans }}</h3>
<input type="hidden" id="arche_url" value="{{ archeUrl }}"/>
<form class="row gy-2 gx-3 align-items-center" id="smartsearch-left">

Expand Down Expand Up @@ -34,35 +34,13 @@
</div>
<hr/>
</div>

<div class="col-lg-12">
<div class="form-outline">
<label class="mx-2 font-weight-bold" for="pageSize">{{ "Page size"|trans }}:</label>
<input class="form-control mr-sm-2 w-100" type="number" value="10" min="1" id="pageSize"/>
</div>
<div class="form-outline mt-2">
<label class="mx-2 font-weight-bold" for="page">{{ "Page"|trans }}:</label>
<div class="input-group mr-sm-2 w-100">
<select class="form-control" id="page" onchange="search();">
<option value="0" selected="selected">1</option>
</select>
<div class="input-group-append">
<div class="input-group-text" id="pageCount">/ 1</div>
</div>
</div>
</div>
</div>

<div class="col-lg-12 mt-2 mb-2">
<input class="smartsearch-btn btn btn-info w-100" data-drupal-selector="edit-submit" type="submit" id="edit-submit" name="op" value="Search">
</div>

</form>

<div class="container-fluid">
<div class="row">
<div class="col-12">
<form class="form">
<div class="col-12 mt-2">
<button type="button" class="btn btn-info" onclick="jQuery('#extendedSearch').toggle();">{{ "Extended Search"|trans }}</button>
<div class="arche_search_toggle_div" id="extendedSearch">
<div id="facets"></div>
<div>
<h4 class="mt-3">{{ "Spatial area"|trans }}</h4>
Expand All @@ -79,35 +57,39 @@
</div>
</div>
<div id="dateFacets"></div>
</form>
<hr/>
</div>
</div>
<div class="col-12">
<h5>
<form class="form-inline">
<button type="button" class="btn btn-info w-100" onclick="$(this).parent().parent().children('div').html('');">{{ "Reset"|trans }}</button>
<br/>

</form>
</h5>
<div id="searchIn"></div>
<div class="col-12 mt-2">
<button type="button" class="btn btn-info" onclick="jQuery('#searchMap').toggle();">{{ "Map"|trans }}</button>
<div class="arche_search_toggle_div" id="searchMap">
map goes here
</div>
</div>
<div class="col-12 mt-2">
<button type="button" class="btn btn-info searchOnlyInBtn" onclick="jQuery('#searchIn').toggle();">{{ "Search only in"|trans }}</button>
<div class="arche_search_toggle_div" id="searchIn">
<div id="searchInInside"></div>
</div>
</div>

<div class="col-lg-12 mt-2">
<div class="form-outline">
<input class="form-check-input ml-2" type="checkbox" id="searchInChb" checked="checked">&nbsp;
<label class="form-check-label mr-2" for="searchInChb">{{ "Search only in"|trans }}</label>
</div>
</div>
<hr/>
<div class="col-12">
<h5>
<form class="form-inline">
<button type="button" class="btn btn-info w-100 resetSmartSearch" >{{ "Reset"|trans }}</button>
<br/>
</form>
</h5>
</div>



</div>
<div class="row">
<div class="col-lg-12">
<div class="col-lg-12 mt-2 mb-2">
<input class="smartsearch-btn btn btn-info w-100" data-drupal-selector="edit-submit" type="submit" id="edit-submit" name="op" value="Search">
<hr/>
</div>
</div>

</div>

0 comments on commit 1578024

Please sign in to comment.