From 16be0c1014708629a56a9379dcdc276a81c1c73a Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 8 Sep 2019 16:30:33 +0200 Subject: [PATCH] calendar now indicates whether date note already exists or not + tooltip --- src/public/javascripts/widgets/calendar.js | 18 +++++++++++++++--- src/public/stylesheets/calendar.css | 7 ++++++- src/routes/api/date_notes.js | 20 +++++++++++++++++++- src/routes/routes.js | 1 + 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/public/javascripts/widgets/calendar.js b/src/public/javascripts/widgets/calendar.js index f455b1d81..26bb314b0 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 = `
@@ -87,8 +88,8 @@ class CalendarWidget extends StandardWidget { }); } - createDay(num, day) { - const $newDay = $('
') + createDay(dateNotesForMonth, num, day) { + const $newDay = $('') .addClass("calendar-date") .attr('data-calendar-date', utils.formatDateISO(this.date)); const $date = $('').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 286fc5ce5..140be6f3b 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 0528d952c..5584f6eb8 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 a18410049..b9df8fe5c 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);