2018-03-27 19:54:05 +05:30
|
|
|
<script>
|
2018-11-08 19:23:39 +05:30
|
|
|
import { mapState, mapActions } from 'vuex';
|
|
|
|
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';
|
2018-12-23 12:14:25 +05:30
|
|
|
import { GlSkeletonLoading } from '@gitlab/ui';
|
|
|
|
import { getDiffMode } from '~/diffs/store/utils';
|
|
|
|
|
|
|
|
const FIRST_CHAR_REGEX = /^(\+|-| )/;
|
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({
|
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() {
|
2018-12-23 12:14:25 +05:30
|
|
|
return getDiffMode(this.discussion.diff_file);
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
hasTruncatedDiffLines() {
|
2018-12-23 12:14:25 +05:30
|
|
|
return (
|
|
|
|
this.discussion.truncated_diff_lines && this.discussion.truncated_diff_lines.length !== 0
|
|
|
|
);
|
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']),
|
|
|
|
fetchDiff() {
|
|
|
|
this.error = false;
|
|
|
|
this.fetchDiscussionDiffLines(this.discussion)
|
|
|
|
.then(this.highlight)
|
|
|
|
.catch(() => {
|
|
|
|
this.error = true;
|
|
|
|
});
|
|
|
|
},
|
2018-12-23 12:14:25 +05:30
|
|
|
trimChar(line) {
|
|
|
|
return line.replace(FIRST_CHAR_REGEX, '');
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2018-12-23 12:14:25 +05:30
|
|
|
userColorSchemeClass: window.gon.user_color_scheme,
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|
2018-03-27 19:54:05 +05:30
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2018-12-23 12:14:25 +05:30
|
|
|
<div :class="{ 'text-file': discussion.diff_file.text }" class="diff-file file-holder">
|
2018-11-08 19:23:39 +05:30
|
|
|
<diff-file-header
|
2018-12-23 12:14:25 +05:30
|
|
|
:discussion-path="discussion.discussion_path"
|
|
|
|
:diff-file="discussion.diff_file"
|
2018-11-08 19:23:39 +05:30
|
|
|
:can-current-user-fork="false"
|
2018-12-23 12:14:25 +05:30
|
|
|
:expanded="!discussion.diff_file.collapsed"
|
2018-11-08 19:23:39 +05:30
|
|
|
/>
|
2018-03-27 19:54:05 +05:30
|
|
|
<div
|
2018-12-23 12:14:25 +05:30
|
|
|
v-if="discussion.diff_file.text"
|
|
|
|
:class="$options.userColorSchemeClass"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="diff-content code"
|
2018-03-27 19:54:05 +05:30
|
|
|
>
|
|
|
|
<table>
|
2018-12-23 12:14:25 +05:30
|
|
|
<template v-if="hasTruncatedDiffLines">
|
|
|
|
<tr
|
|
|
|
v-for="line in discussion.truncated_diff_lines"
|
|
|
|
v-once
|
|
|
|
:key="line.line_code"
|
|
|
|
class="line_holder"
|
2018-11-08 19:23:39 +05:30
|
|
|
>
|
2018-12-23 12:14:25 +05:30
|
|
|
<td class="diff-line-num old_line">{{ line.old_line }}</td>
|
|
|
|
<td class="diff-line-num new_line">{{ line.new_line }}</td>
|
|
|
|
<td :class="line.type" class="line_content" v-html="trimChar(line.rich_text)"></td>
|
|
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
<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>
|
2018-12-23 12:14:25 +05:30
|
|
|
<td v-if="error" class="js-error-lazy-load-diff diff-loading-error-block">
|
|
|
|
{{ error }} 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>
|
2018-12-23 12:14:25 +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">
|
2018-12-23 12:14:25 +05:30
|
|
|
<td class="notes_content" colspan="3"><slot></slot></td>
|
2018-03-27 19:54:05 +05:30
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>
|
2018-12-23 12:14:25 +05:30
|
|
|
<div v-else>
|
2018-12-13 13:39:08 +05:30
|
|
|
<diff-viewer
|
|
|
|
:diff-mode="diffMode"
|
2018-12-23 12:14:25 +05:30
|
|
|
:new-path="discussion.diff_file.new_path"
|
|
|
|
:new-sha="discussion.diff_file.diff_refs.head_sha"
|
|
|
|
:old-path="discussion.diff_file.old_path"
|
|
|
|
:old-sha="discussion.diff_file.diff_refs.base_sha"
|
|
|
|
:file-hash="discussion.diff_file.file_hash"
|
2018-12-13 13:39:08 +05:30
|
|
|
:project-path="projectPath"
|
|
|
|
>
|
|
|
|
<image-diff-overlay
|
|
|
|
slot="image-overlay"
|
|
|
|
:discussions="discussion"
|
2018-12-23 12:14:25 +05:30
|
|
|
:file-hash="discussion.diff_file.file_hash"
|
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>
|