mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
more reliable reimplementation of "create day sub note"
This commit is contained in:
parent
2b4413a1bd
commit
e1e020c1a4
@ -97,15 +97,10 @@ app.on('ready', async () => {
|
|||||||
mainWindow = await createMainWindow();
|
mainWindow = await createMainWindow();
|
||||||
|
|
||||||
const result = globalShortcut.register('CommandOrControl+Alt+P', cls.wrap(async () => {
|
const result = globalShortcut.register('CommandOrControl+Alt+P', cls.wrap(async () => {
|
||||||
const dateNoteService = require('./src/services/date_notes');
|
|
||||||
const dateUtils = require('./src/services/date_utils');
|
|
||||||
|
|
||||||
const parentNote = await dateNoteService.getDateNote(dateUtils.localNowDate());
|
|
||||||
|
|
||||||
// window may be hidden / not in focus
|
// window may be hidden / not in focus
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
|
|
||||||
mainWindow.webContents.send('create-day-sub-note', parentNote.noteId);
|
mainWindow.webContents.send('create-day-sub-note');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
@ -39,6 +39,7 @@ import linkService from './services/link.js';
|
|||||||
import noteAutocompleteService from './services/note_autocomplete.js';
|
import noteAutocompleteService from './services/note_autocomplete.js';
|
||||||
import macInit from './services/mac_init.js';
|
import macInit from './services/mac_init.js';
|
||||||
import cssLoader from './services/css_loader.js';
|
import cssLoader from './services/css_loader.js';
|
||||||
|
import dateNoteService from './services/date_notes.js';
|
||||||
|
|
||||||
// required for CKEditor image upload plugin
|
// required for CKEditor image upload plugin
|
||||||
window.glob.getActiveNode = treeService.getActiveNode;
|
window.glob.getActiveNode = treeService.getActiveNode;
|
||||||
@ -114,20 +115,14 @@ $("body").on("click", "a.external", function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (utils.isElectron()) {
|
if (utils.isElectron()) {
|
||||||
require('electron').ipcRenderer.on('create-day-sub-note', async function(event, parentNoteId) {
|
require('electron').ipcRenderer.on('create-day-sub-note', async function(event) {
|
||||||
await treeService.activateNote(parentNoteId);
|
const todayNote = await dateNoteService.getTodayNote();
|
||||||
|
const node = await treeService.expandToNote(todayNote.noteId);
|
||||||
|
|
||||||
setTimeout(async () => {
|
await treeService.createNote(node, todayNote.noteId, 'into', {
|
||||||
const parentNode = treeService.getActiveNode();
|
type: "text",
|
||||||
|
isProtected: node.data.isProtected
|
||||||
const {note} = await treeService.createNote(parentNode, parentNode.data.noteId, 'into', {
|
});
|
||||||
type: "text",
|
|
||||||
isProtected: parentNode.data.isProtected
|
|
||||||
});
|
|
||||||
|
|
||||||
await treeService.activateNote(note.noteId);
|
|
||||||
|
|
||||||
}, 500);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import utils from './utils.js';
|
|||||||
import server from './server.js';
|
import server from './server.js';
|
||||||
import infoService from "./info.js";
|
import infoService from "./info.js";
|
||||||
import treeCache from "./tree_cache.js";
|
import treeCache from "./tree_cache.js";
|
||||||
import treeBuilder from "./tree_builder.js";
|
|
||||||
|
|
||||||
async function moveBeforeNode(nodesToMove, beforeNode) {
|
async function moveBeforeNode(nodesToMove, beforeNode) {
|
||||||
nodesToMove = filterRootNote(nodesToMove);
|
nodesToMove = filterRootNote(nodesToMove);
|
||||||
|
41
src/public/javascripts/services/date_notes.js
Normal file
41
src/public/javascripts/services/date_notes.js
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import treeCache from "./tree_cache.js";
|
||||||
|
import server from "./server.js";
|
||||||
|
|
||||||
|
/** @return {NoteShort} */
|
||||||
|
async function getTodayNote() {
|
||||||
|
return await getDateNote(dayjs().format("YYYY-MM-DD"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return {NoteShort} */
|
||||||
|
async function getDateNote(date) {
|
||||||
|
const note = await server.get('date-notes/date/' + date);
|
||||||
|
|
||||||
|
await treeCache.reloadParents(note.noteId);
|
||||||
|
|
||||||
|
return await treeCache.getNote(note.noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return {NoteShort} */
|
||||||
|
async function getMonthNote(month) {
|
||||||
|
const note = await server.get('date-notes/month/' + month);
|
||||||
|
|
||||||
|
await treeCache.reloadParents(note.noteId);
|
||||||
|
|
||||||
|
return await treeCache.getNote(note.noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return {NoteShort} */
|
||||||
|
async function getYearNote(year) {
|
||||||
|
const note = await server.get('date-notes/year/' + year);
|
||||||
|
|
||||||
|
await treeCache.reloadParents(note.noteId);
|
||||||
|
|
||||||
|
return await treeCache.getNote(note.noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getTodayNote,
|
||||||
|
getDateNote,
|
||||||
|
getMonthNote,
|
||||||
|
getYearNote
|
||||||
|
}
|
@ -25,6 +25,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
|
|||||||
/** @property {object|null} entity whose event triggered this execution */
|
/** @property {object|null} entity whose event triggered this execution */
|
||||||
this.originEntity = originEntity;
|
this.originEntity = originEntity;
|
||||||
|
|
||||||
|
// to keep consistency with backend API
|
||||||
|
this.dayjs = dayjs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activates note in the tree and in the note detail.
|
* Activates note in the tree and in the note detail.
|
||||||
*
|
*
|
||||||
|
@ -817,5 +817,6 @@ export default {
|
|||||||
getNodesByNoteId,
|
getNodesByNoteId,
|
||||||
checkFolderStatus,
|
checkFolderStatus,
|
||||||
reloadNote,
|
reloadNote,
|
||||||
loadTreeCache
|
loadTreeCache,
|
||||||
|
expandToNote
|
||||||
};
|
};
|
21
src/routes/api/date_notes.js
Normal file
21
src/routes/api/date_notes.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const dateNoteService = require('../../services/date_notes');
|
||||||
|
|
||||||
|
async function getDateNote(req) {
|
||||||
|
return await dateNoteService.getDateNote(req.params.date);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getMonthNote(req) {
|
||||||
|
return await dateNoteService.getMonthNote(req.params.month);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getYearNote(req) {
|
||||||
|
return await dateNoteService.getYearNote(req.params.year);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getDateNote,
|
||||||
|
getMonthNote,
|
||||||
|
getYearNote
|
||||||
|
};
|
@ -30,6 +30,7 @@ const scriptRoute = require('./api/script');
|
|||||||
const senderRoute = require('./api/sender');
|
const senderRoute = require('./api/sender');
|
||||||
const filesRoute = require('./api/file_upload');
|
const filesRoute = require('./api/file_upload');
|
||||||
const searchRoute = require('./api/search');
|
const searchRoute = require('./api/search');
|
||||||
|
const dateNotesRoute = require('./api/date_notes');
|
||||||
|
|
||||||
const log = require('../services/log');
|
const log = require('../services/log');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
@ -153,6 +154,10 @@ function register(app) {
|
|||||||
apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames);
|
apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames);
|
||||||
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
|
apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute);
|
||||||
|
|
||||||
|
apiRoute(GET, '/api/date-notes/date/:date', dateNotesRoute.getDateNote);
|
||||||
|
apiRoute(GET, '/api/date-notes/month/:month', dateNotesRoute.getMonthNote);
|
||||||
|
apiRoute(GET, '/api/date-notes/year/:year', dateNotesRoute.getYearNote);
|
||||||
|
|
||||||
route(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
|
route(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
|
||||||
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);
|
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user