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

160 lines
3.9 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-02-13 22:33:31 +05:30
`${version.commits_count} commit,`,
`${version.commits_count} commits,`,
version.commits_count,
2018-11-08 19:23:39 +05:30
);
},
href(version) {
if (this.showCommitCount) {
2019-02-13 22:33:31 +05:30
return version.version_path;
2018-11-08 19:23:39 +05:30
}
2019-02-13 22:33:31 +05:30
return version.compare_path;
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-02-13 22:33:31 +05:30
return `version ${version.version_index}`;
2018-11-08 19:23:39 +05:30
},
isActive(version) {
if (!version) {
return false;
}
if (this.targetBranch) {
return (
(this.isBase(version) && !this.startVersion) ||
2019-02-13 22:33:31 +05:30
(this.startVersion && this.startVersion.version_index === version.version_index)
2018-11-08 19:23:39 +05:30
);
}
2019-02-13 22:33:31 +05:30
return version.version_index === this.mergeRequestVersion.version_index;
2018-11-08 19:23:39 +05:30
},
isBase(version) {
if (!version || !this.targetBranch) {
return false;
}
return version.versionIndex === -1;
},
isLatest(version) {
return (
2019-02-13 22:33:31 +05:30
this.mergeRequestVersion && version.version_index === this.targetVersions[0].version_index
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-02-13 22:33:31 +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-02-13 22:33:31 +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-02-13 22:33:31 +05:30
<small class="commit-sha"> {{ version.short_commit_sha }} </small>
2018-11-08 19:23:39 +05:30
</div>
<div>
<small>
<template v-if="showCommitCount">
{{ commitsText(version) }}
</template>
<time-ago
2019-02-13 22:33:31 +05:30
v-if="version.created_at"
:time="version.created_at"
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>