2018-03-17 18:26:18 +05:30
|
|
|
<script>
|
2018-05-09 12:01:36 +05:30
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
|
|
|
import { getLocationHash } from '../../lib/utils/url_utility';
|
|
|
|
import Flash from '../../flash';
|
|
|
|
import * as constants from '../constants';
|
2018-11-08 19:23:39 +05:30
|
|
|
import eventHub from '../event_hub';
|
2018-05-09 12:01:36 +05:30
|
|
|
import noteableNote from './noteable_note.vue';
|
|
|
|
import noteableDiscussion from './noteable_discussion.vue';
|
|
|
|
import systemNote from '../../vue_shared/components/notes/system_note.vue';
|
|
|
|
import commentForm from './comment_form.vue';
|
|
|
|
import placeholderNote from '../../vue_shared/components/notes/placeholder_note.vue';
|
|
|
|
import placeholderSystemNote from '../../vue_shared/components/notes/placeholder_system_note.vue';
|
|
|
|
import skeletonLoadingContainer from '../../vue_shared/components/notes/skeleton_note.vue';
|
2018-12-05 23:21:45 +05:30
|
|
|
import highlightCurrentUser from '~/behaviors/markdown/highlight_current_user';
|
2019-02-13 22:33:31 +05:30
|
|
|
import initUserPopovers from '../../user_popovers';
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export default {
|
|
|
|
name: 'NotesApp',
|
|
|
|
components: {
|
|
|
|
noteableNote,
|
|
|
|
noteableDiscussion,
|
|
|
|
systemNote,
|
|
|
|
commentForm,
|
|
|
|
placeholderNote,
|
|
|
|
placeholderSystemNote,
|
2019-02-13 22:33:31 +05:30
|
|
|
skeletonLoadingContainer,
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
noteableData: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
notesData: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
userData: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({}),
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
shouldShow: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
markdownVersion: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: 0,
|
|
|
|
},
|
2019-02-13 22:33:31 +05:30
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2018-12-13 13:39:08 +05:30
|
|
|
isFetching: false,
|
|
|
|
currentFilter: null,
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-12-13 13:39:08 +05:30
|
|
|
...mapGetters([
|
|
|
|
'isNotesFetched',
|
|
|
|
'discussions',
|
|
|
|
'getNotesDataByProp',
|
|
|
|
'isLoading',
|
|
|
|
'commentsDisabled',
|
|
|
|
]),
|
2018-05-09 12:01:36 +05:30
|
|
|
noteableType() {
|
|
|
|
return this.noteableData.noteableType;
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
allDiscussions() {
|
2018-05-09 12:01:36 +05:30
|
|
|
if (this.isLoading) {
|
|
|
|
const totalNotes = parseInt(this.notesData.totalNotes, 10) || 0;
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
return new Array(totalNotes).fill({
|
|
|
|
isSkeletonNote: true,
|
2018-03-17 18:26:18 +05:30
|
|
|
});
|
|
|
|
}
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
return this.discussions;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
shouldShow() {
|
|
|
|
if (!this.isNotesFetched) {
|
|
|
|
this.fetchNotes();
|
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.setNotesData(this.notesData);
|
|
|
|
this.setNoteableData(this.noteableData);
|
|
|
|
this.setUserData(this.userData);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setTargetNoteHash(getLocationHash());
|
|
|
|
eventHub.$once('fetchNotesData', this.fetchNotes);
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
|
|
|
mounted() {
|
2018-11-08 19:23:39 +05:30
|
|
|
if (this.shouldShow) {
|
|
|
|
this.fetchNotes();
|
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
const { parentElement } = this.$el;
|
|
|
|
if (parentElement && parentElement.classList.contains('js-vue-notes-event')) {
|
2018-05-09 12:01:36 +05:30
|
|
|
parentElement.addEventListener('toggleAward', event => {
|
|
|
|
const { awardName, noteId } = event.detail;
|
2019-02-13 22:33:31 +05:30
|
|
|
this.toggleAward({ awardName, noteId });
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-12-05 23:21:45 +05:30
|
|
|
updated() {
|
2019-02-13 22:33:31 +05:30
|
|
|
this.$nextTick(() => {
|
|
|
|
highlightCurrentUser(this.$el.querySelectorAll('.gfm-project_member'));
|
|
|
|
initUserPopovers(this.$el.querySelectorAll('.js-user-link'));
|
|
|
|
});
|
2018-12-05 23:21:45 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
methods: {
|
2019-02-13 22:33:31 +05:30
|
|
|
...mapActions([
|
|
|
|
'setLoadingState',
|
|
|
|
'fetchDiscussions',
|
|
|
|
'poll',
|
|
|
|
'toggleAward',
|
|
|
|
'scrollToNoteIfNeeded',
|
|
|
|
'setNotesData',
|
|
|
|
'setNoteableData',
|
|
|
|
'setUserData',
|
|
|
|
'setLastFetchedAt',
|
|
|
|
'setTargetNoteHash',
|
|
|
|
'toggleDiscussion',
|
|
|
|
'setNotesFetchedState',
|
|
|
|
'expandDiscussion',
|
|
|
|
'startTaskList',
|
|
|
|
]),
|
2018-05-09 12:01:36 +05:30
|
|
|
fetchNotes() {
|
2018-12-13 13:39:08 +05:30
|
|
|
if (this.isFetching) return null;
|
|
|
|
|
|
|
|
this.isFetching = true;
|
|
|
|
|
|
|
|
return this.fetchDiscussions({ path: this.getNotesDataByProp('discussionsPath') })
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(() => {
|
|
|
|
this.initPolling();
|
|
|
|
})
|
2018-05-09 12:01:36 +05:30
|
|
|
.then(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.setLoadingState(false);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setNotesFetchedState(true);
|
2018-11-20 20:47:30 +05:30
|
|
|
eventHub.$emit('fetchedNotesData');
|
2018-12-13 13:39:08 +05:30
|
|
|
this.isFetching = false;
|
2018-05-09 12:01:36 +05:30
|
|
|
})
|
|
|
|
.then(() => this.$nextTick())
|
2019-02-13 22:33:31 +05:30
|
|
|
.then(() => this.startTaskList())
|
2018-05-09 12:01:36 +05:30
|
|
|
.then(() => this.checkLocationHash())
|
|
|
|
.catch(() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.setLoadingState(false);
|
2018-11-08 19:23:39 +05:30
|
|
|
this.setNotesFetchedState(true);
|
|
|
|
Flash('Something went wrong while fetching comments. Please try again.');
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
initPolling() {
|
|
|
|
if (this.isPollingInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
this.setLastFetchedAt(this.getNotesDataByProp('lastFetchedAt'));
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
this.poll();
|
|
|
|
this.isPollingInitialized = true;
|
|
|
|
},
|
|
|
|
checkLocationHash() {
|
|
|
|
const hash = getLocationHash();
|
2018-11-08 19:23:39 +05:30
|
|
|
const noteId = hash && hash.replace(/^note_/, '');
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if (noteId) {
|
2019-02-13 22:33:31 +05:30
|
|
|
const discussion = this.discussions.find(d => d.notes.some(({ id }) => id === noteId));
|
|
|
|
|
|
|
|
if (discussion) {
|
|
|
|
this.expandDiscussion({ discussionId: discussion.id });
|
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2019-02-13 22:33:31 +05:30
|
|
|
systemNote: constants.SYSTEM_NOTE,
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|
2018-03-17 18:26:18 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2019-02-13 22:33:31 +05:30
|
|
|
<div v-show="shouldShow" id="notes">
|
|
|
|
<ul id="notes-list" class="notes main-notes-list timeline">
|
|
|
|
<template v-for="discussion in allDiscussions">
|
|
|
|
<skeleton-loading-container v-if="discussion.isSkeletonNote" :key="discussion.id" />
|
|
|
|
<template v-else-if="discussion.isPlaceholderNote">
|
|
|
|
<placeholder-system-note
|
|
|
|
v-if="discussion.placeholderType === $options.systemNote"
|
|
|
|
:key="discussion.id"
|
|
|
|
:note="discussion.notes[0]"
|
|
|
|
/>
|
|
|
|
<placeholder-note v-else :key="discussion.id" :note="discussion.notes[0]" />
|
|
|
|
</template>
|
|
|
|
<template v-else-if="discussion.individual_note">
|
|
|
|
<system-note
|
|
|
|
v-if="discussion.notes[0].system"
|
|
|
|
:key="discussion.id"
|
|
|
|
:note="discussion.notes[0]"
|
|
|
|
/>
|
|
|
|
<noteable-note v-else :key="discussion.id" :note="discussion.notes[0]" />
|
|
|
|
</template>
|
|
|
|
<noteable-discussion
|
|
|
|
v-else
|
|
|
|
:key="discussion.id"
|
|
|
|
:discussion="discussion"
|
|
|
|
:render-diff-file="true"
|
|
|
|
:help-page-path="helpPagePath"
|
|
|
|
/>
|
|
|
|
</template>
|
2018-03-17 18:26:18 +05:30
|
|
|
</ul>
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
<comment-form
|
2018-12-13 13:39:08 +05:30
|
|
|
v-if="!commentsDisabled"
|
2018-03-27 19:54:05 +05:30
|
|
|
:noteable-type="noteableType"
|
2018-11-08 19:23:39 +05:30
|
|
|
:markdown-version="markdownVersion"
|
2018-03-27 19:54:05 +05:30
|
|
|
/>
|
2018-03-17 18:26:18 +05:30
|
|
|
</div>
|
|
|
|
</template>
|