mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +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 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()
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
||||
};
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user