mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
options UI for selecting support code note MIME types
This commit is contained in:
parent
9d958e1860
commit
c8f59ea547
5
db/migrations/0141__add_code_note_mime_types.sql
Normal file
5
db/migrations/0141__add_code_note_mime_types.sql
Normal file
@ -0,0 +1,5 @@
|
||||
INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced)
|
||||
VALUES ('codeNotesMimeTypes', '["text/x-csrc","text/x-c++src","text/x-csharp","text/css","text/x-go","text/x-groovy","text/x-haskell","text/html","message/http","text/x-java","application/javascript;env=frontend","application/javascript;env=backend","application/json","text/x-kotlin","text/x-markdown","text/x-perl","text/x-php","text/x-python","text/x-ruby",null,"text/x-sql","text/x-swift","text/xml","text/x-yaml"]', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 1);
|
||||
|
||||
INSERT INTO sync (entityName, entityId, sourceId, utcSyncDate)
|
||||
VALUES ('options' ,'codeNotesMimeTypes', 'SYNC_FILL', '2018-01-01T00:00:00.000Z');
|
@ -17,6 +17,7 @@ export async function showDialog() {
|
||||
(await Promise.all([
|
||||
import('./options/advanced.js'),
|
||||
import('./options/appearance.js'),
|
||||
import('./options/code_notes.js'),
|
||||
import('./options/change_password.js'),
|
||||
import('./options/note_revisions.js'),
|
||||
import('./options/protected_session.js'),
|
||||
|
44
src/public/javascripts/dialogs/options/code_notes.js
Normal file
44
src/public/javascripts/dialogs/options/code_notes.js
Normal file
@ -0,0 +1,44 @@
|
||||
import server from "../../services/server.js";
|
||||
import mimeTypesService from "../../services/mime_types.js";
|
||||
import optionsService from "../../services/options.js";
|
||||
|
||||
export default class CodeNotesOptions {
|
||||
constructor() {
|
||||
this.$mimeTypes = $("#options-mime-types");
|
||||
}
|
||||
|
||||
async optionsLoaded(options) {
|
||||
this.$mimeTypes.empty();
|
||||
|
||||
let idCtr = 1;
|
||||
|
||||
for (const mimeType of await mimeTypesService.getMimeTypes()) {
|
||||
const id = "code-mime-type-" + (idCtr++);
|
||||
|
||||
this.$mimeTypes.append($("<li>")
|
||||
.append($('<input type="checkbox">')
|
||||
.attr("id", id)
|
||||
.attr("data-mime-type", mimeType.mime)
|
||||
.prop("checked", mimeType.enabled))
|
||||
.change(() => this.save())
|
||||
.append(" ")
|
||||
.append($('<label>')
|
||||
.attr("for", id)
|
||||
.text(mimeType.title))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
const enabledMimeTypes = [];
|
||||
|
||||
this.$mimeTypes.find("input:checked").each(
|
||||
(i, el) => enabledMimeTypes.push($(el).attr("data-mime-type")));
|
||||
|
||||
const opts = { codeNotesMimeTypes: JSON.stringify(enabledMimeTypes) };
|
||||
|
||||
await server.put('options', opts);
|
||||
|
||||
await optionsService.reloadOptions();
|
||||
}
|
||||
}
|
187
src/public/javascripts/services/mime_types.js
Normal file
187
src/public/javascripts/services/mime_types.js
Normal file
@ -0,0 +1,187 @@
|
||||
import optionsService from "./options.js";
|
||||
|
||||
const MIME_TYPES_DICT = [
|
||||
{ title: "APL", mime: "text/apl" },
|
||||
{ title: "PGP", mime: "application/pgp" },
|
||||
{ title: "ASN.1", mime: "text/x-ttcn-asn" },
|
||||
{ title: "Asterisk", mime: "text/x-asterisk" },
|
||||
{ title: "Brainfuck", mime: "text/x-brainfuck" },
|
||||
{ default: true, title: "C", mime: "text/x-csrc" },
|
||||
{ default: true, title: "C++", mime: "text/x-c++src" },
|
||||
{ title: "Cobol", mime: "text/x-cobol" },
|
||||
{ default: true, title: "C#", mime: "text/x-csharp" },
|
||||
{ title: "Clojure", mime: "text/x-clojure" },
|
||||
{ title: "ClojureScript", mime: "text/x-clojurescript" },
|
||||
{ title: "Closure Stylesheets (GSS)", mime: "text/x-gss" },
|
||||
{ title: "CMake", mime: "text/x-cmake" },
|
||||
{ title: "CoffeeScript", mime: "text/coffeescript" },
|
||||
{ title: "Common Lisp", mime: "text/x-common-lisp" },
|
||||
{ title: "Cypher", mime: "application/x-cypher-query" },
|
||||
{ title: "Cython", mime: "text/x-cython" },
|
||||
{ title: "Crystal", mime: "text/x-crystal" },
|
||||
{ default: true, title: "CSS", mime: "text/css" },
|
||||
{ title: "CQL", mime: "text/x-cassandra" },
|
||||
{ title: "D", mime: "text/x-d" },
|
||||
{ title: "Dart", mime: "application/dart" },
|
||||
{ title: "diff", mime: "text/x-diff" },
|
||||
{ title: "Django", mime: "text/x-django" },
|
||||
{ title: "Dockerfile", mime: "text/x-dockerfile" },
|
||||
{ title: "DTD", mime: "application/xml-dtd" },
|
||||
{ title: "Dylan", mime: "text/x-dylan" },
|
||||
{ title: "EBNF", mime: "text/x-ebnf" },
|
||||
{ title: "ECL", mime: "text/x-ecl" },
|
||||
{ title: "edn", mime: "application/edn" },
|
||||
{ title: "Eiffel", mime: "text/x-eiffel" },
|
||||
{ title: "Elm", mime: "text/x-elm" },
|
||||
{ title: "Embedded Javascript", mime: "application/x-ejs" },
|
||||
{ title: "Embedded Ruby", mime: "application/x-erb" },
|
||||
{ title: "Erlang", mime: "text/x-erlang" },
|
||||
{ title: "Esper", mime: "text/x-esper" },
|
||||
{ title: "Factor", mime: "text/x-factor" },
|
||||
{ title: "FCL", mime: "text/x-fcl" },
|
||||
{ title: "Forth", mime: "text/x-forth" },
|
||||
{ title: "Fortran", mime: "text/x-fortran" },
|
||||
{ title: "F#", mime: "text/x-fsharp" },
|
||||
{ title: "Gas", mime: "text/x-gas" },
|
||||
{ title: "Gherkin", mime: "text/x-feature" },
|
||||
{ title: "GitHub Flavored Markdown", mime: "text/x-gfm" },
|
||||
{ default: true, title: "Go", mime: "text/x-go" },
|
||||
{ default: true, title: "Groovy", mime: "text/x-groovy" },
|
||||
{ title: "HAML", mime: "text/x-haml" },
|
||||
{ default: true, title: "Haskell", mime: "text/x-haskell" },
|
||||
{ title: "Haskell (Literate)", mime: "text/x-literate-haskell" },
|
||||
{ title: "Haxe", mime: "text/x-haxe" },
|
||||
{ title: "HXML", mime: "text/x-hxml" },
|
||||
{ title: "ASP.NET", mime: "application/x-aspx" },
|
||||
{ default: true, title: "HTML", mime: "text/html" },
|
||||
{ default: true, title: "HTTP", mime: "message/http" },
|
||||
{ title: "IDL", mime: "text/x-idl" },
|
||||
{ title: "Pug", mime: "text/x-pug" },
|
||||
{ default: true, title: "Java", mime: "text/x-java" },
|
||||
{ title: "Java Server Pages", mime: "application/x-jsp" },
|
||||
{ default: true, title: 'JavaScript frontend', mime: 'application/javascript;env=frontend' },
|
||||
{ default: true, title: 'JavaScript backend', mime: 'application/javascript;env=backend' },
|
||||
{ default: true, title: "JSON", mime: "application/json" },
|
||||
{ title: "JSON-LD", mime: "application/ld+json" },
|
||||
{ title: "JSX", mime: "text/jsx" },
|
||||
{ title: "Jinja2", mime: "text/jinja2" },
|
||||
{ title: "Julia", mime: "text/x-julia" },
|
||||
{ default: true, title: "Kotlin", mime: "text/x-kotlin" },
|
||||
{ title: "LESS", mime: "text/x-less" },
|
||||
{ title: "LiveScript", mime: "text/x-livescript" },
|
||||
{ title: "Lua", mime: "text/x-lua" },
|
||||
{ default: true, title: "Markdown", mime: "text/x-markdown" },
|
||||
{ title: "mIRC", mime: "text/mirc" },
|
||||
{ title: "MariaDB SQL", mime: "text/x-mariadb" },
|
||||
{ title: "Mathematica", mime: "text/x-mathematica" },
|
||||
{ title: "Modelica", mime: "text/x-modelica" },
|
||||
{ title: "MUMPS", mime: "text/x-mumps" },
|
||||
{ title: "MS SQL", mime: "text/x-mssql" },
|
||||
{ title: "mbox", mime: "application/mbox" },
|
||||
{ title: "MySQL", mime: "text/x-mysql" },
|
||||
{ title: "Nginx", mime: "text/x-nginx-conf" },
|
||||
{ title: "NSIS", mime: "text/x-nsis" },
|
||||
{ title: "NTriples", mime: "application/n-triples" },
|
||||
{ title: "Objective-C", mime: "text/x-objectivec" },
|
||||
{ title: "OCaml", mime: "text/x-ocaml" },
|
||||
{ title: "Octave", mime: "text/x-octave" },
|
||||
{ title: "Oz", mime: "text/x-oz" },
|
||||
{ title: "Pascal", mime: "text/x-pascal" },
|
||||
{ title: "PEG.js", mime: "null" },
|
||||
{ default: true, title: "Perl", mime: "text/x-perl" },
|
||||
{ default: true, title: "PHP", mime: "text/x-php" },
|
||||
{ title: "Pig", mime: "text/x-pig" },
|
||||
{ title: "Plain Text", mime: "text/plain" },
|
||||
{ title: "PLSQL", mime: "text/x-plsql" },
|
||||
{ title: "PostgreSQL", mime: "text/x-pgsql" },
|
||||
{ title: "PowerShell", mime: "application/x-powershell" },
|
||||
{ title: "Properties files", mime: "text/x-properties" },
|
||||
{ title: "ProtoBuf", mime: "text/x-protobuf" },
|
||||
{ default: true, title: "Python", mime: "text/x-python" },
|
||||
{ title: "Puppet", mime: "text/x-puppet" },
|
||||
{ title: "Q", mime: "text/x-q" },
|
||||
{ title: "R", mime: "text/x-rsrc" },
|
||||
{ title: "reStructuredText", mime: "text/x-rst" },
|
||||
{ title: "RPM Changes", mime: "text/x-rpm-changes" },
|
||||
{ title: "RPM Spec", mime: "text/x-rpm-spec" },
|
||||
{ default: true, title: "Ruby", mime: "text/x-ruby" },
|
||||
{ title: "Rust", mime: "text/x-rustsrc" },
|
||||
{ title: "SAS", mime: "text/x-sas" },
|
||||
{ title: "Sass", mime: "text/x-sass" },
|
||||
{ title: "Scala", mime: "text/x-scala" },
|
||||
{ title: "Scheme", mime: "text/x-scheme" },
|
||||
{ title: "SCSS", mime: "text/x-scss" },
|
||||
{ default: true, title: "Shell", mimes: "text/x-sh" },
|
||||
{ title: "Sieve", mime: "application/sieve" },
|
||||
{ title: "Slim", mime: "text/x-slim" },
|
||||
{ title: "Smalltalk", mime: "text/x-stsrc" },
|
||||
{ title: "Smarty", mime: "text/x-smarty" },
|
||||
{ title: "Solr", mime: "text/x-solr" },
|
||||
{ title: "SML", mime: "text/x-sml" },
|
||||
{ title: "Soy", mime: "text/x-soy" },
|
||||
{ title: "SPARQL", mime: "application/sparql-query" },
|
||||
{ title: "Spreadsheet", mime: "text/x-spreadsheet" },
|
||||
{ default: true, title: "SQL", mime: "text/x-sql" },
|
||||
{ title: "SQLite", mime: "text/x-sqlite" },
|
||||
{ title: "Squirrel", mime: "text/x-squirrel" },
|
||||
{ title: "Stylus", mime: "text/x-styl" },
|
||||
{ default: true, title: "Swift", mime: "text/x-swift" },
|
||||
{ title: "sTeX", mime: "text/x-stex" },
|
||||
{ title: "LaTeX", mime: "text/x-latex" },
|
||||
{ title: "SystemVerilog", mime: "text/x-systemverilog" },
|
||||
{ title: "Tcl", mime: "text/x-tcl" },
|
||||
{ title: "Textile", mime: "text/x-textile" },
|
||||
{ title: "TiddlyWiki ", mime: "text/x-tiddlywiki" },
|
||||
{ title: "Tiki wiki", mime: "text/tiki" },
|
||||
{ title: "TOML", mime: "text/x-toml" },
|
||||
{ title: "Tornado", mime: "text/x-tornado" },
|
||||
{ title: "troff", mime: "text/troff" },
|
||||
{ title: "TTCN", mime: "text/x-ttcn" },
|
||||
{ title: "TTCN_CFG", mime: "text/x-ttcn-cfg" },
|
||||
{ title: "Turtle", mime: "text/turtle" },
|
||||
{ title: "TypeScript", mime: "application/typescript" },
|
||||
{ title: "TypeScript-JSX", mime: "text/typescript-jsx" },
|
||||
{ title: "Twig", mime: "text/x-twig" },
|
||||
{ title: "Web IDL", mime: "text/x-webidl" },
|
||||
{ title: "VB.NET", mime: "text/x-vb" },
|
||||
{ title: "VBScript", mime: "text/vbscript" },
|
||||
{ title: "Velocity", mime: "text/velocity" },
|
||||
{ title: "Verilog", mime: "text/x-verilog" },
|
||||
{ title: "VHDL", mime: "text/x-vhdl" },
|
||||
{ title: "Vue.js Component", mime: "text/x-vue" },
|
||||
{ default: true, title: "XML", mime: "text/xml" },
|
||||
{ title: "XQuery", mime: "application/xquery" },
|
||||
{ title: "Yacas", mime: "text/x-yacas" },
|
||||
{ default: true, title: "YAML", mime: "text/x-yaml" },
|
||||
{ title: "Z80", mime: "text/x-z80" },
|
||||
{ title: "mscgen", mime: "text/x-mscgen" },
|
||||
{ title: "xu", mime: "text/x-xu" },
|
||||
{ title: "msgenny", mime: "text/x-msgenny" }
|
||||
];
|
||||
|
||||
let mimeTypes = null;
|
||||
|
||||
function loadMimeTypes(options) {
|
||||
mimeTypes = JSON.parse(JSON.stringify(MIME_TYPES_DICT)); // clone
|
||||
|
||||
const enabledMimeTypes = options.getJson('codeNotesMimeTypes')
|
||||
|| MIME_TYPES_DICT.filter(mt => mt.default).map(mt => mt.mime);
|
||||
|
||||
for (const mt of mimeTypes) {
|
||||
mt.enabled = enabledMimeTypes.includes(mt.mime);
|
||||
}
|
||||
}
|
||||
|
||||
optionsService.addLoadListener(loadMimeTypes);
|
||||
|
||||
async function getMimeTypes() {
|
||||
if (mimeTypes === null) {
|
||||
loadMimeTypes(await options.waitForOptions());
|
||||
}
|
||||
|
||||
return mimeTypes;
|
||||
}
|
||||
|
||||
export default {
|
||||
getMimeTypes
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import treeService from './tree.js';
|
||||
import noteDetailService from './note_detail.js';
|
||||
import server from './server.js';
|
||||
import mimeTypesService from './mime_types.js';
|
||||
|
||||
const NOTE_TYPES = [
|
||||
{ type: "file", title: "File", selectable: false },
|
||||
@ -13,64 +14,6 @@ const NOTE_TYPES = [
|
||||
{ type: "code", mime: 'text/plain', title: "Code", selectable: true }
|
||||
];
|
||||
|
||||
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' }
|
||||
];
|
||||
|
||||
let mimeTypes = null;
|
||||
|
||||
async function getMimeTypes() {
|
||||
if (!mimeTypes) {
|
||||
let customCodeMimeTypes = [];
|
||||
|
||||
try {
|
||||
customCodeMimeTypes = await server.get('custom-code-mime-types');
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Could not retrieve custom mime types: ${e.message}`);
|
||||
}
|
||||
|
||||
mimeTypes = DEFAULT_MIME_TYPES.concat(customCodeMimeTypes);
|
||||
|
||||
mimeTypes.sort((a, b) => a.title < b.title ? -1 : 1);
|
||||
}
|
||||
|
||||
return mimeTypes;
|
||||
}
|
||||
|
||||
export default class NoteTypeContext {
|
||||
/**
|
||||
* @param {TabContext} ctx
|
||||
@ -121,7 +64,11 @@ export default class NoteTypeContext {
|
||||
}
|
||||
}
|
||||
|
||||
for (const mimeType of await getMimeTypes()) {
|
||||
for (const mimeType of await mimeTypesService.getMimeTypes()) {
|
||||
if (!mimeType.enabled) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const $mimeLink = $('<a class="dropdown-item">')
|
||||
.attr("data-mime-type", mimeType.mime)
|
||||
.append('<span class="check">✓</span> ')
|
||||
@ -143,7 +90,7 @@ export default class NoteTypeContext {
|
||||
|
||||
async findTypeTitle(type, mime) {
|
||||
if (type === 'code') {
|
||||
const mimeTypes = await getMimeTypes();
|
||||
const mimeTypes = await mimeTypesService.getMimeTypes();
|
||||
const found = mimeTypes.find(mt => mt.mime === mime);
|
||||
|
||||
return found ? found.title : mime;
|
||||
|
@ -32,7 +32,7 @@ class LinkMapWidget extends StandardWidget {
|
||||
|
||||
this.linkMapService = new LinkMapServiceClass(this.ctx.note, $linkMapContainer, {
|
||||
maxDepth: 1,
|
||||
zoom: 0.7
|
||||
zoom: 0.8
|
||||
});
|
||||
|
||||
await this.linkMapService.render();
|
||||
|
@ -1,24 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const attributesService = require('../../services/attributes');
|
||||
const log = require('../../services/log');
|
||||
|
||||
async function get() {
|
||||
const notes = await attributesService.getNotesWithLabel('codeMimeTypes');
|
||||
let merged = [];
|
||||
|
||||
for (const note of notes) {
|
||||
try {
|
||||
merged = merged.concat(await note.getJsonContent());
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Cannot merge mime types from note=${note.noteId}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get
|
||||
};
|
@ -28,7 +28,8 @@ const ALLOWED_OPTIONS = [
|
||||
'attributesWidget',
|
||||
'linkMapWidget',
|
||||
'noteRevisionsWidget',
|
||||
'whatLinksHereWidget'
|
||||
'whatLinksHereWidget',
|
||||
'codeNotesMimeTypes'
|
||||
];
|
||||
|
||||
async function getOptions() {
|
||||
|
@ -236,8 +236,6 @@ function register(app) {
|
||||
route(POST, '/api/clipper/notes', clipperMiddleware, clipperRoute.createNote, apiResultHandler);
|
||||
route(POST, '/api/clipper/open/:noteId', clipperMiddleware, clipperRoute.openNote, apiResultHandler);
|
||||
|
||||
apiRoute(GET, '/api/custom-code-mime-types', customCodeMimeTypesRoute.get);
|
||||
|
||||
app.use('', router);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
const {TRILIUM_DATA_DIR} = require('./data_dir');
|
||||
|
||||
const APP_DB_VERSION = 140;
|
||||
const APP_DB_VERSION = 141;
|
||||
const SYNC_VERSION = 10;
|
||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#options-sidebar">Sidebar</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#options-code-notes">Code notes</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-toggle="tab" href="#options-change-password">Change password</a>
|
||||
</li>
|
||||
@ -36,6 +39,7 @@
|
||||
<div class="tab-content">
|
||||
<% include options/appearance.ejs %>
|
||||
<% include options/sidebar.ejs %>
|
||||
<% include options/code_notes.ejs %>
|
||||
<% include options/change_password.ejs %>
|
||||
<% include options/protected_session.ejs %>
|
||||
<% include options/note_revisions.ejs %>
|
||||
|
5
src/views/dialogs/options/code_notes.ejs
Normal file
5
src/views/dialogs/options/code_notes.ejs
Normal file
@ -0,0 +1,5 @@
|
||||
<div id="options-code-notes" class="tab-pane">
|
||||
<h4>Available MIME types in the dropdown</h4>
|
||||
|
||||
<ul id="options-mime-types" style="max-height: 500px; overflow: auto; list-style-type: none;"></ul>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user