debian-mirror-gitlab/app/assets/javascripts/notes/components/diff_with_note.vue

188 lines
4.8 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2018-11-08 19:23:39 +05:30
import { mapState, mapActions } from 'vuex';
2019-01-03 12:48:30 +05:30
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2018-11-08 19:23:39 +05:30
import DiffFileHeader from '~/diffs/components/diff_file_header.vue';
2018-12-13 13:39:08 +05:30
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
import ImageDiffOverlay from '~/diffs/components/image_diff_overlay.vue';
2019-01-03 12:48:30 +05:30
import { GlSkeletonLoading } from '@gitlab-org/gitlab-ui';
import { trimFirstCharOfLineContent, getDiffMode } from '~/diffs/store/utils';
2018-03-27 19:54:05 +05:30
2018-05-09 12:01:36 +05:30
export default {
components: {
DiffFileHeader,
2018-12-13 13:39:08 +05:30
GlSkeletonLoading,
DiffViewer,
ImageDiffOverlay,
2018-05-09 12:01:36 +05:30
},
props: {
discussion: {
type: Object,
required: true,
2018-03-27 19:54:05 +05:30
},
2018-05-09 12:01:36 +05:30
},
2018-11-08 19:23:39 +05:30
data() {
return {
error: false,
};
},
2018-05-09 12:01:36 +05:30
computed: {
2018-11-08 19:23:39 +05:30
...mapState({
2019-01-03 12:48:30 +05:30
noteableData: state => state.notes.noteableData,
2018-12-13 13:39:08 +05:30
projectPath: state => state.diffs.projectPath,
2018-11-08 19:23:39 +05:30
}),
2018-12-13 13:39:08 +05:30
diffMode() {
2019-01-03 12:48:30 +05:30
return getDiffMode(this.diffFile);
2018-12-13 13:39:08 +05:30
},
2018-11-08 19:23:39 +05:30
hasTruncatedDiffLines() {
2019-01-03 12:48:30 +05:30
return this.discussion.truncatedDiffLines && this.discussion.truncatedDiffLines.length !== 0;
},
isDiscussionsExpanded() {
return true; // TODO: @fatihacet - Fix this.
},
isCollapsed() {
return this.diffFile.collapsed || false;
},
isImageDiff() {
return !this.diffFile.text;
},
diffFileClass() {
const { text } = this.diffFile;
return text ? 'text-file' : 'js-image-file';
},
diffFile() {
return convertObjectPropsToCamelCase(this.discussion.diffFile, { deep: true });
},
imageDiffHtml() {
return this.discussion.imageDiffHtml;
},
userColorScheme() {
return window.gon.user_color_scheme;
},
normalizedDiffLines() {
if (this.discussion.truncatedDiffLines) {
return this.discussion.truncatedDiffLines.map(line =>
trimFirstCharOfLineContent(convertObjectPropsToCamelCase(line)),
);
}
return [];
2018-11-08 19:23:39 +05:30
},
2018-05-09 12:01:36 +05:30
},
mounted() {
2018-12-13 13:39:08 +05:30
if (!this.hasTruncatedDiffLines) {
2018-11-08 19:23:39 +05:30
this.fetchDiff();
2018-05-09 12:01:36 +05:30
}
},
methods: {
2018-11-08 19:23:39 +05:30
...mapActions(['fetchDiscussionDiffLines']),
2019-01-03 12:48:30 +05:30
rowTag(html) {
return html.outerHTML ? 'tr' : 'template';
},
2018-11-08 19:23:39 +05:30
fetchDiff() {
this.error = false;
this.fetchDiscussionDiffLines(this.discussion)
.then(this.highlight)
.catch(() => {
this.error = true;
});
},
2018-05-09 12:01:36 +05:30
},
};
2018-03-27 19:54:05 +05:30
</script>
<template>
2019-01-03 12:48:30 +05:30
<div
ref="fileHolder"
:class="diffFileClass"
class="diff-file file-holder"
>
2018-11-08 19:23:39 +05:30
<diff-file-header
2019-01-03 12:48:30 +05:30
:discussion-path="discussion.discussionPath"
:diff-file="diffFile"
2018-11-08 19:23:39 +05:30
:can-current-user-fork="false"
2019-01-03 12:48:30 +05:30
:discussions-expanded="isDiscussionsExpanded"
:expanded="!isCollapsed"
2018-11-08 19:23:39 +05:30
/>
2018-03-27 19:54:05 +05:30
<div
2019-01-03 12:48:30 +05:30
v-if="diffFile.text"
:class="userColorScheme"
2018-11-08 19:23:39 +05:30
class="diff-content code"
2018-03-27 19:54:05 +05:30
>
<table>
2019-01-03 12:48:30 +05:30
<tr
v-for="line in normalizedDiffLines"
:key="line.lineCode"
class="line_holder"
>
<td class="diff-line-num old_line">{{ line.oldLine }}</td>
<td class="diff-line-num new_line">{{ line.newLine }}</td>
<td
:class="line.type"
class="line_content"
v-html="line.richText"
2018-11-08 19:23:39 +05:30
>
2019-01-03 12:48:30 +05:30
</td>
</tr>
<tr
v-if="!hasTruncatedDiffLines"
class="line_holder line-holder-placeholder"
>
2018-11-08 19:23:39 +05:30
<td class="old_line diff-line-num"></td>
<td class="new_line diff-line-num"></td>
2019-01-03 12:48:30 +05:30
<td
v-if="error"
class="js-error-lazy-load-diff diff-loading-error-block"
>
Unable to load the diff
2018-11-08 19:23:39 +05:30
<button
class="btn-link btn-link-retry btn-no-padding js-toggle-lazy-diff-retry-button"
@click="fetchDiff"
>
Try again
</button>
</td>
2019-01-03 12:48:30 +05:30
<td
v-else
class="line_content js-success-lazy-load"
>
2018-11-08 19:23:39 +05:30
<span></span>
2018-12-13 13:39:08 +05:30
<gl-skeleton-loading />
2018-11-08 19:23:39 +05:30
<span></span>
</td>
</tr>
2018-03-27 19:54:05 +05:30
<tr class="notes_holder">
2019-01-03 12:48:30 +05:30
<td
class="notes_content"
colspan="3"
>
<slot></slot>
</td>
2018-03-27 19:54:05 +05:30
</tr>
</table>
</div>
2019-01-03 12:48:30 +05:30
<div
v-else
>
2018-12-13 13:39:08 +05:30
<diff-viewer
:diff-mode="diffMode"
2019-01-03 12:48:30 +05:30
:new-path="diffFile.newPath"
:new-sha="diffFile.diffRefs.headSha"
:old-path="diffFile.oldPath"
:old-sha="diffFile.diffRefs.baseSha"
:file-hash="diffFile.fileHash"
2018-12-13 13:39:08 +05:30
:project-path="projectPath"
>
<image-diff-overlay
slot="image-overlay"
:discussions="discussion"
2019-01-03 12:48:30 +05:30
:file-hash="diffFile.fileHash"
2018-12-13 13:39:08 +05:30
:show-comment-icon="true"
:should-toggle-discussion="false"
badge-class="image-comment-badge"
/>
</diff-viewer>
2018-03-27 19:54:05 +05:30
<slot></slot>
</div>
</div>
</template>