2018-06-21 12:22:40 +00:00
|
|
|
<script>
|
2018-10-18 07:50:38 +00:00
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
2019-05-03 07:33:15 +00:00
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2019-04-12 09:27:24 +00:00
|
|
|
import diffLineNoteFormMixin from 'ee_else_ce/notes/mixins/diff_line_note_form';
|
|
|
|
import draftCommentsMixin from 'ee_else_ce/diffs/mixins/draft_comments';
|
2018-06-26 18:49:22 +00:00
|
|
|
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
|
2019-02-15 17:56:50 +00:00
|
|
|
import NotDiffableViewer from '~/vue_shared/components/diff_viewer/viewers/not_diffable.vue';
|
|
|
|
import NoPreviewViewer from '~/vue_shared/components/diff_viewer/viewers/no_preview.vue';
|
2018-06-21 12:22:40 +00:00
|
|
|
import InlineDiffView from './inline_diff_view.vue';
|
|
|
|
import ParallelDiffView from './parallel_diff_view.vue';
|
2019-06-06 15:51:04 +00:00
|
|
|
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
|
2018-10-18 07:50:38 +00:00
|
|
|
import NoteForm from '../../notes/components/note_form.vue';
|
|
|
|
import ImageDiffOverlay from './image_diff_overlay.vue';
|
|
|
|
import DiffDiscussions from './diff_discussions.vue';
|
2020-04-09 06:09:30 +00:00
|
|
|
import eventHub from '../../notes/event_hub';
|
2018-10-18 07:50:38 +00:00
|
|
|
import { IMAGE_DIFF_POSITION_TYPE } from '../constants';
|
|
|
|
import { getDiffMode } from '../store/utils';
|
2019-02-15 17:56:50 +00:00
|
|
|
import { diffViewerModes } from '~/ide/constants';
|
2018-06-21 12:22:40 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2019-05-03 07:33:15 +00:00
|
|
|
GlLoadingIcon,
|
2018-06-21 12:22:40 +00:00
|
|
|
InlineDiffView,
|
|
|
|
ParallelDiffView,
|
2018-06-26 18:49:22 +00:00
|
|
|
DiffViewer,
|
2018-10-18 07:50:38 +00:00
|
|
|
NoteForm,
|
|
|
|
DiffDiscussions,
|
|
|
|
ImageDiffOverlay,
|
2019-02-15 17:56:50 +00:00
|
|
|
NotDiffableViewer,
|
|
|
|
NoPreviewViewer,
|
2019-06-06 15:51:04 +00:00
|
|
|
userAvatarLink,
|
2019-04-12 09:27:24 +00:00
|
|
|
DiffFileDrafts: () => import('ee_component/batch_comments/components/diff_file_drafts.vue'),
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
2019-04-12 09:27:24 +00:00
|
|
|
mixins: [diffLineNoteFormMixin, draftCommentsMixin],
|
2018-06-21 12:22:40 +00:00
|
|
|
props: {
|
|
|
|
diffFile: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-12-13 19:17:19 +00:00
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2018-06-26 18:49:22 +00:00
|
|
|
...mapState({
|
|
|
|
projectPath: state => state.diffs.projectPath,
|
|
|
|
}),
|
2018-07-06 16:26:18 +00:00
|
|
|
...mapGetters('diffs', ['isInlineView', 'isParallelView']),
|
2018-10-18 07:50:38 +00:00
|
|
|
...mapGetters('diffs', ['getCommentFormForDiffFile']),
|
2019-06-06 15:51:04 +00:00
|
|
|
...mapGetters(['getNoteableData', 'noteableType', 'getUserData']),
|
2018-06-26 18:49:22 +00:00
|
|
|
diffMode() {
|
2018-10-18 07:50:38 +00:00
|
|
|
return getDiffMode(this.diffFile);
|
2018-06-26 18:49:22 +00:00
|
|
|
},
|
2019-02-15 17:56:50 +00:00
|
|
|
diffViewerMode() {
|
|
|
|
return this.diffFile.viewer.name;
|
|
|
|
},
|
2018-06-26 18:49:22 +00:00
|
|
|
isTextFile() {
|
2019-02-15 17:56:50 +00:00
|
|
|
return this.diffViewerMode === diffViewerModes.text;
|
|
|
|
},
|
|
|
|
noPreview() {
|
|
|
|
return this.diffViewerMode === diffViewerModes.no_preview;
|
2018-06-26 18:49:22 +00:00
|
|
|
},
|
2019-02-15 17:56:50 +00:00
|
|
|
notDiffable() {
|
|
|
|
return this.diffViewerMode === diffViewerModes.not_diffable;
|
2018-12-13 17:49:05 +00:00
|
|
|
},
|
2018-10-18 07:50:38 +00:00
|
|
|
diffFileCommentForm() {
|
2019-04-12 09:27:24 +00:00
|
|
|
return this.getCommentFormForDiffFile(this.diffFileHash);
|
2018-10-18 07:50:38 +00:00
|
|
|
},
|
|
|
|
showNotesContainer() {
|
2019-04-12 09:27:24 +00:00
|
|
|
return this.imageDiscussions.length || this.diffFileCommentForm;
|
|
|
|
},
|
|
|
|
diffFileHash() {
|
|
|
|
return this.diffFile.file_hash;
|
2018-10-18 07:50:38 +00:00
|
|
|
},
|
2019-06-06 15:51:04 +00:00
|
|
|
author() {
|
|
|
|
return this.getUserData;
|
|
|
|
},
|
2018-10-18 07:50:38 +00:00
|
|
|
},
|
2020-04-09 06:09:30 +00:00
|
|
|
updated() {
|
|
|
|
if (window.gon?.features?.codeNavigation) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
eventHub.$emit('showBlobInteractionZones', this.diffFile.new_path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-10-18 07:50:38 +00:00
|
|
|
methods: {
|
|
|
|
...mapActions('diffs', ['saveDiffDiscussion', 'closeDiffFileCommentForm']),
|
|
|
|
handleSaveNote(note) {
|
|
|
|
this.saveDiffDiscussion({
|
|
|
|
note,
|
|
|
|
formData: {
|
|
|
|
noteableData: this.getNoteableData,
|
|
|
|
noteableType: this.noteableType,
|
|
|
|
diffFile: this.diffFile,
|
|
|
|
positionType: IMAGE_DIFF_POSITION_TYPE,
|
|
|
|
x: this.diffFileCommentForm.x,
|
|
|
|
y: this.diffFileCommentForm.y,
|
2018-11-06 09:40:03 +00:00
|
|
|
width: this.diffFileCommentForm.width,
|
|
|
|
height: this.diffFileCommentForm.height,
|
2018-10-18 07:50:38 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="diff-content">
|
2019-02-15 17:56:50 +00:00
|
|
|
<div class="diff-viewer">
|
2018-06-26 18:49:22 +00:00
|
|
|
<template v-if="isTextFile">
|
|
|
|
<inline-diff-view
|
2019-02-15 17:56:50 +00:00
|
|
|
v-if="isInlineView"
|
2018-06-26 18:49:22 +00:00
|
|
|
:diff-file="diffFile"
|
2018-11-09 19:48:41 +00:00
|
|
|
:diff-lines="diffFile.highlighted_diff_lines || []"
|
2018-12-13 19:17:19 +00:00
|
|
|
:help-page-path="helpPagePath"
|
2018-06-26 18:49:22 +00:00
|
|
|
/>
|
|
|
|
<parallel-diff-view
|
2018-12-14 04:52:13 +00:00
|
|
|
v-else-if="isParallelView"
|
2018-06-26 18:49:22 +00:00
|
|
|
:diff-file="diffFile"
|
2018-11-09 19:48:41 +00:00
|
|
|
:diff-lines="diffFile.parallel_diff_lines || []"
|
2018-12-13 19:17:19 +00:00
|
|
|
:help-page-path="helpPagePath"
|
2018-06-26 18:49:22 +00:00
|
|
|
/>
|
2019-05-03 07:33:15 +00:00
|
|
|
<gl-loading-icon v-if="diffFile.renderingLines" size="md" class="mt-3" />
|
2018-06-26 18:49:22 +00:00
|
|
|
</template>
|
2019-02-15 17:56:50 +00:00
|
|
|
<not-diffable-viewer v-else-if="notDiffable" />
|
|
|
|
<no-preview-viewer v-else-if="noPreview" />
|
2018-06-26 18:49:22 +00:00
|
|
|
<diff-viewer
|
|
|
|
v-else
|
2020-05-20 09:08:11 +00:00
|
|
|
:diff-file="diffFile"
|
2018-06-26 18:49:22 +00:00
|
|
|
:diff-mode="diffMode"
|
2019-02-15 17:56:50 +00:00
|
|
|
:diff-viewer-mode="diffViewerMode"
|
2018-11-09 19:48:41 +00:00
|
|
|
:new-path="diffFile.new_path"
|
|
|
|
:new-sha="diffFile.diff_refs.head_sha"
|
2019-11-13 09:06:41 +00:00
|
|
|
:new-size="diffFile.new_size"
|
2018-11-09 19:48:41 +00:00
|
|
|
:old-path="diffFile.old_path"
|
|
|
|
:old-sha="diffFile.diff_refs.base_sha"
|
2019-11-13 09:06:41 +00:00
|
|
|
:old-size="diffFile.old_size"
|
2019-04-12 09:27:24 +00:00
|
|
|
:file-hash="diffFileHash"
|
2018-10-18 07:50:38 +00:00
|
|
|
:project-path="projectPath"
|
2018-12-06 14:39:29 +00:00
|
|
|
:a-mode="diffFile.a_mode"
|
|
|
|
:b-mode="diffFile.b_mode"
|
2018-10-18 07:50:38 +00:00
|
|
|
>
|
|
|
|
<image-diff-overlay
|
|
|
|
slot="image-overlay"
|
2019-04-12 09:27:24 +00:00
|
|
|
:discussions="imageDiscussions"
|
|
|
|
:file-hash="diffFileHash"
|
2018-10-18 07:50:38 +00:00
|
|
|
:can-comment="getNoteableData.current_user.can_create_note"
|
|
|
|
/>
|
2018-11-16 20:07:38 +00:00
|
|
|
<div v-if="showNotesContainer" class="note-container">
|
2019-06-06 15:51:04 +00:00
|
|
|
<user-avatar-link
|
|
|
|
v-if="diffFileCommentForm && author"
|
|
|
|
:link-href="author.path"
|
|
|
|
:img-src="author.avatar_url"
|
|
|
|
:img-alt="author.name"
|
|
|
|
:img-size="40"
|
|
|
|
class="d-none d-sm-block new-comment"
|
|
|
|
/>
|
2018-10-18 07:50:38 +00:00
|
|
|
<diff-discussions
|
|
|
|
v-if="diffFile.discussions.length"
|
|
|
|
class="diff-file-discussions"
|
|
|
|
:discussions="diffFile.discussions"
|
|
|
|
:should-collapse-discussions="true"
|
|
|
|
:render-avatar-badge="true"
|
|
|
|
/>
|
2019-04-12 09:27:24 +00:00
|
|
|
<diff-file-drafts :file-hash="diffFileHash" class="diff-file-discussions" />
|
2018-10-18 07:50:38 +00:00
|
|
|
<note-form
|
|
|
|
v-if="diffFileCommentForm"
|
|
|
|
ref="noteForm"
|
|
|
|
:is-editing="false"
|
|
|
|
:save-button-title="__('Comment')"
|
|
|
|
class="diff-comment-form new-note discussion-form discussion-form-container"
|
2019-04-12 09:27:24 +00:00
|
|
|
@handleFormUpdateAddToReview="addToReview"
|
2018-10-18 07:50:38 +00:00
|
|
|
@handleFormUpdate="handleSaveNote"
|
2019-04-12 09:27:24 +00:00
|
|
|
@cancelForm="closeDiffFileCommentForm(diffFileHash)"
|
2018-11-16 20:07:38 +00:00
|
|
|
/>
|
2018-10-18 07:50:38 +00:00
|
|
|
</div>
|
|
|
|
</diff-viewer>
|
2018-06-21 12:22:40 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|