publish API to allow manipulating list of allowed mime types for #192

This commit is contained in:
azivner 2018-10-07 14:25:17 +02:00
parent 5f95ab95c9
commit b09071eb9b
2 changed files with 62 additions and 37 deletions

View File

@ -5,6 +5,7 @@ import infoService from './info.js';
import linkService from './link.js';
import treeCache from './tree_cache.js';
import noteDetailService from './note_detail.js';
import noteTypeService from './note_type.js';
/**
* This is the main frontend API interface for scripts. It's published in the local "api" object.
@ -204,6 +205,24 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
* @param {function} func - callback called on note change as user is typing (not necessarily tied to save event)
*/
this.onNoteChange = noteDetailService.onNoteChange;
/**
* @method
* @returns {array} list of default code mime types
*/
this.getDefaultCodeMimeTypes = noteTypeService.getDefaultCodeMimeTypes;
/**
* @method
* @returns {array} list of currently used code mime types
*/
this.getCodeMimeTypes = noteTypeService.getCodeMimeTypes;
/**
* @method
* @param {array} types - list of mime types to be used
*/
this.setCodeMimeTypes = noteTypeService.setCodeMimeTypes;
}
export default FrontendScriptApi;

View File

@ -7,6 +7,43 @@ const $executeScriptButton = $("#execute-script-button");
const $toggleEditButton = $('#toggle-edit-button');
const $renderButton = $('#render-button');
const DEFAULT_MIME_TYPES = [
{ mime: 'text/x-csrc', title: 'C' },
{ mime: 'text/x-c++src', title: 'C++' },
{ mime: 'text/x-csharp', title: 'C#' },
{ mime: 'text/x-clojure', title: 'Clojure' },
{ mime: 'text/css', title: 'CSS' },
{ mime: 'text/x-dockerfile', title: 'Dockerfile' },
{ mime: 'text/x-erlang', title: 'Erlang' },
{ mime: 'text/x-feature', title: 'Gherkin' },
{ mime: 'text/x-go', title: 'Go' },
{ mime: 'text/x-groovy', title: 'Groovy' },
{ mime: 'text/x-haskell', title: 'Haskell' },
{ mime: 'text/html', title: 'HTML' },
{ mime: 'message/http', title: 'HTTP' },
{ mime: 'text/x-java', title: 'Java' },
{ mime: 'application/javascript;env=frontend', title: 'JavaScript frontend' },
{ mime: 'application/javascript;env=backend', title: 'JavaScript backend' },
{ mime: 'application/json', title: 'JSON' },
{ mime: 'text/x-kotlin', title: 'Kotlin' },
{ mime: 'text/x-stex', title: 'LaTex' },
{ mime: 'text/x-lua', title: 'Lua' },
{ mime: 'text/x-markdown', title: 'Markdown' },
{ mime: 'text/x-objectivec', title: 'Objective C' },
{ mime: 'text/x-pascal', title: 'Pascal' },
{ mime: 'text/x-perl', title: 'Perl' },
{ mime: 'text/x-php', title: 'PHP' },
{ mime: 'text/x-python', title: 'Python' },
{ mime: 'text/x-ruby', title: 'Ruby' },
{ mime: 'text/x-rustsrc', title: 'Rust' },
{ mime: 'text/x-scala', title: 'Scala' },
{ mime: 'text/x-sh', title: 'Shell' },
{ mime: 'text/x-sql', title: 'SQL' },
{ mime: 'text/x-swift', title: 'Swift' },
{ mime: 'text/xml', title: 'XML' },
{ mime: 'text/x-yaml', title: 'YAML' }
];
const noteTypeModel = new NoteTypeModel();
function NoteTypeModel() {
@ -15,42 +52,7 @@ function NoteTypeModel() {
this.type = ko.observable('text');
this.mime = ko.observable('');
this.codeMimeTypes = ko.observableArray([
{ mime: 'text/x-csrc', title: 'C' },
{ mime: 'text/x-c++src', title: 'C++' },
{ mime: 'text/x-csharp', title: 'C#' },
{ mime: 'text/x-clojure', title: 'Clojure' },
{ mime: 'text/css', title: 'CSS' },
{ mime: 'text/x-dockerfile', title: 'Dockerfile' },
{ mime: 'text/x-erlang', title: 'Erlang' },
{ mime: 'text/x-feature', title: 'Gherkin' },
{ mime: 'text/x-go', title: 'Go' },
{ mime: 'text/x-groovy', title: 'Groovy' },
{ mime: 'text/x-haskell', title: 'Haskell' },
{ mime: 'text/html', title: 'HTML' },
{ mime: 'message/http', title: 'HTTP' },
{ mime: 'text/x-java', title: 'Java' },
{ mime: 'application/javascript;env=frontend', title: 'JavaScript frontend' },
{ mime: 'application/javascript;env=backend', title: 'JavaScript backend' },
{ mime: 'application/json', title: 'JSON' },
{ mime: 'text/x-kotlin', title: 'Kotlin' },
{ mime: 'text/x-stex', title: 'LaTex' },
{ mime: 'text/x-lua', title: 'Lua' },
{ mime: 'text/x-markdown', title: 'Markdown' },
{ mime: 'text/x-objectivec', title: 'Objective C' },
{ mime: 'text/x-pascal', title: 'Pascal' },
{ mime: 'text/x-perl', title: 'Perl' },
{ mime: 'text/x-php', title: 'PHP' },
{ mime: 'text/x-python', title: 'Python' },
{ mime: 'text/x-ruby', title: 'Ruby' },
{ mime: 'text/x-rustsrc', title: 'Rust' },
{ mime: 'text/x-scala', title: 'Scala' },
{ mime: 'text/x-sh', title: 'Shell' },
{ mime: 'text/x-sql', title: 'SQL' },
{ mime: 'text/x-swift', title: 'Swift' },
{ mime: 'text/xml', title: 'XML' },
{ mime: 'text/x-yaml', title: 'YAML' }
]);
this.codeMimeTypes = ko.observableArray(DEFAULT_MIME_TYPES);
this.typeString = function() {
const type = self.type();
@ -149,5 +151,9 @@ export default {
noteTypeModel.mime(mime);
noteTypeModel.updateExecuteScriptButtonVisibility();
}
},
getDefaultCodeMimeTypes: () => DEFAULT_MIME_TYPES.slice(),
getCodeMimeTypes: () => noteTypeModel.codeMimeTypes(),
setCodeMimeTypes: types => noteTypeModel.codeMimeTypes(types)
};