Commit 2c8c8403 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

1186: Present new tag clouds

Task-Url: https://pm.winseda.de/issues/1186
parent 026c091f
h5, .h5 {
font-size: 16px;
}
/*! Shared application.css */
......@@ -111,6 +115,26 @@
/*margin-bottom: 10px;*/
}
.aggregation-carousel {
border: 1px solid #888;
padding: 5px;
}
.aggregation-carousel .item {
text-align: center;
}
.aggregation-carousel .item h5 {
border-bottom: 1px solid #888;
padding-bottom: 10px;
}
.aggregation-carousel .wordcloud {
text-align: center;
vertical-align: middle;
}
}
/*!
* Recent functionality additions (no-refactor-zone)
*/
......
......@@ -75,6 +75,9 @@ var QueryHandler = function(options) {
"~eu.dariah.de.minfba.search.view.datamodel_info.datamodels",
"~eu.dariah.de.minfba.search.view.datamodel_info.no_query_possible",
"~eu.dariah.de.minfba.search.search.collections.terms",
"~eu.dariah.de.minfba.search.search.collections.subjects",
"~eu.dariah.de.minfba.search.view.result.n_of_m_results",
"~eu.dariah.de.minfba.search.view.result.results_in_n_collections",
"~eu.dariah.de.minfba.search.view.result.no_results",
......@@ -304,12 +307,12 @@ QueryHandler.prototype.delaySearch = function(timestamp) {
QueryHandler.prototype.processResponseExecutedQueries = function(queries, explain) {
$("#executed-queries").text("");
if (explain) {
$("#search-results-container a[href='#search-results-2']").closest("li").removeClass("hide");
$("#search-results-container a[href='#search-results-explanations-tab']").closest("li").removeClass("hide");
for (var i=0; i<queries.length; i++) {
$("#executed-queries").append("<pre>" + queries[i] + "</pre>");
}
} else {
$("#search-results-container a[href='#search-results-2']").closest("li").addClass("hide");
$("#search-results-container a[href='#search-results-explanations-tab']").closest("li").addClass("hide");
}
}
......@@ -330,6 +333,8 @@ QueryHandler.prototype.processResponse = function(data, isShowMore) {
dataType: "text",
success: function(template) {
_this.processResponseResources(isShowMore, data.resultElements, data.startIndex, data.totalHits, data.took, data.hasMore, template);
_this.processResponseTerms();
_this.processResponseSubjects();
_this.processResponseDatasources(data.resultDatasources);
},
error : function() {}
......@@ -337,6 +342,64 @@ QueryHandler.prototype.processResponse = function(data, isShowMore) {
};
QueryHandler.prototype.processResponseSubjects = function() {
$("#search-results-subjects").html("<div id=\"subjects-wordcloud-Subject\" class=\"wordcloud\"></div><div id=\"subjects-wordcloud-significant-Subject\" class=\"wordcloud\"></div>");
var _this = this;
var tagQuery = this.buildQuery(false);
tagQuery.tagAggregators = ["Subject"];
tagQuery.size = this.options.wordcloud.tags.size;
$.ajax({
url: __util.composeUrl("query/tags/"),
data: JSON.stringify({query : tagQuery }),
context: {
aggs : tagQuery.tagAggregators,
},
type: "POST",
dataType: "json",
contentType: "application/json",
success: function(data) {
for (var i=0; i<this.aggs.length; i++) {
if (data.tags.hasOwnProperty(this.aggs[i])) {
_this.fillWordcloud("#subjects-wordcloud-" + this.aggs[i], data.tags[this.aggs[i]]);
}
}
},
error: __util.processServerError
});
}
QueryHandler.prototype.processResponseTerms = function() {
$("#search-results-terms").html("<div id=\"terms-wordcloud-Wordcloud\" class=\"wordcloud\"></div><div id=\"terms-wordcloud-significant-Wordcloud\" class=\"wordcloud\"></div>");
var _this = this;
var tagQuery = this.buildQuery(false);
tagQuery.tagAggregators = ["Wordcloud"];
tagQuery.size = this.options.wordcloud.tags.size;
$.ajax({
url: __util.composeUrl("query/tags/"),
data: JSON.stringify({query : tagQuery }),
context: {
aggs : tagQuery.tagAggregators,
},
type: "POST",
dataType: "json",
contentType: "application/json",
success: function(data) {
for (var i=0; i<this.aggs.length; i++) {
if (data.tags.hasOwnProperty(this.aggs[i])) {
_this.fillWordcloud("#terms-wordcloud-" + this.aggs[i], data.tags[this.aggs[i]]);
}
}
},
error: __util.processServerError
});
}
QueryHandler.prototype.processResponseDatasources = function(datasources) {
$("#search-results-collections").text("");
$(".search-available-collection-doccount").text("");
......@@ -360,11 +423,36 @@ QueryHandler.prototype.processResponseDatasources = function(datasources) {
provider += fmtDocCount + " " + __translator.translate("~eu.dariah.de.minfba.search.view.datamodel_info.documents");
}
provider += "</small></h4>" +
"<div id=\"datasource-wordcloud-" + datasources[i].providerId + "\" class=\"wordcloud\" style=\"text-align: left;\">" +
"</div>";
"<div id=\"datasource-aggregation-carousel-" + datasources[i].providerId + "\" class=\"aggregation-carousel carousel slide\" data-ride=\"carousel\">" +
"<ol class=\"carousel-indicators\">" +
"<li data-target=\"#datasource-aggregation-carousel-" + datasources[i].providerId + "\" data-slide-to=\"0\" class=\"active\"></li>" +
"<li data-target=\"#datasource-aggregation-carousel-" + datasources[i].providerId + "\" data-slide-to=\"1\"></li>" +
"</ol>" +
"<div class=\"carousel-inner\" role=\"listbox\">" +
"<div class=\"item active\">" +
"<h5>" + __translator.translate("~eu.dariah.de.minfba.search.search.collections.terms") + "</h5>" +
"<div id=\"datasource-wordcloud-" + datasources[i].providerId + "-Wordcloud\" class=\"wordcloud\" style=\"height: " + this.options.wordcloud.height + "px;\"></div>" +
"</div>" +
"<div class=\"item\">" +
"<h5>" + __translator.translate("~eu.dariah.de.minfba.search.search.collections.subjects") + "</h5>" +
"<div id=\"datasource-wordcloud-" + datasources[i].providerId + "-Subject\" class=\"wordcloud\" style=\"height: " + this.options.wordcloud.height + "px;\"></div>" +
"</div>" +
"</div>" +
"<a class=\"left carousel-control\" href=\"#datasource-aggregation-carousel-" + datasources[i].providerId + "\" role=\"button\" data-slide=\"prev\">" +
"<span class=\"glyphicon glyphicon-chevron-left\" aria-hidden=\"true\"></span>" +
"<span class=\"sr-only\">Previous</span>" +
"</a>" +
"<a class=\"right carousel-control\" href=\"#datasource-aggregation-carousel-" + datasources[i].providerId + "\" role=\"button\" data-slide=\"next\">" +
"<span class=\"glyphicon glyphicon-chevron-right\" aria-hidden=\"true\"></span>" +
"<span class=\"sr-only\">Next</span>" +
"</a>" +
"</div>" +
"</div>";
$("#search-results-collections").append(provider);
$("#datasource-aggregation-carousel-" + datasources[i].providerId).carousel({interval: false});
$("#search-available-collection-" + datasources[i].providerId).find(".search-available-collection-doccount").text(fmtDocCount);
var tagQuery = this.buildQuery(false);
......@@ -372,42 +460,59 @@ QueryHandler.prototype.processResponseDatasources = function(datasources) {
// Deep clone of the original query
/*var tagQuery = jQuery.extend(true, {}, _this.query);*/
tagQuery.sourceIds = [ datasources[i].providerId ];
tagQuery.tagAggregator = this.options.wordcloud.tags.aggregator;
tagQuery.tagAggregators = ["Wordcloud", "Subject"];
tagQuery.size = this.options.wordcloud.tags.size;
//if (datasources[i].loadTags) {
if (datasources[i].loadTags) {
$.ajax({
url: __util.composeUrl("query/tags/"),
data: JSON.stringify({query : tagQuery }),
context: {
datasourceId: datasources[i].providerId,
aggs : tagQuery.tagAggregators
},
type: "POST",
dataType: "json",
contentType: "application/json",
success: function(data) { _this.fillWordcloud(data, true); },
success: function(data) {
for (var i=0; i<this.aggs.length; i++) {
if (data.tags.hasOwnProperty(this.aggs[i])) {
var onclick;
if (this.aggs[i]=="Wordcloud") {
onclick = function(tag) { _this.expandSearch(tag.text); }
} else {
onclick = function(tag) { _this.expandSearch(tag.text); }
}
_this.fillWordcloud("#datasource-wordcloud-" + this.datasourceId + "-" + this.aggs[i], data.tags[this.aggs[i]], false, onclick);
}
}
},
error: __util.processServerError
});
//}
}
}
sourceSelection.renderDatasourceList();
};
QueryHandler.prototype.fillWordcloud = function(data, significant) {
QueryHandler.prototype.fillWordcloud = function(container, data, significant, onclick) {
var _this = this;
var tags = [];
for (var i=0; i<data.tags.length; i++) {
for (var i=0; i<data.length; i++) {
tags.push({
text: data.tags[i].term,
size: (data.tags[i].weight * _this.options.wordcloud.tagsize.factor) + _this.options.wordcloud.tagsize.offset,
title: data.tags[i].count + " occurences"
text: data[i].term.length>35 ? (data[i].term.substring(0, 32) + "...") : data[i].term,
size: (data[i].weight * _this.options.wordcloud.tagsize.factor) + _this.options.wordcloud.tagsize.offset,
title: data[i].count + " occurences"
});
}
if (tags.length==0) {
if (significant) {
$("#datasource-wordcloud-" + data.datasourceIds[0]).html(__translator.translate("~eu.dariah.de.minfba.search.view.result.no_significant_terms"));
$(container).html(__translator.translate("~eu.dariah.de.minfba.search.view.result.no_significant_terms"));
} else {
$("#datasource-wordcloud-" + data.datasourceIds[0]).html(__translator.translate("~eu.dariah.de.minfba.search.view.result.no_frequent_terms"));
$(container).html(__translator.translate("~eu.dariah.de.minfba.search.view.result.no_frequent_terms"));
}
return;
}
......@@ -415,12 +520,12 @@ QueryHandler.prototype.fillWordcloud = function(data, significant) {
var width = $("#search-results-container").width() - 50;
this.clouds.push (new TagCloud({
tags: tags,
containerSelector: "#datasource-wordcloud-" + data.datasourceIds[0],
containerSelector: container,
animateTransform: _this.options.wordcloud.animate,
animateTransformDir: _this.options.wordcloud.animateDirection,
w: width,
h: _this.options.wordcloud.height,
textClickEvent: function(tag) { _this.handleTagTextClicked(tag); }
textClickEvent: function(tag) { if (onclick!==undefined) { onclick(tag); } }
}));
};
......@@ -553,6 +658,7 @@ QueryHandler.prototype.handleObjects = function(objects, index) {
};
QueryHandler.prototype.handleSubject = function(subject) {
var _this = this;
var strPrimary = undefined;
var strNormal = "";
if (subject.NameAttribution!==undefined) {
......@@ -560,9 +666,8 @@ QueryHandler.prototype.handleSubject = function(subject) {
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++) {
for (var j=0; j<subject.NameAttribution.Additional.length; j++) {
strNormal += ", " + subject.NameAttribution.Additional[j]["~"];
}
} else {
strNormal += ", " + subject.NameAttribution.Additional["~"];
......@@ -592,40 +697,44 @@ QueryHandler.prototype.handleSubject = function(subject) {
label.data("queryFilter", query);
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 search-result-label-wrapper'>")
.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");
}
queryHandler.doSearchDelayed();
});
$("#applied-filters-container #applied-filters").append(filter).append(" ");
$("#applied-filters-container").removeClass("hide");
queryHandler.doSearchDelayed();
_this.addFilter($(this).data("queryFilter"), $(this).html());
});
return $("<div class='search-result-label-wrapper'>").append(label);
}
QueryHandler.prototype.addFilter = function(queryFilter, html) {
var match = false;
$(".applied-filter").each(function() {
if (JSON.stringify($(this).data("queryFilter"))===JSON.stringify(queryFilter)) {
match = true;
}
});
if (match) {
return;
}
var filterLabel = $("<span class='label search-result-label'>")
.html(html)
.append("&nbsp;<i class=\"fa fa-cross\" aria-hidden=\"true\"></i>");
var filter = $("<div class='applied-filter search-result-label-wrapper'>")
.data("queryFilter", queryFilter)
.html(filterLabel)
.bind("click", function() {
$(this).remove();
if ($("#applied-filters-container .applied-filter").length==0) {
$("#applied-filters-container").addClass("hide");
}
queryHandler.doSearchDelayed();
});
$("#applied-filters-container #applied-filters").append(filter).append(" ");
$("#applied-filters-container").removeClass("hide");
queryHandler.doSearchDelayed();
};
QueryHandler.prototype.removeAllFilters = function() {
$('#applied-filters-container .applied-filter').remove();
$('#applied-filters-container').addClass('hide');
......
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