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

150 lines
4.1 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';
2019-02-15 15:39:39 +05:30
import { GlTooltipDirective, GlLink, GlButton } from '@gitlab/ui';
2018-12-05 23:21:45 +05:30
import { __ } from '~/locale';
2019-03-02 22:35:43 +05:30
import { polyfillSticky } from '~/lib/utils/sticky';
2018-12-05 23:21:45 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2018-11-08 19:23:39 +05:30
import CompareVersionsDropdown from './compare_versions_dropdown.vue';
2019-03-02 22:35:43 +05:30
import SettingsDropdown from './settings_dropdown.vue';
import DiffStats from './diff_stats.vue';
2019-05-18 00:54:41 +05:30
import { CENTERED_LIMITED_CONTAINER_CLASSES } from '../constants';
2018-11-08 19:23:39 +05:30
export default {
components: {
CompareVersionsDropdown,
2018-12-05 23:21:45 +05:30
Icon,
2019-02-15 15:39:39 +05:30
GlLink,
GlButton,
2019-03-02 22:35:43 +05:30
SettingsDropdown,
DiffStats,
2018-12-05 23:21:45 +05:30
},
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-11-08 19:23:39 +05:30
},
props: {
mergeRequestDiffs: {
type: Array,
required: true,
},
mergeRequestDiff: {
type: Object,
required: false,
2019-02-15 15:39:39 +05:30
default: () => ({}),
2018-11-08 19:23:39 +05:30
},
targetBranch: {
type: Object,
required: false,
default: null,
},
2019-05-18 00:54:41 +05:30
isLimitedContainer: {
type: Boolean,
required: false,
default: false,
},
2018-11-08 19:23:39 +05:30
},
computed: {
2019-03-02 22:35:43 +05:30
...mapGetters('diffs', ['hasCollapsedFile', 'diffFilesLength']),
...mapState('diffs', [
'commit',
'showTreeList',
'startVersion',
'latestVersionPath',
'addedLines',
'removedLines',
]),
2018-11-08 19:23:39 +05:30
comparableDiffs() {
return this.mergeRequestDiffs.slice(1);
},
2018-12-05 23:21:45 +05:30
showDropdowns() {
return !this.commit && this.mergeRequestDiffs.length;
},
2019-03-02 22:35:43 +05:30
fileTreeIcon() {
return this.showTreeList ? 'collapse-left' : 'expand-left';
},
toggleFileBrowserTitle() {
return this.showTreeList ? __('Hide file browser') : __('Show file browser');
},
baseVersionPath() {
return this.mergeRequestDiff.base_version_path;
},
},
2019-05-18 00:54:41 +05:30
created() {
this.CENTERED_LIMITED_CONTAINER_CLASSES = CENTERED_LIMITED_CONTAINER_CLASSES;
},
2019-03-02 22:35:43 +05:30
mounted() {
polyfillSticky(this.$el);
2018-12-05 23:21:45 +05:30
},
methods: {
...mapActions('diffs', [
'setInlineDiffViewType',
'setParallelDiffViewType',
'expandAllFiles',
'toggleShowTreeList',
]),
2018-11-08 19:23:39 +05:30
},
};
</script>
<template>
2019-05-18 00:54:41 +05:30
<div class="mr-version-controls border-top border-bottom">
<div
class="mr-version-menus-container content-block"
:class="{
[CENTERED_LIMITED_CONTAINER_CLASSES]: isLimitedContainer,
}"
>
2018-12-05 23:21:45 +05:30
<button
2019-02-15 15:39:39 +05:30
v-gl-tooltip.hover
2018-12-05 23:21:45 +05:30
type="button"
class="btn btn-default append-right-8 js-toggle-tree-list"
:class="{
2019-02-15 15:39:39 +05:30
active: showTreeList,
2018-12-05 23:21:45 +05:30
}"
2019-03-02 22:35:43 +05:30
:title="toggleFileBrowserTitle"
2018-12-05 23:21:45 +05:30
@click="toggleShowTreeList"
>
2019-03-02 22:35:43 +05:30
<icon :name="fileTreeIcon" />
2018-12-05 23:21:45 +05:30
</button>
2019-02-15 15:39:39 +05:30
<div v-if="showDropdowns" class="d-flex align-items-center compare-versions-container">
2018-12-05 23:21:45 +05:30
Changes between
<compare-versions-dropdown
:other-versions="mergeRequestDiffs"
:merge-request-version="mergeRequestDiff"
:show-commit-count="true"
class="mr-version-dropdown"
/>
and
<compare-versions-dropdown
:other-versions="comparableDiffs"
2019-03-02 22:35:43 +05:30
:base-version-path="baseVersionPath"
2018-12-05 23:21:45 +05:30
:start-version="startVersion"
:target-branch="targetBranch"
class="mr-version-compare-dropdown"
/>
</div>
2019-02-15 15:39:39 +05:30
<div v-else-if="commit">
{{ __('Viewing commit') }}
<gl-link :href="commit.commit_url" class="monospace">{{ commit.short_id }}</gl-link>
</div>
<div class="inline-parallel-buttons d-none d-md-flex ml-auto">
2019-03-02 22:35:43 +05:30
<diff-stats
:diff-files-length="diffFilesLength"
:added-lines="addedLines"
:removed-lines="removedLines"
/>
2019-02-15 15:39:39 +05:30
<gl-button
v-if="commit || startVersion"
:href="latestVersionPath"
class="append-right-8 js-latest-version"
2018-12-05 23:21:45 +05:30
>
2019-02-15 15:39:39 +05:30
{{ __('Show latest version') }}
</gl-button>
2019-05-18 00:54:41 +05:30
<gl-button v-show="hasCollapsedFile" class="append-right-8" @click="expandAllFiles">
2018-12-05 23:21:45 +05:30
{{ __('Expand all') }}
2019-05-18 00:54:41 +05:30
</gl-button>
2019-03-02 22:35:43 +05:30
<settings-dropdown />
2018-12-05 23:21:45 +05:30
</div>
2018-11-08 19:23:39 +05:30
</div>
</div>
</template>