support for loading and saving type and mime

This commit is contained in:
azivner
2018-01-21 23:36:09 -05:00
parent f9631ff59f
commit e56fb6d2d4
8 changed files with 40 additions and 20 deletions

View File

@@ -70,6 +70,8 @@ const noteEditor = (function() {
}
else if (note.detail.type === 'code') {
note.detail.note_text = codeEditor.getValue();
codeEditor.setOption("mode", note.detail.mime);
}
else {
throwError("Unrecognized type: " + note.detail.type);
@@ -131,6 +133,9 @@ const noteEditor = (function() {
noteTitleEl.val(currentNote.detail.note_title);
noteType.setNoteType(currentNote.detail.type);
noteType.setNoteMime(currentNote.detail.mime);
if (currentNote.detail.type === 'text') {
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
editor.setData(currentNote.detail.note_text ? currentNote.detail.note_text : "<p></p>");
@@ -189,7 +194,6 @@ const noteEditor = (function() {
codeEditor = CodeMirror($("#note-detail-code")[0], {
value: "",
mode: "javascript",
viewportMargin: Infinity
});
@@ -205,18 +209,6 @@ const noteEditor = (function() {
noteDetailEl.attr("tabindex", 2);
});
$(document).bind('keydown', 'alt+q', async e => {
const note = getCurrentNote();
const type = note.detail.type;
const newType = type === "text" ? "code" : "text";
await server.put('notes/' + note.detail.note_id + '/type/' + newType);
await reload();
e.preventDefault();
});
setInterval(saveNoteIfChanged, 5000);
return {

View File

@@ -21,9 +21,11 @@ const noteType = (function() {
{ 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: 'text/javascript', title: 'JavaScript' },
{ mime: 'application/javascript', title: 'JavaScript' },
{ mime: 'application/json', title: 'JSON' },
{ mime: 'text/x-kotlin', title: 'Kotlin' },
{ mime: 'text/x-lua', title: 'Lua' },
{ mime: 'text/x-markdown', title: 'Markdown' },
@@ -64,24 +66,45 @@ const noteType = (function() {
}
};
async function save() {
const note = noteEditor.getCurrentNote();
await server.put('notes/' + note.detail.note_id
+ '/type/' + encodeURIComponent(self.type())
+ '/mime/' + encodeURIComponent(self.mime()));
await noteEditor.reload();
}
this.selectText = function() {
self.type('text');
self.mime('');
save();
};
this.selectCode = function() {
self.type('code');
self.mime('');
save();
};
this.selectCodeMime = function(el) {
self.type('code');
self.mime(el.mime);
save();
};
}
ko.applyBindings(noteTypeModel, document.getElementById('note-type'));
return {
getNoteType: () => noteTypeModel.type(),
setNoteType: type => noteTypeModel.type(type),
getNoteMime: () => noteTypeModel.mime(),
setNoteMime: mime => noteTypeModel.mime(mime)
};
})();