Skip to content

Commit

Permalink
Merge pull request #28 from Mark-Powers/master
Browse files Browse the repository at this point in the history
Mark day with dot that has note entry
  • Loading branch information
leenzhu authored Sep 3, 2024
2 parents 0d1e367 + 361e172 commit b853d26
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import VanillaCalendar from '@uvarov.frontend/vanilla-calendar';
//import '@uvarov.frontend/vanilla-calendar/build/themes/light.min.css';
//import '@uvarov.frontend/vanilla-calendar/build/themes/dark.min.css';

declare const webviewApi: any;

function padding(v) {
return ('0' + v).slice(-2)
}
Expand All @@ -25,6 +27,8 @@ const monday_first = date_ele.getAttribute('iso8601') === 'true'
const timeFmt:any = parseInt(date_ele.getAttribute('timeFmt'),10)
const theme:any = date_ele.getAttribute('theme')
const enableWeekNum = date_ele.getAttribute('weekNum') === 'true'
const enableCalendarHighlight = date_ele.getAttribute('enableCalendarHighlight') === "true"

const calendar = new VanillaCalendar('#datepicker', {
actions: {
clickDay(e, dates) {
Expand All @@ -39,6 +43,15 @@ const calendar = new VanillaCalendar('#datepicker', {
console.log(`Vanilla Calendar: hour: ${hours} minutes: ${minutes}`)
console.log(`Vanilla Calendar: keeping: ${keeping}`)
},
getDays(day, date, HTMLElement, HTMLButtonElement) {
if(enableCalendarHighlight){
webviewApi.postMessage({"type": "noteExists", "date": date}).then(res => {
if(res){
HTMLButtonElement.classList.add("vanilla-calendar-day_noted");
}
})
}
},
},
settings: {
iso8601: monday_first,
Expand Down
43 changes: 41 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ joplin.plugins.register({
await dialogs.addScript(dialog, "./vanilla-calendar.min.css");
await dialogs.addScript(dialog, "./light.min.css");
await dialogs.addScript(dialog, "./dark.min.css");
await dialogs.addScript(dialog, "vnilla-calendar-ext.css");
await dialogs.addScript(dialog, "./calendar.js");
await dialogs.setButtons(dialog, [
{ id: "ok", title: "OK" },
Expand All @@ -243,8 +244,37 @@ joplin.plugins.register({
const timeFmt = await joplin.settings.value('TimeFmt') || 0;
const theme = await joplin.settings.value('Theme') || "light"
const enableWeekNum = await joplin.settings.value('WeekNum') || false

await dialogs.setHtml(dialog, `<form name="picker" ><div id="datepicker" iso8601=${iso8601} timeFmt=${timeFmt} theme=${theme} weekNum=${enableWeekNum}></div><input id="j_date" name="date" type="hidden"><input id="j_time" name="time" type="hidden"></form>`);
const enableCalendarHighlight = await joplin.settings.value("HighlightCalendar")
await dialogs.setHtml(dialog, `<form name="picker"><div id="datepicker" iso8601=${iso8601} timeFmt=${timeFmt} theme=${theme} weekNum=${enableWeekNum} enableCalendarHighlight=${enableCalendarHighlight}></div><input id="j_date" name="date" type="hidden"><input id="j_time" name="time" type="hidden"></form>`);
joplin.views.panels.onMessage(dialog, async (msg) => {
if(msg.type == "noteExists"){
// Convert the date to local time
const d = new Date(new Date(msg.date).getTime() + new Date().getTimezoneOffset()*60*1000)
let noteName = await makeNoteName(d);
let parts = noteName.split("/")

// Look for a note with that name
const paths = parts.slice(0, -1)
const noteTitle = parts[parts.length - 1]
async function traverse(parent_id, depth){
if(depth == -1){
return true
}
let folder = await joplin.data.get(['folders', parent_id]);
if(folder.title == paths[depth]){
return await traverse(folder.parent_id, depth-1)
}
return false
}
let notes = await joplin.data.get(["search"], { query: noteTitle, type: "note" })
for(const note of notes.items){
if(await traverse(note.parent_id, paths.length - 1)){
return true
}
}
return false
}
});
const ret = await dialogs.open(dialog);

if (ret.id == "ok") {
Expand Down Expand Up @@ -422,6 +452,15 @@ joplin.plugins.register({
label: 'Tag Names',
description: "Custom tag names, each value is separated by ','. eg",
},
'HighlightCalendar': {
value: false,
type: SettingItemType.Bool,
section: 'Journal',
public: true,
advanced: true,
label: 'Enable Calendar Highlights',
description: "Highlight days with notes on the calendar",
},
});

await joplin.commands.register({
Expand Down
9 changes: 9 additions & 0 deletions src/vnilla-calendar-ext.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vanilla-calendar-day_noted::after {
content: '';
position: absolute;
bottom: 0px;
width: 6px;
height: 6px;
border-radius: 3px;
background-color: gray;
}

0 comments on commit b853d26

Please sign in to comment.