Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modal with links to matches for classification entries (#656) #661

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions app/controllers/nwbib/Classification.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ private SearchResponse classificationData() {
private enum Property {
LABEL("http://www.w3.org/2004/02/skos/core#prefLabel"), //
BROADER("http://www.w3.org/2004/02/skos/core#broader"), //
NOTATION("http://www.w3.org/2004/02/skos/core#notation");
NOTATION("http://www.w3.org/2004/02/skos/core#notation"), //
NARROW_MATCH("http://www.w3.org/2004/02/skos/core#narrowMatch"), //
EXACT_MATCH("http://www.w3.org/2004/02/skos/core#exactMatch");

String value;

Expand Down Expand Up @@ -449,19 +451,35 @@ private static void collectLabelAndValue(SearchHit hit, JsonNode json,
if (label != null) {
String id = toNwbibNamespace(hit.getId());
String notation = notation(json);
ImmutableMap<String, ?> map = ImmutableMap.of(//
"value", id, //
"label",
(style == Label.PLAIN || notation.isEmpty() ? ""
: "<span class='notation'>" + notation + "</span>" + " ")
+ label.findValue("@value").asText(), //
"hits", Lobid.getTotalHitsNwbibClassification(id), //
"notation", notation, //
"focus", focus(json));
ImmutableMap<String, Object> map = ImmutableMap.<String, Object> builder()//
.put("value", id) //
.put("label",
(style == Label.PLAIN || notation.isEmpty() ? ""
: "<span class='notation'>" + notation + "</span>" + " ")
+ label.findValue("@value").asText()) //
.put("hits", Lobid.getTotalHitsNwbibClassification(id)) //
.put("notation", notation) //
.put("focus", focus(json)) //
.put("matches", matches(json)).build();
result.add(Json.toJson(map));
}
}

private static List<String> matches(JsonNode json) {
List<String> result = new ArrayList<>();
addMatches(json, Property.NARROW_MATCH, result);
addMatches(json, Property.EXACT_MATCH, result);
return result;
}

private static void addMatches(JsonNode json, Property p,
List<String> result) {
JsonNode match = json.findValue(p.value);
if (match != null) {
match.forEach(m -> result.add(m.get("@id").textValue()));
}
}

static String toNwbibNamespace(String id) {
return id //
.replace("http://purl.org/lobid/nwbib-spatial#n", NWBIB_SPATIAL + "N")
Expand Down
24 changes: 24 additions & 0 deletions app/views/tags/browse_list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
normalized = entryLabel.replaceAll("ß", "ss") + entryLabel.replaceAll("ss", "ß");
value = (json\"value").as[String];
hits = (json\"hits").asOpt[scala.Long].getOrElse(0L);
matches = (json\"matches").asOpt[Seq[String]].getOrElse(Seq());
anchor = value.split("[/#]").last;
textToCopy = (if(entryLabel.contains("span")){entryLabel.split("</span> ")(1)}else{entryLabel}) + "$$0" + value) {
<li id='@anchor'>@if(id=="root" && !placeholder.contains("Register") && t!="Wikidata" && t!="Zeitschriften") { <b>@Html(entryLabel)</b> } else {
Expand All @@ -89,6 +90,29 @@
case _ => value
}}">@hits</a>)
}
@if(!matches.isEmpty()) {
<button type="button" class="btn btn-link btn-xs" data-toggle="modal" data-target="#@matches.hashCode"><span class="octicon octicon-link"></span></button>
<div id="@matches.hashCode" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="[email protected]">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="[email protected]">Links für @Html(entryLabel)</h4>
</div>
<div class="modal-body">
@for(link <- matches) { <p><a href="@link" target="_blank">
@link match {
case x if x.contains("d-nb.info/gnd") => { <img src='@controllers.routes.Assets.at("images/gnd.png")' style="width:1em" alt="Gemeinsame Normdatei (GND)"> }
case x if x.contains("wikidata.org") => { <img src='@controllers.routes.Assets.at("images/wikidata.png")' style="width:1em" alt="Wikidata"> }
case _ => { <span class="octicon octicon-link"></span> }
}
@link</a></p>
}
</div>
</div>
</div>
</div>
}
@if(t!="Zeitschriften"){<span @if(t!="Wikidata"){class='copy-link'}><a data-toggle="tooltip" data-placement="right" title="Identifikator und Bezeichnung in die Zwischenablage kopieren" href="#" onclick="copyToClipboard('@textToCopy', $(this));return false;"><span class="octicon octicon-clippy"></span></a></span>}
<div style="display: none">@normalized</div>
}
Expand Down
Binary file added public/images/gnd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wikidata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.