Skip to content

Commit

Permalink
clarin vcr
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Sep 2, 2024
1 parent d797e4f commit 3150b00
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 110 deletions.
2 changes: 1 addition & 1 deletion arche_core_gui.module
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function arche_core_gui_theme($existing, $type, $theme, $path)
'variables' => ['data' => NULL, 'identifier' => NULL],
],
'arche-discover' => [
'variables' => ['data' => NULL, 'identifier' => NULL],
'variables' => ['data' => NULL, 'vcrUrl' => NULL],
],
'dissemination-3d-viewer' => [
'variables' => ['data' => NULL],
Expand Down
3 changes: 0 additions & 3 deletions js/smartsearch-url-func.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ jQuery(function ($) {
}

window.getSearchParamsFromUrl = function (url) {
//function getSearchParamsFromUrl(url) {
var paramsString = "";
if (url.split('/browser/discover?')[1]) {
paramsString = url.split('/browser/discover?')[1];
} else {
paramsString = url.split('/browser/discover/')[1];
}

paramsString = paramsString.replace('?q', 'q');

window.guiObj = {};
window.guiObj = window.parseQueryString(paramsString);
window.firstLoad = false;
Expand Down
89 changes: 43 additions & 46 deletions js/smartsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ jQuery(function ($) {
$('#searchInValue').val(resourceId);
var buttonId = $(this).attr('id');
if (buttonId === 'removeSearchInElementBtn') { // Check if the id is equal to 'yourId'
$('#searchIn').empty();
$('#searchIn').hide();
$('#searchInValue').val("");
$('#searchIn').hide();
//$('.discover-content-main .smart-result-row .searchInBtn').prop('disabled', false);
} else {
$('#searchIn').empty();
$('#searchIn').hide();
$('#searchInValue').val("");
$('#searchIn').hide();
//$('.discover-content-main .smart-result-row .searchInBtn').prop('disabled', false);
} else {
searchInAdd(resourceId, $(this).data('resource-title'));
$('#searchIn').show();
}

window.executeTheSearch();
/*
// Get the id attribute value of the clicked button
// Get the id attribute value of the clicked button
if (buttonId === 'removeSearchInElementBtn') { // Check if the id is equal to 'yourId'
$('#searchIn').empty();
$('#searchIn').hide();
Expand Down Expand Up @@ -161,7 +161,7 @@ jQuery(function ($) {

// Replace the specific part with a single &
var newUrl = paramsString.replace(pattern, '&');

window.guiObj = {};
// Fix any potential issues with dangling & or multiple & in a row
newUrl = newUrl.replace(/&&/, '&').replace(/\?&/, '?').replace(/&$/, '');
Expand Down Expand Up @@ -265,9 +265,6 @@ jQuery(function ($) {
};
*/
param.error = function (xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
if (error === 'timeout') {
$('.main-content-row').html('<div class="alert alert-danger" role="alert">' + Drupal.t("Timeout error, please refine your Query!") + '</div>');
} else {
Expand All @@ -289,35 +286,9 @@ jQuery(function ($) {
}
}

/**
* Perform the main search function
* @returns {undefined}
*/
function search() {
window.token++;
$('.main-content-warnings').html('');
var localToken = window.token;

if (window.popstateActive === 'true') {
window.firstLoad = false;
}

if (window.firstLoad) {
return showJustSearchFacets();
}

var searchStr = $('#sm-hero-str').val();
var pagerPage = (window.getGuiSearchParams('actualPage') ?? 1) - 1;
//var guiFacets_ = (getGuiSearchParams('facets')) ? getGuiSearchParams('facets') : {};

if (searchStr === "") {
searchStr = (window.getGuiSearchParams('q')) ? window.getGuiSearchParams('q') : "";
}

updateSearchStrInput(searchStr);

window.buildParams = function (searchStr, pagerPage, apiUrl = '/browser/api/smartsearch') {
var param = {
url: '/browser/api/smartsearch',
url: apiUrl,
method: 'get',
data: {
q: searchStr,
Expand All @@ -332,6 +303,7 @@ jQuery(function ($) {
//noCache: $('#noCache').is(':checked') ? 1 : 0
}
};

//if we have already selected facets from the url then we have to update
// the facets
if (window.getGuiSearchParams('facets')) {
Expand Down Expand Up @@ -401,6 +373,37 @@ jQuery(function ($) {
param.data.facets['map'] = 'POLYGON((' + coord.map((x) => x[0] + ' ' + x[1]).join(',') + '))';
}
}
return param;
}

/**
* Perform the main search function
* @returns {undefined}
*/
function search() {
window.token++;
$('.main-content-warnings').html('');
var localToken = window.token;

if (window.popstateActive === 'true') {
window.firstLoad = false;
}

if (window.firstLoad) {
return showJustSearchFacets();
}

var searchStr = $('#sm-hero-str').val();
var pagerPage = (window.getGuiSearchParams('actualPage') ?? 1) - 1;
//var guiFacets_ = (getGuiSearchParams('facets')) ? getGuiSearchParams('facets') : {};

if (searchStr === "") {
searchStr = (window.getGuiSearchParams('q')) ? window.getGuiSearchParams('q') : "";
}

updateSearchStrInput(searchStr);

var param = window.buildParams(searchStr, pagerPage);

//updateUrl(param.data);
var t0 = new Date();
Expand All @@ -415,13 +418,9 @@ jQuery(function ($) {
param.fail = function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
$('.main-content-row').html('<div class="alert alert-danger" role="alert">' + Drupal.t("Error! Search API has the following error: " + error) + '</div>');

};

param.error = function (xhr, status, error) {
console.log(xhr);
console.log(status);
console.log(error);
if (error === 'timeout') {
$('.main-content-row').html('<div class="alert alert-danger" role="alert">' + Drupal.t("Timeout error, please refine your Query!") + '</div>');
$(".discover-left input, .discover-left textarea, .discover-left select, .discover-left button").prop("disabled", false);
Expand All @@ -435,8 +434,6 @@ jQuery(function ($) {
$.ajax(param);
}



/**
* Load the latest url after the user clicked the back button on the browser
* @returns {undefined}
Expand Down
100 changes: 47 additions & 53 deletions js/vcrSubmit.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
jQuery(function ($) {


$("#getClarinVCR").click(function (e) {

e.preventDefault();
//$('#submit-search-vcr').hide();
$("#getClarinVCR").click(function (event) {
event.preventDefault();
$('#getClarinVCR').hide();
$('#vcr-data-loading').show();
setInterval(blink_text('vcr-data-loading'), 10000);

var searchStr = $('#sm-hero-str').val();
var pagerPage = (window.getGuiSearchParams('actualPage') ?? 1) - 1;
//var guiFacets_ = (getGuiSearchParams('facets')) ? getGuiSearchParams('facets') : {};

if (searchStr === "") {
searchStr = (window.getGuiSearchParams('q')) ? window.getGuiSearchParams('q') : "";
}

let metavalue = vcrMeta();
let url = "/browser/api/vcr/" + metavalue;
$.ajax({
type: "GET",
url: url,
success: function (data) {

buildAndSubmitVcrForm($('#search-clarinurl').val(), data);

$('#vcr-data-loading').hide();
$('#vcr-search-result-text').append('VCR Data Submitted');
setTimeout(
function ()
{

//$('#dynamicVcr').submit(function() { e.preventDefault();});
var param = window.buildParams(searchStr, pagerPage, '/browser/api/vcr/');
param.success = function (x) {
buildAndSubmitVcrForm($('#search-clarinurl').val(), x);
$('#vcr-data-loading').hide();
$('#vcr-search-result-text').append('VCR Data Submitted');
setTimeout(
function () {
//$('#dynamicVcr').submit(function (e) {
// e.preventDefault();
//});
$('#vcr-search-result-text').hide();
$('#submit-search-vcr').show();
}, 2000);
},
error: function(data) {
$('#vcr-search-result-text').append('Error: ' + data.responseText);
}
});
$('#getClarinVCR').show();
},
4000);
};

param.fail = function (xhr, textStatus, errorThrown) {
$('#vcr-search-result-text').append(Drupal.t('VCR Data Submit Failed'));
};

param.error = function (xhr, status, error) {
$('#vcr-search-result-text').append(Drupal.t('VCR Data Submit Failed') + error);
};
param.timeout = 60000;
$.ajax(param);



});
Expand All @@ -42,37 +51,22 @@ jQuery(function ($) {
}

function buildAndSubmitVcrForm(clarinUrl, data) {

$('<form action="' + clarinUrl + '" method="POST" target="_blank" id="dynamicVcr" class="dynamicVcrForm">\n\
<input type="hidden" name="name" value="ArcheCollection"/>\n\</form>').appendTo('#vcr-search-form');
let obj = JSON.parse(data);
$.each(obj, function (key, value) {
$('<input type="hidden" id="vcrResourceUri" name="resourceUri"/>').val(JSON.stringify(value)).appendTo('#dynamicVcr');
var dataObj = {};
dataObj.uri = value.uri;
dataObj.title = value.title;
dataObj.description = value.description;
$('<input type="hidden" name="resourceUri"/>').val(JSON.stringify(dataObj)).appendTo('#dynamicVcr');
});

$('#dynamicVcr').submit();

}

/**
* Get the search string values for the vcr data
* @returns string
*/
function vcrMeta() {
let url = window.location.href;

if(url.includes('/browser/discover/root')) {
return "type=acdh:TopCollection";
}else if (url.includes('/search/')) {
url = url.substring(url.indexOf("/search/") + 8);
return url.split('&payload', 8)[0];
} else {
alert('This is not a search page!');
}
setTimeout(function () {
$('#dynamicVcr').submit();
}, 200);

}






});

2 changes: 2 additions & 0 deletions src/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ public function detailView(string $identifier) {
}

public function discoverView($str = NULL) {

$return = [
'#theme' => 'arche-discover',
'#cache' => ['max-age' => 0],
'#vcrUrl' => $this->config->clarinVcrUrl,
'#attached' => [
'library' => [
'arche_core_gui/discover-view',
Expand Down
2 changes: 1 addition & 1 deletion templates/arche-discover.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="col-lg-3 discover-left" >
{{ include(arche_core_gui_path ~ '/templates/blocks/discover-smart-search.html.twig', {'data': data } ) }}
<br>
{{ include(arche_core_gui_path ~ '/templates/blocks/clarin-vcr-block.html.twig', {'data': data } ) }}
{{ include(arche_core_gui_path ~ '/templates/blocks/clarin-vcr-block.html.twig', {'vcrUrl': vcrUrl } ) }}
</div>

<div class="col-lg-9 discover-main " >
Expand Down
16 changes: 10 additions & 6 deletions templates/blocks/clarin-vcr-block.html.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<div class="res-act-button">
<a href="#" id="getClarinVCR" data-vcrdata="{{ data }}" >{{ "Add to CLARIN Virtual Collection"|trans }}</a>
<div id="vcr-data-loading" style="display:none">
<span class="">{{ "VCR Data Loading..."|trans }}</span>
</div>
<div class="col-12 mt-2">
<input type="hidden" id="search-clarinurl" value="{{ vcrUrl }}">
<a href="#" class="btn btn-arche-blue w-100 smartsearch-btn" id="getClarinVCR">{{ "Add to CLARIN Virtual Collection"|trans }}</a>
<div id="vcr-search-form"></div>
<div id="vcr-search-result"><span class="res-title" id="vcr-search-result-text"></span></div>
<div id="vcr-data-loading" style="display:none"><span class="res-title">{{ "VCR Data Loading..."|trans }}</span></div>


<!--
<div id="vcr-div">
<form action="{{ url }}" method="POST" target="_blank">
<input type="hidden" name="name" value="ArcheCollection"/>
<input type="hidden" name="resourceUri" value="{{ data }}"/>
</form>
</div>
</div>-->
</div>


0 comments on commit 3150b00

Please sign in to comment.