mirror of
https://github.com/zadam/trilium.git
synced 2025-02-24 23:13:43 +08:00
allow per workspace calendars, fixes #2959
This commit is contained in:
parent
4c93334d90
commit
3ebfaec1bc
4 changed files with 34 additions and 5 deletions
|
@ -204,6 +204,7 @@ const ATTR_HELP = {
|
|||
"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",
|
||||
"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",
|
||||
"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",
|
||||
|
|
|
@ -29,6 +29,7 @@ module.exports = [
|
|||
{ type: 'label', name: 'workspace' },
|
||||
{ type: 'label', name: 'workspaceIconClass' },
|
||||
{ type: 'label', name: 'workspaceTabBackgroundColor' },
|
||||
{ type: 'label', name: 'workspaceCalendarRoot' },
|
||||
{ type: 'label', name: 'searchHome' },
|
||||
{ type: 'label', name: 'hoistedInbox' },
|
||||
{ type: 'label', name: 'hoistedSearchHome' },
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
"use strict";
|
||||
|
||||
const noteService = require('./notes');
|
||||
const becca = require('../becca/becca');
|
||||
const attributeService = require('./attributes');
|
||||
const dateUtils = require('./date_utils');
|
||||
const sql = require('./sql');
|
||||
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 YEAR_LABEL = 'yearNote';
|
||||
|
@ -26,7 +30,15 @@ function createNote(parentNote, noteTitle) {
|
|||
|
||||
/** @returns {Note} */
|
||||
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) {
|
||||
sql.transactional(() => {
|
||||
|
@ -55,7 +67,8 @@ function getYearNote(dateStr, rootNote = null) {
|
|||
|
||||
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) {
|
||||
return yearNote;
|
||||
|
@ -95,7 +108,8 @@ function getMonthNote(dateStr, rootNote = null) {
|
|||
const monthStr = dateStr.substr(0, 7);
|
||||
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) {
|
||||
return monthNote;
|
||||
|
@ -137,15 +151,16 @@ function getDayNoteTitle(rootNote, dayNumber, dateObj) {
|
|||
|
||||
/** @returns {Note} */
|
||||
function getDayNote(dateStr) {
|
||||
const rootNote = getRootCalendarNote();
|
||||
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) {
|
||||
return dateNote;
|
||||
}
|
||||
|
||||
const rootNote = getRootCalendarNote();
|
||||
const monthNote = getMonthNote(dateStr, rootNote);
|
||||
const dayNumber = dateStr.substr(8, 2);
|
||||
|
||||
|
|
|
@ -173,6 +173,17 @@ function findResultsWithQuery(query, 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) {
|
||||
const searchContext = new SearchContext({
|
||||
fastSearch: true,
|
||||
|
@ -279,5 +290,6 @@ function formatAttribute(attr) {
|
|||
module.exports = {
|
||||
searchNotesForAutocomplete,
|
||||
findResultsWithQuery,
|
||||
findFirstNoteWithQuery,
|
||||
searchNotes
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue