2021-02-04 07:09:25 -05:00
|
|
|
<script>
|
|
|
|
import { GlButton } from '@gitlab/ui';
|
|
|
|
import csrf from '~/lib/utils/csrf';
|
2021-05-04 08:10:04 -04:00
|
|
|
import { joinPaths } from '~/lib/utils/url_utility';
|
2021-02-22 19:11:11 -05:00
|
|
|
import RevisionCard from './revision_card.vue';
|
2021-02-04 07:09:25 -05:00
|
|
|
|
|
|
|
export default {
|
|
|
|
csrf,
|
|
|
|
components: {
|
2021-02-22 19:11:11 -05:00
|
|
|
RevisionCard,
|
2021-02-04 07:09:25 -05:00
|
|
|
GlButton,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
projectCompareIndexPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
refsProjectPath: {
|
|
|
|
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,
|
|
|
|
},
|
2021-05-04 08:10:04 -04:00
|
|
|
defaultProject: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
projects: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
from: {
|
|
|
|
projects: this.projects,
|
|
|
|
selectedProject: this.defaultProject,
|
|
|
|
revision: this.paramsFrom,
|
|
|
|
refsProjectPath: this.refsProjectPath,
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
selectedProject: this.defaultProject,
|
|
|
|
revision: this.paramsTo,
|
|
|
|
refsProjectPath: this.refsProjectPath,
|
|
|
|
},
|
|
|
|
};
|
2021-02-04 07:09:25 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onSubmit() {
|
|
|
|
this.$refs.form.submit();
|
|
|
|
},
|
2021-05-04 08:10:04 -04:00
|
|
|
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'
|
|
|
|
},
|
2021-02-04 07:09:25 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<form
|
|
|
|
ref="form"
|
2021-02-22 19:11:11 -05:00
|
|
|
class="js-requires-input js-signature-container"
|
2021-02-04 07:09:25 -05:00
|
|
|
method="POST"
|
|
|
|
:action="projectCompareIndexPath"
|
|
|
|
>
|
|
|
|
<input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
|
2021-02-22 19:11:11 -05:00
|
|
|
<div
|
|
|
|
class="gl-lg-flex-direction-row gl-lg-display-flex gl-align-items-center compare-revision-cards"
|
2021-02-04 07:09:25 -05:00
|
|
|
>
|
2021-02-22 19:11:11 -05:00
|
|
|
<revision-card
|
2021-05-04 08:10:04 -04:00
|
|
|
data-testid="sourceRevisionCard"
|
|
|
|
:refs-project-path="to.refsProjectPath"
|
2021-02-22 19:11:11 -05:00
|
|
|
revision-text="Source"
|
|
|
|
params-name="to"
|
2021-05-04 08:10:04 -04:00
|
|
|
:params-branch="to.revision"
|
|
|
|
:projects="to.projects"
|
|
|
|
:selected-project="to.selectedProject"
|
|
|
|
@selectProject="onSelectProject"
|
|
|
|
@selectRevision="onSelectRevision"
|
2021-02-22 19:11:11 -05:00
|
|
|
/>
|
|
|
|
<div
|
|
|
|
class="compare-ellipsis gl-display-flex gl-justify-content-center gl-align-items-center gl-my-4 gl-md-my-0"
|
|
|
|
data-testid="ellipsis"
|
|
|
|
>
|
|
|
|
...
|
|
|
|
</div>
|
|
|
|
<revision-card
|
2021-05-04 08:10:04 -04:00
|
|
|
data-testid="targetRevisionCard"
|
|
|
|
:refs-project-path="from.refsProjectPath"
|
2021-02-22 19:11:11 -05:00
|
|
|
revision-text="Target"
|
|
|
|
params-name="from"
|
2021-05-04 08:10:04 -04:00
|
|
|
:params-branch="from.revision"
|
|
|
|
:projects="from.projects"
|
|
|
|
:selected-project="from.selectedProject"
|
|
|
|
@selectProject="onSelectProject"
|
|
|
|
@selectRevision="onSelectRevision"
|
2021-02-22 19:11:11 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="gl-mt-4">
|
2021-08-02 08:09:59 -04:00
|
|
|
<gl-button category="primary" variant="confirm" @click="onSubmit">
|
2021-02-22 19:11:11 -05:00
|
|
|
{{ s__('CompareRevisions|Compare') }}
|
|
|
|
</gl-button>
|
2021-05-04 08:10:04 -04:00
|
|
|
<gl-button data-testid="swapRevisionsButton" class="btn btn-default" @click="onSwapRevision">
|
|
|
|
{{ s__('CompareRevisions|Swap revisions') }}
|
|
|
|
</gl-button>
|
2021-02-22 19:11:11 -05:00
|
|
|
<gl-button
|
|
|
|
v-if="projectMergeRequestPath"
|
|
|
|
:href="projectMergeRequestPath"
|
|
|
|
data-testid="projectMrButton"
|
|
|
|
class="btn btn-default gl-button"
|
|
|
|
>
|
|
|
|
{{ s__('CompareRevisions|View open merge request') }}
|
|
|
|
</gl-button>
|
|
|
|
<gl-button
|
|
|
|
v-else-if="createMrPath"
|
|
|
|
:href="createMrPath"
|
|
|
|
data-testid="createMrButton"
|
|
|
|
class="btn btn-default gl-button"
|
|
|
|
>
|
|
|
|
{{ s__('CompareRevisions|Create merge request') }}
|
|
|
|
</gl-button>
|
|
|
|
</div>
|
2021-02-04 07:09:25 -05:00
|
|
|
</form>
|
|
|
|
</template>
|