Skip to content

Commit

Permalink
Merge branch '452-links' of https://github.com/hbz/nwbib
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteeg authored and sol committed Feb 4, 2019
2 parents 3885d33 + ac4780c commit 5f89a52
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 68 deletions.
44 changes: 18 additions & 26 deletions app/controllers/nwbib/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,32 +284,6 @@ public static Promise<Result> show(final String id) {
"", "", true, "", "", "", "", "");
}

/**
* @param q The query
* @param callback The JSONP callback
* @param t The type filter ("Raumsystematik" or "Sachsystematik")
* @return Subject data for the given query
*/
public static Promise<Result> subject(final String q, final String callback,
final String t) {
String cacheId = String.format("%s.%s.%s.%s", "subject", q, callback, t);
@SuppressWarnings("unchecked")
Promise<Result> cachedResult = (Promise<Result>) Cache.get(cacheId);
if (cachedResult != null)
return cachedResult;
Logger.debug("Not cached: {}, will cache for one day", cacheId);
Promise<JsonNode> jsonPromise =
Promise.promise(() -> Classification.ids(q, t));
Promise<Result> result;
if (!callback.isEmpty())
result = jsonPromise.map((JsonNode json) -> ok(
String.format("%s(%s)", callback, Json.stringify(json))));
else
result = jsonPromise.map((JsonNode json) -> ok(json));
cacheOnRedeem(cacheId, result, ONE_DAY);
return result;
}

/**
* @param t The register type ("Raumsystematik" or "Sachsystematik")
* @return The alphabetical register for the given classification type
Expand Down Expand Up @@ -395,6 +369,24 @@ public static Result classification(final String t) {
return result;
}

/**
* @param t The data type: classification or register
* @return Classification or register for "Raumsystematik"
*/
public static Result spatial(String t) {
String data = "Raumsystematik";
return t.equals("classification") ? classification(data) : register(data);
}

/**
* @param t The data type: classification or register
* @return Classification data for "Sachsystematik"
*/
public static Result subjects(String t) {
String data = "Sachsystematik";
return t.equals("classification") ? classification(data) : register(data);
}

// Prototype, see https://github.com/hbz/nwbib/issues/392
private static Result classificationResultWikidata(JsonNode json, String t,
String placeholder) {
Expand Down
24 changes: 0 additions & 24 deletions app/controllers/nwbib/WikidataLocations.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.elasticsearch.common.lang3.tuple.Pair;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -149,26 +147,4 @@ private static Promise<WSResponse> cachedRequest(String key,
return promise;
}

// Prototype, see https://github.com/hbz/nwbib/issues/392
@SuppressWarnings("javadoc")
public static String searchLink(String id) {
try {
int cacheDuration = Integer.MAX_VALUE;
return Cache.getOrElse("spatialQuery." + id, () -> {
String baseUrl = "http://lobid.org/resources/search";
String q = String.format("spatial.id:\"%s\"", id);
String fullUrl = baseUrl + "?q=" + q;
Pair<String, Long> labelAndHits =
Pair.of(label(id), Lobid.getTotalHitsNwbibClassification(id));
String html = String.format(
"<a title='Nach Titeln suchen | %s' href='%s'><span class='glyphicon glyphicon-search'></span></a> ",
labelAndHits.getLeft(), fullUrl);
return labelAndHits.getRight() > 0L ? html : "";
}, cacheDuration);
} catch (Exception e) {
Logger.error("Could not query for " + id, e);
return "";
}
}

}
2 changes: 1 addition & 1 deletion app/views/browse_classification.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<span class="glyphicon glyphicon-repeat"></span></a>
</p>
} else {
<p><a href="@nwbib.routes.Application.register(t)"><span class="glyphicon glyphicon-sort-by-alphabet"></span> A-Z Register</a></p>
<p><a href="@if(t=="Raumsystematik"){@nwbib.routes.Application.spatial("register")}else{@nwbib.routes.Application.subjects("register")}"><span class="glyphicon glyphicon-sort-by-alphabet"></span> A-Z Register</a></p>
}
}
2 changes: 1 addition & 1 deletion app/views/browse_register.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

