summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/noteable_note.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/notes/components/noteable_note.vue')
-rw-r--r--app/assets/javascripts/notes/components/noteable_note.vue260
1 files changed, 130 insertions, 130 deletions
diff --git a/app/assets/javascripts/notes/components/noteable_note.vue b/app/assets/javascripts/notes/components/noteable_note.vue
index 6d5501d7d98..3554027d2b4 100644
--- a/app/assets/javascripts/notes/components/noteable_note.vue
+++ b/app/assets/javascripts/notes/components/noteable_note.vue
@@ -1,152 +1,152 @@
<script>
- import $ from 'jquery';
- import { mapGetters, mapActions } from 'vuex';
- import { escape } from 'underscore';
- import Flash from '../../flash';
- import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
- import noteHeader from './note_header.vue';
- import noteActions from './note_actions.vue';
- import noteBody from './note_body.vue';
- import eventHub from '../event_hub';
- import noteable from '../mixins/noteable';
- import resolvable from '../mixins/resolvable';
+import $ from 'jquery';
+import { mapGetters, mapActions } from 'vuex';
+import { escape } from 'underscore';
+import Flash from '../../flash';
+import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
+import noteHeader from './note_header.vue';
+import noteActions from './note_actions.vue';
+import noteBody from './note_body.vue';
+import eventHub from '../event_hub';
+import noteable from '../mixins/noteable';
+import resolvable from '../mixins/resolvable';
- export default {
- components: {
- userAvatarLink,
- noteHeader,
- noteActions,
- noteBody,
+export default {
+ components: {
+ userAvatarLink,
+ noteHeader,
+ noteActions,
+ noteBody,
+ },
+ mixins: [noteable, resolvable],
+ props: {
+ note: {
+ type: Object,
+ required: true,
},
- mixins: [
- noteable,
- resolvable,
- ],
- props: {
- note: {
- type: Object,
- required: true,
- },
+ },
+ data() {
+ return {
+ isEditing: false,
+ isDeleting: false,
+ isRequesting: false,
+ isResolving: false,
+ };
+ },
+ computed: {
+ ...mapGetters(['targetNoteHash', 'getUserData']),
+ author() {
+ return this.note.author;
},
- data() {
+ classNameBindings() {
return {
- isEditing: false,
- isDeleting: false,
- isRequesting: false,
- isResolving: false,
+ 'is-editing': this.isEditing && !this.isRequesting,
+ 'is-requesting being-posted': this.isRequesting,
+ 'disabled-content': this.isDeleting,
+ target: this.targetNoteHash === this.noteAnchorId,
};
},
- computed: {
- ...mapGetters([
- 'targetNoteHash',
- 'getUserData',
- ]),
- author() {
- return this.note.author;
- },
- classNameBindings() {
- return {
- 'is-editing': this.isEditing && !this.isRequesting,
- 'is-requesting being-posted': this.isRequesting,
- 'disabled-content': this.isDeleting,
- target: this.targetNoteHash === this.noteAnchorId,
- };
- },
- canReportAsAbuse() {
- return this.note.report_abuse_path && this.author.id !== this.getUserData.id;
- },
- noteAnchorId() {
- return `note_${this.note.id}`;
- },
+ canReportAsAbuse() {
+ return (
+ this.note.report_abuse_path && this.author.id !== this.getUserData.id
+ );
},
-
- created() {
- eventHub.$on('enterEditMode', ({ noteId }) => {
- if (noteId === this.note.id) {
- this.isEditing = true;
- this.scrollToNoteIfNeeded($(this.$el));
- }
- });
+ noteAnchorId() {
+ return `note_${this.note.id}`;
},
+ },
- methods: {
- ...mapActions([
- 'deleteNote',
- 'updateNote',
- 'toggleResolveNote',
- 'scrollToNoteIfNeeded',
- ]),
- editHandler() {
+ created() {
+ eventHub.$on('enterEditMode', ({ noteId }) => {
+ if (noteId === this.note.id) {
this.isEditing = true;
- },
- deleteHandler() {
- // eslint-disable-next-line no-alert
- if (confirm('Are you sure you want to delete this comment?')) {
- this.isDeleting = true;
+ this.scrollToNoteIfNeeded($(this.$el));
+ }
+ });
+ },
- this.deleteNote(this.note)
- .then(() => {
- this.isDeleting = false;
- })
- .catch(() => {
- Flash('Something went wrong while deleting your note. Please try again.');
- this.isDeleting = false;
- });
- }
- },
- formUpdateHandler(noteText, parentElement, callback) {
- const data = {
- endpoint: this.note.path,
- note: {
- target_type: this.noteableType,
- target_id: this.note.noteable_id,
- note: { note: noteText },
- },
- };
- this.isRequesting = true;
- this.oldContent = this.note.note_html;
- this.note.note_html = escape(noteText);
+ methods: {
+ ...mapActions([
+ 'deleteNote',
+ 'updateNote',
+ 'toggleResolveNote',
+ 'scrollToNoteIfNeeded',
+ ]),
+ editHandler() {
+ this.isEditing = true;
+ },
+ deleteHandler() {
+ // eslint-disable-next-line no-alert
+ if (confirm('Are you sure you want to delete this comment?')) {
+ this.isDeleting = true;
- this.updateNote(data)
+ this.deleteNote(this.note)
.then(() => {
- this.isEditing = false;
- this.isRequesting = false;
- this.oldContent = null;
- $(this.$refs.noteBody.$el).renderGFM();
- this.$refs.noteBody.resetAutoSave();
- callback();
+ this.isDeleting = false;
})
.catch(() => {
- this.isRequesting = false;
- this.isEditing = true;
- this.$nextTick(() => {
- const msg = 'Something went wrong while editing your comment. Please try again.';
- Flash(msg, 'alert', this.$el);
- this.recoverNoteContent(noteText);
- callback();
- });
+ Flash(
+ 'Something went wrong while deleting your note. Please try again.',
+ );
+ this.isDeleting = false;
});
- },
- formCancelHandler(shouldConfirm, isDirty) {
- if (shouldConfirm && isDirty) {
- // eslint-disable-next-line no-alert
- if (!confirm('Are you sure you want to cancel editing this comment?')) return;
- }
- this.$refs.noteBody.resetAutoSave();
- if (this.oldContent) {
- this.note.note_html = this.oldContent;
+ }
+ },
+ formUpdateHandler(noteText, parentElement, callback) {
+ const data = {
+ endpoint: this.note.path,
+ note: {
+ target_type: this.noteableType,
+ target_id: this.note.noteable_id,
+ note: { note: noteText },
+ },
+ };
+ this.isRequesting = true;
+ this.oldContent = this.note.note_html;
+ this.note.note_html = escape(noteText);
+
+ this.updateNote(data)
+ .then(() => {
+ this.isEditing = false;
+ this.isRequesting = false;
this.oldContent = null;
- }
- this.isEditing = false;
- },
- recoverNoteContent(noteText) {
- // we need to do this to prevent noteForm inconsistent content warning
- // this is something we intentionally do so we need to recover the content
- this.note.note = noteText;
- this.$refs.noteBody.$refs.noteForm.note.note = noteText;
- },
+ $(this.$refs.noteBody.$el).renderGFM();
+ this.$refs.noteBody.resetAutoSave();
+ callback();
+ })
+ .catch(() => {
+ this.isRequesting = false;
+ this.isEditing = true;
+ this.$nextTick(() => {
+ const msg =
+ 'Something went wrong while editing your comment. Please try again.';
+ Flash(msg, 'alert', this.$el);
+ this.recoverNoteContent(noteText);
+ callback();
+ });
+ });
+ },
+ formCancelHandler(shouldConfirm, isDirty) {
+ if (shouldConfirm && isDirty) {
+ // eslint-disable-next-line no-alert
+ if (!confirm('Are you sure you want to cancel editing this comment?'))
+ return;
+ }
+ this.$refs.noteBody.resetAutoSave();
+ if (this.oldContent) {
+ this.note.note_html = this.oldContent;
+ this.oldContent = null;
+ }
+ this.isEditing = false;
+ },
+ recoverNoteContent(noteText) {
+ // we need to do this to prevent noteForm inconsistent content warning
+ // this is something we intentionally do so we need to recover the content
+ this.note.note = noteText;
+ this.$refs.noteBody.$refs.noteForm.note.note = noteText;
},
- };
+ },
+};
</script>
<template>