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

204 lines
5.4 KiB
Vue
Raw Normal View History

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';
2019-02-15 15:39:39 +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,
},
2019-02-15 15:39:39 +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']),
2019-05-30 16:15:17 +05:30
isCollapsed() {
return this.file.collapsed || false;
},
2018-11-08 19:23:39 +05:30
viewBlobLink() {
return sprintf(
__('You can %{linkStart}view the blob%{linkEnd} instead.'),
{
2019-02-15 15:39:39 +05:30
linkStart: `<a href="${_.escape(this.file.view_path)}">`,
2018-11-08 19:23:39 +05:30
linkEnd: '</a>',
},
false,
);
},
2019-05-30 16:15:17 +05:30
showExpandMessage() {
return (
this.isCollapsed ||
(!this.file.highlighted_diff_lines &&
!this.isLoadingCollapsedDiff &&
!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() {
2019-02-15 15:39:39 +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: {
2019-05-30 16:15:17 +05:30
'file.collapsed': function fileCollapsedWatch(newVal, oldVal) {
2018-12-13 13:39:08 +05:30
if (!newVal && oldVal && !this.hasDiffLines) {
this.handleLoadCollapsedDiff();
}
},
2018-11-08 19:23:39 +05:30
},
2019-02-15 15:39:39 +05:30
created() {
eventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.handleLoadCollapsedDiff);
},
2018-11-08 19:23:39 +05:30
methods: {
2019-05-30 16:15:17 +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 {
2019-05-30 16:15:17 +05:30
this.file.collapsed = !this.file.collapsed;
this.file.renderIt = true;
2018-11-08 19:23:39 +05:30
}
},
handleLoadCollapsedDiff() {
this.isLoadingCollapsedDiff = true;
this.loadCollapsedDiff(this.file)
.then(() => {
this.isLoadingCollapsedDiff = false;
2019-05-30 16:15:17 +05:30
this.file.collapsed = false;
this.file.renderIt = true;
2018-11-20 20:47:30 +05:30
})
.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
2019-02-15 15:39:39 +05:30
:id="file.file_hash"
2018-12-05 23:21:45 +05:30
:class="{
2019-02-15 15:39:39 +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"
/>
2019-02-15 15:39:39 +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">
2019-02-15 15:39:39 +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
2019-02-15 15:39:39 +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"
2019-02-15 15:39:39 +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>
2019-05-30 16:15:17 +05:30
<diff-content
v-if="!isCollapsed && file.renderIt"
:class="{ hidden: isCollapsed || file.too_large }"
:diff-file="file"
:help-page-path="helpPagePath"
/>
2019-02-15 15:39:39 +05:30
<gl-loading-icon v-if="showLoadingIcon" class="diff-content loading" />
2019-05-30 16:15:17 +05:30
<div v-else-if="showExpandMessage" 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.too_large" 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>
2018-11-08 19:23:39 +05:30
</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>