diff --git a/grails-app/assets/javascripts/show.js b/grails-app/assets/javascripts/show.js index b092ebcec..83f86132c 100644 --- a/grails-app/assets/javascripts/show.js +++ b/grails-app/assets/javascripts/show.js @@ -197,10 +197,17 @@ $(document).ready(function() { relatedRecordReason: relatedRecordReason, }, function (data) { + // when add assertion succeeds, we update alert settings (only when myannotation is enabled) + if (OCC_REC.myAnnotationEnabled) { + var new_state = $('#notifyChangeCheckbox').prop('checked'); + var actionpath = new_state ? "/occurrences/subscribeMyAnnotation" : "/occurrences/unsubscribeMyAnnotation"; + $.post(OCC_REC.contextPath + actionpath); + } + $('#assertionSubmitProgress').css({'display': 'none'}); $("#submitSuccess").html("Thanks for flagging the problem!"); $("#issueFormSubmit").hide(); - $("input:reset").hide(); + $("input#cancel").hide(); $("input#close").show(); //retrieve all assertions $.get(OCC_REC.contextPath + '/assertions/' + OCC_REC.recordUuid, function (data) { // recordUuid=${record.raw.uuid} @@ -229,6 +236,18 @@ $(document).ready(function() { $(el).html(replaceURLWithHTMLLinks(html)); // convert it }); + $('#assertionButton').click(function (e) { + // if myannotation enabled, to retrieve current settings + if (OCC_REC.myAnnotationEnabled) { + // by default off + $("#notifyChangeCheckbox").prop('checked', false); + var getAlerts = OCC_REC.contextPath + "/occurrences/alerts"; + $.getJSON(getAlerts, function (data) { + var myAnnotationEnabled = data && data.myannotation && data.myannotation.length > 0; + $("#notifyChangeCheckbox").prop('checked', myAnnotationEnabled); + }) + } + }) // bind to form "close" button TODO $("input#close").on("click", function(e) { diff --git a/grails-app/controllers/au/org/ala/biocache/hubs/OccurrenceController.groovy b/grails-app/controllers/au/org/ala/biocache/hubs/OccurrenceController.groovy index efc3b71e1..4c2ecc683 100644 --- a/grails-app/controllers/au/org/ala/biocache/hubs/OccurrenceController.groovy +++ b/grails-app/controllers/au/org/ala/biocache/hubs/OccurrenceController.groovy @@ -725,4 +725,34 @@ class OccurrenceController { return userPref.expand } + + def getAlerts() { + String userId = authService?.getUserId() + if (userId == null) { + response.status = 404 + render ([error: 'userId must be supplied to get alerts'] as JSON) + } else { + render webServicesService.getAlerts(userId) as JSON + } + } + + def subscribeMyAnnotation() { + String userId = authService?.getUserId() + if (userId == null) { + response.status = 404 + render ([error: 'userId must be supplied to add alert'] as JSON) + } else { + render webServicesService.subscribeMyAnnotation(userId) as JSON + } + } + + def unsubscribeMyAnnotation() { + String userId = authService?.getUserId() + if (userId == null) { + response.status = 404 + render ([error: 'userId must be supplied to delete alert'] as JSON) + } else { + render webServicesService.unsubscribeMyAnnotation(userId) as JSON + } + } } diff --git a/grails-app/i18n/messages_en.properties b/grails-app/i18n/messages_en.properties index 35b4bb9c1..941e1efad 100644 --- a/grails-app/i18n/messages_en.properties +++ b/grails-app/i18n/messages_en.properties @@ -135,6 +135,7 @@ show.issueform.label01 = Issue type: show.issueform.label02 = Comment: show.issueform.label03 = Duplicate Record ID: show.issueform.label04 = Duplicate Reason: +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 diff --git a/grails-app/init/biocache/hubs/BootStrap.groovy b/grails-app/init/biocache/hubs/BootStrap.groovy index 78264cd69..8df5a2a0a 100644 --- a/grails-app/init/biocache/hubs/BootStrap.groovy +++ b/grails-app/init/biocache/hubs/BootStrap.groovy @@ -3,8 +3,20 @@ package biocache.hubs class BootStrap { def messageSource def application + def grailsApplication + def grailsUrlMappingsHolder def init = { servletContext -> + + // if my annotation feature turned on, add url mapping to handle add/remove my annotation alert requests + if (grailsApplication.config.getProperty('alerts.myannotation.enabled', Boolean, false)) { + grailsUrlMappingsHolder.addMappings({ + "/occurrences/alerts"(controller: 'occurrence', action: [GET: 'getAlerts']) + "/occurrences/subscribeMyAnnotation"(controller: 'occurrence', action: [POST: 'subscribeMyAnnotation']) + "/occurrences/unsubscribeMyAnnotation"(controller: 'occurrence', action: [POST: 'unsubscribeMyAnnotation']) + }) + } + messageSource.setBasenames( "file:///var/opt/atlas/i18n/downloads-plugin/messages", "file:///opt/atlas/i18n/downloads-plugin/messages", diff --git a/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy b/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy index 3641093b7..434f3f53e 100644 --- a/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy +++ b/grails-app/services/au/org/ala/biocache/hubs/WebServicesService.groovy @@ -112,6 +112,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 subscribeMyAnnotation(String userId) { + String url = "${grailsApplication.config.alerts.baseUrl}" + "/api/alerts/user/" + userId + "/subscribeMyAnnotation" + postFormData(url, [:], grailsApplication.config.alerts.apiKey as String) + } + + def unsubscribeMyAnnotation(String userId) { + String url = "${grailsApplication.config.alerts.baseUrl}" + "/api/alerts/user/" + userId + "/unsubscribeMyAnnotation" + postFormData(url, [:], grailsApplication.config.alerts.apiKey as String) + } + def JSONObject getDuplicateRecordDetails(JSONObject record) { log.debug "getDuplicateRecordDetails -> ${record?.processed?.occurrence?.associatedOccurrences}" if (record?.processed?.occurrence?.associatedOccurrences) { diff --git a/grails-app/views/occurrence/_recordSidebar.gsp b/grails-app/views/occurrence/_recordSidebar.gsp index 43f1e91cf..abed77be5 100644 --- a/grails-app/views/occurrence/_recordSidebar.gsp +++ b/grails-app/views/occurrence/_recordSidebar.gsp @@ -375,9 +375,16 @@

+ + +

+ +

+
+

" class="btn btn-primary" /> - " class="btn btn-default" onClick="$('#loginOrFlag').modal('hide');"/> + " class="btn btn-default" onClick="$('#loginOrFlag').modal('hide');"/> " class="btn btn-default" style="display:none;"/>

diff --git a/grails-app/views/occurrence/show.gsp b/grails-app/views/occurrence/show.gsp index c0abd35f8..e1aab7e0c 100644 --- a/grails-app/views/occurrence/show.gsp +++ b/grails-app/views/occurrence/show.gsp @@ -59,7 +59,8 @@ status="s">'${sds}': '${grailsApplication.config.sensitiveDatasets[sds]}'${s < (sensitiveDatasets.size() - 1) ? ',' : ''} }, - hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean} + hasGoogleKey: ${grailsApplication.config.google.apikey as Boolean}, + myAnnotationEnabled: ${(grailsApplication.config.getProperty("alerts.myannotation.enabled", Boolean, false))} } var BC_CONF = OCC_REC; // For compatibility with common JS components which require BC_CONF