Skip to content

Commit

Permalink
Merge pull request #636 from AtlasOfLivingAustralia/619-add-annotatio…
Browse files Browse the repository at this point in the history
…n-comment-edit-button

#619 add edit button for annotation comments
  • Loading branch information
adam-collins authored Feb 25, 2025
2 parents da44939 + 2701381 commit f1309b7
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 18 deletions.
94 changes: 83 additions & 11 deletions grails-app/assets/javascripts/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function init() {
var relatedRecordReason = $('#relatedRecordReason').val();
var userDisplayName = OCC_REC.userDisplayName //'${userDisplayName}';
var recordUuid = OCC_REC.recordUuid //'${ala:escapeJS(record.raw.rowKey)}';
var assertionId = $('#assertionId').val();
if(code!=""){
$('#assertionSubmitProgress').css({'display':'block'});

Expand Down Expand Up @@ -234,6 +235,7 @@ function init() {
userDisplayName: userDisplayName,
relatedRecordId: relatedRecordId,
relatedRecordReason: relatedRecordReason,
updateId: assertionId
},
function (data) {
// when add assertion succeeds, we update alert settings (only when myannotation is enabled)
Expand Down Expand Up @@ -472,6 +474,26 @@ function init() {
}
});

$('#loginOrFlag').on('show.bs.modal', function (event) {
var editMode = $('#editMode').val();
if (editMode === 'true') {
// alter form for edit mode
$('#loginOrFlag').find('#loginOrFlagLabel').text(jQuery.i18n.prop('show.loginorflag.title.edit'));
$('#loginOrFlag').find('#issue').prop('disabled', true);

// the assertionId, issue code and comment are set elsewhere
} else {
// reset form to default state for creating a new issue, probably not required as the page does a reload
$('#loginOrFlag').find('#loginOrFlagLabel').text(jQuery.i18n.prop('show.loginorflag.title'));
$('#loginOrFlag').find('#issue').prop('disabled', false);

var code = $('#loginOrFlag').find('#issue').children().first().val();
$('#loginOrFlag').find('#issue').val(code);
$('#loginOrFlag').find('#issueComment').val("");
$('#loginOrFlag').find('#assertionId').val("");
}
});

}

