diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:13 +0300 |
commit | 736d36d8597d0d1ec1b47644e6d091c3f4a78f45 (patch) | |
tree | a38f6fef2b7147416b31f8294a9389b3bb472c87 /app | |
parent | 5426ca9908085087d465fa52800335f408eb965a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/snippet/snippet_bundle.js | 48 | ||||
-rw-r--r-- | app/models/deployment.rb | 11 | ||||
-rw-r--r-- | app/views/shared/snippets/_form.html.haml | 2 |
3 files changed, 52 insertions, 9 deletions
diff --git a/app/assets/javascripts/snippet/snippet_bundle.js b/app/assets/javascripts/snippet/snippet_bundle.js index 652531a1289..8e952fe9358 100644 --- a/app/assets/javascripts/snippet/snippet_bundle.js +++ b/app/assets/javascripts/snippet/snippet_bundle.js @@ -1,14 +1,50 @@ /* global ace */ - -import $ from 'jquery'; +import Editor from '~/editor/editor_lite'; import setupCollapsibleInputs from './collapsible_input'; -export default () => { - const editor = ace.edit('editor'); +let editor; + +const initAce = () => { + editor = ace.edit('editor'); + + const form = document.querySelector('.snippet-form-holder form'); + const content = document.querySelector('.snippet-file-content'); + form.addEventListener('submit', () => { + content.value = editor.getValue(); + }); +}; - $('.snippet-form-holder form').on('submit', () => { - $('.snippet-file-content').val(editor.getValue()); +const initMonaco = () => { + const editorEl = document.getElementById('editor'); + const contentEl = document.querySelector('.snippet-file-content'); + const fileNameEl = document.querySelector('.snippet-file-name'); + const form = document.querySelector('.snippet-form-holder form'); + + editor = new Editor(); + editor.createInstance({ + el: editorEl, + blobPath: fileNameEl.value, + blobContent: contentEl.value, }); + fileNameEl.addEventListener('change', () => { + editor.updateModelLanguage(fileNameEl.value); + }); + + form.addEventListener('submit', () => { + contentEl.value = editor.getValue(); + }); +}; + +export const initEditor = () => { + if (window?.gon?.features?.monacoSnippets) { + initMonaco(); + } else { + initAce(); + } setupCollapsibleInputs(); }; + +export default () => { + initEditor(); +}; diff --git a/app/models/deployment.rb b/app/models/deployment.rb index fe42fb93633..fbb59173a3c 100644 --- a/app/models/deployment.rb +++ b/app/models/deployment.rb @@ -229,7 +229,14 @@ class Deployment < ApplicationRecord end def link_merge_requests(relation) - select = relation.select(['merge_requests.id', id]).to_sql + # NOTE: relation.select will perform column deduplication, + # when id == environment_id it will outputs 2 columns instead of 3 + # i.e.: + # MergeRequest.select(1, 2).to_sql #=> SELECT 1, 2 FROM "merge_requests" + # MergeRequest.select(1, 1).to_sql #=> SELECT 1 FROM "merge_requests" + select = relation.select('merge_requests.id', + "#{id} as deployment_id", + "#{environment_id} as environment_id").to_sql # We don't use `Gitlab::Database.bulk_insert` here so that we don't need to # first pluck lots of IDs into memory. @@ -238,7 +245,7 @@ class Deployment < ApplicationRecord # for the same deployment, only inserting any missing merge requests. DeploymentMergeRequest.connection.execute(<<~SQL) INSERT INTO #{DeploymentMergeRequest.table_name} - (merge_request_id, deployment_id) + (merge_request_id, deployment_id, environment_id) #{select} ON CONFLICT DO NOTHING SQL diff --git a/app/views/shared/snippets/_form.html.haml b/app/views/shared/snippets/_form.html.haml index 3c2c751c579..b07992c6890 100644 --- a/app/views/shared/snippets/_form.html.haml +++ b/app/views/shared/snippets/_form.html.haml @@ -28,7 +28,7 @@ .js-file-title.file-title-flex-parent = f.text_field :file_name, placeholder: s_("Snippets|Give your file a name to add code highlighting, e.g. example.rb for Ruby"), class: 'form-control snippet-file-name qa-snippet-file-name' .file-content.code - %pre#editor= @snippet.content + %pre#editor{ data: { 'editor-loading': true } }= @snippet.content = f.hidden_field :content, class: 'snippet-file-content' .form-group |