Skip to content

Commit 6de2e07

Browse files
committed
#269 Stay the same page when a species name is updated
Include a imageUrl fix
1 parent d61ef51 commit 6de2e07

File tree

5 files changed

+142
-14
lines changed

5 files changed

+142
-14
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/views/speciesListItem/list.gsp

+121-8
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,8 @@
942991
</tr>
943992
</thead>
944993
<tbody>
994+
%{-- <div v-scope="SpeciesList(JSON.parse('${json_results}'))" @vue:mounted="mounted"></div>--}%
995+
945996
<g:each var="result" in="${results}" status="i">
946997
<g:set var="recId" value="${result.id}"/>
947998
%{-- <g:set var="bieTitle">${message(code:'public.lists.view.table.tooltip03', default:'species page for')} <i>${result.rawScientificName}</i></g:set>--}%
@@ -981,21 +1032,21 @@
9811032
${result.matchedName}
9821033
</g:else>
9831034
</td>
984-
<td id="img_${result.guid}">
1035+
<td id="img_${result.guid}" class="imageUrl">
9851036
<g:if test="${result.imageUrl}">
9861037
<a href="${bieUrl}/species/${result.guid}" title="click to view species page"><img
9871038
src="${result.imageUrl}"
9881039
class="smallSpeciesImage"/></a>
9891040
</g:if>
9901041
</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>
1042+
<td class="author">${result.author}</td>
1043+
<td id="cn_${result.guid}" class="commonName" >${result.commonName}</td>
1044+
<td id="fm_${result.guid}" class="family">${result.family}</td>
1045+
<td id="kn_${result.guid}" class="kingdom">${result.kingdom}</td>
9951046
<g:each in="${keys}" var="key">
9961047
<g:set var="kvp" value="${result.kvpValues.find { it.key == key }}"/>
9971048
<g:set var="val" value="${kvp?.vocabValue ?: kvp?.value}"/>
998-
<td class="kvp ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
1049+
<td class="kvp ${key.replace(" ","_")} ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
9991050
</td>
10001051
</g:each>
10011052
</tr>
@@ -1133,5 +1184,67 @@
11331184
});
11341185
});
11351186
</asset:script>
1187+
1188+
<script type="module">
1189+
import { createApp } from 'https://unpkg.com/petite-vue?module'
1190+
function SpeciesList(data) {
1191+
return {
1192+
$template: '#display-species-list',
1193+
speciesList: data,
1194+
mounted() {
1195+
1196+
},
1197+
1198+
click() {
1199+
alert("i am vue")
1200+
},
1201+
1202+
save() {
1203+
alert("saved")
1204+
}
1205+
1206+
}
1207+
}
1208+
1209+
createApp({
1210+
SpeciesList
1211+
}).mount()
1212+
</script>
1213+
<template id="display-species-list">
1214+
1215+
<table>
1216+
<tr v-for="(species, i) in speciesList" :id="'row_'+species.id">
1217+
<td class="action">
1218+
<div class="btn-group action-btn-group-width" role="group">
1219+
<a class="btn btn-default btn-xs viewRecordButton" href="#viewRecord"
1220+
title="${message(code:'public.lists.view.table.tooltip01', default:'view record')}" :data-id="species.id"><i
1221+
class="glyphicon glyphicon-info-sign"></i></a>
1222+
<g:if test="${userCanEditData}">
1223+
<a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip04', default:'edit')}"
1224+
:data-remote-url="'${createLink(controller: 'editor', action: 'editRecordScreen')}?id=' + species.id"
1225+
:data-target="'#editRecord_'+species.id" data-toggle="modal"><i
1226+
class="glyphicon glyphicon-pencil"></i></a>
1227+
<a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip05', default:'delete')}"
1228+
:data-target="'#deleteRecord_'+species.id" data-toggle="modal"><i
1229+
class="glyphicon glyphicon-trash"></i></a>
1230+
</g:if>
1231+
</div>
1232+
</td>
1233+
<td class="rawScientificName">
1234+
{{species.rawScientificName}}
1235+
<p v-if="species.guid == null">
1236+
<br/>(unmatched - try <a
1237+
:href="'http://google.com/search?q=' + species.rawScientificName.trim()}"
1238+
target="google" class="btn btn-primary btn-xs">Google</a>,
1239+
<a href="'${grailsApplication.config.biocache.baseURL}/occurrences/search?q='+species.rawScientificName.trim()"
1240+
target="biocache" class="btn btn-success btn-xs">${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>)
1241+
</p>
1242+
</td>
1243+
</tr>
1244+
</table>
1245+
1246+
</template>
1247+
1248+
11361249
</body>
11371250
</html>

0 commit comments

Comments
 (0)