debian-mirror-gitlab/app/assets/javascripts/diffs/components/diff_content.vue

148 lines
4.6 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
2018-12-13 13:39:08 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2018-11-08 19:23:39 +05:30
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
2019-05-18 00:54:41 +05:30
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-11-08 19:23:39 +05:30
import InlineDiffView from './inline_diff_view.vue';
import ParallelDiffView from './parallel_diff_view.vue';
2018-12-13 13:39:08 +05:30
import NoteForm from '../../notes/components/note_form.vue';
import ImageDiffOverlay from './image_diff_overlay.vue';
import DiffDiscussions from './diff_discussions.vue';
import { IMAGE_DIFF_POSITION_TYPE } from '../constants';
import { getDiffMode } from '../store/utils';
2019-05-18 00:54:41 +05:30
import { diffViewerModes } from '~/ide/constants';
2018-11-08 19:23:39 +05:30
export default {
components: {
InlineDiffView,
ParallelDiffView,
DiffViewer,
2018-12-13 13:39:08 +05:30
NoteForm,
DiffDiscussions,
ImageDiffOverlay,
2019-05-18 00:54:41 +05:30
NotDiffableViewer,
NoPreviewViewer,
2018-11-08 19:23:39 +05:30
},
props: {
diffFile: {
type: Object,
required: true,
},
2019-02-15 15:39:39 +05:30
helpPagePath: {
type: String,
required: false,
default: '',
},
2018-11-08 19:23:39 +05:30
},
computed: {
...mapState({
projectPath: state => state.diffs.projectPath,
endpoint: state => state.diffs.endpoint,
}),
...mapGetters('diffs', ['isInlineView', 'isParallelView']),
2018-12-13 13:39:08 +05:30
...mapGetters('diffs', ['getCommentFormForDiffFile']),
...mapGetters(['getNoteableData', 'noteableType']),
2018-11-08 19:23:39 +05:30
diffMode() {
2018-12-13 13:39:08 +05:30
return getDiffMode(this.diffFile);
2018-11-08 19:23:39 +05:30
},
2019-05-18 00:54:41 +05:30
diffViewerMode() {
return this.diffFile.viewer.name;
},
2018-11-08 19:23:39 +05:30
isTextFile() {
2019-05-18 00:54:41 +05:30
return this.diffViewerMode === diffViewerModes.text;
},
noPreview() {
return this.diffViewerMode === diffViewerModes.no_preview;
2018-11-08 19:23:39 +05:30
},
2019-05-18 00:54:41 +05:30
notDiffable() {
return this.diffViewerMode === diffViewerModes.not_diffable;
2019-02-15 15:39:39 +05:30
},
2018-12-13 13:39:08 +05:30
diffFileCommentForm() {
2019-02-15 15:39:39 +05:30
return this.getCommentFormForDiffFile(this.diffFile.file_hash);
2018-12-13 13:39:08 +05:30
},
showNotesContainer() {
return this.diffFile.discussions.length || this.diffFileCommentForm;
},
},
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,
width: this.diffFileCommentForm.width,
height: this.diffFileCommentForm.height,
},
});
},
2018-11-08 19:23:39 +05:30
},
};
</script>
<template>
<div class="diff-content">
2019-05-18 00:54:41 +05:30
<div class="diff-viewer">
2018-11-08 19:23:39 +05:30
<template v-if="isTextFile">
<inline-diff-view
2019-05-18 00:54:41 +05:30
v-if="isInlineView"
2018-11-08 19:23:39 +05:30
:diff-file="diffFile"
2019-02-15 15:39:39 +05:30
:diff-lines="diffFile.highlighted_diff_lines || []"
:help-page-path="helpPagePath"
2018-11-08 19:23:39 +05:30
/>
<parallel-diff-view
2019-02-15 15:39:39 +05:30
v-else-if="isParallelView"
2018-11-08 19:23:39 +05:30
:diff-file="diffFile"
2019-02-15 15:39:39 +05:30
:diff-lines="diffFile.parallel_diff_lines || []"
:help-page-path="helpPagePath"
2018-11-08 19:23:39 +05:30
/>
</template>
2019-05-18 00:54:41 +05:30
<not-diffable-viewer v-else-if="notDiffable" />
<no-preview-viewer v-else-if="noPreview" />
2018-11-08 19:23:39 +05:30
<diff-viewer
v-else
:diff-mode="diffMode"
2019-05-18 00:54:41 +05:30
:diff-viewer-mode="diffViewerMode"
2019-02-15 15:39:39 +05:30
:new-path="diffFile.new_path"
:new-sha="diffFile.diff_refs.head_sha"
:old-path="diffFile.old_path"
:old-sha="diffFile.diff_refs.base_sha"
:file-hash="diffFile.file_hash"
2018-12-13 13:39:08 +05:30
:project-path="projectPath"
2019-02-15 15:39:39 +05:30
:a-mode="diffFile.a_mode"
:b-mode="diffFile.b_mode"
2018-12-13 13:39:08 +05:30
>
<image-diff-overlay
slot="image-overlay"
:discussions="diffFile.discussions"
2019-02-15 15:39:39 +05:30
:file-hash="diffFile.file_hash"
2018-12-13 13:39:08 +05:30
:can-comment="getNoteableData.current_user.can_create_note"
/>
2019-02-15 15:39:39 +05:30
<div v-if="showNotesContainer" class="note-container">
2018-12-13 13:39:08 +05:30
<diff-discussions
v-if="diffFile.discussions.length"
class="diff-file-discussions"
:discussions="diffFile.discussions"
:should-collapse-discussions="true"
:render-avatar-badge="true"
/>
<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"
@handleFormUpdate="handleSaveNote"
2019-03-02 22:35:43 +05:30
@cancelForm="closeDiffFileCommentForm(diffFile.file_hash)"
2019-02-15 15:39:39 +05:30
/>
2018-12-13 13:39:08 +05:30
</div>
</diff-viewer>
2018-11-08 19:23:39 +05:30
</div>
</div>
</template>