Skip to content

Build your personal knowledge base with Trilium Notes

calendar now indicates whether date note already exists or not + tooltip

zadam16be0c101470
diff --git a/src/public/javascripts/widgets/calendar.js b/src/public/javascripts/widgets/calendar.js
index f455b1d81d..26bb314b03 100644
--- a/src/public/javascripts/widgets/calendar.js
+++ b/src/public/javascripts/widgets/calendar.js
@@ -3,6 +3,7 @@ import libraryLoader from "../services/library_loader.js";
import utils from "../services/utils.js";
import dateNoteService from "../services/date_notes.js";
import treeService from "../services/tree.js";
+import server from "../services/server.js";
const TPL = `
<div class="calendar-widget">
@@ -87,8 +88,8 @@ class CalendarWidget extends StandardWidget {
});
}
- createDay(num, day) {
- const $newDay = $('<div>')
+ createDay(dateNotesForMonth, num, day) {
+ const $newDay = $('<a>')
.addClass("calendar-date")
.attr('data-calendar-date', utils.formatDateISO(this.date));
const $date = $('<span>').html(num);
@@ -102,6 +103,13 @@ class CalendarWidget extends StandardWidget {
}
}
+ const dateNoteId = dateNotesForMonth[utils.formatDateISO(this.date)];
+
+ if (dateNoteId) {
+ $newDay.addClass('calendar-date-exists');
+ $newDay.attr("data-note-path", dateNoteId);
+ }
+
if (this.isEqual(this.date, this.activeDate)) {
$newDay.addClass('calendar-date-active');
}
@@ -120,10 +128,14 @@ class CalendarWidget extends StandardWidget {
&& a.getDate() === b.getDate();
}
- createMonth() {
+ async createMonth() {
+ const month = utils.formatDateISO(this.date).substr(0, 7);
+ const dateNotesForMonth = await server.get('date-notes/notes-for-month/' + month);
+
const currentMonth = this.date.getMonth();
while (this.date.getMonth() === currentMonth) {
this.createDay(
+ dateNotesForMonth,
this.date.getDate(),
this.date.getDay(),
this.date.getFullYear()
diff --git a/src/public/stylesheets/calendar.css b/src/public/stylesheets/calendar.css
index 286fc5ce5f..140be6f3b8 100755
--- a/src/public/stylesheets/calendar.css
+++ b/src/public/stylesheets/calendar.css
@@ -66,7 +66,8 @@
flex-direction: column;
flex: 0 0 14.28%;
max-width: 14.28%;
- padding: 0.6rem 0;
+ padding: 0.4rem 0;
+ font-size: 120%;
}
.calendar-widget .calendar-date:hover {
@@ -83,6 +84,10 @@
font-weight: bold;
}
+.calendar-widget .calendar-date-exists {
+ text-decoration: underline !important;
+}
+
.calendar-widget .calendar-date:not(.calendar-date-active) {
cursor: pointer;
}
\ No newline at end of file
diff --git a/src/routes/api/date_notes.js b/src/routes/api/date_notes.js
index 0528d952cd..5584f6eb8f 100644
--- a/src/routes/api/date_notes.js
+++ b/src/routes/api/date_notes.js
@@ -1,6 +1,7 @@
"use strict";
const dateNoteService = require('../../services/date_notes');
+const sql = require('../../services/sql');
async function getDateNote(req) {
return await dateNoteService.getDateNote(req.params.date);
@@ -14,8 +15,25 @@ async function getYearNote(req) {
return await dateNoteService.getYearNote(req.params.year);
}
+async function getDateNotesForMonth(req) {
+ const month = req.params.month;
+
+ return sql.getMap(`
+ SELECT
+ attr.value AS date,
+ notes.noteId
+ FROM notes
+ JOIN attributes attr USING(noteId)
+ WHERE notes.isDeleted = 0
+ AND attr.isDeleted = 0
+ AND attr.type = 'label'
+ AND attr.name = 'dateNote'
+ AND attr.value LIKE '${month}%'`);
+}
+
module.exports = {
getDateNote,
getMonthNote,
- getYearNote
+ getYearNote,
+ getDateNotesForMonth
};
\ No newline at end of file
diff --git a/src/routes/routes.js b/src/routes/routes.js
index a184100492..b9df8fe5c0 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -166,6 +166,7 @@ function register(app) {
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);
+ apiRoute(GET, '/api/date-notes/notes-for-month/:month', dateNotesRoute.getDateNotesForMonth);
route(GET, '/api/images/:noteId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware], imageRoute.uploadImage, apiResultHandler);