2018-11-08 19:23:39 +05:30
|
|
|
<script>
|
2018-11-20 20:47:30 +05:30
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2018-11-08 19:23:39 +05:30
|
|
|
import _ from 'underscore';
|
|
|
|
import { __, sprintf } from '~/locale';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
|
|
|
|
import DiffFileHeader from './diff_file_header.vue';
|
|
|
|
import DiffContent from './diff_content.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
DiffFileHeader,
|
|
|
|
DiffContent,
|
|
|
|
LoadingIcon,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
file: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
canCurrentUserFork: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoadingCollapsedDiff: false,
|
|
|
|
forkMessageVisible: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2018-11-20 20:47:30 +05:30
|
|
|
...mapGetters(['isNotesFetched', 'discussionsStructuredByLineCode']),
|
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.'),
|
|
|
|
{
|
|
|
|
linkStart: `<a href="${_.escape(this.file.viewPath)}">`,
|
|
|
|
linkEnd: '</a>',
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showExpandMessage() {
|
2018-11-20 20:47:30 +05:30
|
|
|
return (
|
|
|
|
this.isCollapsed ||
|
|
|
|
!this.file.highlightedDiffLines &&
|
|
|
|
!this.isLoadingCollapsedDiff &&
|
|
|
|
!this.file.tooLarge &&
|
|
|
|
this.file.text
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showLoadingIcon() {
|
|
|
|
return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed);
|
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-11-20 20:47:30 +05:30
|
|
|
const { highlightedDiffLines, parallelDiffLines } = this.file;
|
|
|
|
if (!highlightedDiffLines && parallelDiffLines !== undefined && !parallelDiffLines.length) {
|
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(
|
|
|
|
() => {
|
|
|
|
this.assignDiscussionsToDiff(this.discussionsStructuredByLineCode);
|
|
|
|
},
|
|
|
|
{ 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
|
|
|
|
:id="file.fileHash"
|
|
|
|
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"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-if="forkMessageVisible"
|
|
|
|
class="js-file-fork-suggestion-section file-fork-suggestion">
|
|
|
|
<span class="file-fork-suggestion-note">
|
|
|
|
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.
|
|
|
|
</span>
|
|
|
|
<a
|
|
|
|
:href="file.forkPath"
|
|
|
|
class="js-fork-suggestion-button btn btn-grouped btn-inverted btn-success"
|
|
|
|
>
|
|
|
|
Fork
|
|
|
|
</a>
|
|
|
|
<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-11-08 19:23:39 +05:30
|
|
|
:class="{ hidden: isCollapsed || file.tooLarge }"
|
|
|
|
:diff-file="file"
|
|
|
|
/>
|
|
|
|
<loading-icon
|
2018-11-20 20:47:30 +05:30
|
|
|
v-if="showLoadingIcon"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="diff-content loading"
|
|
|
|
/>
|
|
|
|
<div
|
2018-11-20 20:47:30 +05:30
|
|
|
v-else-if="showExpandMessage"
|
2018-11-08 19:23:39 +05:30
|
|
|
class="nothing-here-block diff-collapsed"
|
|
|
|
>
|
|
|
|
{{ __('This diff is collapsed.') }}
|
|
|
|
<a
|
|
|
|
class="click-to-expand js-click-to-expand"
|
|
|
|
href="#"
|
|
|
|
@click.prevent="handleToggle"
|
|
|
|
>
|
|
|
|
{{ __('Click to expand it.') }}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-if="file.tooLarge"
|
|
|
|
class="nothing-here-block diff-collapsed js-too-large-diff"
|
|
|
|
>
|
|
|
|
{{ __('This source diff could not be displayed because it is too large.') }}
|
|
|
|
<span v-html="viewBlobLink"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|