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

300 lines
8.5 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
import _ from 'underscore';
import { mapActions, mapGetters } from 'vuex';
2020-01-01 13:55:28 +05:30
import { GlButton, GlTooltipDirective, GlTooltip, GlLoadingIcon } from '@gitlab/ui';
import { polyfillSticky } from '~/lib/utils/sticky';
2018-11-08 19:23:39 +05:30
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import Icon from '~/vue_shared/components/icon.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import { truncateSha } from '~/lib/utils/text_utility';
import { __, s__, sprintf } from '~/locale';
2019-07-07 11:18:12 +05:30
import { diffViewerModes } from '~/ide/constants';
2018-11-08 19:23:39 +05:30
import EditButton from './edit_button.vue';
2019-03-02 22:35:43 +05:30
import DiffStats from './diff_stats.vue';
2020-01-01 13:55:28 +05:30
import { scrollToElement } from '~/lib/utils/common_utils';
2018-11-08 19:23:39 +05:30
export default {
components: {
2019-07-07 11:18:12 +05:30
GlTooltip,
GlLoadingIcon,
GlButton,
2018-11-08 19:23:39 +05:30
ClipboardButton,
EditButton,
Icon,
FileIcon,
2019-03-02 22:35:43 +05:30
DiffStats,
2018-11-08 19:23:39 +05:30
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-11-08 19:23:39 +05:30
},
props: {
2018-12-13 13:39:08 +05:30
discussionPath: {
type: String,
required: false,
default: '',
},
2018-11-08 19:23:39 +05:30
diffFile: {
type: Object,
required: true,
},
collapsible: {
type: Boolean,
required: false,
default: false,
},
addMergeRequestButtons: {
type: Boolean,
required: false,
default: false,
},
expanded: {
type: Boolean,
required: false,
default: true,
},
canCurrentUserFork: {
type: Boolean,
required: true,
},
},
computed: {
2018-11-18 11:00:15 +05:30
...mapGetters('diffs', ['diffHasExpandedDiscussions', 'diffHasDiscussions']),
2019-07-07 11:18:12 +05:30
diffContentIDSelector() {
return `#diff-content-${this.diffFile.file_hash}`;
},
2018-11-08 19:23:39 +05:30
titleLink() {
if (this.diffFile.submodule) {
2019-02-15 15:39:39 +05:30
return this.diffFile.submodule_tree_url || this.diffFile.submodule_link;
2018-11-08 19:23:39 +05:30
}
2019-07-07 11:18:12 +05:30
if (!this.discussionPath) {
return this.diffContentIDSelector;
}
2018-12-13 13:39:08 +05:30
return this.discussionPath;
2018-11-08 19:23:39 +05:30
},
filePath() {
if (this.diffFile.submodule) {
2019-02-15 15:39:39 +05:30
return `${this.diffFile.file_path} @ ${truncateSha(this.diffFile.blob.id)}`;
2018-11-08 19:23:39 +05:30
}
2019-02-15 15:39:39 +05:30
if (this.diffFile.deleted_file) {
return sprintf(__('%{filePath} deleted'), { filePath: this.diffFile.file_path }, false);
2018-11-08 19:23:39 +05:30
}
2019-02-15 15:39:39 +05:30
return this.diffFile.file_path;
2018-11-08 19:23:39 +05:30
},
isUsingLfs() {
2019-02-15 15:39:39 +05:30
return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs';
2018-11-08 19:23:39 +05:30
},
collapseIcon() {
return this.expanded ? 'chevron-down' : 'chevron-right';
},
viewFileButtonText() {
2019-02-15 15:39:39 +05:30
const truncatedContentSha = _.escape(truncateSha(this.diffFile.content_sha));
2018-11-08 19:23:39 +05:30
return sprintf(
s__('MergeRequests|View file @ %{commitId}'),
2019-07-07 11:18:12 +05:30
{ commitId: truncatedContentSha },
2018-11-08 19:23:39 +05:30
false,
);
},
viewReplacedFileButtonText() {
2019-02-15 15:39:39 +05:30
const truncatedBaseSha = _.escape(truncateSha(this.diffFile.diff_refs.base_sha));
2018-11-08 19:23:39 +05:30
return sprintf(
s__('MergeRequests|View replaced file @ %{commitId}'),
{
commitId: `<span class="commit-sha">${truncatedBaseSha}</span>`,
},
false,
);
},
2018-11-18 11:00:15 +05:30
gfmCopyText() {
2019-02-15 15:39:39 +05:30
return `\`${this.diffFile.file_path}\``;
2018-11-18 11:00:15 +05:30
},
2019-07-07 11:18:12 +05:30
isFileRenamed() {
2019-12-04 20:38:33 +05:30
return this.diffFile.renamed_file;
2019-07-07 11:18:12 +05:30
},
isModeChanged() {
return this.diffFile.viewer.name === diffViewerModes.mode_changed;
},
expandDiffToFullFileTitle() {
if (this.diffFile.isShowingFullFile) {
return s__('MRDiff|Show changes only');
}
return s__('MRDiff|Show full file');
},
2018-11-08 19:23:39 +05:30
},
2019-02-15 15:39:39 +05:30
mounted() {
polyfillSticky(this.$refs.header);
},
2018-11-08 19:23:39 +05:30
methods: {
2019-09-30 21:07:59 +05:30
...mapActions('diffs', [
'toggleFileDiscussions',
'toggleFileDiscussionWrappers',
'toggleFullDiff',
]),
2019-12-04 20:38:33 +05:30
handleToggleFile() {
this.$emit('toggleFile');
2018-11-08 19:23:39 +05:30
},
showForkMessage() {
this.$emit('showForkMessage');
},
2019-07-07 11:18:12 +05:30
handleFileNameClick(e) {
const isLinkToOtherPage =
this.diffFile.submodule_tree_url || this.diffFile.submodule_link || this.discussionPath;
if (!isLinkToOtherPage) {
e.preventDefault();
const selector = this.diffContentIDSelector;
scrollToElement(document.querySelector(selector));
window.location.hash = selector;
}
},
2018-11-08 19:23:39 +05:30
},
};
</script>
<template>
<div
ref="header"
class="js-file-title file-title file-title-flex-parent"
2019-12-04 20:38:33 +05:30
@click.self="handleToggleFile"
2018-11-08 19:23:39 +05:30
>
<div class="file-header-content">
<icon
v-if="collapsible"
2019-12-04 20:38:33 +05:30
ref="collapseIcon"
2018-11-08 19:23:39 +05:30
:name="collapseIcon"
:size="16"
aria-hidden="true"
class="diff-toggle-caret append-right-5"
2019-12-04 20:38:33 +05:30
@click.stop="handleToggleFile"
2018-11-08 19:23:39 +05:30
/>
2019-07-07 11:18:12 +05:30
<a
v-once
id="diffFile.file_path"
ref="titleWrapper"
2019-12-04 20:38:33 +05:30
class="append-right-4"
2019-07-07 11:18:12 +05:30
:href="titleLink"
@click="handleFileNameClick"
>
2018-11-08 19:23:39 +05:30
<file-icon
:file-name="filePath"
:size="18"
aria-hidden="true"
2019-12-04 20:38:33 +05:30
css-classes="append-right-5"
2018-11-08 19:23:39 +05:30
/>
2019-07-07 11:18:12 +05:30
<span v-if="isFileRenamed">
2018-11-08 19:23:39 +05:30
<strong
2019-02-15 15:39:39 +05:30
v-gl-tooltip
:title="diffFile.old_path"
2018-11-08 19:23:39 +05:30
class="file-title-name"
2019-02-15 15:39:39 +05:30
v-html="diffFile.old_path_html"
2018-12-05 23:21:45 +05:30
></strong>
2018-11-08 19:23:39 +05:30
<strong
2019-02-15 15:39:39 +05:30
v-gl-tooltip
:title="diffFile.new_path"
2018-11-08 19:23:39 +05:30
class="file-title-name"
2019-02-15 15:39:39 +05:30
v-html="diffFile.new_path_html"
2018-12-05 23:21:45 +05:30
></strong>
2018-11-08 19:23:39 +05:30
</span>
2019-02-15 15:39:39 +05:30
<strong v-else v-gl-tooltip :title="filePath" class="file-title-name" data-container="body">
2018-11-08 19:23:39 +05:30
{{ filePath }}
</strong>
</a>
<clipboard-button
2019-12-21 20:55:43 +05:30
:title="__('Copy file path')"
2019-02-15 15:39:39 +05:30
:text="diffFile.file_path"
2018-11-18 11:00:15 +05:30
:gfm="gfmCopyText"
2018-11-08 19:23:39 +05:30
css-class="btn-default btn-transparent btn-clipboard"
/>
2019-09-04 21:01:54 +05:30
<small v-if="isModeChanged" ref="fileMode" class="mr-1">
2019-02-15 15:39:39 +05:30
{{ diffFile.a_mode }} {{ diffFile.b_mode }}
2018-11-08 19:23:39 +05:30
</small>
2019-02-15 15:39:39 +05:30
<span v-if="isUsingLfs" class="label label-lfs append-right-5"> {{ __('LFS') }} </span>
2018-11-08 19:23:39 +05:30
</div>
<div
v-if="!diffFile.submodule && addMergeRequestButtons"
class="file-actions d-none d-sm-block"
>
2019-03-02 22:35:43 +05:30
<diff-stats :added-lines="diffFile.added_lines" :removed-lines="diffFile.removed_lines" />
2019-07-07 11:18:12 +05:30
<div class="btn-group" role="group">
<template v-if="diffFile.blob && diffFile.blob.readable_text">
2019-09-04 21:01:54 +05:30
<span v-gl-tooltip.hover :title="s__('MergeRequests|Toggle comments for this file')">
<gl-button
2019-12-04 20:38:33 +05:30
ref="toggleDiscussionsButton"
2019-09-04 21:01:54 +05:30
:disabled="!diffHasDiscussions(diffFile)"
2019-12-04 20:38:33 +05:30
:class="{ active: diffHasExpandedDiscussions(diffFile) }"
2019-09-04 21:01:54 +05:30
class="js-btn-vue-toggle-comments btn"
2019-10-12 21:52:04 +05:30
data-qa-selector="toggle_comments_button"
2019-09-04 21:01:54 +05:30
type="button"
2019-12-04 20:38:33 +05:30
@click="toggleFileDiscussionWrappers(diffFile)"
2019-09-04 21:01:54 +05:30
>
<icon name="comment" />
</gl-button>
</span>
2019-05-18 00:54:41 +05:30
2019-07-07 11:18:12 +05:30
<edit-button
v-if="!diffFile.deleted_file"
:can-current-user-fork="canCurrentUserFork"
:edit-path="diffFile.edit_path"
:can-modify-blob="diffFile.can_modify_blob"
@showForkMessage="showForkMessage"
/>
</template>
2019-05-30 16:15:17 +05:30
2019-07-07 11:18:12 +05:30
<a
v-if="diffFile.replaced_view_path"
2019-12-04 20:38:33 +05:30
ref="replacedFileButton"
2019-07-07 11:18:12 +05:30
:href="diffFile.replaced_view_path"
2019-12-04 20:38:33 +05:30
class="btn view-file"
2019-07-07 11:18:12 +05:30
v-html="viewReplacedFileButtonText"
>
</a>
<gl-button
v-if="!diffFile.is_fully_expanded"
ref="expandDiffToFullFileButton"
v-gl-tooltip.hover
:title="expandDiffToFullFileTitle"
2019-12-04 20:38:33 +05:30
class="expand-file"
2019-07-07 11:18:12 +05:30
@click="toggleFullDiff(diffFile.file_path)"
>
<gl-loading-icon v-if="diffFile.isLoadingFullFile" color="dark" inline />
<icon v-else-if="diffFile.isShowingFullFile" name="doc-changes" />
<icon v-else name="doc-expand" />
</gl-button>
<gl-button
ref="viewButton"
v-gl-tooltip.hover
:href="diffFile.view_path"
target="blank"
2019-12-04 20:38:33 +05:30
class="view-file"
2019-07-07 11:18:12 +05:30
:title="viewFileButtonText"
>
2019-07-31 22:56:46 +05:30
<icon name="doc-text" />
2019-07-07 11:18:12 +05:30
</gl-button>
<a
v-if="diffFile.external_url"
2019-12-04 20:38:33 +05:30
ref="externalLink"
2019-07-07 11:18:12 +05:30
v-gl-tooltip.hover
:href="diffFile.external_url"
:title="`View on ${diffFile.formatted_external_url}`"
target="_blank"
rel="noopener noreferrer"
2019-12-04 20:38:33 +05:30
class="btn btn-file-option"
2019-07-07 11:18:12 +05:30
>
<icon name="external-link" />
</a>
</div>
2018-11-08 19:23:39 +05:30
</div>
</div>
</template>