2017-06-14 19:36:53 -04:00
|
|
|
<script>
|
2017-07-28 13:48:13 -04:00
|
|
|
import { mapGetters } from 'vuex';
|
2017-07-26 07:02:01 -04:00
|
|
|
import eventHub from '../event_hub';
|
2017-09-14 07:01:07 -04:00
|
|
|
import issueWarning from '../../vue_shared/components/issue/issue_warning.vue';
|
2017-08-11 06:45:05 -04:00
|
|
|
import markdownField from '../../vue_shared/components/markdown/field.vue';
|
2017-09-14 07:01:07 -04:00
|
|
|
import issuableStateMixin from '../mixins/issuable_state';
|
2017-06-14 19:36:53 -04:00
|
|
|
|
2017-07-26 07:02:01 -04:00
|
|
|
export default {
|
2017-08-11 06:45:05 -04:00
|
|
|
name: 'issueNoteForm',
|
2017-07-26 07:02:01 -04:00
|
|
|
props: {
|
|
|
|
noteBody: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
noteId: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
saveButtonTitle: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'Save comment',
|
|
|
|
},
|
2017-07-28 13:43:19 -04:00
|
|
|
discussion: {
|
2017-07-28 13:48:13 -04:00
|
|
|
type: Object,
|
2017-07-28 13:43:19 -04:00
|
|
|
required: false,
|
2017-08-10 07:25:08 -04:00
|
|
|
default: () => ({}),
|
2017-08-02 11:22:38 -04:00
|
|
|
},
|
|
|
|
isEditing: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2017-06-14 19:36:53 -04:00
|
|
|
},
|
2017-07-26 07:02:01 -04:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
note: this.noteBody,
|
|
|
|
conflictWhileEditing: false,
|
2017-08-02 11:52:24 -04:00
|
|
|
isSubmitting: false,
|
2017-07-26 07:02:01 -04:00
|
|
|
};
|
2017-07-17 18:07:42 -04:00
|
|
|
},
|
2017-07-26 07:02:01 -04:00
|
|
|
components: {
|
2017-09-14 07:01:07 -04:00
|
|
|
issueWarning,
|
2017-07-26 07:02:01 -04:00
|
|
|
markdownField,
|
2017-06-14 19:36:53 -04:00
|
|
|
},
|
2017-07-26 07:02:01 -04:00
|
|
|
computed: {
|
2017-07-28 13:48:13 -04:00
|
|
|
...mapGetters([
|
|
|
|
'getDiscussionLastNote',
|
2017-11-30 17:44:41 -05:00
|
|
|
'getNoteableData',
|
|
|
|
'getNoteableDataByProp',
|
2017-08-02 11:22:38 -04:00
|
|
|
'getNotesDataByProp',
|
|
|
|
'getUserDataByProp',
|
2017-07-28 13:48:13 -04:00
|
|
|
]),
|
2017-07-26 07:02:01 -04:00
|
|
|
noteHash() {
|
|
|
|
return `#note_${this.noteId}`;
|
|
|
|
},
|
2017-08-17 13:25:56 -04:00
|
|
|
markdownPreviewPath() {
|
2017-11-30 17:44:41 -05:00
|
|
|
return this.getNoteableDataByProp('preview_note_path');
|
2017-08-02 11:22:38 -04:00
|
|
|
},
|
2017-08-17 13:25:56 -04:00
|
|
|
markdownDocsPath() {
|
|
|
|
return this.getNotesDataByProp('markdownDocsPath');
|
2017-08-02 11:22:38 -04:00
|
|
|
},
|
2017-08-17 13:25:56 -04:00
|
|
|
quickActionsDocsPath() {
|
|
|
|
return !this.isEditing ? this.getNotesDataByProp('quickActionsDocsPath') : undefined;
|
2017-08-02 11:22:38 -04:00
|
|
|
},
|
|
|
|
currentUserId() {
|
|
|
|
return this.getUserDataByProp('id');
|
2017-08-02 11:52:24 -04:00
|
|
|
},
|
|
|
|
isDisabled() {
|
|
|
|
return !this.note.length || this.isSubmitting;
|
|
|
|
},
|
2017-06-14 19:36:53 -04:00
|
|
|
},
|
2017-07-26 07:02:01 -04:00
|
|
|
methods: {
|
|
|
|
handleUpdate() {
|
2017-08-02 11:52:24 -04:00
|
|
|
this.isSubmitting = true;
|
2017-08-21 12:05:40 -04:00
|
|
|
|
|
|
|
this.$emit('handleFormUpdate', this.note, this.$refs.editNoteForm, () => {
|
|
|
|
this.isSubmitting = false;
|
|
|
|
});
|
2017-07-26 07:02:01 -04:00
|
|
|
},
|
|
|
|
editMyLastNote() {
|
|
|
|
if (this.note === '') {
|
2017-08-10 07:25:08 -04:00
|
|
|
const lastNoteInDiscussion = this.getDiscussionLastNote(this.discussion);
|
2017-07-10 17:53:52 -04:00
|
|
|
|
2017-07-28 13:48:13 -04:00
|
|
|
if (lastNoteInDiscussion) {
|
2017-07-26 07:02:01 -04:00
|
|
|
eventHub.$emit('enterEditMode', {
|
2017-07-28 13:48:13 -04:00
|
|
|
noteId: lastNoteInDiscussion.id,
|
2017-07-26 07:02:01 -04:00
|
|
|
});
|
|
|
|
}
|
2017-07-10 17:53:52 -04:00
|
|
|
}
|
2017-07-26 07:02:01 -04:00
|
|
|
},
|
2017-07-28 07:53:51 -04:00
|
|
|
cancelHandler(shouldConfirm = false) {
|
|
|
|
// Sends information about confirm message and if the textarea has changed
|
2017-08-10 07:25:08 -04:00
|
|
|
this.$emit('cancelFormEdition', shouldConfirm, this.noteBody !== this.note);
|
2017-08-02 11:52:24 -04:00
|
|
|
},
|
2017-07-10 17:53:52 -04:00
|
|
|
},
|
2017-09-14 07:01:07 -04:00
|
|
|
mixins: [
|
|
|
|
issuableStateMixin,
|
|
|
|
],
|
2017-07-26 07:02:01 -04:00
|
|
|
mounted() {
|
|
|
|
this.$refs.textarea.focus();
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
noteBody() {
|
2017-08-10 07:25:08 -04:00
|
|
|
if (this.note === this.noteBody) {
|
2017-07-26 07:02:01 -04:00
|
|
|
this.note = this.noteBody;
|
|
|
|
} else {
|
|
|
|
this.conflictWhileEditing = true;
|
|
|
|
}
|
|
|
|
},
|
2017-07-20 17:56:14 -04:00
|
|
|
},
|
2017-07-26 07:02:01 -04:00
|
|
|
};
|
2017-06-14 19:36:53 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2017-08-03 09:56:01 -04:00
|
|
|
<div ref="editNoteForm" class="note-edit-form current-note-edit-form">
|
2017-07-17 18:07:42 -04:00
|
|
|
<div
|
|
|
|
v-if="conflictWhileEditing"
|
|
|
|
class="js-conflict-edit-warning alert alert-danger">
|
|
|
|
This comment has changed since you started editing, please review the
|
|
|
|
<a
|
|
|
|
:href="noteHash"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer">updated comment</a>
|
|
|
|
to ensure information is not lost.
|
|
|
|
</div>
|
2017-08-03 09:56:01 -04:00
|
|
|
<div class="flash-container timeline-content"></div>
|
2017-07-28 07:53:51 -04:00
|
|
|
<form
|
2017-08-14 07:52:57 -04:00
|
|
|
class="edit-note common-note-form js-quick-submit gfm-form">
|
2017-09-14 07:01:07 -04:00
|
|
|
|
|
|
|
<issue-warning
|
2017-11-30 17:44:41 -05:00
|
|
|
v-if="hasWarning(getNoteableData)"
|
|
|
|
:is-locked="isLocked(getNoteableData)"
|
|
|
|
:is-confidential="isConfidential(getNoteableData)"
|
2017-09-14 07:01:07 -04:00
|
|
|
/>
|
|
|
|
|
2017-06-14 19:36:53 -04:00
|
|
|
<markdown-field
|
2017-08-17 13:25:56 -04:00
|
|
|
:markdown-preview-path="markdownPreviewPath"
|
|
|
|
:markdown-docs-path="markdownDocsPath"
|
|
|
|
:quick-actions-docs-path="quickActionsDocsPath"
|
2017-07-29 14:26:29 -04:00
|
|
|
:add-spacing-classes="false">
|
2017-06-14 19:36:53 -04:00
|
|
|
<textarea
|
2017-08-12 20:00:22 -04:00
|
|
|
id="note_note"
|
2017-07-18 03:25:20 -04:00
|
|
|
name="note[note]"
|
2017-08-14 06:35:58 -04:00
|
|
|
class="note-textarea js-gfm-input js-autosize markdown-area js-vue-issue-note-form js-vue-textarea"
|
2017-08-02 11:22:38 -04:00
|
|
|
:data-supports-quick-actions="!isEditing"
|
2017-06-14 19:36:53 -04:00
|
|
|
aria-label="Description"
|
|
|
|
v-model="note"
|
|
|
|
ref="textarea"
|
|
|
|
slot="textarea"
|
|
|
|
placeholder="Write a comment or drag your files here..."
|
2017-08-08 19:24:49 -04:00
|
|
|
@keydown.meta.enter="handleUpdate()"
|
|
|
|
@keydown.up="editMyLastNote()"
|
2017-07-03 18:31:11 -04:00
|
|
|
@keydown.esc="cancelHandler(true)">
|
2017-06-14 19:36:53 -04:00
|
|
|
</textarea>
|
|
|
|
</markdown-field>
|
|
|
|
<div class="note-form-actions clearfix">
|
|
|
|
<button
|
2017-08-14 07:52:57 -04:00
|
|
|
type="button"
|
2017-08-08 19:24:49 -04:00
|
|
|
@click="handleUpdate()"
|
2017-08-02 11:52:24 -04:00
|
|
|
:disabled="isDisabled"
|
2017-08-08 09:54:43 -04:00
|
|
|
class="js-vue-issue-save btn btn-save">
|
2017-06-20 17:45:59 -04:00
|
|
|
{{saveButtonTitle}}
|
2017-06-14 19:36:53 -04:00
|
|
|
</button>
|
|
|
|
<button
|
2017-07-28 13:43:19 -04:00
|
|
|
@click="cancelHandler()"
|
2017-08-11 14:54:26 -04:00
|
|
|
class="btn btn-cancel note-edit-cancel"
|
2017-06-14 19:36:53 -04:00
|
|
|
type="button">
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|