Commit 6a14a515 authored by Phil Hughes's avatar Phil Hughes

Show warning if realtime data has changed since the form has opened

parent f5675666
...@@ -81,11 +81,11 @@ export default { ...@@ -81,11 +81,11 @@ export default {
openForm() { openForm() {
if (!this.showForm) { if (!this.showForm) {
this.showForm = true; this.showForm = true;
this.store.formState = { this.store.formState = Object.assign(this.store.formState, {
title: this.state.titleText, title: this.state.titleText,
confidential: this.isConfidential, confidential: this.isConfidential,
description: this.state.descriptionText, description: this.state.descriptionText,
}; });
} }
}, },
closeForm() { closeForm() {
...@@ -128,7 +128,14 @@ export default { ...@@ -128,7 +128,14 @@ export default {
resource: this.service, resource: this.service,
method: 'getData', method: 'getData',
successCallback: (res) => { successCallback: (res) => {
this.store.updateState(res.json()); const data = res.json();
const shouldUpdate = this.store.stateShouldUpdate(data);
this.store.updateState(data);
if (this.showForm && (shouldUpdate.title || shouldUpdate.description)) {
this.store.formState.lockedWarningVisible = true;
}
}, },
errorCallback(err) { errorCallback(err) {
throw new Error(err); throw new Error(err);
......
<script> <script>
import eventHub from '../event_hub';
import lockedWarning from './locked_warning.vue';
import titleField from './fields/title.vue'; import titleField from './fields/title.vue';
import descriptionField from './fields/description.vue'; import descriptionField from './fields/description.vue';
import editActions from './edit_actions.vue'; import editActions from './edit_actions.vue';
...@@ -24,16 +26,26 @@ ...@@ -24,16 +26,26 @@
}, },
}, },
components: { components: {
lockedWarning,
titleField, titleField,
descriptionField, descriptionField,
editActions, editActions,
confidentialCheckbox, confidentialCheckbox,
}, },
methods: {
closeForm() {
eventHub.$emit('close.form');
this.formState.lockedWarningVisible = false;
},
},
}; };
</script> </script>
<template> <template>
<form> <form>
<locked-warning
v-if="formState.lockedWarningVisible"
@closeForm="closeForm" />
<title-field <title-field
:form-state="formState" /> :form-state="formState" />
<confidential-checkbox <confidential-checkbox
......
<script>
export default {
methods: {
closeForm() {
this.$emit('closeForm');
},
},
};
</script>
<template>
<div class="alert alert-danger">
Someone edited the issue the same time you did. Please check out
<a
href="#"
role="button"
@click.prevent="closeForm">the issue</a>
and make sure your changes will not unintentionally remove theirs.
</div>
</template>
...@@ -16,6 +16,7 @@ export default class Store { ...@@ -16,6 +16,7 @@ export default class Store {
title: '', title: '',
confidential: false, confidential: false,
description: '', description: '',
lockedWarningVisible: false,
}; };
} }
...@@ -27,4 +28,11 @@ export default class Store { ...@@ -27,4 +28,11 @@ export default class Store {
this.state.taskStatus = data.task_status; this.state.taskStatus = data.task_status;
this.state.updatedAt = data.updated_at; this.state.updatedAt = data.updated_at;
} }
stateShouldUpdate(data) {
return {
title: this.state.titleText !== data.title_text,
description: this.state.descriptionText !== data.description_text,
};
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment