debian-mirror-gitlab/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue

173 lines
5.3 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2018-11-20 20:47:30 +05:30
import _ from 'underscore';
import { n__, s__, sprintf } from '~/locale';
2018-11-18 11:00:15 +05:30
import { mergeUrlParams, webIDEUrl } from '~/lib/utils/url_utility';
2018-11-08 19:23:39 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2018-05-09 12:01:36 +05:30
import clipboardButton from '~/vue_shared/components/clipboard_button.vue';
2018-11-20 20:47:30 +05:30
import tooltip from '~/vue_shared/directives/tooltip';
import TooltipOnTruncate from '~/vue_shared/components/tooltip_on_truncate.vue';
2019-02-15 15:39:39 +05:30
import MrWidgetIcon from './mr_widget_icon.vue';
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
export default {
name: 'MRWidgetHeader',
components: {
2018-11-08 19:23:39 +05:30
Icon,
2018-05-09 12:01:36 +05:30
clipboardButton,
2018-11-20 20:47:30 +05:30
TooltipOnTruncate,
2019-02-15 15:39:39 +05:30
MrWidgetIcon,
2018-11-20 20:47:30 +05:30
},
directives: {
tooltip,
2018-05-09 12:01:36 +05:30
},
props: {
mr: {
type: Object,
required: true,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
},
computed: {
shouldShowCommitsBehindText() {
return this.mr.divergedCommitsCount > 0;
2018-03-17 18:26:18 +05:30
},
2018-11-20 20:47:30 +05:30
commitsBehindText() {
2018-12-05 23:21:45 +05:30
return sprintf(
s__(
'mrWidget|The source branch is %{commitsBehindLinkStart}%{commitsBehind}%{commitsBehindLinkEnd} the target branch',
),
{
commitsBehindLinkStart: `<a href="${_.escape(this.mr.targetBranchPath)}">`,
commitsBehind: n__('%d commit behind', '%d commits behind', this.mr.divergedCommitsCount),
commitsBehindLinkEnd: '</a>',
},
false,
);
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
branchNameClipboardData() {
// This supports code in app/assets/javascripts/copy_to_clipboard.js that
// works around ClipboardJS limitations to allow the context-specific
// copy/pasting of plain text or GFM.
return JSON.stringify({
text: this.mr.sourceBranch,
gfm: `\`${this.mr.sourceBranch}\``,
});
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
webIdePath() {
2018-11-20 20:47:30 +05:30
if (this.mr.canPushToSourceBranch) {
2018-12-05 23:21:45 +05:30
return mergeUrlParams(
{
target_project:
this.mr.sourceProjectFullPath !== this.mr.targetProjectFullPath
? this.mr.targetProjectFullPath
: '',
},
webIDEUrl(`/${this.mr.sourceProjectFullPath}/merge_requests/${this.mr.iid}`),
);
2018-11-20 20:47:30 +05:30
}
return null;
2018-05-09 12:01:36 +05:30
},
2018-11-20 20:47:30 +05:30
ideButtonTitle() {
return !this.mr.canPushToSourceBranch
2018-12-05 23:21:45 +05:30
? s__(
'mrWidget|You are not allowed to edit this project directly. Please fork to make changes.',
)
2018-11-20 20:47:30 +05:30
: '';
2018-05-09 12:01:36 +05:30
},
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
2018-11-08 19:23:39 +05:30
<div class="mr-source-target append-bottom-default">
2019-02-15 15:39:39 +05:30
<mr-widget-icon name="git-merge" />
2018-11-08 19:23:39 +05:30
<div class="git-merge-container d-flex">
<div class="normal">
<strong>
2019-02-15 15:39:39 +05:30
{{ s__('mrWidget|Request to merge') }}
2018-11-20 20:47:30 +05:30
<tooltip-on-truncate
:title="mr.sourceBranch"
truncate-target="child"
class="label-branch label-truncate js-source-branch"
2018-11-08 19:23:39 +05:30
v-html="mr.sourceBranchLink"
2018-11-20 20:47:30 +05:30
/><clipboard-button
2018-11-08 19:23:39 +05:30
:text="branchNameClipboardData"
2019-12-21 20:55:43 +05:30
:title="__('Copy branch name')"
2018-11-08 19:23:39 +05:30
css-class="btn-default btn-transparent btn-clipboard"
/>
2019-02-15 15:39:39 +05:30
{{ s__('mrWidget|into') }}
2018-11-20 20:47:30 +05:30
<tooltip-on-truncate
:title="mr.targetBranch"
truncate-target="child"
class="label-branch label-truncate"
2018-03-17 18:26:18 +05:30
>
2019-02-15 15:39:39 +05:30
<a :href="mr.targetBranchTreePath" class="js-target-branch"> {{ mr.targetBranch }} </a>
2018-11-20 20:47:30 +05:30
</tooltip-on-truncate>
2018-11-08 19:23:39 +05:30
</strong>
<div
v-if="shouldShowCommitsBehindText"
class="diverged-commits-count"
2018-11-20 20:47:30 +05:30
v-html="commitsBehindText"
2019-02-15 15:39:39 +05:30
></div>
2018-11-08 19:23:39 +05:30
</div>
2018-03-17 18:26:18 +05:30
2019-07-07 11:18:12 +05:30
<div class="branch-actions d-flex">
<template v-if="mr.isOpen">
<a
v-if="!mr.sourceBranchRemoved"
v-tooltip
:href="webIdePath"
:title="ideButtonTitle"
:class="{ disabled: !mr.canPushToSourceBranch }"
class="btn btn-default js-web-ide d-none d-md-inline-block append-right-8"
data-placement="bottom"
tabindex="0"
role="button"
>
{{ s__('mrWidget|Open in Web IDE') }}
</a>
<button
:disabled="mr.sourceBranchRemoved"
data-target="#modal_merge_info"
data-toggle="modal"
2019-09-04 21:01:54 +05:30
class="btn btn-default js-check-out-branch append-right-8"
2019-07-07 11:18:12 +05:30
type="button"
>
{{ s__('mrWidget|Check out branch') }}
</button>
</template>
2018-12-05 23:21:45 +05:30
<span class="dropdown">
2018-11-08 19:23:39 +05:30
<button
type="button"
2019-07-07 11:18:12 +05:30
class="btn dropdown-toggle qa-dropdown-toggle"
2018-11-08 19:23:39 +05:30
data-toggle="dropdown"
2019-09-30 21:07:59 +05:30
:aria-label="__('Download as')"
2018-11-08 19:23:39 +05:30
aria-haspopup="true"
aria-expanded="false"
>
2019-02-15 15:39:39 +05:30
<icon name="download" /> <i class="fa fa-caret-down" aria-hidden="true"> </i>
2018-11-08 19:23:39 +05:30
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
2019-07-07 11:18:12 +05:30
<a
:href="mr.emailPatchesPath"
class="js-download-email-patches qa-download-email-patches"
download
>
2019-02-15 15:39:39 +05:30
{{ s__('mrWidget|Email patches') }}
2018-11-08 19:23:39 +05:30
</a>
</li>
<li>
2019-07-07 11:18:12 +05:30
<a
:href="mr.plainDiffPath"
class="js-download-plain-diff qa-download-plain-diff"
download
>
2019-02-15 15:39:39 +05:30
{{ s__('mrWidget|Plain diff') }}
2018-11-08 19:23:39 +05:30
</a>
</li>
</ul>
</span>
</div>
2018-03-17 18:26:18 +05:30
</div>
</div>
</template>