2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
2018-12-05 23:21:45 +05:30
|
|
|
import { mapActions, mapGetters, mapState } from 'vuex';
|
2018-11-08 19:23:39 +05:30
|
|
|
import _ from 'underscore';
|
|
|
|
import { __, sprintf } from '~/locale';
|
|
|
|
import createFlash from '~/flash';
|
2018-12-23 12:14:25 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import eventHub from '../../notes/event_hub';
|
2018-11-08 19:23:39 +05:30
|
|
|
import DiffFileHeader from './diff_file_header.vue';
|
|
|
|
import DiffContent from './diff_content.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
DiffFileHeader,
|
|
|
|
DiffContent,
|
2018-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
canCurrentUserFork: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-12-23 12:14:25 +05:30
|
|
|
helpPagePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoadingCollapsedDiff: false,
|
|
|
|
forkMessageVisible: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-12-05 23:21:45 +05:30
|
|
|
...mapState('diffs', ['currentDiffFileId']),
|
2018-12-13 13:39:08 +05:30
|
|
|
...mapGetters(['isNotesFetched']),
|
|
|
|
...mapGetters('diffs', ['getDiffFileDiscussions']),
|
2018-11-08 19:23:39 +05:30
|
|
|
isCollapsed() {
|
|
|
|
return this.file.collapsed || false;
|
|
|
|
},
|
|
|
|
viewBlobLink() {
|
|
|
|
return sprintf(
|
|
|
|
__('You can %{linkStart}view the blob%{linkEnd} instead.'),
|
|
|
|
{
|
2018-12-23 12:14:25 +05:30
|
|
|
linkStart: `<a href="${_.escape(this.file.view_path)}">`,
|
2018-11-08 19:23:39 +05:30
|
|
|
linkEnd: '</a>',
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showExpandMessage() {
|
2018-11-20 20:47:30 +05:30
|
|
|
return (
|
|
|
|
this.isCollapsed ||
|
2018-12-23 12:14:25 +05:30
|
|
|
(!this.file.highlighted_diff_lines &&
|
2018-12-13 13:39:08 +05:30
|
|
|
!this.isLoadingCollapsedDiff &&
|
2018-12-23 12:14:25 +05:30
|
|
|
!this.file.too_large &&
|
|
|
|
this.file.text &&
|
|
|
|
!this.file.renamed_file &&
|
|
|
|
!this.file.mode_changed)
|
2018-11-20 20:47:30 +05:30
|
|
|
);
|
|
|
|
},
|
|
|
|
showLoadingIcon() {
|
|
|
|
return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
hasDiffLines() {
|
2018-12-23 12:14:25 +05:30
|
|
|
return (
|
|
|
|
this.file.highlighted_diff_lines &&
|
|
|
|
this.file.parallel_diff_lines &&
|
|
|
|
this.file.parallel_diff_lines.length > 0
|
|
|
|
);
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
'file.collapsed': function fileCollapsedWatch(newVal, oldVal) {
|
|
|
|
if (!newVal && oldVal && !this.hasDiffLines) {
|
|
|
|
this.handleLoadCollapsedDiff();
|
|
|
|
}
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2018-12-23 12:14:25 +05:30
|
|
|
created() {
|
|
|
|
eventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.handleLoadCollapsedDiff);
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
methods: {
|
2018-11-20 20:47:30 +05:30
|
|
|
...mapActions('diffs', ['loadCollapsedDiff', 'assignDiscussionsToDiff']),
|
2018-11-08 19:23:39 +05:30
|
|
|
handleToggle() {
|
2018-12-13 13:39:08 +05:30
|
|
|
if (!this.hasDiffLines) {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.handleLoadCollapsedDiff();
|
|
|
|
} else {
|
|
|
|
this.file.collapsed = !this.file.collapsed;
|
2018-11-20 20:47:30 +05:30
|
|
|
this.file.renderIt = true;
|
2018-11-08 19:23:39 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
handleLoadCollapsedDiff() {
|
|
|
|
this.isLoadingCollapsedDiff = true;
|
|
|
|
|
|
|
|
this.loadCollapsedDiff(this.file)
|
|
|
|
.then(() => {
|
|
|
|
this.isLoadingCollapsedDiff = false;
|
|
|
|
this.file.collapsed = false;
|
2018-11-20 20:47:30 +05:30
|
|
|
this.file.renderIt = true;
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
requestIdleCallback(
|
|
|
|
() => {
|
2018-12-13 13:39:08 +05:30
|
|
|
this.assignDiscussionsToDiff(this.getDiffFileDiscussions(this.file));
|
2018-11-20 20:47:30 +05:30
|
|
|
},
|
|
|
|
{ timeout: 1000 },
|
|
|
|
);
|
2018-11-08 19:23:39 +05:30
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isLoadingCollapsedDiff = false;
|
|
|
|
createFlash(__('Something went wrong on our end. Please try again!'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showForkMessage() {
|
|
|
|
this.forkMessageVisible = true;
|
|
|
|
},
|
|
|
|
hideForkMessage() {
|
|
|
|
this.forkMessageVisible = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
2018-12-23 12:14:25 +05:30
|
|
|
:id="file.file_hash"
|
2018-12-05 23:21:45 +05:30
|
|
|
:class="{
|
2018-12-23 12:14:25 +05:30
|
|
|
'is-active': currentDiffFileId === file.file_hash,
|
2018-12-05 23:21:45 +05:30
|
|
|
}"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="diff-file file-holder"
|
|
|
|
>
|
|
|
|
<diff-file-header
|
|
|
|
:can-current-user-fork="canCurrentUserFork"
|
|
|
|
:diff-file="file"
|
|
|
|
:collapsible="true"
|
|
|
|
:expanded="!isCollapsed"
|
|
|
|
:add-merge-request-buttons="true"
|
|
|
|
class="js-file-title file-title"
|
|
|
|
@toggleFile="handleToggle"
|
|
|
|
@showForkMessage="showForkMessage"
|
|
|
|
/>
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
<div v-if="forkMessageVisible" class="js-file-fork-suggestion-section file-fork-suggestion">
|
2018-11-08 19:23:39 +05:30
|
|
|
<span class="file-fork-suggestion-note">
|
2018-12-23 12:14:25 +05:30
|
|
|
You're not allowed to <span class="js-file-fork-suggestion-section-action">edit</span> files
|
|
|
|
in this project directly. Please fork this project, make your changes there, and submit a
|
|
|
|
merge request.
|
2018-11-08 19:23:39 +05:30
|
|
|
</span>
|
|
|
|
<a
|
2018-12-23 12:14:25 +05:30
|
|
|
:href="file.fork_path"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="js-fork-suggestion-button btn btn-grouped btn-inverted btn-success"
|
2018-12-23 12:14:25 +05:30
|
|
|
>Fork</a
|
2018-11-08 19:23:39 +05:30
|
|
|
>
|
|
|
|
<button
|
|
|
|
class="js-cancel-fork-suggestion-button btn btn-grouped"
|
|
|
|
type="button"
|
|
|
|
@click="hideForkMessage"
|
|
|
|
>
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<diff-content
|
2018-11-20 20:47:30 +05:30
|
|
|
v-if="!isCollapsed && file.renderIt"
|
2018-12-23 12:14:25 +05:30
|
|
|
:class="{ hidden: isCollapsed || file.too_large }"
|
2018-11-08 19:23:39 +05:30
|
|
|
:diff-file="file"
|
2018-12-23 12:14:25 +05:30
|
|
|
:help-page-path="helpPagePath"
|
2018-11-08 19:23:39 +05:30
|
|
|
/>
|
2018-12-23 12:14:25 +05:30
|
|
|
<gl-loading-icon v-if="showLoadingIcon" class="diff-content loading" />
|
|
|
|
<div v-else-if="showExpandMessage" class="nothing-here-block diff-collapsed">
|
2018-11-08 19:23:39 +05:30
|
|
|
{{ __('This diff is collapsed.') }}
|
2018-12-23 12:14:25 +05:30
|
|
|
<a class="click-to-expand js-click-to-expand" href="#" @click.prevent="handleToggle">{{
|
|
|
|
__('Click to expand it.')
|
|
|
|
}}</a>
|
2018-11-08 19:23:39 +05:30
|
|
|
</div>
|
2018-12-23 12:14:25 +05:30
|
|
|
<div v-if="file.too_large" class="nothing-here-block diff-collapsed js-too-large-diff">
|
2018-11-08 19:23:39 +05:30
|
|
|
{{ __('This source diff could not be displayed because it is too large.') }}
|
|
|
|
<span v-html="viewBlobLink"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
<style>
|
|
|
|
@keyframes shadow-fade {
|
|
|
|
from {
|
|
|
|
box-shadow: 0 0 4px #919191;
|
|
|
|
}
|
|
|
|
|
|
|
|
to {
|
|
|
|
box-shadow: 0 0 0 #dfdfdf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.diff-file.is-active {
|
|
|
|
box-shadow: 0 0 0 #dfdfdf;
|
|
|
|
animation: shadow-fade 1.2s 0.1s 1;
|
|
|
|
}
|
|
|
|
</style>
|