Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions airflow/www/static/js/connection_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ $(document).ready(() => {
$("form#model_form div.well.well-sm button:submit")
);

// Change conn.extra TextArea widget to CodeMirror
const textArea = document.getElementById("extra");
const editor = CodeMirror.fromTextArea(textArea, {
mode: { name: "javascript", json: true },
gutters: ["CodeMirror-lint-markers"],
lineWrapping: true,
lint: true,
});

// beautify JSON
const jsonData = editor.getValue();
const parsedData = JSON.parse(jsonData);
const formattedData = JSON.stringify(parsedData, null, 2);
editor.setValue(formattedData);

/**
* Changes the connection type.
* @param {string} connType The connection type to change to.
Expand Down Expand Up @@ -296,6 +311,8 @@ $(document).ready(() => {
// payload.
if (this.name === "extra") {
let extra;
// save the contents of the CodeMirror editor to the textArea
editor.save();
try {
extra = JSON.parse(this.value);
} catch (e) {
Expand Down Expand Up @@ -353,19 +370,4 @@ $(document).ready(() => {

// Initialize the form by setting a connection type.
changeConnType(connTypeElem.value);

// Change conn.extra TextArea widget to CodeMirror
const textArea = document.getElementById("extra");
const editor = CodeMirror.fromTextArea(textArea, {
mode: { name: "javascript", json: true },
gutters: ["CodeMirror-lint-markers"],
lineWrapping: true,
lint: true,
});

// beautify JSON
const jsonData = editor.getValue();
const data = JSON.parse(jsonData);
const formattedData = JSON.stringify(data, null, 2);
editor.setValue(formattedData);
});