Skip to content

Commit

Permalink
Merge pull request #205 from AtlasOfLivingAustralia/develop
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
Rita-C authored Feb 17, 2020
2 parents 7f84591 + 8041c1a commit e49b3ac
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 45 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ buildscript {
}
}

version "1.4.22"
version "1.4.23-SNAPSHOT"

group "au.org.ala.plugins.grails"

apply plugin:"eclipse"
Expand Down
3 changes: 1 addition & 2 deletions grails-app/assets/javascripts/species.show.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function showSpeciesPage() {
////setup controls
addAlerts();
loadBhl();
loadTrove(SHOW_CONF.troveUrl, SHOW_CONF.scientificName,'trove-integration','trove-result-list','previousTrove','nextTrove');
loadTrove(SHOW_CONF.troveUrl, SHOW_CONF.scientificName, SHOW_CONF.synonyms, 'trove-integration','trove-result-list','previousTrove','nextTrove');
}

function loadSpeciesLists(){
Expand Down Expand Up @@ -754,7 +754,6 @@ function loadBhl(start, rows, scroll) {
if (!rows) {
rows = 10;
}
// var url = "http://localhost:8080/bhl-ftindex-demo/search/ajaxSearch?q=" + $("#tbSearchTerm").val();
var source = SHOW_CONF.bhlUrl;
var taxonName = SHOW_CONF.scientificName ;
var synonyms = SHOW_CONF.synonyms;
Expand Down
92 changes: 56 additions & 36 deletions grails-app/assets/javascripts/trove.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,43 @@
*/

var TROVE = {
s: 0,
n: 10,
url: "http://api.trove.nla.gov.au/result?key=fvt2q0qinduian5d&zone=book&encoding=json",
q: "",
totalResults: 0,
divId: '',
nextButtonId:'',
previousButtonId:'',
containerDivId:''
s: '*',
sPrevious: '',
previousUrl: null,
showPrevious: false,
currentUrl: null,
n: 10,
q: '',
query: '',
totalResults: 0,
pageNumber: 0,
nextStart: null,
divId: '',
nextButtonId: '',
previousButtonId: '',
containerDivId: ''
}

function getTroveUrl(){
return TROVE.url + '&q=' + TROVE.q + '&s=' + TROVE.s + '&n=' + TROVE.n;
var sNext = (TROVE.nextStart != null) ? TROVE.nextStart : TROVE.s;
// https://help.nla.gov.au/trove/building-with-trove/api-version-2-technical-guide
var url = TROVE.showPrevious ? TROVE.previousUrl :
TROVE.url + '&q=' + encodeURIComponent(TROVE.q) + '&s=' + encodeURIComponent(sNext) + '&n=' + TROVE.n + '&bulkHarvest=true';
TROVE.currentUrl = url;
return url;
}

function loadTrove(url, query, containerDivId, resultsDivId, previousButtonId, nextButtonId){
function loadTrove(url, query, synonyms, containerDivId, resultsDivId, previousButtonId, nextButtonId){
TROVE.query = query;
if (synonyms) {
for (var i = 0; i < synonyms.length; i++) {
query = query + '" OR "' + (synonyms[i]);
TROVE.query += ', ' + synonyms[i];
}
}

TROVE.url = url;
TROVE.q = query;
TROVE.q = '"' + query + '"';
TROVE.containerDivId = containerDivId
TROVE.divId = resultsDivId
TROVE.nextButtonId = nextButtonId;
Expand All @@ -42,16 +61,18 @@ function loadTrove(url, query, containerDivId, resultsDivId, previousButtonId, n
}

function troveNextPage(){
if( (TROVE.s + TROVE.n) < TROVE.totalResults){
TROVE.s += TROVE.n;
if(TROVE.nextStart != null){ //not first or last page
TROVE.previousUrl = TROVE.currentUrl;
TROVE.pageNumber++;
queryTrove();
scrollToTopOfTrove();
}
}

function trovePreviousPage(){
if(TROVE.s > 0){
TROVE.s -= TROVE.n;
if (TROVE.sPrevious != "*"){
TROVE.showPrevious = true;
TROVE.pageNumber--;
queryTrove();
scrollToTopOfTrove();
}
Expand All @@ -69,55 +90,54 @@ function queryTrove(){
data: null,
jsonp: "callback",
success: function(data) {
// console.log("Success....results: " + data.response.zone[0].records.total);
TROVE.totalResults = data.response.zone[0].records.total;
TROVE.nextStart = (data.response.zone[0].records.nextStart == undefined) ? null : data.response.zone[0].records.nextStart;
TROVE.sPrevious = data.response.zone[0].records.s;
TROVE.showPrevious = false;

if(TROVE.totalResults == 0){
$('#'+TROVE.containerDivId).css({display:'none'});
} else {
var buff = '<div class="results-summary">Number of matches in Trove: ' + TROVE.totalResults +'</div>'
var buff = '<div class="results-summary">Number of matches in Trove: ' + TROVE.totalResults;
buff += ' for ' + TROVE.query + '</div>'
$.each(data.response.zone[0].records.work, function(index, value){
//console.log(value.title);
buff += '<div class="result">';
//buff += '<a href="' + value.troveUrl + '">';
// buff += '<a href="' + value.troveUrl + '">';
buff += '<h3>';
buff += '<span class="troveIdx">';
buff += '<b>'+ (index + TROVE.s + 1) +'</b>.&nbsp;';
buff += '<b>'+ (index + 1 + (TROVE.pageNumber*TROVE.n)) +'</b>.&nbsp;';
buff += '</span>';
buff += '<span class="title"><a href="' + value.troveUrl + '">' + value.title + '</a></span>';
buff += '</h3>';
if(value.contributor != null){
buff += '<p class="contributors">Contributors: ';
var contribIdx = 0;
$.each(value.contributor, function(ci, cv){
//console.log('contributor: ' + cv);
if(contribIdx>0){
buff += '; ';
}
buff += '<span class="contributor">' + cv + '</span>';
contribIdx = contribIdx+1;
//console.log('contributor: ' + cv);
if(contribIdx>0){
buff += '; ';
}
buff += '<span class="contributor">' + cv + '</span>';
contribIdx = contribIdx+1;
});
buff += '</p>';
}
if(value.issued != null){
buff += '<p class="dateIssued">Date issued: ' + value.issued + '</p>';
buff += '<p class="dateIssued">Date issued: ' + value.issued + '</p>';
}
buff += '</div>';
buff += '</div>';
});
var prevStart = TROVE.s;
var nextStart = TROVE.s + TROVE.n;
var maxItems = TROVE.totalResults;

buff += '<div id="trove-button-bar">';
if (prevStart > 0) {
if (TROVE.sPrevious != "*") {
buff += '<input type="button" class="btn" value="Previous page" onclick="trovePreviousPage()">';
buff += '&nbsp;&nbsp;&nbsp;';
}
buff += '&nbsp;&nbsp;&nbsp;';
if (nextStart < maxItems) {
if (TROVE.nextStart != null) {
buff += '<input type="button" class="btn" value="Next page" onclick="troveNextPage()">';
}

buff += '</div>';

$('#'+TROVE.divId).html(buff);
}
},
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/species/_literature.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div id="trove-integration" class="column-wrap" style="padding-top:50px;">
%{--<h2>&nbsp;</h2>--}%
<hr />
<h3>Name references found in <a href="${grailsApplication.config.literature.trove.url}/result?q=%22${synonyms?.join('%22+OR+%22')}%22" target="_blank">Trove - NLA</a></h3>
<h3>Name references found in <a href="${grailsApplication.config.literature.trove.url}/result?q=%22${synonyms?.join('%22+OR+%22')}%22" target="_trove">Trove - NLA</a></h3>

<div id="trove-result-list" class="result-list">
<!-- Search results go here -->
Expand Down
4 changes: 2 additions & 2 deletions grails-app/views/species/_overview.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
<div class="panel panel-default panel-actions">
<div class="panel-body">
<ul class="list-unstyled">
<g:if test="${citizenSciUrl}">
<g:if test="${citizenSciUrl && guid && scientificName}">
<li>
<a href="${java.text.MessageFormat.format(citizenSciUrl, URLEncoder.encode(guid), URLEncoder.encode(scientificName))}"><span class="glyphicon glyphicon-map-marker"></span> <g:message code="label.recordSighting" default="Record a sighting"/></a>
<a href="${java.text.MessageFormat.format(citizenSciUrl, URLEncoder.encode(guid, "UTF-8"), URLEncoder.encode(scientificName, "UTF-8"))}"><span class="glyphicon glyphicon-map-marker"></span> <g:message code="label.recordSighting" default="Record a sighting"/></a>
</li>
</g:if>
<li><a id="alertsButton" href="#"><span
Expand Down
4 changes: 2 additions & 2 deletions grails-app/views/species/search.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@
<li><g:link controller="species" action="imageSearch" params="[id:result.guid]">View images of species within this ${result.rank}</g:link></li>
</g:if>

<g:if test="${grailsApplication.config.sightings.url}">
<li><a href="${java.text.MessageFormat.format(grailsApplication.config.sightings.url, URLEncoder.encode(result.guid), URLEncoder.encode(result.name))}"><g:message code="label.recordSighting" default="Record a sighting"/></a></li>
<g:if test="${grailsApplication.config.sightings.url && result.guid && result.name}">
<li><a href="${java.text.MessageFormat.format(grailsApplication.config.sightings.url, URLEncoder.encode(result.guid, "UTF-8"), URLEncoder.encode(result.name, "UTF-8"))}"><g:message code="label.recordSighting" default="Record a sighting"/></a></li>
</g:if>
<g:if test="${grailsApplication.config.occurrenceCounts.enabled.toBoolean() && result?.occurrenceCount?:0 > 0}">
<li>
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/species/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
layersServiceUrl: "${grailsApplication.config.layersService.baseURL}",
collectoryUrl: "${grailsApplication.config.collectory.baseURL}",
profileServiceUrl: "${grailsApplication.config.profileService.baseURL}",
imageServiceBaseUrl:"${grailsApplication.config.image.baseURL}",
imageServiceBaseUrl:"${grailsApplication.config.imageServiceBaseURL}",
guid: "${guid}",
scientificName: "${tc?.taxonConcept?.nameString ?: ''}",
rankString: "${tc?.taxonConcept?.rankString ?: ''}",
Expand Down

0 comments on commit e49b3ac

Please sign in to comment.