mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
calendar now indicates whether date note already exists or not + tooltip
This commit is contained in:
parent
c82de8b6b2
commit
16be0c1014
@ -3,6 +3,7 @@ import libraryLoader from "../services/library_loader.js";
|
|||||||
import utils from "../services/utils.js";
|
import utils from "../services/utils.js";
|
||||||
import dateNoteService from "../services/date_notes.js";
|
import dateNoteService from "../services/date_notes.js";
|
||||||
import treeService from "../services/tree.js";
|
import treeService from "../services/tree.js";
|
||||||
|
import server from "../services/server.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="calendar-widget">
|
<div class="calendar-widget">
|
||||||
@ -87,8 +88,8 @@ class CalendarWidget extends StandardWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createDay(num, day) {
|
createDay(dateNotesForMonth, num, day) {
|
||||||
const $newDay = $('<div>')
|
const $newDay = $('<a>')
|
||||||
.addClass("calendar-date")
|
.addClass("calendar-date")
|
||||||
.attr('data-calendar-date', utils.formatDateISO(this.date));
|
.attr('data-calendar-date', utils.formatDateISO(this.date));
|
||||||
const $date = $('<span>').html(num);
|
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)) {
|
if (this.isEqual(this.date, this.activeDate)) {
|
||||||
$newDay.addClass('calendar-date-active');
|
$newDay.addClass('calendar-date-active');
|
||||||
}
|
}
|
||||||
@ -120,10 +128,14 @@ class CalendarWidget extends StandardWidget {
|
|||||||
&& a.getDate() === b.getDate();
|
&& 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();
|
const currentMonth = this.date.getMonth();
|
||||||
while (this.date.getMonth() === currentMonth) {
|
while (this.date.getMonth() === currentMonth) {
|
||||||
this.createDay(
|
this.createDay(
|
||||||
|
dateNotesForMonth,
|
||||||
this.date.getDate(),
|
this.date.getDate(),
|
||||||
this.date.getDay(),
|
this.date.getDay(),
|
||||||
this.date.getFullYear()
|
this.date.getFullYear()
|
||||||
|
@ -66,7 +66,8 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
flex: 0 0 14.28%;
|
flex: 0 0 14.28%;
|
||||||
max-width: 14.28%;
|
max-width: 14.28%;
|
||||||
padding: 0.6rem 0;
|
padding: 0.4rem 0;
|
||||||
|
font-size: 120%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.calendar-widget .calendar-date:hover {
|
.calendar-widget .calendar-date:hover {
|
||||||
@ -83,6 +84,10 @@
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.calendar-widget .calendar-date-exists {
|
||||||
|
text-decoration: underline !important;
|
||||||
|
}
|
||||||
|
|
||||||
.calendar-widget .calendar-date:not(.calendar-date-active) {
|
.calendar-widget .calendar-date:not(.calendar-date-active) {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const dateNoteService = require('../../services/date_notes');
|
const dateNoteService = require('../../services/date_notes');
|
||||||
|
const sql = require('../../services/sql');
|
||||||
|
|
||||||
async function getDateNote(req) {
|
async function getDateNote(req) {
|
||||||
return await dateNoteService.getDateNote(req.params.date);
|
return await dateNoteService.getDateNote(req.params.date);
|
||||||
@ -14,8 +15,25 @@ async function getYearNote(req) {
|
|||||||
return await dateNoteService.getYearNote(req.params.year);
|
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 = {
|
module.exports = {
|
||||||
getDateNote,
|
getDateNote,
|
||||||
getMonthNote,
|
getMonthNote,
|
||||||
getYearNote
|
getYearNote,
|
||||||
|
getDateNotesForMonth
|
||||||
};
|
};
|
@ -166,6 +166,7 @@ function register(app) {
|
|||||||
apiRoute(GET, '/api/date-notes/date/:date', dateNotesRoute.getDateNote);
|
apiRoute(GET, '/api/date-notes/date/:date', dateNotesRoute.getDateNote);
|
||||||
apiRoute(GET, '/api/date-notes/month/:month', dateNotesRoute.getMonthNote);
|
apiRoute(GET, '/api/date-notes/month/:month', dateNotesRoute.getMonthNote);
|
||||||
apiRoute(GET, '/api/date-notes/year/:year', dateNotesRoute.getYearNote);
|
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(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