Skip to content

Commit

Permalink
Merge pull request dbca-wa#337 from awf-dbca/no-change-no-save
Browse files Browse the repository at this point in the history
S&C prevent saving if no changes made
  • Loading branch information
xzzy authored May 17, 2024
2 parents 8aac6e9 + faddbb9 commit 9b965b7
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ export default {
type: Object,
required: true
},
species_community_original: {
type: Object,
required: true
},
is_internal: {
type: Boolean,
default: false
Expand Down Expand Up @@ -571,6 +575,7 @@ export default {
}).then((response) => {
vm.updatingPublishing = false;
vm.species_community.publishing_status = response.body;
vm.species_community_original.publishing_status = helpers.copyObject(vm.species_community.publishing_status);
swal.fire({
title: 'Saved',
text: 'Publishing settings have been updated',
Expand All @@ -594,7 +599,16 @@ export default {
vm.updatingPublishing = true;
//if not already public, we make it public (notify user first)
//but only if it is active
if (vm.isPublic && vm.isActive) {
if (helpers.checkForChange(vm.species_community_original.publishing_status,vm.species_community.publishing_status)) {
swal.fire({
title: 'Error',
text: 'No changes made',
icon: 'error',
confirmButtonColor:'#226fbb',
});
vm.updatingPublishing = false;
}
else if (vm.isPublic && vm.isActive) {
//send just publishing form data
let data = JSON.stringify(vm.species_community.publishing_status)
vm.updatePublishing(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ export default {
type: Object,
required: true
},
species_community_original: {
type: Object,
required: true
},
// this prop is only send from split species form to make the original species readonly
is_readonly: {
type: Boolean,
Expand Down Expand Up @@ -924,6 +928,7 @@ export default {
}).then((response) => {
vm.updatingPublishing = false;
vm.species_community.publishing_status = response.body;
vm.species_community_original.publishing_status = helpers.copyObject(vm.species_community.publishing_status);
swal.fire({
title: 'Saved',
text: 'Publishing settings have been updated',
Expand All @@ -947,7 +952,16 @@ export default {
vm.updatingPublishing = true;
//if not already public, we make it public (notify user first)
//but only if it is active
if (vm.isPublic && vm.isActive) {
if (helpers.checkForChange(vm.species_community_original.publishing_status,vm.species_community.publishing_status)) {
swal.fire({
title: 'Error',
text: 'No changes made',
icon: 'error',
confirmButtonColor:'#226fbb',
});
vm.updatingPublishing = false;
}
else if (vm.isPublic && vm.isActive) {
//send just publishing form data
let data = JSON.stringify(vm.species_community.publishing_status)
vm.updatePublishing(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<div v-if="is_internal || is_public" class="tab-pane fade show active" :id="profileBody" role="tabpanel"
aria-labelledby="pills-profile-tab">
<Community v-if="isCommunity" ref="community_information" id="communityInformation"
:is_internal="is_internal" :species_community="species_community">
:is_internal="is_internal" :species_community="species_community" :species_community_original="species_community_original">
</Community>
<Species v-else ref="species_information" id="speciesInformation" :is_internal="is_internal"
:species_community="species_community" :is_readonly="is_readonly"
:species_community="species_community" :species_community_original="species_community_original" :is_readonly="is_readonly"
:rename_species="rename_species">
</Species>
</div>
Expand Down Expand Up @@ -83,6 +83,10 @@ export default {
type: Object,
required: true
},
species_community_original: {
type: Object,
required: true
},
is_external: {
type: Boolean,
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export default {
type: Object,
required: true
},
species_community_original: {
type: Object,
required: true
},
is_internal: {
type: Boolean,
required: true
Expand Down Expand Up @@ -136,6 +140,7 @@ export default {
}).then((response) => {
vm.updatingPublishing = false;
vm.species_community.publishing_status = response.body;
vm.species_community_original.publishing_status = helpers.copyObject(vm.species_community.publishing_status);
swal.fire({
title: 'Saved',
text: 'Record has been made public',
Expand All @@ -152,6 +157,7 @@ export default {
icon: 'error',
confirmButtonColor:'#226fbb',
});
vm.species_community.publishing_status = helpers.copyObject(vm.species_community_original.publishing_status);
vm.updatingPublishing = false;
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<form :action="species_community_form_url" method="post" name="new_species"
enctype="multipart/form-data">
<ProposalSpeciesCommunities ref="species_communities"
:species_community="species_community" id="speciesCommunityStart"
:species_community="species_community" :species_community_original="species_community_original" id="speciesCommunityStart"
:is_internal="true" :is_readonly="species_community.readonly">
</ProposalSpeciesCommunities>
<input type="hidden" name="csrfmiddlewaretoken" :value="csrf_token" />
Expand Down Expand Up @@ -178,8 +178,8 @@
@refreshFromResponse="refreshFromResponse" />
<SpeciesRename ref="species_rename" :species_community_original="species_community" :is_internal="true"
@refreshFromResponse="refreshFromResponse" />
<MakePublic ref="make_public" :species_community="species_community" :is_internal="true"
@refreshFromResponse="refreshFromResponse" />
<MakePublic ref="make_public" :species_community="species_community" :species_community_original="species_community_original"
:is_internal="true" @refreshFromResponse="refreshFromResponse" />
</div>
</template>
<script>
Expand All @@ -204,6 +204,7 @@ export default {
let vm = this;
return {
"species_community": null,
"species_community_original": null,
form: null,
savingSpeciesCommunity: false,
saveExitSpeciesCommunity: false,
Expand Down Expand Up @@ -490,6 +491,7 @@ export default {
await vm.$http.post(vm.species_community_form_url, payload).then(res => {
vm.species_community = res.body;
vm.species_community_original = helpers.copyObject(vm.species_community); //update original after save
swal.fire({
title: "Saved",
text: "Your changes has been saved" + was_public,
Expand Down Expand Up @@ -561,6 +563,20 @@ export default {
},
can_submit: function (check_action) {
let vm = this;
if (check_action != 'submit') {
//remove publishing status for check as it is handled separately
let sc_no_ps = helpers.copyObject(vm.species_community);
let sco_no_ps = helpers.copyObject(vm.species_community_original);
sc_no_ps.publishing_status = undefined;
sco_no_ps.publishing_status = undefined;
if (helpers.checkForChange(sco_no_ps,sc_no_ps)) {
return ["No changes made"]
}
}
let blank_fields = []
if (vm.species_community.group_type == 'flora' || vm.species_community.group_type == 'fauna') {
if (vm.species_community.taxonomy_id == null || vm.species_community.taxonomy_id == '') {
Expand Down Expand Up @@ -616,6 +632,7 @@ export default {
helpers.add_endpoint_json(api_endpoints.species, vm.species_community.id + '/submit')
vm.$http.post(submit_url, payload).then(res => {
vm.species_community = res.body;
vm.species_community_original = helpers.copyObject(vm.species_community);
// vm.$router.push({
// name: 'submit_cs_proposal',
// params: { conservation_status_obj: vm.conservation_status_obj}
Expand Down Expand Up @@ -647,8 +664,8 @@ export default {
},
refreshFromResponse: function (response) {
let vm = this;
vm.original_species_community = helpers.copyObject(response.body);
vm.species_community = helpers.copyObject(response.body);
vm.species_community_original = copyObject(vm.species_community);
},
splitSpecies: async function () {
this.$refs.species_split.species_community_original = this.species_community;
Expand Down Expand Up @@ -767,6 +784,7 @@ export default {
}).then((response) => {
vm.updatingPublishing = false;
vm.species_community.publishing_status = response.body;
vm.species_community_original.publishing_status = helpers.copyObject(vm.species_community.publishing_status);
swal.fire({
title: 'Saved',
text: 'Record has been made private',
Expand Down Expand Up @@ -801,6 +819,7 @@ export default {
Vue.http.get(`/api/species/${to.params.species_community_id}/internal_species.json`).then(res => {
next(vm => {
vm.species_community = res.body.species_obj; //--temp species_obj
vm.species_community_original = helpers.copyObject(vm.species_community);
vm.uploadedID = vm.species_community.image_doc;
});
},
Expand All @@ -813,6 +832,7 @@ export default {
Vue.http.get(`/api/community/${to.params.species_community_id}/internal_community.json`).then(res => {
next(vm => {
vm.species_community = res.body.community_obj; //--temp community_obj
vm.species_community_original = helpers.copyObject(vm.species_community);
vm.uploadedID = vm.species_community.image_doc;
});
},
Expand Down
9 changes: 9 additions & 0 deletions boranga/frontend/boranga/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,13 @@ module.exports = {
// })
// })
// },

checkForChange: function(before, after) {
//compare two objects, return true if the are the same
console.log(before);
console.log(after);
//JSON.stringify does not guarantee order and removes keys with undefined values
//that is acceptable for this use case, however
return JSON.stringify(before) === JSON.stringify(after);
}
};

0 comments on commit 9b965b7

Please sign in to comment.