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

Feature my annotations #391

Merged
merged 13 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
51 changes: 47 additions & 4 deletions grails-app/assets/javascripts/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,34 @@ $(document).ready(function() {
e.preventDefault();
var comment = $("#issueComment").val();
var code = $("#issue").val();
var userDisplayName = OCC_REC.userDisplayName //'${userDisplayName}';
var recordUuid = OCC_REC.recordUuid //'${ala:escapeJS(record.raw.rowKey)}';
var userDisplayName = OCC_REC.userDisplayName; //'${userDisplayName}';
var recordUuid = OCC_REC.recordUuid; //'${ala:escapeJS(record.raw.rowKey)}';
if(code!=""){
$('#assertionSubmitProgress').css({'display':'block'});

if (allMyAnnotations) {
var orig_state = $('#notifyChangeCheckbox').prop('data-origstate');
var new_state = $('#notifyChangeCheckbox').prop('checked');

// only update when user changed preference
if (orig_state !== new_state) {
// to add alerts
if (new_state) {
var addAlerts = OCC_REC.alertsURL + "/occurrences/addAlert?userId=" + OCC_REC.userId + "&queryId=";
for (var i = 0; i < allMyAnnotations.length; i++) {
// console.log('post to: ' + addAlerts + allMyAnnotations[i].id)
$.post(addAlerts + allMyAnnotations[i].id);
}
} else { // to remove alerts
var deleteAlerts = OCC_REC.alertsURL + "/occurrences/deleteAlert?userId=" + OCC_REC.userId + "&queryId=";
for (var i = 0; i < allMyAnnotations.length; i++) {
// console.log('post to ' + deleteAlerts + allMyAnnotations[i].id)
$.post(deleteAlerts + allMyAnnotations[i].id);
}
}
}
}

$.get( OCC_REC.contextPath + "/assertions/" + OCC_REC.recordUuid, function(data) {
var bPreventAddingIssue = false;
for (var i = 0; i < data.userAssertions.length; i++) {
Expand All @@ -64,7 +87,6 @@ $(document).ready(function() {
alert("You cannot flag an issue with the same type that has already been verified.");
return;
} else {

$.post(OCC_REC.contextPath + "/occurrences/assertions/add",
{
recordUuid: recordUuid,
Expand Down Expand Up @@ -107,6 +129,28 @@ $(document).ready(function() {
$(el).html(replaceURLWithHTMLLinks(html)); // convert it
});

var allMyAnnotations = null;

$('#assertionButton').click(function (e) {
var getAlerts = OCC_REC.alertsURL + "/occurrences/userAlerts?userId=" + OCC_REC.userId;
$.getJSON(getAlerts, function (alerts) {
var myAnnotationAlertOn = false;
if (alerts !== null && alerts.enabledMyAnnotations.length > 0) {
myAnnotationAlertOn = true;
}

if (alerts !== null && alerts.allMyAnnotations.length > 0) {
allMyAnnotations = alerts.allMyAnnotations;
}

if (allMyAnnotations === null) {
$("#notifyChange").hide();
} else {
$("#notifyChangeCheckbox").prop('checked', myAnnotationAlertOn);
$("#notifyChangeCheckbox").prop('data-origstate', myAnnotationAlertOn);
}
})
})

// bind to form "close" button TODO
$("input#close").on("click", function(e) {
Expand Down Expand Up @@ -494,7 +538,6 @@ function updateConfirmVerificationEvents(occUuid, assertionUuid, userDisplayName
}

console.log("Submitting an assertion with userAssertionStatus: " + userAssertionStatus)

$.post(OCC_REC.contextPath + "/occurrences/assertions/add",
{ recordUuid: occUuid,
code: code,
Expand Down
2 changes: 2 additions & 0 deletions grails-app/conf/plugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ biocache.indexedFieldsUrl = "${biocache.baseUrl}/index/fields"
collections.baseUrl = "https://collections.ala.org.au"
alerts.baseUrl = "https://alerts.ala.org.au"
speciesList.baseURL = "https://lists.ala.org.au"
alerts.baseURL = 'https://alerts-test.ala.org.au'
alexhuang091 marked this conversation as resolved.
Show resolved Hide resolved
alerts.apiKey = "64ad0d69-4f6b-4f39-8e10-22a1b7062ff7"
alexhuang091 marked this conversation as resolved.
Show resolved Hide resolved
useDownloadPlugin = ""

// for images-client-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class BiocacheHubsUrlMappings {
"/occurrences/next"(controller: 'occurrence', action: 'next')
"/occurrences/previous"(controller: 'occurrence', action: 'previous')
"/occurrences/dataQualityExcludeCounts"(controller: 'occurrence', action: 'dataQualityExcludeCounts')
"/occurrences/userAlerts"(controller: 'occurrence', action: 'getUserAlerts')
"/occurrences/addAlert"(controller: 'occurrence', action: 'addAlert')
"/occurrences/deleteAlert"(controller: 'occurrence', action: 'deleteAlert')
"/occurrences/$id"(controller: 'occurrence', action: 'show')
"/occurrence/$id"(controller: 'occurrence', action: 'show')
"/assertions/$id"(controller: 'assertions', action: 'assertions')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package au.org.ala.biocache.hubs

import au.org.ala.dataquality.model.QualityProfile
import au.org.ala.web.CASRoles
import com.google.common.base.Stopwatch
import com.maxmind.geoip2.record.Location
import grails.converters.JSON
import groovy.util.logging.Slf4j
Expand Down Expand Up @@ -634,4 +633,16 @@ class OccurrenceController {
data.count = qualityService.getExcludeCount(params.categoryLabel, profile.getCategories(), requestParams)
render data as JSON
}

def getUserAlerts() {
render webServicesService.userAlerts(params.userId) as JSON
alexhuang091 marked this conversation as resolved.
Show resolved Hide resolved
}

def addAlert() {
render webServicesService.addAlert(params.userId, params.queryId) as JSON
}

def deleteAlert() {
render webServicesService.deleteAlert(params.userId, params.queryId) as JSON
}
}
1 change: 1 addition & 0 deletions grails-app/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ show.loginorflag.div01.navigator = Click here
show.loginorflag.div02.label = You are logged in as
show.issueform.label01 = Issue type:
show.issueform.label02 = Comment:
show.issueform.notifyme = Notify me when records I have annotated are updated
show.issueform.button.submit = Submit
show.issueform.button.cancel = Cancel
show.issueform.button.close = Close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ class WebServicesService {
getJsonElements(url)
}

def userAlerts(String userId) {
def url = "${grailsApplication.config.alerts.baseURL}" + "/api/alerts/user/" + userId
return getJsonElements(url, "${grailsApplication.config.alerts.apiKey}")
}

def addAlert(String userId, String queryId) {
def url = "${grailsApplication.config.alerts.baseURL}" + "/api/alerts/user/" + userId + "/subscribe/" + queryId
getJsonElements(url, "${grailsApplication.config.alerts.apiKey}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add / delete should use POST HTTP verbs instead of GET

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these calls new? May need to update the alerts side to only allow POST unless there's existing code calling them with GET

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use POST to send the add/delete.

But I didn't create a new function for POST, just reused the postFormData with empty data supplied.

}

def deleteAlert(String userId, String queryId) {
def url = "${grailsApplication.config.alerts.baseURL}" + "/api/alerts/user/" + userId + "/unsubscribe/" + queryId
getJsonElements(url, "${grailsApplication.config.alerts.apiKey}")
}

def JSONObject getDuplicateRecordDetails(JSONObject record) {
log.debug "getDuplicateRecordDetails -> ${record?.processed?.occurrence?.associatedOccurrences}"
if (record?.processed?.occurrence?.associatedOccurrences) {
Expand Down Expand Up @@ -398,12 +413,15 @@ class WebServicesService {
* @param url
* @return
*/
JSONElement getJsonElements(String url) {
JSONElement getJsonElements(String url, String apiKey = null) {
log.debug "(internal) getJson URL = " + url
def conn = new URL(url).openConnection()
try {
conn.setConnectTimeout(10000)
conn.setReadTimeout(50000)
if (apiKey != null) {
conn.setRequestProperty('apiKey', apiKey)
}
return JSON.parse(conn.getInputStream(), "UTF-8")
} catch (Exception e) {
def error = "Failed to get json from web service (${url}). ${e.getClass()} ${e.getMessage()}, ${e}"
Expand Down
5 changes: 5 additions & 0 deletions grails-app/views/occurrence/_recordSidebar.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@
<label for="issueComment" style="vertical-align:top;"><g:message code="show.issueform.label02" default="Comment:"/></label>
<textarea name="comment" id="issueComment" style="width:380px;height:150px;" placeholder="Please add a comment here..."></textarea>
</p>

<p style="margin-top:30px;">
<label style="width:100%" id="notifyChange"><input type="checkbox" id="notifyChangeCheckbox" name="notifyChange" value="">&nbsp;<g:message code="show.issueform.notifyme" default="Notify me when records I have annotated are updated"/></label>
</p>

<p style="margin-top:20px;">
<input id="issueFormSubmit" type="submit" value="<g:message code="show.issueform.button.submit" default="Submit"/>" class="btn btn-primary" />
<input type="reset" value="<g:message code="show.issueform.button.cancel" default="Cancel"/>" class="btn btn-default" onClick="$('#loginOrFlag').modal('hide');"/>
Expand Down
3 changes: 2 additions & 1 deletion grails-app/views/occurrence/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
status="s">'${sds}': '${grailsApplication.config.sensitiveDatasets[sds]}'${s < (sensitiveDatasets.size() - 1) ? ',' : ''}
</g:each>
},
hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean}
hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean},
alertsURL: "${grailsApplication.config.grails.serverURL}"
}

// Google charts
Expand Down