@main("NWBib - " + placeholder.replace("filtern","").trim) {
@tags.browse_list(classification, null, t, placeholder)
<p><a href="@nwbib.routes.Application.classification(t)"><span class="octicon octicon-list-ordered"></span> Systematik</a></p>
<p><a href="@if(t=="Raumsystematik"){@nwbib.routes.Application.spatial()}else{@nwbib.routes.Application.subjects()}"><span class="octicon octicon-list-ordered"></span> Systematik</a></p>
}
4 changes: 2 additions & 2 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
<a href="@nwbib.routes.Application.topics()">Themensuche</a>
</li>
<li @if(title.contains("Raumsystematik")){class="active"}>
<a href="@nwbib.routes.Application.classification("Raumsystematik")">Regionen</a>
<a href="@nwbib.routes.Application.spatial()">Regionen</a>
</li>
<li @if(title.contains("Sachsystematik")){class="active"}>
<a href="@nwbib.routes.Application.classification("Sachsystematik")">Sachgebiete</a>
<a href="@nwbib.routes.Application.subjects()">Sachgebiete</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Ergänzende Suche<b class="caret"></b></a>
Expand Down
54 changes: 44 additions & 10 deletions app/views/tags/browse_list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,51 @@
@ul(classes: Option[Seq[JsValue]], id: String) = {
@if(!classes.isEmpty){
<ul id="@id">
<script>$('#root').hide()</script>
<script>
$('#root').hide();
function expand(node) {
$('#root').find('a').css('background-color', 'white');
node.find('ul').first().show();
toggleState(node.find('div.treeItemIcon').first(), true);
node.find('a').first().css("background-color", "#E7E7E7");
node.parents('ul:not(#root)').each(function() {
$(this).show();
toggleState($(this).parent().find('div.treeItemIcon').first(), true);
});
}
function toggleState(node, expanded) {
var isCollapsed = $(node).hasClass('treeFolderCollapsed');
if (expanded || (expanded === undefined && isCollapsed)) {
$(node).removeClass('treeFolderCollapsed');
} else {
$(node).addClass('treeFolderCollapsed');
}
}
</script>
@for(json <- classes.getOrElse(Seq());
entryLabel = label(json);
normalized = entryLabel.replaceAll("ß", "ss") + entryLabel.replaceAll("ss", "ß");
value = (json\"value").as[String];
hits = (json\"hits").asOpt[scala.Long].getOrElse(0L)) {
<li>@if(id=="root" && !placeholder.contains("Register") && t!="Wikidata" && t!="Zeitschriften") { <b>@Html(entryLabel)</b> } else {
@if(hits>0 || t=="Zeitschriften"){
<a href="@{t match {
hits = (json\"hits").asOpt[scala.Long].getOrElse(0L);
anchor = value.split("[/#]").last) {
<li id='@anchor'>@if(id=="root" && !placeholder.contains("Register") && t!="Wikidata" && t!="Zeitschriften") { <b>@Html(entryLabel)</b> } else {
<a onclick="$('#nwbibQueryHidden').val(''); $('#nwbibQueryHidden').change(); $('#collapseAll').click(); expand($('#@anchor'));" href="@{t match {
case "Zeitschriften" => value
case "Wikidata" => value
case "Raumsystematik" => "#"+anchor
case "Sachsystematik" => "#"+anchor
case _ => value
}}">@Html(entryLabel)</a> @if(hits>0){
(<a href="@{t match {
case "Wikidata" => nwbib.routes.Application.search(q=s"""spatial.id:"$value"""")
case "Raumsystematik" => nwbib.routes.Application.search(nwbibspatial=value)
case "Sachsystematik" => nwbib.routes.Application.search(nwbibsubject=value)
case _ => value
}}">@Html(entryLabel)</a> @if(hits>0){(@hits)}
} else { @Html(entryLabel) } <div style="display: none">@normalized</div>
}}">@hits</a>)
}
<div style="display: none">@normalized</div>
}
@if(t=="Wikidata"){
@Html(controllers.nwbib.WikidataLocations.searchLink(value))
@for(gnd <- (json\"gnd").asOpt[String]; if !gnd.isEmpty){
<a title='Verknüpften GND-Eintrag anzeigen' href='http://lobid.org/gnd/@gnd'><small><span class="label label-info">gnd</span></small></a>
}
Expand All @@ -47,7 +73,10 @@
}

