mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
allow per workspace calendars, fixes #2959
This commit is contained in:
parent
4c93334d90
commit
3ebfaec1bc
@ -204,6 +204,7 @@ const ATTR_HELP = {
|
|||||||
"workspace": "marks this note as a workspace which allows easy hoisting",
|
"workspace": "marks this note as a workspace which allows easy hoisting",
|
||||||
"workspaceIconClass": "defines box icon CSS class which will be used in tab when hoisted to this note",
|
"workspaceIconClass": "defines box icon CSS class which will be used in tab when hoisted to this note",
|
||||||
"workspaceTabBackgroundColor": "CSS color used in the note tab when hoisted to this note",
|
"workspaceTabBackgroundColor": "CSS color used in the note tab when hoisted to this note",
|
||||||
|
"workspaceCalendarRoot": "Defines per-workspace calendar root",
|
||||||
"searchHome": "new search notes will be created as children of this note",
|
"searchHome": "new search notes will be created as children of this note",
|
||||||
"hoistedSearchHome": "new search notes will be created as children of this note when hoisted to some ancestor of this note",
|
"hoistedSearchHome": "new search notes will be created as children of this note when hoisted to some ancestor of this note",
|
||||||
"inbox": "default inbox location for new notes",
|
"inbox": "default inbox location for new notes",
|
||||||
|
@ -29,6 +29,7 @@ module.exports = [
|
|||||||
{ type: 'label', name: 'workspace' },
|
{ type: 'label', name: 'workspace' },
|
||||||
{ type: 'label', name: 'workspaceIconClass' },
|
{ type: 'label', name: 'workspaceIconClass' },
|
||||||
{ type: 'label', name: 'workspaceTabBackgroundColor' },
|
{ type: 'label', name: 'workspaceTabBackgroundColor' },
|
||||||
|
{ type: 'label', name: 'workspaceCalendarRoot' },
|
||||||
{ type: 'label', name: 'searchHome' },
|
{ type: 'label', name: 'searchHome' },
|
||||||
{ type: 'label', name: 'hoistedInbox' },
|
{ type: 'label', name: 'hoistedInbox' },
|
||||||
{ type: 'label', name: 'hoistedSearchHome' },
|
{ type: 'label', name: 'hoistedSearchHome' },
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const noteService = require('./notes');
|
const noteService = require('./notes');
|
||||||
|
const becca = require('../becca/becca');
|
||||||
const attributeService = require('./attributes');
|
const attributeService = require('./attributes');
|
||||||
const dateUtils = require('./date_utils');
|
const dateUtils = require('./date_utils');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const protectedSessionService = require('./protected_session');
|
const protectedSessionService = require('./protected_session');
|
||||||
|
const cls = require("./cls");
|
||||||
|
const searchService = require('../services/search/services/search');
|
||||||
|
const SearchContext = require('../services/search/search_context');
|
||||||
|
|
||||||
const CALENDAR_ROOT_LABEL = 'calendarRoot';
|
const CALENDAR_ROOT_LABEL = 'calendarRoot';
|
||||||
const YEAR_LABEL = 'yearNote';
|
const YEAR_LABEL = 'yearNote';
|
||||||
@ -26,7 +30,15 @@ function createNote(parentNote, noteTitle) {
|
|||||||
|
|
||||||
/** @returns {Note} */
|
/** @returns {Note} */
|
||||||
function getRootCalendarNote() {
|
function getRootCalendarNote() {
|
||||||
let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
|
let rootNote;
|
||||||
|
|
||||||
|
if (cls.getHoistedNoteId() !== 'root') {
|
||||||
|
rootNote = searchService.findFirstNoteWithQuery('#workspaceCalendarRoot', new SearchContext({ignoreHoistedNote: false}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rootNote === null) {
|
||||||
|
rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
|
||||||
|
}
|
||||||
|
|
||||||
if (!rootNote) {
|
if (!rootNote) {
|
||||||
sql.transactional(() => {
|
sql.transactional(() => {
|
||||||
@ -55,7 +67,8 @@ function getYearNote(dateStr, rootNote = null) {
|
|||||||
|
|
||||||
const yearStr = dateStr.trim().substr(0, 4);
|
const yearStr = dateStr.trim().substr(0, 4);
|
||||||
|
|
||||||
let yearNote = attributeService.getNoteWithLabel(YEAR_LABEL, yearStr);
|
let yearNote = searchService.findFirstNoteWithQuery(`#${YEAR_LABEL}="${yearStr}"`,
|
||||||
|
new SearchContext({ancestorNoteId: rootNote.noteId}));
|
||||||
|
|
||||||
if (yearNote) {
|
if (yearNote) {
|
||||||
return yearNote;
|
return yearNote;
|
||||||
@ -95,7 +108,8 @@ function getMonthNote(dateStr, rootNote = null) {
|
|||||||
const monthStr = dateStr.substr(0, 7);
|
const monthStr = dateStr.substr(0, 7);
|
||||||
const monthNumber = dateStr.substr(5, 2);
|
const monthNumber = dateStr.substr(5, 2);
|
||||||
|
|
||||||
let monthNote = attributeService.getNoteWithLabel(MONTH_LABEL, monthStr);
|
let monthNote = searchService.findFirstNoteWithQuery(`#${MONTH_LABEL}="${monthStr}"`,
|
||||||
|
new SearchContext({ancestorNoteId: rootNote.noteId}));
|
||||||
|
|
||||||
if (monthNote) {
|
if (monthNote) {
|
||||||
return monthNote;
|
return monthNote;
|
||||||
@ -137,15 +151,16 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) {
|
|||||||
|
|
||||||
/** @returns {Note} */
|
/** @returns {Note} */
|
||||||
function getDayNote(dateStr) {
|
function getDayNote(dateStr) {
|
||||||
|
const rootNote = getRootCalendarNote();
|
||||||
dateStr = dateStr.trim().substr(0, 10);
|
dateStr = dateStr.trim().substr(0, 10);
|
||||||
|
|
||||||
let dateNote = attributeService.getNoteWithLabel(DATE_LABEL, dateStr);
|
let dateNote = searchService.findFirstNoteWithQuery(`#${DATE_LABEL}="${dateStr}"`,
|
||||||
|
new SearchContext({ancestorNoteId: rootNote.noteId}));
|
||||||
|
|
||||||
if (dateNote) {
|
if (dateNote) {
|
||||||
return dateNote;
|
return dateNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootNote = getRootCalendarNote();
|
|
||||||
const monthNote = getMonthNote(dateStr, rootNote);
|
const monthNote = getMonthNote(dateStr, rootNote);
|
||||||
const dayNumber = dateStr.substr(8, 2);
|
const dayNumber = dateStr.substr(8, 2);
|
||||||
|
|
||||||
|
@ -173,6 +173,17 @@ function findResultsWithQuery(query, searchContext) {
|
|||||||
return findResultsWithExpression(expression, searchContext);
|
return findResultsWithExpression(expression, searchContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} query
|
||||||
|
* @param {SearchContext} searchContext
|
||||||
|
* @return {Note|null}
|
||||||
|
*/
|
||||||
|
function findFirstNoteWithQuery(query, searchContext) {
|
||||||
|
const searchResults = findResultsWithQuery(query, searchContext);
|
||||||
|
|
||||||
|
return searchResults.length > 0 ? becca.notes[searchResults[0].noteId] : null;
|
||||||
|
}
|
||||||
|
|
||||||
function searchNotesForAutocomplete(query) {
|
function searchNotesForAutocomplete(query) {
|
||||||
const searchContext = new SearchContext({
|
const searchContext = new SearchContext({
|
||||||
fastSearch: true,
|
fastSearch: true,
|
||||||
@ -279,5 +290,6 @@ function formatAttribute(attr) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
searchNotesForAutocomplete,
|
searchNotesForAutocomplete,
|
||||||
findResultsWithQuery,
|
findResultsWithQuery,
|
||||||
|
findFirstNoteWithQuery,
|
||||||
searchNotes
|
searchNotes
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user