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 linkService from './link.js';
import treeCache from './tree_cache.js'; import treeCache from './tree_cache.js';
import noteDetailService from './note_detail.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. * 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) * @param {function} func - callback called on note change as user is typing (not necessarily tied to save event)
*/ */
this.onNoteChange = noteDetailService.onNoteChange; 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; export default FrontendScriptApi;

View File

@ -7,15 +7,7 @@ const $executeScriptButton = $("#execute-script-button");
const $toggleEditButton = $('#toggle-edit-button'); const $toggleEditButton = $('#toggle-edit-button');
const $renderButton = $('#render-button'); const $renderButton = $('#render-button');
const noteTypeModel = new NoteTypeModel(); const DEFAULT_MIME_TYPES = [
function NoteTypeModel() {
const self = this;
this.type = ko.observable('text');
this.mime = ko.observable('');
this.codeMimeTypes = ko.observableArray([
{ mime: 'text/x-csrc', title: 'C' }, { mime: 'text/x-csrc', title: 'C' },
{ mime: 'text/x-c++src', title: 'C++' }, { mime: 'text/x-c++src', title: 'C++' },
{ mime: 'text/x-csharp', title: 'C#' }, { mime: 'text/x-csharp', title: 'C#' },
@ -50,7 +42,17 @@ function NoteTypeModel() {
{ mime: 'text/x-swift', title: 'Swift' }, { mime: 'text/x-swift', title: 'Swift' },
{ mime: 'text/xml', title: 'XML' }, { mime: 'text/xml', title: 'XML' },
{ mime: 'text/x-yaml', title: 'YAML' } { mime: 'text/x-yaml', title: 'YAML' }
]); ];
const noteTypeModel = new NoteTypeModel();
function NoteTypeModel() {
const self = this;
this.type = ko.observable('text');
this.mime = ko.observable('');
this.codeMimeTypes = ko.observableArray(DEFAULT_MIME_TYPES);
this.typeString = function() { this.typeString = function() {
const type = self.type(); const type = self.type();
@ -149,5 +151,9 @@ export default {
noteTypeModel.mime(mime); noteTypeModel.mime(mime);
noteTypeModel.updateExecuteScriptButtonVisibility(); noteTypeModel.updateExecuteScriptButtonVisibility();
} },
getDefaultCodeMimeTypes: () => DEFAULT_MIME_TYPES.slice(),
getCodeMimeTypes: () => noteTypeModel.codeMimeTypes(),
setCodeMimeTypes: types => noteTypeModel.codeMimeTypes(types)
}; };