You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var quarterOfYear = require('dayjs/plugin/quarterOfYear');
var isoWeek = require('dayjs/plugin/isoWeek');
api.dayjs.extend(quarterOfYear);
api.dayjs.extend(isoWeek);
const calendarRootNote = api.getNoteWithLabel('calendarRoot');
if (!calendarRootNote) {
console.log('calendarRootNote does not exist');
return;
}
const dayNote = api.getNote(api.originEntity.noteId);
const noteDate = dayNote.getOwnedLabelValue('dateNote');
if (!noteDate) {
console.log('Not a day note');
return;
}
const noteYear = noteDate.split('-')[0];
const noteMonth = noteDate.split('-')[1];
const noteQuarter = 'Q' + api.dayjs(`${noteYear}-${noteMonth}`).quarter();
const noteWeek = 'W' + `0${api.dayjs(noteDate).isoWeek()}`.slice(-2);
const yearNote = api.getYearNote(noteYear);
const quarterNote = getNote(
'quarterNote',
`${noteYear}-${noteQuarter}`,
'ZoQ5rqHgTj5x',
yearNote.noteId
);
const quarterOrMonthNotes = yearNote.getChildNotes();
for (let i = 0; i < quarterOrMonthNotes.length; i++) {
if (quarterOrMonthNotes[i].getAttribute('label', 'monthNote')) {
moveNote(quarterOrMonthNotes[i], quarterNote.noteId, yearNote.noteId);
}
}
const monthNote = api.getNoteWithLabel('monthNote', `${noteYear}-${noteMonth}`);
const weekNote = getNote('weekNote', `${noteYear}-${noteWeek}`, 'dr6Zu0nCmsNn', monthNote.noteId);
moveNote(dayNote, weekNote.noteId, monthNote.noteId);
const currentMonthNotes = weekNote.getParentNotes();
let cloneWeekNote = true;
for (let i = 0; i < currentMonthNotes.length; i++){
console.log(currentMonthNotes[i])
if (currentMonthNotes[i].getAttribute('label', 'monthNote') === `${noteYear}-${noteMonth}`){
cloneWeekNote = false;
}
}
if (cloneWeekNote){
weekNote.cloneTo(monthNote.noteId);
}
if (!dayNote.title.startsWith(`${noteYear}-${noteMonth}`)){
dayNote.title = `${noteYear}-${noteMonth}-` + dayNote.title;
}
if (!monthNote.title.startsWith(noteYear)){
monthNote.title = `${noteYear}-` + monthNote.title;
}
getNote
module.exports = function (labelName, labelValue, templateId, newParentNoteId) {
let note=api.getNoteWithLabel(labelName, labelValue);
let calendarNote=api.getNoteWithLabel('calendarRoot');
if(!note){
note=api.createTextNote(calendarNote.noteId,labelValue,"").note;
note.setRelation('template',templateId);
note.setLabel(labelName,labelValue);
note.setLabel('sorted');
moveNote(note, newParentNoteId, calendarNote.noteId);
}
return note
}
moveNote
module.exports = function (movingNote, newParentNoteId, oldParentNoteId) {
movingNote.cloneTo(newParentNoteId);
api.ensureNoteIsAbsentFromParent(movingNote.noteId,oldParentNoteId);
}
It's creating a week note if not exist and move the day note to the weeknote. But now it can only create day note under month note, it either create new week note nor move day note to existing week note.
It runs on note attribute creation before, and I have tried to run on note creation. Both doesn't work now.
See snippet:
getNote
moveNote
It's creating a week note if not exist and move the day note to the weeknote. But now it can only create day note under month note, it either create new week note nor move day note to existing week note.
It runs on note attribute creation before, and I have tried to run on note creation. Both doesn't work now.
Originally posted by @JYC333 in #417 (comment)
The text was updated successfully, but these errors were encountered: