Skip to content

Commit 69407f0

Browse files
committed
#269 Stay the same page when a species is updated
1 parent d61ef51 commit 69407f0

File tree

4 files changed

+138
-9
lines changed

4 files changed

+138
-9
lines changed

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

+119-8
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,55 @@
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+
var td = row.find("td."+item.name);
123+
if (td.length > 0) {
124+
td.html("<div>"+ item.value +"</div>");
125+
}
126+
});
127+
128+
var speciesUrl = "${createLink(controller: "ws", action: 'findSpeciesByName')}"
129+
$.get(speciesUrl,{ name: rawScientificName, id:id}, function( result ) {
130+
var guid = result.guid;
131+
if (guid === "" || guid === null || guid === undefined){
132+
//raw name
133+
var google = "http://google.com/search?q=" + rawScientificName;
134+
var biocache = "${grailsApplication.config.biocache.baseURL}/occurrences/search?q="+rawScientificName;
135+
var guidText= rawScientificName + "<br>(unmatched - try <a href='" + google +"' target='google' class='btn btn-primary btn-xs'>Google</a>," +
136+
"<a href='" + biocache +" target='biocache' class='btn btn-success btn-xs'>${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>)";
137+
138+
row.find("td.rawScientificName").html(guidText);
139+
row.find("td.matchedName").html(result.matchedName);
140+
row.find("td.imageUrl").html("");
141+
} else {
142+
var bie = "<a href=${bieUrl}/species/" + guid + " title='click to view species page'>"+result.matchedName + "</a>"
143+
row.find("td.matchedName").html(bie)
144+
145+
if(result.imageUrl === "" || result.imageUrl === null || result.imageUrl === undefined) {
146+
row.find("td.imageUrl").html("");
147+
} else {
148+
var image_url ="<a href=${bieUrl}/species/"+guid+" title='click to view species page'><img src="+result.imageUrl+" class='smallSpeciesImage'/></a>";
149+
row.find("td.imageUrl").html(image_url);
150+
}
151+
}
152+
153+
row.find("td.author").text(result.author);
154+
var terms = ["commonName", "family","kingdom"];
155+
terms.forEach( function(item) {
156+
var td = row.find("td."+item);
157+
if ( td.length>0 ) {
158+
td.text(result[item]);
159+
td[0].id= td[0].id.substring(0,3) + guid;
160+
}
161+
})
162+
})
163+
}
117164
}).error(function(jqXHR, textStatus, error) {
118165
alert("An error occurred: " + error + " - " + jqXHR.responseText);
119166
$(modal).modal('hide');
@@ -942,6 +989,8 @@
942989
</tr>
943990
</thead>
944991
<tbody>
992+
%{-- <div v-scope="SpeciesList(JSON.parse('${json_results}'))" @vue:mounted="mounted"></div>--}%
993+
945994
<g:each var="result" in="${results}" status="i">
946995
<g:set var="recId" value="${result.id}"/>
947996
%{-- <g:set var="bieTitle">${message(code:'public.lists.view.table.tooltip03', default:'species page for')} <i>${result.rawScientificName}</i></g:set>--}%
@@ -981,21 +1030,21 @@
9811030
${result.matchedName}
9821031
</g:else>
9831032
</td>
984-
<td id="img_${result.guid}">
1033+
<td id="img_${result.guid}" class="imageUrl">
9851034
<g:if test="${result.imageUrl}">
9861035
<a href="${bieUrl}/species/${result.guid}" title="click to view species page"><img
9871036
src="${result.imageUrl}"
9881037
class="smallSpeciesImage"/></a>
9891038
</g:if>
9901039
</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>
1040+
<td class="author">${result.author}</td>
1041+
<td id="cn_${result.guid}" class="commonName" >${result.commonName}</td>
1042+
<td id="fm_${result.guid}" class="family">${result.family}</td>
1043+
<td id="kn_${result.guid}" class="kingdom">${result.kingdom}</td>
9951044
<g:each in="${keys}" var="key">
9961045
<g:set var="kvp" value="${result.kvpValues.find { it.key == key }}"/>
9971046
<g:set var="val" value="${kvp?.vocabValue ?: kvp?.value}"/>
998-
<td class="kvp ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
1047+
<td class="kvp ${key} ${val?.length() > 35 ? 'scrollWidth' : ''}"><div>${val}</div>
9991048
</td>
10001049
</g:each>
10011050
</tr>
@@ -1133,5 +1182,67 @@
11331182
});
11341183
});
11351184
</asset:script>
1185+
1186+
<script type="module">
1187+
import { createApp } from 'https://unpkg.com/petite-vue?module'
1188+
function SpeciesList(data) {
1189+
return {
1190+
$template: '#display-species-list',
1191+
speciesList: data,
1192+
mounted() {
1193+
1194+
},
1195+
1196+
click() {
1197+
alert("i am vue")
1198+
},
1199+
1200+
save() {
1201+
alert("saved")
1202+
}
1203+
1204+
}
1205+
}
1206+
1207+
createApp({
1208+
SpeciesList
1209+
}).mount()
1210+
</script>
1211+
<template id="display-species-list">
1212+
1213+
<table>
1214+
<tr v-for="(species, i) in speciesList" :id="'row_'+species.id">
1215+
<td class="action">
1216+
<div class="btn-group action-btn-group-width" role="group">
1217+
<a class="btn btn-default btn-xs viewRecordButton" href="#viewRecord"
1218+
title="${message(code:'public.lists.view.table.tooltip01', default:'view record')}" :data-id="species.id"><i
1219+
class="glyphicon glyphicon-info-sign"></i></a>
1220+
<g:if test="${userCanEditData}">
1221+
<a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip04', default:'edit')}"
1222+
:data-remote-url="'${createLink(controller: 'editor', action: 'editRecordScreen')}?id=' + species.id"
1223+
:data-target="'#editRecord_'+species.id" data-toggle="modal"><i
1224+
class="glyphicon glyphicon-pencil"></i></a>
1225+
<a class="btn btn-default btn-xs" href="#" title="${message(code:'public.lists.view.table.tooltip05', default:'delete')}"
1226+
:data-target="'#deleteRecord_'+species.id" data-toggle="modal"><i
1227+
class="glyphicon glyphicon-trash"></i></a>
1228+
</g:if>
1229+
</div>
1230+
</td>
1231+
<td class="rawScientificName">
1232+
{{species.rawScientificName}}
1233+
<p v-if="species.guid == null">
1234+
<br/>(unmatched - try <a
1235+
:href="'http://google.com/search?q=' + species.rawScientificName.trim()}"
1236+
target="google" class="btn btn-primary btn-xs">Google</a>,
1237+
<a href="'${grailsApplication.config.biocache.baseURL}/occurrences/search?q='+species.rawScientificName.trim()"
1238+
target="biocache" class="btn btn-success btn-xs">${message(code:'generic.lists.button.Occurrences.label', default:'Occurrences')}</a>)
1239+
</p>
1240+
</td>
1241+
</tr>
1242+
</table>
1243+
1244+
</template>
1245+
1246+
11361247
</body>
11371248
</html>

0 commit comments

Comments
 (0)