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

174 lines
4.1 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
import Icon from '~/vue_shared/components/icon.vue';
import { n__, __ } from '~/locale';
import TimeAgo from '~/vue_shared/components/time_ago_tooltip.vue';
export default {
components: {
Icon,
TimeAgo,
},
props: {
otherVersions: {
type: Array,
required: false,
default: () => [],
},
mergeRequestVersion: {
type: Object,
required: false,
default: null,
},
startVersion: {
type: Object,
required: false,
default: null,
},
targetBranch: {
type: Object,
required: false,
default: null,
},
showCommitCount: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
baseVersion() {
return {
name: 'hii',
versionIndex: -1,
};
},
targetVersions() {
if (this.mergeRequestVersion) {
return this.otherVersions;
}
return [...this.otherVersions, this.targetBranch];
},
selectedVersionName() {
const selectedVersion = this.startVersion || this.targetBranch || this.mergeRequestVersion;
return this.versionName(selectedVersion);
},
},
methods: {
commitsText(version) {
return n__(
2019-01-03 12:48:30 +05:30
`${version.commitsCount} commit,`,
`${version.commitsCount} commits,`,
version.commitsCount,
2018-11-08 19:23:39 +05:30
);
},
href(version) {
if (this.showCommitCount) {
2019-01-03 12:48:30 +05:30
return version.versionPath;
2018-11-08 19:23:39 +05:30
}
2019-01-03 12:48:30 +05:30
return version.comparePath;
2018-11-08 19:23:39 +05:30
},
versionName(version) {
if (this.isLatest(version)) {
return __('latest version');
}
if (this.targetBranch && (this.isBase(version) || !version)) {
return this.targetBranch.branchName;
}
2019-01-03 12:48:30 +05:30
return `version ${version.versionIndex}`;
2018-11-08 19:23:39 +05:30
},
isActive(version) {
if (!version) {
return false;
}
if (this.targetBranch) {
return (
(this.isBase(version) && !this.startVersion) ||
2019-01-03 12:48:30 +05:30
(this.startVersion && this.startVersion.versionIndex === version.versionIndex)
2018-11-08 19:23:39 +05:30
);
}
2019-01-03 12:48:30 +05:30
return version.versionIndex === this.mergeRequestVersion.versionIndex;
2018-11-08 19:23:39 +05:30
},
isBase(version) {
if (!version || !this.targetBranch) {
return false;
}
return version.versionIndex === -1;
},
isLatest(version) {
return (
2019-01-03 12:48:30 +05:30
this.mergeRequestVersion && version.versionIndex === this.targetVersions[0].versionIndex
2018-11-08 19:23:39 +05:30
);
},
},
};
</script>
<template>
<span class="dropdown inline">
<a
2018-12-05 23:21:45 +05:30
class="dropdown-menu-toggle btn btn-default w-100"
2018-11-08 19:23:39 +05:30
data-toggle="dropdown"
aria-expanded="false"
>
2019-01-03 12:48:30 +05:30
<span>
{{ selectedVersionName }}
</span>
<icon
:size="12"
name="angle-down"
class="position-absolute"
/>
2018-11-08 19:23:39 +05:30
</a>
<div class="dropdown-menu dropdown-select dropdown-menu-selectable">
<div class="dropdown-content">
<ul>
2019-01-03 12:48:30 +05:30
<li
v-for="version in targetVersions"
:key="version.id"
>
<a
:class="{ 'is-active': isActive(version) }"
:href="href(version)"
>
2018-11-08 19:23:39 +05:30
<div>
<strong>
{{ versionName(version) }}
<template v-if="isBase(version)">
(base)
</template>
</strong>
</div>
<div>
2019-01-03 12:48:30 +05:30
<small class="commit-sha">
{{ version.truncatedCommitSha }}
</small>
2018-11-08 19:23:39 +05:30
</div>
<div>
<small>
<template v-if="showCommitCount">
{{ commitsText(version) }}
</template>
<time-ago
2019-01-03 12:48:30 +05:30
v-if="version.createdAt"
:time="version.createdAt"
2018-11-08 19:23:39 +05:30
class="js-timeago js-timeago-render"
/>
</small>
</div>
</a>
</li>
</ul>
</div>
</div>
</span>
</template>
2018-12-05 23:21:45 +05:30
<style>
.dropdown {
min-width: 0;
max-height: 170px;
}
</style>