/**
Expand Down Expand Up @@ -552,6 +574,8 @@ function refreshUserAnnotations(){
if (userAssertion.code != 50000) {
$clone.prop('id', "userAnnotation_" + userAssertion.uuid);
$clone.find('.issue').text(jQuery.i18n.prop(userAssertion.name)).attr('i18nkey', userAssertion.name);
$clone.find('.issueCode').text(userAssertion.code);
$clone.find('.issueComment').text(userAssertion.comment);
$clone.find('.user').text(userAssertion.userDisplayName);
if (userAssertion.hasOwnProperty('comment')) {
$clone.find('.comment').text('Comment: ' + userAssertion.comment);
Expand Down Expand Up @@ -613,7 +637,7 @@ function refreshUserAnnotations(){
$clone.find('.userEntity').text(', ' + userAssertion.userEntityName);
}

//if the current user is the author of the annotation, they can delete
//if the current user is the author of the annotation, they can delete and edit
if(OCC_REC.userId == userAssertion.userId){
$clone.find('.deleteAnnotation').css({display:'block'});
$clone.find('.deleteAnnotation').attr('id', userAssertion.uuid);
Expand Down Expand Up @@ -674,7 +698,7 @@ function refreshUserAnnotations(){
}
}

updateDeleteEvents(enableDelete, disableDelete);
updateEditDeleteEvents(enableDelete, disableDelete);
});
}

Expand All @@ -687,6 +711,28 @@ function updateDeleteVerificationEvents(relatedAssertionId) {
deleteAssertion(OCC_REC.recordUuid, this.parentElement.parentElement.id.split('_').pop());
}
});

$('#userAnnotation_' + relatedAssertionId + ' .editVerificationButton').off("click");
$('#userAnnotation_' + relatedAssertionId + ' .editVerificationButton').on("click", function (e) {
e.preventDefault();

var element = $(this.parentElement.parentElement);

// reset the form on open
var assertionId = this.parentElement.parentElement.id.split('_').pop();
var code = element.find('.qaStatus').attr('i18nkey').split('.').pop();
var comment = element.find('.comment').text();
$("#verifyComment").val(comment);
$("#userAssertionStatusSelection").val(code);
$(".verifyAsk").show();
$(".verifyDone").hide();
$("#verifySpinner").hide();
updateConfirmVerificationEvents(OCC_REC.recordUuid, relatedAssertionId, OCC_REC.userDisplayName, assertionId);

$("#userAssertionStatusSelection").attr('disabled', 'disabled')

$('#verifyRecordModal').modal('show');
});
}

function deleteAssertionPrompt(event) {
Expand All @@ -698,23 +744,47 @@ function deleteAssertionPrompt(event) {
}
}

function updateDeleteEvents(enableDelete, disableDelete){
function updateEditDeleteEvents(enableDelete, disableDelete){

for(var i = 0; i < enableDelete.length; i++){
$('#userAnnotation_' + enableDelete[i] + ' .deleteAnnotation').off("click");
$('#userAnnotation_' + enableDelete[i] + ' .deleteAnnotation').click({rec_uuid: OCC_REC.recordUuid, qa_uuid: enableDelete[i]}, deleteAssertionPrompt);
$('#userAnnotation_' + enableDelete[i] + ' .deleteAnnotationButton').off("click");
$('#userAnnotation_' + enableDelete[i] + ' .deleteAnnotationButton').click({rec_uuid: OCC_REC.recordUuid, qa_uuid: enableDelete[i]}, deleteAssertionPrompt);

$('#userAnnotation_' + enableDelete[i] + ' .editAnnotationButton').off("click");
$('#userAnnotation_' + enableDelete[i] + ' .editAnnotationButton').attr('annotationId', enableDelete[i]);
$('#userAnnotation_' + enableDelete[i] + ' .editAnnotationButton').on("click", function(e){
e.preventDefault();

// update loginOrFlag modal state
var annotationId = $(this).attr('annotationId');
var code = $('#userAnnotation_' +annotationId + ' .issueCode').text();
var comment = $('#userAnnotation_' + annotationId + ' .issueComment').text();
$('#loginOrFlag').find('#issue').val(code);
$('#loginOrFlag').find('#editMode').val('true');
$('#loginOrFlag').find('#assertionId').val(annotationId);
$('#loginOrFlag').find('#issueComment').val(comment);

$('#loginOrFlag').modal('show');
});

updateVerificationEvents(enableDelete[i]);
}

for(var i = 0; i < disableDelete.length; i++){
$('#userAnnotation_' + disableDelete[i] + ' .editAnnotationButton').attr('disabled', 'disabled');
$('#userAnnotation_' + disableDelete[i] + ' .editAnnotationButton').attr('title', 'Unable to edit, as this assertion has a verification');
$('#userAnnotation_' + disableDelete[i] + ' .editAnnotationButton').off("click");
$('#userAnnotation_' + disableDelete[i] + ' .editAnnotationButton').on("click", function (e) {
e.preventDefault();
});

$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotationButton').attr('disabled', 'disabled');
$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotationButton').attr('title', 'Unable to delete, as this assertion has a verification');


$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotation').off("click");
$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotation').on("click", function (e) {
$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotationButton').off("click");
$('#userAnnotation_' + disableDelete[i] + ' .deleteAnnotationButton').on("click", function (e) {
e.preventDefault();
});

updateVerificationEvents(disableDelete[i]);
}

Expand All @@ -735,7 +805,8 @@ function updateVerificationEvents(assertionId) {
});
}

function updateConfirmVerificationEvents(occUuid, assertionUuid, userDisplayName){
// provide assertionId when editing a verification, do not provide when creating a verification
function updateConfirmVerificationEvents(occUuid, assertionUuid, userDisplayName, updateId){

$('.closeVerify').on("click", function(e){
e.preventDefault();
Expand Down Expand Up @@ -765,7 +836,8 @@ function updateConfirmVerificationEvents(occUuid, assertionUuid, userDisplayName
userAssertionStatus: userAssertionStatus,
assertionUuid: assertionUuid,
userId: OCC_REC.userId,
userDisplayName: userDisplayName},
userDisplayName: userDisplayName,
updateId: updateId },
function(data) {
// service simply returns status or OK or FORBIDDEN, so assume it worked...
$(".verifyAsk").fadeOut();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AssertionsController {
String assertionUuid = params.assertionUuid ?: ""
String relatedRecordId = params.relatedRecordId ?: ''
String relatedRecordReason = params.relatedRecordReason ?: ''
String updateId = params.updateId ?: ''
UserDetails userDetails = authService?.userDetails() // will return null if not available/not logged in

if (recordUuid && code && userDetails) {
Expand All @@ -66,7 +67,7 @@ class AssertionsController {
}

log.info("Adding assertion to UUID: ${recordUuid}, code: ${code}, comment: ${comment}, userAssertionStatus: ${userAssertionStatus}, userId: ${userDetails.userId}, userEmail: ${userDetails.email}")
Map postResponse = webServicesService.addAssertion(recordUuid, code, comment, userDetails.userId, userDetails.displayName, userAssertionStatus, assertionUuid, relatedRecordId, relatedRecordReason)
Map postResponse = webServicesService.addAssertion(recordUuid, code, comment, userDetails.userId, userDetails.displayName, userAssertionStatus, assertionUuid, relatedRecordId, relatedRecordReason, updateId)

if (postResponse.statusCode == 201) {
log.info("Called REST service. Assertion should be added")
Expand Down
3 changes: 3 additions & 0 deletions grails-app/i18n/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ show.sidebar01.volunteer.navigator = DigiVol
show.button.viewdraftbutton.span = See draft in DigiVol
show.button.assertionbutton.span = Flag an issue
show.loginorflag.title = Flag an issue
show.loginorflag.title.edit = Edit an issue
show.loginorflag.div01.label = Login please:
show.loginorflag.div01.navigator = Click here
show.loginorflag.div02.label = You are logged in as
Expand Down Expand Up @@ -227,6 +228,8 @@ show.userannotationtemplate.p01.navigator = View more with this annotation
show.userannotationtemplate.p02.navigator = Delete this annotation
show.userannotationtemplate.p03.navigator = Verify this annotation
show.userannotationtemplate.p04.navigator = Delete this verification
show.userannotationtemplate.p05.navigator = Edit
show.userannotationtemplate.p06.navigator = Edit
show.userannotationtemplate.relatedrecord.userduplicate.a = View duplicated record
show.userannotationtemplate.relatedrecord.default.a = View related record
show.headingbar02.title = Record Not Found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class WebServicesService {
*/
Map addAssertion(String recordUuid, String code, String comment, String userId, String userDisplayName,
String userAssertionStatus, String assertionUuid, String relatedRecordId,
String relatedRecordReason) {
String relatedRecordReason, String updateId) {
Map postBody = [
recordUuid : recordUuid,
code : code,
Expand All @@ -226,7 +226,8 @@ class WebServicesService {
relatedRecordId : relatedRecordId,
relatedRecordReason: relatedRecordReason,
userId : userId,
userDisplayName : userDisplayName
userDisplayName : userDisplayName,
updateId : updateId
]

postFormData(grailsApplication.config.getProperty('biocache.baseUrl') + "/occurrences/assertions/add", postBody, true, true)
Expand Down
2 changes: 2 additions & 0 deletions grails-app/views/occurrence/_recordSidebar.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@
<div>
<g:message code="show.loginorflag.div02.label" default="You are logged in as"/> <strong>${userDisplayName} (${alatag.loggedInUserEmail()})</strong>.
<form id="issueForm">
<input type="hidden" name="assertionId" id="assertionId" value=""/>
<input type="hidden" name="editMode" id="editMode" value="false"/>
<p style="margin-top:20px;">
<label for="issue"><g:message code="show.issueform.label01" default="Issue type:"/></label>
<select name="issue" id="issue" autocomplete="off">
Expand Down
18 changes: 14 additions & 4 deletions grails-app/views/occurrence/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,21 @@
</g:link>
</p>
<p class="comment"></p>
<p class="hide issueCode"></p>
<p class="hide issueComment"></p>
<p class="hide userDisplayName"></p>
<p class="created small"></p>
<p class="viewMore" style="display:none;">
<a class="viewMoreLink" href="#"><g:message code="show.userannotationtemplate.p01.navigator" default="View more with this annotation"/></a>
</p>
<p class="deleteAnnotation" style="display:block;">
<a class="editAnnotationButton btn btn-danger" href="#">
<g:message code="show.userannotationtemplate.p05.navigator" default="Edit"/>
<span class="editAssertionSubmitProgress" style="display:none;">
<asset:image src="indicator.gif" alt="indicator icon"/>
</span>
</a>
<a class="deleteAnnotationButton btn btn-danger" href="#">
<i class="glyphicon glyphicon-remove"> </i> &nbsp;
<g:message code="show.userannotationtemplate.p02.navigator" default="Delete this annotation"/>
<span class="deleteAssertionSubmitProgress" style="display:none;">
<asset:image src="indicator.gif" alt="indicator icon"/>
Expand Down Expand Up @@ -838,9 +845,12 @@
<td class="created"></td>
<td class="deleteVerification">
<g:if test="${isCollectionAdmin}">
<a class="deleteVerificationButton btn btn-danger" style="text-align: right" href="#">
<g:message code="show.userannotationtemplate.p04.navigator" default="Delete this verification"/>
</a>
<a class="editVerificationButton btn btn-danger" style="text-align: right" href="#">
<g:message code="show.userannotationtemplate.p06.navigator" default="Edit"/>
</a>
<a class="deleteVerificationButton btn btn-danger" style="text-align: right" href="#">
<g:message code="show.userannotationtemplate.p04.navigator" default="Delete this verification"/>
</a>
</g:if>
</td>
</tr>
Expand Down

0 comments on commit f1309b7

Please sign in to comment.