note_body.vue 2.5 KB
Newer Older
1
<script>
F
Fatih Acet 已提交
2 3 4 5 6 7
import $ from 'jquery';
import noteEditedText from './note_edited_text.vue';
import noteAwardsList from './note_awards_list.vue';
import noteAttachment from './note_attachment.vue';
import noteForm from './note_form.vue';
import autosave from '../mixins/autosave';
8

F
Fatih Acet 已提交
9 10 11 12 13 14 15 16 17 18 19 20
export default {
  components: {
    noteEditedText,
    noteAwardsList,
    noteAttachment,
    noteForm,
  },
  mixins: [autosave],
  props: {
    note: {
      type: Object,
      required: true,
F
Filipa Lacerda 已提交
21
    },
F
Fatih Acet 已提交
22 23 24
    canEdit: {
      type: Boolean,
      required: true,
25
    },
F
Fatih Acet 已提交
26 27 28 29
    isEditing: {
      type: Boolean,
      required: false,
      default: false,
30
    },
F
Fatih Acet 已提交
31 32 33 34 35 36 37 38 39 40
  },
  computed: {
    noteBody() {
      return this.note.note;
    },
  },
  mounted() {
    this.renderGFM();

    if (this.isEditing) {
F
Felipe Artur 已提交
41
      this.initAutoSave(this.note);
F
Fatih Acet 已提交
42 43 44 45
    }
  },
  updated() {
    this.renderGFM();
46

F
Fatih Acet 已提交
47 48
    if (this.isEditing) {
      if (!this.autosave) {
F
Felipe Artur 已提交
49
        this.initAutoSave(this.note);
F
Fatih Acet 已提交
50 51
      } else {
        this.setAutoSave();
52
      }
F
Fatih Acet 已提交
53 54 55 56 57
    }
  },
  methods: {
    renderGFM() {
      $(this.$refs['note-body']).renderGFM();
58
    },
F
Fatih Acet 已提交
59 60 61 62
    handleFormUpdate(note, parentElement, callback) {
      this.$emit('handleFormUpdate', note, parentElement, callback);
    },
    formCancelHandler(shouldConfirm, isDirty) {
F
Felipe Artur 已提交
63
      this.$emit('cancelForm', shouldConfirm, isDirty);
F
Filipa Lacerda 已提交
64
    },
F
Fatih Acet 已提交
65 66
  },
};
67 68 69
</script>

<template>
70 71
  <div
    ref="note-body"
72
    :class="{ 'js-task-list-container': canEdit }"
73
    class="note-body">
74
    <div
75 76
      class="note-text md"
      v-html="note.note_html"></div>
77
    <note-form
78
      v-if="isEditing"
79
      ref="noteForm"
80
      :is-editing="isEditing"
81
      :note-body="noteBody"
82
      :note-id="note.id"
83
      :markdown-version="note.cached_markdown_version"
84
      @handleFormUpdate="handleFormUpdate"
F
Felipe Artur 已提交
85
      @cancelForm="formCancelHandler"
F
Filipa Lacerda 已提交
86
    />
87 88 89 90 91
    <textarea
      v-if="canEdit"
      v-model="note.note"
      :data-update-url="note.path"
      class="hidden js-task-list-field"></textarea>
S
Simon Knox 已提交
92
    <note-edited-text
93
      v-if="note.last_edited_at"
94 95
      :edited-at="note.last_edited_at"
      :edited-by="note.last_edited_by"
96
      action-text="Edited"
F
Felipe Artur 已提交
97
      class="note_edited_ago"
F
Filipa Lacerda 已提交
98
    />
S
Simon Knox 已提交
99
    <note-awards-list
100
      v-if="note.award_emoji && note.award_emoji.length"
101 102
      :note-id="note.id"
      :note-author-id="note.author.id"
103
      :awards="note.award_emoji"
104
      :toggle-award-path="note.toggle_award_path"
105
      :can-award-emoji="note.current_user.can_award_emoji"
F
Filipa Lacerda 已提交
106
    />
S
Simon Knox 已提交
107
    <note-attachment
108
      v-if="note.attachment"
109
      :attachment="note.attachment"
F
Filipa Lacerda 已提交
110
    />
111 112
  </div>
</template>