All files / app/assets/javascripts/projects/compare/components app.vue

100% Statements 12/12
100% Branches 4/4
100% Functions 6/6
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150  1x 1x 1x 1x                                                                                         19x                               1x     1x   1x 1x     1x     1x           69x                                                                                                                                    
<script>
import { GlButton } from '@gitlab/ui';
import csrf from '~/lib/utils/csrf';
import { joinPaths } from '~/lib/utils/url_utility';
import RevisionCard from './revision_card.vue';
 
export default {
  csrf,
  components: {
    RevisionCard,
    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,
    },
    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,
      },
    };
  },
  methods: {
    onSubmit() {
      this.$refs.form.submit();
    },
    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'
    },
  },
};
</script>
 
<template>
  <form
    ref="form"
    class="js-requires-input js-signature-container"
    method="POST"
    :action="projectCompareIndexPath"
  >
    <input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
    <div
      class="gl-lg-flex-direction-row gl-lg-display-flex gl-align-items-center compare-revision-cards"
    >
      <revision-card
        data-testid="sourceRevisionCard"
        :refs-project-path="to.refsProjectPath"
        revision-text="Source"
        params-name="to"
        :params-branch="to.revision"
        :projects="to.projects"
        :selected-project="to.selectedProject"
        @selectProject="onSelectProject"
        @selectRevision="onSelectRevision"
      />
      <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
        data-testid="targetRevisionCard"
        :refs-project-path="from.refsProjectPath"
        revision-text="Target"
        params-name="from"
        :params-branch="from.revision"
        :projects="from.projects"
        :selected-project="from.selectedProject"
        @selectProject="onSelectProject"
        @selectRevision="onSelectRevision"
      />
    </div>
    <div class="gl-mt-4">
      <gl-button category="primary" variant="confirm" @click="onSubmit">
        {{ s__('CompareRevisions|Compare') }}
      </gl-button>
      <gl-button data-testid="swapRevisionsButton" class="btn btn-default" @click="onSwapRevision">
        {{ s__('CompareRevisions|Swap revisions') }}
      </gl-button>
      <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>
  </form>
</template>