diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index e46625ad5..9f7b63121 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -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", diff --git a/src/services/builtin_attributes.js b/src/services/builtin_attributes.js index 814f1deaf..0bf610b95 100644 --- a/src/services/builtin_attributes.js +++ b/src/services/builtin_attributes.js @@ -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' }, diff --git a/src/services/date_notes.js b/src/services/date_notes.js index b595791c0..5e9f3fecb 100644 --- a/src/services/date_notes.js +++ b/src/services/date_notes.js @@ -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); diff --git a/src/services/search/services/search.js b/src/services/search/services/search.js index ea6594e67..2c7dc000e 100644 --- a/src/services/search/services/search.js +++ b/src/services/search/services/search.js @@ -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 };