Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « new « creations « merge_requests « projects « pages « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8cb1462c8838318c00f05bcc6afdbae189fad2fe (plain)
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
import Vue from 'vue';

import { mountMarkdownEditor } from 'ee_else_ce/vue_shared/components/markdown/mount_markdown_editor';

import { findTargetBranch } from 'ee_else_ce/pages/projects/merge_requests/creations/new/branch_finder';

import initPipelines from '~/commit/pipelines/pipelines_bundle';
import MergeRequest from '~/merge_request';
import CompareApp from '~/merge_requests/components/compare_app.vue';
import { __ } from '~/locale';
import IssuableTemplateSelectors from '~/issuable/issuable_template_selectors';

const mrNewCompareNode = document.querySelector('.js-merge-request-new-compare');
if (mrNewCompareNode) {
  const targetCompareEl = document.getElementById('js-target-project-dropdown');
  const sourceCompareEl = document.getElementById('js-source-project-dropdown');
  const compareEl = document.querySelector('.js-merge-request-new-compare');
  const targetBranch = Vue.observable({ name: '' });

  const currentSourceBranch = JSON.parse(sourceCompareEl.dataset.currentBranch);
  // eslint-disable-next-line no-new
  new Vue({
    el: sourceCompareEl,
    name: 'SourceCompareApp',
    provide: {
      currentProject: JSON.parse(sourceCompareEl.dataset.currentProject),
      branchCommitPath: compareEl.dataset.sourceBranchUrl,
      inputs: {
        project: {
          id: 'merge_request_source_project_id',
          name: 'merge_request[source_project_id]',
        },
        branch: {
          id: 'merge_request_source_branch',
          name: 'merge_request[source_branch]',
        },
      },
      i18n: {
        projectHeaderText: __('Select source project'),
        branchHeaderText: __('Select source branch'),
      },
      toggleClass: {
        project: 'js-source-project',
        branch: 'js-source-branch gl-font-monospace',
      },
      compareSide: 'source',
    },
    methods: {
      async selectedBranch(branchName) {
        const targetBranchName = await findTargetBranch(branchName);

        if (targetBranchName) {
          targetBranch.name = targetBranchName;
        }
      },
    },
    render(h) {
      return h(CompareApp, {
        props: {
          currentBranch: currentSourceBranch,
        },
        on: {
          'select-branch': this.selectedBranch,
        },
      });
    },
  });

  const currentTargetBranch = JSON.parse(targetCompareEl.dataset.currentBranch);
  // eslint-disable-next-line no-new
  new Vue({
    el: targetCompareEl,
    name: 'TargetCompareApp',
    provide: {
      currentProject: JSON.parse(targetCompareEl.dataset.currentProject),
      projectsPath: targetCompareEl.dataset.targetProjectsPath,
      branchCommitPath: compareEl.dataset.targetBranchUrl,
      inputs: {
        project: {
          id: 'merge_request_target_project_id',
          name: 'merge_request[target_project_id]',
        },
        branch: {
          id: 'merge_request_target_branch',
          name: 'merge_request[target_branch]',
        },
      },
      i18n: {
        projectHeaderText: __('Select target project'),
        branchHeaderText: __('Select target branch'),
      },
      toggleClass: {
        project: 'js-target-project',
        branch: 'js-target-branch gl-font-monospace',
      },
    },
    computed: {
      currentBranch() {
        if (targetBranch.name) {
          return { text: targetBranch.name, value: targetBranch.name };
        }

        return currentTargetBranch;
      },
    },
    render(h) {
      return h(CompareApp, { props: { currentBranch: this.currentBranch } });
    },
  });
} else {
  const mrNewSubmitNode = document.querySelector('.js-merge-request-new-submit');
  // eslint-disable-next-line no-new
  new MergeRequest({
    action: mrNewSubmitNode.dataset.mrSubmitAction,
  });
  initPipelines();
  // eslint-disable-next-line no-new
  new IssuableTemplateSelectors({ warnTemplateOverride: true, editor: mountMarkdownEditor() });
}