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

1312: Implement initial vocabulary browsing mechanism

Task-Url: https://pm.winseda.de/issues/1312
parent 09299f8e
......@@ -65,7 +65,7 @@ Search.prototype.isExplain = function() {
};
Search.prototype.resize = function() {
this.queryHandler.resize();
this.tagClouds.resize();
};
Search.prototype.getSelectedSourceIds = function() {
......@@ -80,15 +80,47 @@ Search.prototype.expandSearch = function(expression) {
this.queryHandler.expandSearch(expression);
};
Search.prototype.addFilterTerm = function(filter, type, term) {
Search.prototype.addFilterTerm = function(filter, type, term, control) {
var filters = JSON.parse($("#selected-filters").val());
filters.push({
filter: filter,
type: type,
term: term
})
var isNew = true;
for (var i=0; i<filters.length; i++) {
if (filters[i].label==filter) {
isNew=false;
filters[i].terms.push({
type: type,
term: term
});
}
}
if (isNew) {
filters.push({
label: filter,
terms: [{
type: type,
term: term
}]
});
}
$(control).parent().addClass("selected");
$("#selected-filters").val(JSON.stringify(filters));
this.queryHandler.doSearchDelayed();
this.queryHandler.doSearch();
};
Search.prototype.removeFilterTerm = function(filter, type, term, control) {
var filters = JSON.parse($("#selected-filters").val());
for (var i=0; i<filters.length; i++) {
if (filters[i].label==filter) {
for (var j=0; j<filters[i].terms.length; j++) {
if (filters[i].terms[j].type===type && filters[i].terms[j].term===term) {
filters[i].terms.splice(j, 1);
break;
}
}
}
}
$(control).parent().removeClass("selected");
$("#selected-filters").val(JSON.stringify(filters));
this.queryHandler.doSearch();
};
Search.prototype.showMoreFilterTerms = function(index) {
......
......@@ -260,16 +260,17 @@ QueryHandler.prototype.removeAllFilters = function() {
QueryHandler.prototype.buildQuery = function(isShowMore) {
var query = {
filters : []
entities: [],
filters: JSON.parse($("#selected-filters").val())
};
$(".applied-filter").each(function() {
query.filters.push($(this).data("queryFilter"));
query.entities.push($(this).data("queryFilter"));
});
// Simple query view
if ($("#expression").length>0) {
query.queryString = $("#expression").val();
if ((query.queryString==null || query.queryString=="") && query.filters.length==0) {
if ((query.queryString==null || query.queryString=="") && query.entities.length==0 && query.filters.length==0) {
return null;
}
} else {
......@@ -286,7 +287,7 @@ QueryHandler.prototype.buildQuery = function(isShowMore) {
doQuery = true;
}
});
if (!doQuery && query.filters.length==0) {
if (!doQuery && query.entities.length==0 && query.filters.length==0) {
return null;
}
query.schemaId = $("#schemaId").val();
......@@ -296,8 +297,7 @@ QueryHandler.prototype.buildQuery = function(isShowMore) {
query.explain = $("#explain").prop('checked');
query.sourceIds = search.getSelectedSourceIds();
query.customSearch = this.options.customSearch;
//query.providerIds = JSON.parse($("#providerIds").val());
//query.userCollectionId = parseInt($("#userCollectionId").val());
......
......@@ -27,7 +27,8 @@ var ResponseHandler = function(options) {
explanationContainer: $("#executed-queries")
}
__translator.addTranslations([ "~eu.dariah.de.minfba.search.view.result.no_results",
__translator.addTranslations([ "~eu.dariah.de.minfba.search.view.filter.more",
"~eu.dariah.de.minfba.search.view.result.no_results",
"~eu.dariah.de.minfba.search.view.result.n_of_m_results",
"~eu.dariah.de.minfba.search.view.result.resources.no_preview",
"~eu.dariah.de.minfba.search.view.result.no_title",
......@@ -47,6 +48,7 @@ ResponseHandler.prototype.process = function(data, isShowMore) {
this.processExecutedQueries(data.executedQueries);
this.processResources(isShowMore, data.resultElements, data.startIndex, data.totalHits, data.took, data.hasMore);
this.processResponseDatasources(data.resultDatasources);
this.processFilters(data.availableFilters);
//_this.processResponseTerms();
//_this.processResponseSubjects();
......@@ -54,6 +56,66 @@ ResponseHandler.prototype.process = function(data, isShowMore) {
};
ResponseHandler.prototype.processFilters = function(filters) {
var selFilters = JSON.parse($("#selected-filters").val());
$(".search-available-filter-container").html("");
if (filters!=undefined) {
for (var i=0; i<filters.length; i++) {
var filterSelected = null;
for (var k=0; k<selFilters.length; k++) {
if (selFilters[k].label===filters[i].label) {
filterSelected = selFilters[k];
}
}
$(".search-available-filter-container").append("<h3>" + filters[i].localLabel + "</h3>");
var ul = $("<ul id='search-available-filter-" + i + "'>");
for (var j=0; j<filters[i].terms.length; j++) {
var term = filters[i].terms[j];
var selected = false;
var classes = "";
if (filterSelected!=null) {
for (var l=0; l<filterSelected.terms.length; l++) {
if (filterSelected.terms[l].term===term.term && filterSelected.terms[l].type===term.type) {
selected = true;
}
}
}
if (j>4) {
classes += "hide";
}
if (selected) {
classes += " selected";
}
ul.append( "<li " + (classes.length>0 ? "class='" + classes + "'" : "") + ">" +
"<button class='btn btn-inline' onclick=\"search." + (selected ? 'removeFilterTerm' : 'addFilterTerm') + "('" + filters[i].label + "', '" + term.type + "', '" + term.term + "', this);\">" +
(selected ? "<i class=\"fas fa-times\"></i> " : "") + term.term + " (" + term.count + ")" +
"</button></li>");
}
$(".search-available-filter-container").append(ul);
if (filters[i].totalSize>4) {
$(".search-available-filter-container").append(
"<button id=\"btn-search-available-filter-more-" + i + "\" class=\"btn btn-inline btn-search-available-filter-more\" onclick=\"search.showMoreFilterTerms('" + i + "');\">" +
__translator.translate("~eu.dariah.de.minfba.search.view.filter.more") +
"</button>");
}
}
}
};
ResponseHandler.prototype.processExecutedQueries = function(queries) {
this.elements.explanationContainer.empty();
if (search.isExplain()) {
......
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