Commit a761a623 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

444: Prevent fallback to all collections if sourceId specified, but not

found (OPENED)

Task-Url: search#444
parent 32e1d5de
......@@ -36,7 +36,10 @@ var ResponseHandler = function(options) {
"~eu.dariah.de.minfba.search.view.result.resources.hits_in_document",
"~eu.dariah.de.minfba.search.view.result.show_more",
"~eu.dariah.de.minfba.search.search.keywords",
"~eu.dariah.de.minfba.common.view.label.none"
"~eu.dariah.de.minfba.common.view.label.none",
"~eu.dariah.de.minfba.search.view.labels.unknown_collection",
"~eu.dariah.de.minfba.search.view.notifications.selected_collections_unknown",
"~eu.dariah.de.minfba.search.view.notifications.selected_collection_unknown"
]);
this.imageQueue = [];
};
......@@ -567,6 +570,9 @@ ResponseHandler.prototype.handleSubject = function(subject) {
ResponseHandler.prototype.processResponseDatasources = function(datasources) {
$("#search-results-collections").text("");
$(".search-available-collection-doccount").text("");
$(".search-available-collection.unknown-collection").remove();
$("#search-notifications-container").text("");
$("#search-notifications-container").addClass("hide");
if (datasources==null || datasources.length==0) {
$("#search-results-collections-heading").text(__translator.translate("~eu.dariah.de.minfba.search.view.result.no_results"));
......@@ -574,7 +580,8 @@ ResponseHandler.prototype.processResponseDatasources = function(datasources) {
return;
}
var _this = this;
let unknownCounter = 0;
$("#search-results-collections-heading").text(String.format(__translator.translate("~eu.dariah.de.minfba.search.view.result.results_in_n_collections"), datasources.length));
for (var i=0; i<datasources.length; i++) {
......@@ -613,7 +620,54 @@ ResponseHandler.prototype.processResponseDatasources = function(datasources) {
$("#search-results-collections").append(provider);
$("#search-available-collection-" + datasources[i].providerId).find(".search-available-collection-doccount").text(fmtDocCount);
// Handle unknown or previously unknown (before reload of page) collections
let collTag = $("#search-available-collection-" + datasources[i].providerId);
if (collTag.length>0) {
collTag.find(".search-available-collection-doccount").text(fmtDocCount);
} else {
let id = datasources[i].providerId;
// Replace with (probably rather new and) now found id
if (id.includes("~")) {
let oldId = id.substring(0, id.indexOf("~"));
let replaceId = id.substring(id.indexOf("~")+1);
// Replace now known source id
let selectedIds = JSON.parse($("#selected-datasources").val());
for (var j=0; j<selectedIds.length; j++) {
if (selectedIds[j]==oldId) {
selectedIds[j]=replaceId;
}
}
$("#selected-datasources").val(JSON.stringify(selectedIds));
let sourceTag = $("#search-available-collection-" + replaceId);
// Already there now -> just show
if (sourceTag.length>0) {
sourceTag.addClass("selected");
}
// Not there -> insert for now
else {
$("#search-available-collections").append(
'<li class="search-available-collection selected" id="search-available-collection-' + replaceId + '" style="color: rgb(0, 0, 0);">' +
'<span class="search-available-collection-doccount">' + fmtDocCount + '</span> ' + datasources[i].providerName + '</li>'
)
}
}
// Actual unknown datasource
else if (id.includes(":")) {
$("#search-available-collections").append(
'<li class="search-available-collection unknown-collection selected" id="search-available-collection-' + datasources[i].providerId + '" style="color: rgb(0, 0, 0);">'+
'<span class="search-available-collection-doccount"></span> <em>'+ __translator.translate("~eu.dariah.de.minfba.search.view.labels.unknown_collection") + '</em></li>'
)
unknownCounter++;
}
}
var tagQuery = search.queryHandler.buildQuery(false);
......@@ -657,6 +711,16 @@ ResponseHandler.prototype.processResponseDatasources = function(datasources) {
}
}
if (unknownCounter>0) {
$("#search-notifications-container").removeClass("hide");
$("#search-notifications-container").append('<div class="alert alert-warning" role="alert">' +
'<em class="fas fa-info-circle"></em> ' +
(unknownCounter==1 ?
__translator.translate("~eu.dariah.de.minfba.search.view.notifications.selected_collection_unknown") :
__translator.translate("~eu.dariah.de.minfba.search.view.notifications.selected_collections_unknown")) +
'</div>');
}
search.sourceSelection.renderDatasourceList();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment