Skip to content

Commit 363cf5e

Browse files
committed
Squashed commit of the following:
commit 6b28f79 Author: QBai <31238531+qifeng-bai@users.noreply.github.com> Date: Wed Sep 20 12:49:50 2023 +1000 #269 imageUrl fix commit c6705e1 Author: QBai <31238531+qifeng-bai@users.noreply.github.com> Date: Wed Sep 20 12:40:28 2023 +1000 #269 increase max=1000 remove example code commit 6de2e07 Author: QBai <31238531+qifeng-bai@users.noreply.github.com> Date: Tue Sep 19 08:56:46 2023 +1000 #269 Stay the same page when a species name is updated Include a imageUrl fix
1 parent d61ef51 commit 363cf5e

File tree

6 files changed

+82
-15
lines changed

6 files changed

+82
-15
lines changed

grails-app/controllers/au/org/ala/specieslist/EditorController.groovy

+2-5
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,14 @@ class EditorController {
213213
if (params.rawScientificName.trim() != sli.rawScientificName.trim()) {
214214
log.debug "rawScientificName is different: " + params.rawScientificName + " VS " + sli.rawScientificName
215215
sli.rawScientificName = params.rawScientificName
216-
changed = true
217216
// lookup guid
218217
helperService.matchNameToSpeciesListItem(sli.rawScientificName, sli, sli.mylist)
219218
//sli.guid = helperService.findAcceptedLsidByScientificName(sli.rawScientificName)?: helperService.findAcceptedLsidByCommonName(sli.rawScientificName)
220-
}
221-
if (changed) {
222-
log.debug "re-matching name for ${params.rawScientificName}"
223-
helperService.matchNameToSpeciesListItem(sli.rawScientificName, sli, sli.mylist)
219+
helperService.getCommonNamesAndUpdateRecords([sli],[sli.guid])
224220
sl.lastMatched = new Date()
225221
}
226222

223+
227224
if (!sli.validate()) {
228225
def message = "Could not update SpeciesListItem: ${sli.rawScientificName} - " + sli.errors.allErrors
229226
log.error message

grails-app/controllers/au/org/ala/specieslist/SpeciesListItemController.groovy

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package au.org.ala.specieslist
1818

1919
import com.opencsv.CSVWriter
2020
import grails.converters.JSON
21+
import groovy.json.JsonBuilder
22+
import groovy.json.JsonOutput
2123

2224
class SpeciesListItemController {
2325

@@ -133,10 +135,13 @@ class SpeciesListItemController {
133135

134136
log.debug("Checking speciesList: " + speciesList)
135137
log.debug("Checking editors: " + speciesList.editors)
138+
def speciesListItems = queryService.getSpeciesListItemsByParams(requestParams, baseQueryAndParamsForListingSLI)
139+
140+
136141
render(view: 'list', model: [
137142
speciesList: speciesList,
138143
params: requestParams,
139-
results: queryService.getSpeciesListItemsByParams(requestParams, baseQueryAndParamsForListingSLI),
144+
results: speciesListItems,
140145
totalCount: queryService.getTotalCountByParams(requestParams, baseQueryAndParams),
141146
noMatchCount: noMatchCount,
142147
distinctCount: queryService.getDistinctCountByParams(requestParams, baseQueryAndParams),

grails-app/controllers/au/org/ala/specieslist/UrlMappings.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class UrlMappings {
4646
}
4747

4848
//"/ws/speciesListItems" (controller: "webService", action: "getListItemDetails")
49+
"/ws/findSpeciesByName" (controller: "webService", action: "findSpeciesByName")
4950
"/ws/speciesListItems/keys" (controller: "webService", action: "listKeys")
5051
"/ws/speciesListItems/byKeys" (controller: "webService", action: "listItemsByKeys")
5152

grails-app/controllers/au/org/ala/specieslist/WebServiceController.groovy

+12
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,18 @@ class WebServiceController {
643643
)
644644
]
645645
)
646+
647+
@Path("/ws/findSpeciesByName/")
648+
def findSpeciesByName() {
649+
def name = params.name
650+
def id = params.id
651+
def species = null
652+
if (name && id) {
653+
species = SpeciesListItem.findByRawScientificNameAndId(name.trim(), id)
654+
}
655+
render species as JSON
656+
}
657+
646658
@Path("/ws/speciesListItemKvp/{druid}")
647659
def getSpeciesListItemKvp() {
648660
def speciesListDruid = params.druid

grails-app/services/au/org/ala/specieslist/HelperService.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ class HelperService {
581581
sli.commonName = null
582582
sli.family = null
583583
sli.kingdom = null
584+
sli.imageUrl = null
584585
}
585586
}
586587

grails-app/views/speciesListItem/list.gsp

+60-9
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,57 @@
112112

113113
$.post("${createLink(controller: "editor", action: 'editRecord')}", thisFormData, function(data, textStatus, jqXHR) {
114114
$(modal).modal('hide');
115-
alert(jqXHR.responseText);
116-
window.location.reload(true);
115+
var idItem = thisFormData.find(o=>o.name === "id");
116+
var rawScientificName = thisFormData.find(o=>o.name === "rawScientificName")?.value;
117+
if (idItem) {
118+
var id = idItem.value;
119+
var row = $("tr#row_"+ id);
120+
//Only change rawScientificName, and KVP
121+
thisFormData.forEach(item=>{
122+
//Avoid keys such as 'Profile No'
123+
var td = row.find("td."+item.name.replace(" ", "_"));
124+
if (td.length > 0) {
125+
td.html("<div>"+ item.value +"</div>");
126+
}
127+
});
128+
129+
var speciesUrl = "${createLink(controller: "ws", action: 'findSpeciesByName')}"
130+
$.get(speciesUrl,{ name: rawScientificName, id:id}, function( result ) {
131+
var updatedIcon = "<i class='glyphicon glyphicon-check text-success'></i> ";
132+
var guid = result.guid;
133+
if (guid === "" || guid === null || guid === undefined){
134+
//raw name
135+
var google = "http://google.com/search?q=" + rawScientificName;
136+
var biocache = "${grailsApplication.config.biocache.baseURL}/occurrences/search?q="+rawScientificName;
137+
var guidText= updatedIcon + rawScientificName + "<br>(unmatched - try <a href='" + google +"' target='google' class='btn btn-primary btn-xs'>Google</a>," +
138+
"<a href='" + biocache +" target='biocache' class='btn btn-success btn-xs'>${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>)";
139+
140+
row.find("td.rawScientificName").html(guidText);
141+
row.find("td.matchedName").html(result.matchedName);
142+
row.find("td.imageUrl").html("");
143+
} else {
144+
var bie = "<a href=${bieUrl}/species/" + guid + " title='click to view species page'>"+result.matchedName + "</a>"
145+
row.find("td.matchedName").html(bie)
146+
row.find("td.rawScientificName").html( "<div>"+ updatedIcon + rawScientificName +"</div>");
147+
148+
if(result.imageUrl === "" || result.imageUrl === null || result.imageUrl === undefined) {
149+
row.find("td.imageUrl").html("");
150+
} else {
151+
var image_url ="<a href=${bieUrl}/species/"+guid+" title='click to view species page'><img src="+result.imageUrl+" class='smallSpeciesImage'/></a>";
152+
row.find("td.imageUrl").html(image_url);
153+
}
154+
}
155+
row.find("td.author").text(result.author);
156+
var terms = ["commonName", "family","kingdom"];
157+
terms.forEach( function(item) {
158+
var td = row.find("td."+item);
159+
if ( td.length>0 ) {
160+
td.text(result[item]);
161+
td[0].id= td[0].id.substring(0,3) + guid;
162+
}
163+
})
164+
})
165+
}
117166
}).error(function(jqXHR, textStatus, error) {
118167
alert("An error occurred: " + error + " - " + jqXHR.responseText);
119168
$(modal).modal('hide');
@@ -942,6 +991,7 @@
942991
</tr>
943992
</thead>
944993
<tbody>
994+
945995
<g:each var="result" in="${results}" status="i">
946996
<g:set var="recId" value="${result.id}"/>
947997
%{-- <g:set var="bieTitle">${message(code:'public.lists.view.table.tooltip03', default:'species page for')} <i>${result.rawScientificName}</i></g:set>--}%
@@ -981,21 +1031,21 @@
9811031
${result.matchedName}
9821032
</g:else>
9831033
</td>
984-
<td id="img_${result.guid}">
1034+
<td id="img_${result.guid}" class="imageUrl">
9851035
<g:if test="${result.imageUrl}">
9861036
<a href="${bieUrl}/species/${result.guid}" title="click to view species page"><img
9871037
src="${result.imageUrl}"
9881038
class="smallSpeciesImage"/></a>
9891039
</g:if>
9901040
</td>
991-
<td>${result.author}</td>
992-
<td id="cn_${result.guid}">${result.commonName}</td>
993-
<td id="fm_${result.guid}">${result.family}</td>
994-
<td id="kn_${result.guid}">${result.kingdom}</td>
1041+
<td class="author">${result.author}</td>
1042+
<td id="cn_${result.guid}" class="commonName" >${result.commonName}</td>
1043+
<td id="fm_${result.guid}" class="family">${result.family}</td>
1044+
<td id="kn_${result.guid}" class="kingdom">${result.kingdom}</td>
9951045
<g:each in="${keys}" var="key">
9961046
<g:set var="kvp" value="${result.kvpValues.find { it.key == key }}"/>
9971047
<g:set var="val" value="${kvp?.vocabValue ?: kvp?.value}"/>
998-
<td class="kvp ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
1048+
<td class="kvp ${key.replace(" ","_")} ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
9991049
</td>
10001050
</g:each>
10011051
</tr>
@@ -1008,7 +1058,7 @@
10081058
<div class="searchWidgets">
10091059
${message(code:'generic.lists.ItemsPerPage', default:'Items per page:')}
10101060
<select id="maxItems" onchange="reloadWithMax(this)">
1011-
<g:each in="${[10, 25, 50, 100]}" var="max">
1061+
<g:each in="${[10, 25, 50, 100, 500, 1000]}" var="max">
10121062
<option ${(params.max == max) ? 'selected="selected"' : ''}>${max}</option>
10131063
</g:each>
10141064
</select>
@@ -1133,5 +1183,6 @@
11331183
});
11341184
});
11351185
</asset:script>
1186+
11361187
</body>
11371188
</html>

0 commit comments

Comments
 (0)