<dl>
<dt></dt><dd><input placeholder="@placeholder" type="text" id="nwbibQuery" class="form-control" onchange="if(this.value!=''){$('#expandAll').click()}else{$('#collapseAll').click()};"/></dd>
<dt></dt><dd>
<input placeholder="@placeholder" type="text" id="nwbibQuery" class="form-control" onchange="if(this.value!=''){$('#expandAll').click()}else{$('#collapseAll').click()};"/>
<input type="hidden" id="nwbibQueryHidden" onchange="$('#expandAll').click();"/>
</dd>
@if(subs!=null && !subs.values.isEmpty){
<dt></dt><dd><a href="#" id="collapseAll">alle einklappen</a> | <a href="#" id="expandAll">alle ausklappen</a></dd>
}
Expand All @@ -65,9 +94,14 @@
<script type="text/javascript">
$(function() {
$('#nwbibQuery').treeListFilter('#root', 200);
$('#nwbibQueryHidden').treeListFilter('#root', 200);
$('#root').fileTreeView('#expandAll', '#collapseAll', 'folder', @if(subs==null||subs.size()==0){false}else{true});
$('#collapseAll').click();
$('#root').show()
$('#root').show();
var fragment = window.location.hash;
if(fragment) {
expand($(fragment));
}
});
</script>
}
3 changes: 2 additions & 1 deletion conf/nwbib.routes
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ GET /help controllers.nwbib.Application.help()
GET /advanced controllers.nwbib.Application.advanced()
GET /topics controllers.nwbib.Application.topics(q?="")
GET /search controllers.nwbib.Application.search(q?="", person?="", name?="", subject?="", id?="", publisher?="", issued?="", medium ?= "", nwbibspatial ?= "", nwbibsubject ?= "", from:Int?=0, size:Int?=25, owner?="", t?="", sort ?= "newest", details:Boolean?=false, location ?= "", word?="", corporation?="", raw?="", format?="html")
GET /subject controllers.nwbib.Application.subject(q?="", callback?="", t?="")
GET /register controllers.nwbib.Application.register(t?="")
GET /classification controllers.nwbib.Application.classification(t?="")
GET /subjects controllers.nwbib.Application.subjects(t?="classification")
GET /spatial controllers.nwbib.Application.spatial(t?="classification")
GET /journals controllers.nwbib.Application.journals()
GET /facets controllers.nwbib.Application.facets(q,person?="", name?="", subject?="", id?="", publisher?="", issued?="", medium ?= "", nwbibspatial ?= "", nwbibsubject ?= "", from:Int,size:Int,owner,t,field,sort, location?="", word?="", corporation?="", raw?="")

Expand Down
2 changes: 1 addition & 1 deletion test/tests/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void classificationNwbibspatial()
List<String> nwbibspatials = Classification
.toJsonLd(new URL(CONFIG.getString("index.data.nwbibspatial")));
nwbibspatials.forEach(System.out::println);
assertThat(nwbibspatials.size()).isEqualTo(49);
assertThat(nwbibspatials.size()).isEqualTo(47);
assertThat(nwbibspatials.toString()).contains("Nordrhein-Westfalen")
.contains("Rheinland").contains("Grafschaft, Herzogtum Jülich");
}
Expand Down
3 changes: 1 addition & 2 deletions test/tests/InternalIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void renderTemplate() {
"", "", "", "", from, size, 0L, "", "", "", "", "", "", "");
assertThat(html.contentType()).isEqualTo("text/html");
String text = Helpers.contentAsString(html);
assertThat(text).contains("NWBib").contains("buch")
.contains("Sachsystematik").contains("Raumsystematik");
assertThat(text).contains("NWBib").contains("buch");
});
}

Expand Down

0 comments on commit 5f89a52

Please sign in to comment.