mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
support for loading and saving type and mime
This commit is contained in:
parent
f9631ff59f
commit
e56fb6d2d4
1
migrations/0069__add_mime_to_note.sql
Normal file
1
migrations/0069__add_mime_to_note.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE notes ADD COLUMN mime TEXT NOT NULL DEFAULT 'text/html';
|
@ -70,6 +70,8 @@ const noteEditor = (function() {
|
|||||||
}
|
}
|
||||||
else if (note.detail.type === 'code') {
|
else if (note.detail.type === 'code') {
|
||||||
note.detail.note_text = codeEditor.getValue();
|
note.detail.note_text = codeEditor.getValue();
|
||||||
|
|
||||||
|
codeEditor.setOption("mode", note.detail.mime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throwError("Unrecognized type: " + note.detail.type);
|
throwError("Unrecognized type: " + note.detail.type);
|
||||||
@ -131,6 +133,9 @@ const noteEditor = (function() {
|
|||||||
|
|
||||||
noteTitleEl.val(currentNote.detail.note_title);
|
noteTitleEl.val(currentNote.detail.note_title);
|
||||||
|
|
||||||
|
noteType.setNoteType(currentNote.detail.type);
|
||||||
|
noteType.setNoteMime(currentNote.detail.mime);
|
||||||
|
|
||||||
if (currentNote.detail.type === 'text') {
|
if (currentNote.detail.type === 'text') {
|
||||||
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
|
// temporary workaround for https://github.com/ckeditor/ckeditor5-enter/issues/49
|
||||||
editor.setData(currentNote.detail.note_text ? currentNote.detail.note_text : "<p></p>");
|
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], {
|
codeEditor = CodeMirror($("#note-detail-code")[0], {
|
||||||
value: "",
|
value: "",
|
||||||
mode: "javascript",
|
|
||||||
viewportMargin: Infinity
|
viewportMargin: Infinity
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -205,18 +209,6 @@ const noteEditor = (function() {
|
|||||||
noteDetailEl.attr("tabindex", 2);
|
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);
|
setInterval(saveNoteIfChanged, 5000);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -21,9 +21,11 @@ const noteType = (function() {
|
|||||||
{ mime: 'text/x-go', title: 'Go' },
|
{ mime: 'text/x-go', title: 'Go' },
|
||||||
{ mime: 'text/x-groovy', title: 'Groovy' },
|
{ mime: 'text/x-groovy', title: 'Groovy' },
|
||||||
{ mime: 'text/x-haskell', title: 'Haskell' },
|
{ mime: 'text/x-haskell', title: 'Haskell' },
|
||||||
|
{ mime: 'text/html', title: 'HTML' },
|
||||||
{ mime: 'message/http', title: 'HTTP' },
|
{ mime: 'message/http', title: 'HTTP' },
|
||||||
{ mime: 'text/x-java', title: 'Java' },
|
{ 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-kotlin', title: 'Kotlin' },
|
||||||
{ mime: 'text/x-lua', title: 'Lua' },
|
{ mime: 'text/x-lua', title: 'Lua' },
|
||||||
{ mime: 'text/x-markdown', title: 'Markdown' },
|
{ 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() {
|
this.selectText = function() {
|
||||||
self.type('text');
|
self.type('text');
|
||||||
self.mime('');
|
self.mime('');
|
||||||
|
|
||||||
|
save();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectCode = function() {
|
this.selectCode = function() {
|
||||||
self.type('code');
|
self.type('code');
|
||||||
self.mime('');
|
self.mime('');
|
||||||
|
|
||||||
|
save();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.selectCodeMime = function(el) {
|
this.selectCodeMime = function(el) {
|
||||||
self.type('code');
|
self.type('code');
|
||||||
self.mime(el.mime);
|
self.mime(el.mime);
|
||||||
|
|
||||||
|
save();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ko.applyBindings(noteTypeModel, document.getElementById('note-type'));
|
ko.applyBindings(noteTypeModel, document.getElementById('note-type'));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
getNoteType: () => noteTypeModel.type(),
|
||||||
|
setNoteType: type => noteTypeModel.type(type),
|
||||||
|
|
||||||
|
getNoteMime: () => noteTypeModel.mime(),
|
||||||
|
setNoteMime: mime => noteTypeModel.mime(mime)
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -77,8 +77,7 @@ async function importNotes(dir, parentNoteId) {
|
|||||||
note_position: notePos,
|
note_position: notePos,
|
||||||
is_expanded: 0,
|
is_expanded: 0,
|
||||||
is_deleted: 0,
|
is_deleted: 0,
|
||||||
date_modified: now,
|
date_modified: now
|
||||||
type: 'text'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await sync_table.addNoteTreeSync(noteTreeId);
|
await sync_table.addNoteTreeSync(noteTreeId);
|
||||||
@ -89,6 +88,8 @@ async function importNotes(dir, parentNoteId) {
|
|||||||
note_text: noteText,
|
note_text: noteText,
|
||||||
is_deleted: 0,
|
is_deleted: 0,
|
||||||
is_protected: 0,
|
is_protected: 0,
|
||||||
|
type: 'text',
|
||||||
|
mime: 'text/html',
|
||||||
date_created: now,
|
date_created: now,
|
||||||
date_modified: now
|
date_modified: now
|
||||||
});
|
});
|
||||||
|
@ -93,14 +93,15 @@ router.put('/:noteId/protect-sub-tree/:isProtected', auth.checkApiAuth, wrap(asy
|
|||||||
res.send({});
|
res.send({});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.put('/:noteId/type/:type', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.put('/:noteId/type/:type/mime/:mime', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
const noteId = req.params.noteId;
|
const noteId = req.params.noteId;
|
||||||
const type = req.params.type;
|
const type = req.params.type;
|
||||||
|
const mime = req.params.mime;
|
||||||
const sourceId = req.headers.source_id;
|
const sourceId = req.headers.source_id;
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
await sql.doInTransaction(async () => {
|
||||||
await sql.execute("UPDATE notes SET type = ?, date_modified = ? WHERE note_id = ?",
|
await sql.execute("UPDATE notes SET type = ?, mime = ?, date_modified = ? WHERE note_id = ?",
|
||||||
[type, utils.nowDate(), noteId]);
|
[type, mime, utils.nowDate(), noteId]);
|
||||||
|
|
||||||
await sync_table.addNoteSync(noteId, sourceId);
|
await sync_table.addNoteSync(noteId, sourceId);
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const build = require('./build');
|
const build = require('./build');
|
||||||
const packageJson = require('../package');
|
const packageJson = require('../package');
|
||||||
|
|
||||||
const APP_DB_VERSION = 68;
|
const APP_DB_VERSION = 69;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
app_version: packageJson.version,
|
app_version: packageJson.version,
|
||||||
|
@ -40,6 +40,7 @@ async function createNewNote(parentNoteId, note, sourceId) {
|
|||||||
note_text: note.note_text ? note.note_text : '',
|
note_text: note.note_text ? note.note_text : '',
|
||||||
is_protected: note.is_protected,
|
is_protected: note.is_protected,
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
mime: 'text/html',
|
||||||
date_created: now,
|
date_created: now,
|
||||||
date_modified: now
|
date_modified: now
|
||||||
});
|
});
|
||||||
|
@ -441,6 +441,7 @@
|
|||||||
<script src="libraries/codemirror/codemirror.js"></script>
|
<script src="libraries/codemirror/codemirror.js"></script>
|
||||||
<link rel="stylesheet" href="libraries/codemirror/codemirror.css">
|
<link rel="stylesheet" href="libraries/codemirror/codemirror.css">
|
||||||
<script src="libraries/codemirror/mode/javascript/javascript.js"></script>
|
<script src="libraries/codemirror/mode/javascript/javascript.js"></script>
|
||||||
|
<script src="libraries/codemirror/mode/xml/xml.js"></script>
|
||||||
|
|
||||||
<link href="stylesheets/style.css" rel="stylesheet">
|
<link href="stylesheets/style.css" rel="stylesheet">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user