Commit 44b99c59 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

1183: Implement search result filtering

Task-Url: https://pm.winseda.de/issues/1183
parent aef57157
......@@ -86,17 +86,23 @@
padding: 10px 0px;
}
.search-result-objects .label {
font-size: 90%;
padding: 5px 5px 3px 5px;
margin-right: 5px;
}
.search-result-label {
border: 1px solid #002547;
background-color: #FFF;
color: #002547;
cursor: pointer;
font-size: 90%;
padding: 5px 5px 3px 5px;
margin-right: 5px;
}
#applied-filters-container {
padding: 10px 5px;
}
.applied-filter {
/*margin-bottom: 10px;*/
}
/*!
......
......@@ -483,11 +483,7 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
content.push(["link", ""]);
}
if (resultElements[i].info.Presentation.Objects!==undefined) {
content.push(["objects", "<div class='search-result-objects'>" + this.handleObjects(resultElements[i].info.Presentation.Objects) + "</div>"]);
} else {
content.push(["objects", ""]);
}
/*if (resultElements[i].info.Presentation.Images!==undefined && resultElements[i].info.Presentation.Images.Resource!==undefined) {
......@@ -498,6 +494,7 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
}*/
$("#search-results-resources").append(this.renderResultItem(itemTemplate, content, hideElements));
if (resultElements[i].info.Presentation.Images!==undefined && resultElements[i].info.Presentation.Images.Resource!==undefined) {
this.handleImages(resultElements[i].collectionId, resultElements[i].endpointId, resultElements[i].datasetId, this.getValues(resultElements[i].info.Presentation.Images.Resource), i, false);
} else {
......@@ -505,6 +502,10 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
this.handleImages(resultElements[i].collectionId, resultElements[i].endpointId, resultElements[i].datasetId, this.getValues(resultElements[i].info.Presentation.Images.Placeholder), i, true);
}
}
if (resultElements[i].info.Presentation.Objects!==undefined) {
this.handleObjects(resultElements[i].info.Presentation.Objects, i);
}
} else {
content.push(["title", "<em>" + __translator.translate("~eu.dariah.de.minfba.search.view.result.no_title") + "</em>"]);
content.push(["link", ""]);
......@@ -520,49 +521,91 @@ QueryHandler.prototype.processResponseResources = function(isShowMore, resultEle
};
QueryHandler.prototype.handleObjects = function(objects) {
var result = "";
QueryHandler.prototype.handleObjects = function(objects, index) {
var result = [];
if (objects.Subject!==undefined) {
if(objects.Subject instanceof Array) {
for (var i=0; i<objects.Subject.length; i++) {
result += this.handleSubject(objects.Subject[i]);
result.push(this.handleSubject(objects.Subject[i]));
}
} else {
result += this.handleSubject(objects.Subject);
result.push(this.handleSubject(objects.Subject));
}
}
return result;
$("#search-result-objects-" + index).append(result);
};
QueryHandler.prototype.handleSubject = function(subject) {
var strSubject = "";
var strSubjectQuery = "[Subject: ";
var strPrimary = undefined;
var strNormal = "";
if (subject.NameAttribution!==undefined) {
strSubjectQuery += "[Name: ";
if (subject.NameAttribution.Primary!==undefined) {
strSubject = subject.NameAttribution.Primary["~"];
strSubjectQuery += '"' + subject.NameAttribution.Primary["~"] + '"';
strPrimary = subject.NameAttribution.Primary["~"];
if (subject.NameAttribution.Additional!==undefined) {
if (subject.NameAttribution.Additional instanceof Array) {
for (var j=0; i<subject.NameAttribution.Additional.length; j++) {
strSubject += " " + subject.NameAttribution.Additional[j]["~"];
strSubjectQuery += ', "' + subject.NameAttribution.Additional[j]["~"] + '"';
strNormal += ", " + subject.NameAttribution.Additional[j]["~"];
}
} else {
strSubject += " " + subject.NameAttribution.Additional["~"];
strSubjectQuery += ', "' + subject.NameAttribution.Additional["~"] + '"';
strNormal += ", " + subject.NameAttribution.Additional["~"];
}
}
} else if (subject.NameAttribution.Name!==undefined) {
strSubject = subject.NameAttribution.Name["~"];
strSubjectQuery += '"' + subject.NameAttribution.Name["~"] + '"';
strNormal = subject.NameAttribution.Name["~"];
}
strSubjectQuery += "]";
}
strSubjectQuery += "]";
return "<span class=\"label search-result-label\" onclick='queryHandler.expandSearch(unescape(\"" + escape(strSubjectQuery) + "\"));'>" +
"<i class=\"fa fa-users\" aria-hidden=\"true\"></i> " + __util.escapeHtml(strSubject) +
"</span>";
var query = {
_presentation : {
Presentation : {
Objects : {
Subject : subject
}
}
}
}
var label = $("<span class=\"label search-result-label\"><i class=\"fa fa-users\" aria-hidden=\"true\"></i> </span>");
if (strPrimary!==undefined) {
$(label).append("<u>" + __util.escapeHtml(strPrimary) + "</u>");
}
$(label).append(__util.escapeHtml(strNormal));
label.data("queryFilter", subject);
label.bind("click", function() {
var match = false;
var _this = this;
$(".applied-filter").each(function() {
if (JSON.stringify($(this).data("queryFilter"))===JSON.stringify($(_this).data("queryFilter"))) {
match = true;
}
});
if (match) {
return;
}
var filterLabel = $("<span class='label search-result-label'>")
.html($(this).html())
.append("&nbsp;<i class=\"fa fa-cross\" aria-hidden=\"true\"></i>");
var filter = $("<div class='applied-filter pull-left'>")
.data("queryFilter", $(this).data("queryFilter"))
.html(filterLabel)
.bind("click", function() {
$(this).remove();
if ($("#applied-filters-container .applied-filter").length==0) {
$("#applied-filters-container").addClass("hide");
}
});
$("#applied-filters-container #applied-filters").append(filter).append(" ");
$("#applied-filters-container").removeClass("hide");
});
return label;
}
......
Supports Markdown
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