debian-mirror-gitlab/app/assets/javascripts/projects/compare/components/app.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

192 lines
5.2 KiB
Vue
Raw Normal View History

2021-03-11 19:13:27 +05:30
<script>
2022-11-25 23:54:43 +05:30
import { GlDropdown, GlDropdownItem, GlButton } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import csrf from '~/lib/utils/csrf';
2021-06-08 01:23:25 +05:30
import { joinPaths } from '~/lib/utils/url_utility';
2021-04-17 20:07:23 +05:30
import RevisionCard from './revision_card.vue';
2021-03-11 19:13:27 +05:30
export default {
csrf,
components: {
2021-04-17 20:07:23 +05:30
RevisionCard,
2021-03-11 19:13:27 +05:30
GlButton,
2022-11-25 23:54:43 +05:30
GlDropdown,
GlDropdownItem,
2021-03-11 19:13:27 +05:30
},
props: {
projectCompareIndexPath: {
type: String,
required: true,
},
2022-08-27 11:52:29 +05:30
sourceProjectRefsPath: {
type: String,
required: true,
},
targetProjectRefsPath: {
2021-03-11 19:13:27 +05:30
type: String,
required: true,
},
paramsFrom: {
type: String,
required: false,
default: null,
},
paramsTo: {
type: String,
required: false,
default: null,
},
projectMergeRequestPath: {
type: String,
required: true,
},
createMrPath: {
type: String,
required: true,
},
2022-08-27 11:52:29 +05:30
sourceProject: {
type: Object,
required: true,
},
targetProject: {
2021-06-08 01:23:25 +05:30
type: Object,
required: true,
},
projects: {
type: Array,
required: true,
},
2022-11-25 23:54:43 +05:30
straight: {
type: Boolean,
required: true,
},
2021-06-08 01:23:25 +05:30
},
data() {
return {
from: {
projects: this.projects,
2022-08-27 11:52:29 +05:30
selectedProject: this.targetProject,
2021-06-08 01:23:25 +05:30
revision: this.paramsFrom,
2022-08-27 11:52:29 +05:30
refsProjectPath: this.targetProjectRefsPath,
2021-06-08 01:23:25 +05:30
},
to: {
2022-08-27 11:52:29 +05:30
selectedProject: this.sourceProject,
2021-06-08 01:23:25 +05:30
revision: this.paramsTo,
2022-08-27 11:52:29 +05:30
refsProjectPath: this.sourceProjectRefsPath,
2021-06-08 01:23:25 +05:30
},
2022-11-25 23:54:43 +05:30
isStraight: this.straight,
2021-06-08 01:23:25 +05:30
};
2021-03-11 19:13:27 +05:30
},
2022-11-25 23:54:43 +05:30
computed: {
straightModeDropdownItems() {
return [
{
modeType: 'off',
isEnabled: false,
content: '..',
testId: 'disableStraightModeButton',
},
{
modeType: 'on',
isEnabled: true,
content: '...',
testId: 'enableStraightModeButton',
},
];
},
},
2021-03-11 19:13:27 +05:30
methods: {
onSubmit() {
this.$refs.form.submit();
},
2021-06-08 01:23:25 +05:30
onSelectProject({ direction, project }) {
const refsPath = joinPaths(gon.relative_url_root || '', `/${project.name}`, '/refs');
// direction is either 'from' or 'to'
this[direction].refsProjectPath = refsPath;
this[direction].selectedProject = project;
},
onSelectRevision({ direction, revision }) {
this[direction].revision = revision; // direction is either 'from' or 'to'
},
onSwapRevision() {
[this.from, this.to] = [this.to, this.from]; // swaps 'from' and 'to'
},
2022-11-25 23:54:43 +05:30
setStraightMode(isStraight) {
this.isStraight = isStraight;
},
2021-03-11 19:13:27 +05:30
},
};
</script>
<template>
<form
ref="form"
2021-04-17 20:07:23 +05:30
class="js-requires-input js-signature-container"
2021-03-11 19:13:27 +05:30
method="POST"
:action="projectCompareIndexPath"
>
<input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
2021-04-17 20:07:23 +05:30
<div
class="gl-lg-flex-direction-row gl-lg-display-flex gl-align-items-center compare-revision-cards"
2021-03-11 19:13:27 +05:30
>
2021-04-17 20:07:23 +05:30
<revision-card
2021-06-08 01:23:25 +05:30
data-testid="sourceRevisionCard"
:refs-project-path="to.refsProjectPath"
2021-04-17 20:07:23 +05:30
revision-text="Source"
params-name="to"
2021-06-08 01:23:25 +05:30
:params-branch="to.revision"
:projects="to.projects"
:selected-project="to.selectedProject"
@selectProject="onSelectProject"
@selectRevision="onSelectRevision"
2021-04-17 20:07:23 +05:30
/>
<div
2022-11-25 23:54:43 +05:30
class="gl-display-flex gl-justify-content-center gl-align-items-center gl-align-self-end gl-my-3 gl-md-my-0 gl-pl-3 gl-pr-3"
2021-04-17 20:07:23 +05:30
data-testid="ellipsis"
>
2022-11-25 23:54:43 +05:30
<input :value="isStraight ? 'true' : 'false'" type="hidden" name="straight" />
<gl-dropdown data-testid="modeDropdown" :text="isStraight ? '...' : '..'" size="small">
<gl-dropdown-item
v-for="mode in straightModeDropdownItems"
:key="mode.modeType"
:is-check-item="true"
:is-checked="isStraight == mode.isEnabled"
:data-testid="mode.testId"
@click="setStraightMode(mode.isEnabled)"
>
<span class="dropdown-menu-inner-content"> {{ mode.content }} </span>
</gl-dropdown-item>
</gl-dropdown>
2021-04-17 20:07:23 +05:30
</div>
<revision-card
2021-06-08 01:23:25 +05:30
data-testid="targetRevisionCard"
:refs-project-path="from.refsProjectPath"
2021-04-17 20:07:23 +05:30
revision-text="Target"
params-name="from"
2021-06-08 01:23:25 +05:30
:params-branch="from.revision"
:projects="from.projects"
:selected-project="from.selectedProject"
@selectProject="onSelectProject"
@selectRevision="onSelectRevision"
2021-04-17 20:07:23 +05:30
/>
</div>
2022-08-13 15:12:31 +05:30
<div class="gl-display-flex gl-mt-6 gl-gap-3">
2021-10-27 15:23:28 +05:30
<gl-button category="primary" variant="confirm" @click="onSubmit">
2021-04-17 20:07:23 +05:30
{{ s__('CompareRevisions|Compare') }}
</gl-button>
2022-08-13 15:12:31 +05:30
<gl-button data-testid="swapRevisionsButton" @click="onSwapRevision">
2021-06-08 01:23:25 +05:30
{{ s__('CompareRevisions|Swap revisions') }}
</gl-button>
2021-04-17 20:07:23 +05:30
<gl-button
v-if="projectMergeRequestPath"
:href="projectMergeRequestPath"
data-testid="projectMrButton"
>
{{ s__('CompareRevisions|View open merge request') }}
</gl-button>
2022-08-13 15:12:31 +05:30
<gl-button v-else-if="createMrPath" :href="createMrPath" data-testid="createMrButton">
2021-04-17 20:07:23 +05:30
{{ s__('CompareRevisions|Create merge request') }}
</gl-button>
</div>
2021-03-11 19:13:27 +05:30
</form>
</template>