-
Notifications
You must be signed in to change notification settings - Fork 33
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
Changes from 10 commits
acde860
8d1323d
7c22ecf
19c2c2a
5d66f2c
b3f10d7
4bbd71d
6dc61c2
55bd9e1
c190131
5095643
5d0c871
f468d30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,21 @@ $(document).ready(function() { | |
if(code!=""){ | ||
$('#assertionSubmitProgress').css({'display':'block'}); | ||
|
||
if (myAnnotationQueryId) { | ||
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) { | ||
$.post(OCC_REC.alertsURL + "/occurrences/addAlert?queryId=" + myAnnotationQueryId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this OCC_REC property and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I hadn't got down to the code below in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} else { // to remove alerts | ||
$.post(OCC_REC.alertsURL + "/occurrences/deleteAlert?queryId=" + myAnnotationQueryId); | ||
} | ||
} | ||
} | ||
|
||
$.get( OCC_REC.contextPath + "/assertions/" + OCC_REC.recordUuid, function(data) { | ||
var bPreventAddingIssue = false; | ||
for (var i = 0; i < data.userAssertions.length; i++) { | ||
|
@@ -152,7 +167,6 @@ $(document).ready(function() { | |
alert("You can't mark a record as a duplicate of itself"); | ||
return; | ||
} else { | ||
|
||
$.post(OCC_REC.contextPath + "/occurrences/assertions/add", | ||
{ | ||
recordUuid: recordUuid, | ||
|
@@ -197,6 +211,40 @@ $(document).ready(function() { | |
$(el).html(replaceURLWithHTMLLinks(html)); // convert it | ||
}); | ||
|
||
var myAnnotationQueryId = null | ||
|
||
$('#assertionButton').click(function (e) { | ||
var getAlerts = OCC_REC.alertsURL + "/occurrences/alerts"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto above comment about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
var myAnnotationEnabled = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable can be moved inside the .getJSON There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
$.getJSON(getAlerts, function (data) { | ||
if (data.enabledQueries) { | ||
for (var i = 0; i < data.enabledQueries.length; i++) { | ||
if (data.enabledQueries[i].name.indexOf(OCC_REC.alertName) !== -1) { | ||
myAnnotationEnabled = true; | ||
myAnnotationQueryId = data.enabledQueries[i].id | ||
} | ||
} | ||
} | ||
|
||
if (data.disabledQueries) { | ||
for (var i = 0; i < data.disabledQueries.length; i++) { | ||
if (data.disabledQueries[i].name.indexOf(OCC_REC.alertName) !== -1) { | ||
myAnnotationEnabled = false; | ||
myAnnotationQueryId = data.disabledQueries[i].id | ||
} | ||
} | ||
} | ||
|
||
// if can't find 'my annotation' hide the check box | ||
if (myAnnotationQueryId === null) { | ||
$("#notifyChange").hide(); | ||
} else { | ||
$("#notifyChangeCheckbox").prop('checked', myAnnotationEnabled); | ||
$("#notifyChangeCheckbox").prop('data-origstate', myAnnotationEnabled); | ||
} | ||
}) | ||
}) | ||
|
||
// bind to form "close" button TODO | ||
$("input#close").on("click", function(e) { | ||
|
@@ -598,7 +646,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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -639,4 +638,19 @@ class OccurrenceController { | |
data.count = qualityService.getExcludeCount(params.categoryLabel, profile.getCategories(), requestParams) | ||
render data as JSON | ||
} | ||
|
||
def getAlerts() { | ||
String userId = authService?.getUserId() | ||
render ((userId == null) ? [error: 'userId must be supplied to get alerts'] : webServicesService.getAlerts(userId)) as JSON | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error responses should have a non 200 series HTTP status code. These error maps aren't checked for in the JS that calls them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solved. In JS the checkbox is initially hidden now. So only when call is successful will show it. |
||
} | ||
|
||
def addAlert() { | ||
String userId = authService?.getUserId() | ||
render ((userId == null) ? [error: 'userId must be supplied to add alert'] : webServicesService.addAlert(userId, params.queryId)) as JSON | ||
} | ||
|
||
def deleteAlert() { | ||
String userId = authService?.getUserId() | ||
render ((userId == null) ? [error: 'userId must be supplied to delete alert'] : webServicesService.deleteAlert(userId, params.queryId)) as JSON | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,21 @@ class WebServicesService { | |
getJsonElements(url) | ||
} | ||
|
||
def getAlerts(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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add / delete should use POST HTTP verbs instead of GET There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -401,12 +416,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}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,9 @@ | |
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}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above, remove this and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just FYI for next time (think I've said this before) - preferred way to write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - but Alex didn't add the hasGoogleKey line, that was already here, he just added the comma to add to the JS config object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missed that - I stand corrected 👍 |
||
alertName: "${grailsApplication.config.myannotation.name}" | ||
} | ||
|
||
// Google charts | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you add / remove alerts even if the form submit is invalid? What if the assertion add fails?
If the add / delete Alert works, shouldn't you update $('#notifyChangeCheckbox').prop('data-origstate') in case the form is resubmitted after a validation error, otherwise you might have a duplicate add / delete call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add/delete alert is now moved into success callback of add assertion. So only when an assertion is added successfully an add/delete will be called.