Skip to content

Commit adc97bf

Browse files
committed
Fix theme settings
1 parent 0df2fd4 commit adc97bf

File tree

9 files changed

+46
-31
lines changed

9 files changed

+46
-31
lines changed

airflow_code_editor/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.1.0
1+
7.1.1

airflow_code_editor/static/airflow_code_editor.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airflow_code_editor/static/airflow_code_editor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

airflow_code_editor/templates/index_tail.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
jQuery(document).ready(function() {
88
// Init
99
var csrfToken = "{{ csrf_token() }}";
10-
init(csrfToken);
10+
var themesPath = "{{ url_for('static', filename='code_editor/css/theme') }}";
11+
init(csrfToken, themesPath);
1112
});
1213

1314
</script>

changelog.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,11 @@
426426

427427
- Send git api result in JSON format
428428
- CodeMirror upgrade
429+
430+
## 7.1.1
431+
432+
2022-10-29
433+
434+
### Fix
435+
436+
- Fix theme settings

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "airflow-code-editor",
3-
"version": "7.1.0",
3+
"version": "7.1.1",
44
"description": "A plugin for [Apache Airflow](https://github.com/apache/airflow) that allows you to edit DAGs in browser. It provides a file managing interface within specified directories and it can be used to edit and download your files. If git support is enabled, the DAGs are stored in a Git repository. You may use it to view Git history, review local changes and commit.",
55
"private": true,
66
"repository": {

src/commons.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const COLORS = [
1919

2020
var csrfToken = null;
2121
var vueApp = null;
22+
var themesPath = null;
2223

2324
export function showError(message) {
2425
if (vueApp) {
@@ -105,7 +106,20 @@ export function git(args, callback) {
105106
});
106107
}
107108

108-
export function initApp(app, target, teleportTarget, csrfTokenParam) {
109+
export function importTheme(theme) {
110+
// Import an editor theme
111+
return new Promise((resolve, reject) => {
112+
let link = document.createElement('link');
113+
link.onload = () => resolve(true);
114+
link.rel = 'stylesheet';
115+
link.type = 'text/css';
116+
link.href = themesPath + '/' + theme + '.css';
117+
document.getElementsByTagName('head')[0].appendChild(link);
118+
});
119+
}
120+
121+
export function initApp(app, target, teleportTarget, csrfTokenParam, themesPathParam) {
122+
themesPath = themesPathParam;
109123
// CSRF Token setup
110124
initCsrfToken(csrfTokenParam);
111125
// Add VueUniversalModal

src/components/Editor.vue

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<script>
4747
import axios from 'axios';
4848
import { defineComponent, markRaw } from 'vue';
49-
import { normalize, prepareHref, git, showError } from '../commons';
49+
import { normalize, prepareHref, git, showError, importTheme } from '../commons';
5050
import Breadcrumb from './Breadcrumb.vue';
5151
import Icon from './Icon.vue';
5252
import SettingsDialog from './dialogs/SettingsDialog.vue';
@@ -169,31 +169,23 @@ export default defineComponent({
169169
if (this.editor) {
170170
this.editor.setOption(option, value);
171171
}
172-
// Store settings in localStorage
173-
if (option == 'keyMap') {
174-
option = 'mode';
175-
}
176-
localStorage.setItem('airflow_code_editor_' + option, value);
177172
},
178173
setTheme(theme) {
179174
// Set editor theme
180175
if (theme == 'default') {
181176
this.setOption('theme', theme);
182177
} else {
183-
let link = document.createElement('link');
184-
link.onload = () => this.setOption('theme', theme);
185-
let baseUrl = jQuery('link[rel=stylesheet]').filter((i, e) => e.href.match(/gitweb.css/) !== null)[0].href.split('/gitweb.css')[0];;
186-
link.rel = 'stylesheet';
187-
link.type = 'text/css';
188-
link.href = baseUrl + '/theme/' + theme + '.css';
189-
document.getElementsByTagName('head')[0].appendChild(link);
178+
importTheme(theme).then(() => this.setOption('theme', theme));
190179
}
191180
},
192181
updateSettings(config) {
193182
this.config.theme = config.theme;
194183
this.config.mode = config.mode;
195-
this.setTheme(this.config.theme);
196-
this.setOption('keyMap', this.config.mode);
184+
this.setTheme(this.config.theme); // Set theme
185+
this.setOption('keyMap', this.config.mode); // Set editor mode
186+
// Save setting on the local storage
187+
localStorage.setItem('airflow_code_editor_theme', config.theme);
188+
localStorage.setItem('airflow_code_editor_mode', config.mode);
197189
},
198190
saveAction() {
199191
// Save button action

src/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { createApp } from 'vue';
22
import App from './components/App.vue';
33
import { initApp } from './commons';
44

5-
window.init = function(csrfTokenParam) {
5+
window.init = function(csrfTokenParam, themesPath) {
66
const target = '#global-container';
77
const teleportTarget = '#airflow-code-editor-modals';
88
// CodeMirror
99
window.CodeMirror.modeURL = '/static/code_editor/mode/%N/%N.js';
1010
// Init app
1111
jQuery(target).appendTo(jQuery('body'));
1212
const app = createApp(App);
13-
window.app = initApp(app, target, teleportTarget, csrfTokenParam);
13+
window.app = initApp(app, target, teleportTarget, csrfTokenParam, themesPath);
1414
}

0 commit comments

Comments
 (0)