Skip to content

Allow filter editable files by extension #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import flaskcode
app = Flask(__name__)
app.config.from_object(flaskcode.default_config)
app.config['FLASKCODE_RESOURCE_BASEPATH'] = '/path/to/resource/folder'
app.config['FLASKCODE_ALLOWED_EXTENSIONS'] = 'txt'
app.register_blueprint(flaskcode.blueprint, url_prefix='/flaskcode')

@app.route('/')
Expand Down
6 changes: 6 additions & 0 deletions flaskcode.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
2 changes: 2 additions & 0 deletions flaskcode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
def manipulate_url_values(endpoint, values):
if endpoint != 'flaskcode.static':
resource_basepath = current_app.config.get('FLASKCODE_RESOURCE_BASEPATH')
g.flaskcode_allowed_extensions = current_app.config.get('FLASKCODE_ALLOWED_EXTENSIONS')
if not (resource_basepath and os.path.isdir(resource_basepath)):
abort(500, '`FLASKCODE_RESOURCE_BASEPATH` is not a valid directory path')
else:
Expand All @@ -40,6 +41,7 @@ def process_template_context():
app_version=__version__,
app_title=current_app.config.get('FLASKCODE_APP_TITLE', default_config.FLASKCODE_APP_TITLE),
editor_theme=current_app.config.get('FLASKCODE_EDITOR_THEME', default_config.FLASKCODE_EDITOR_THEME),
flaskcode_js=current_app.config.get('FLASKCODE_JS', default_config.FLASKCODE_JS)
)


Expand Down
10 changes: 8 additions & 2 deletions flaskcode/default_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# -*- coding: utf-8 -*-
FLASKCODE_APP_TITLE = 'FlaskCode'
FLASKCODE_EDITOR_THEME = 'vs-dark'
FLASKCODE_APP_TITLE = "FlaskCode"
FLASKCODE_EDITOR_THEME = "vs-dark"
FLASKCODE_RESOURCE_BASEPATH = None
FLASKCODE_JS = {
"defaultExt": "yml",
"defaultLangId": "yaml",
"allowedLangIds": ["yaml"],
"availableLanguages": {"*": 'de'},
}
24 changes: 15 additions & 9 deletions flaskcode/static/js/flaskcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ flaskcode.editorWidget = {
};
flaskcode.editorElement = null;

flaskcode.languages = [];
flaskcode.defaultExt = 'txt';
flaskcode.defaultLangId = 'plaintext';
flaskcode.defaultLang = null;
flaskcode.fallbackLang = null;
flaskcode.languages = flaskcode.languages || [];
flaskcode.defaultExt = flaskcode.defaultExt || 'txt';
flaskcode.defaultLangId = flaskcode.defaultLangId || 'plaintext';
flaskcode.defaultLang = flaskcode.defaultLang || null;
flaskcode.fallbackLang = flaskcode.fallbackLang || null;

flaskcode.$editorContainer = null;
flaskcode.$editorBody = null;
Expand Down Expand Up @@ -52,6 +52,12 @@ $(function () {
$('ul#dir-tree').treed();
flaskcode.setEditorState(flaskcode.editorStates.INIT);

require.config({
'vs/nls': {
'availableLanguages': flaskcode.availableLanguages
}
});

require(['vs/editor/editor.main'], function() {
flaskcode.languages = monaco.languages.getLanguages();
flaskcode.allowedLangIds = flaskcode.languages.map(function (lang) { return lang.id; });
Expand Down Expand Up @@ -99,11 +105,11 @@ $(function () {
case 'toggle_collapse':
options.$trigger.click();
break;

case 'open':
flaskcode.openResource(options.$trigger);
break;

case 'create_new_file':
flaskcode.openNewFileModal(options.$trigger);
break;
Expand All @@ -116,7 +122,7 @@ $(function () {
hide: function (options) {},
},
});

$('#fileNameModal').on('shown.bs.modal', function () {
$(this).find('#new_filename').focus();
});
Expand Down Expand Up @@ -459,7 +465,7 @@ flaskcode.saveResourceState = function () {
};

flaskcode.restoreResourceState = function () {
if (flaskcode.editorWidget.editor && flaskcode.editorWidget.editor.getModel()
if (flaskcode.editorWidget.editor && flaskcode.editorWidget.editor.getModel()
&& flaskcode.editorWidget.resourceName && flaskcode.storage.get(flaskcode.editorWidget.resourceName)) {
flaskcode.editorWidget.editor.restoreViewState(JSON.parse(flaskcode.storage.get(flaskcode.editorWidget.resourceName)));
}
Expand Down
Loading