mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
feat(calendar): do no longer require #
or ~
to be specified by the user
to signify that the provided attribute is a label or a relation. It will now work either way, giving preference to the label if one is found.
This commit is contained in:
parent
85917d7207
commit
5658f22f9a
@ -231,8 +231,8 @@ export default class CalendarView extends ViewMode {
|
|||||||
|
|
||||||
// Since they can be customized via calendar:startDate=$foo and calendar:endDate=$bar we need to determine the
|
// Since they can be customized via calendar:startDate=$foo and calendar:endDate=$bar we need to determine the
|
||||||
// attributes to be effectively updated
|
// attributes to be effectively updated
|
||||||
const startAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:startDate").shift()?.value.replace("#", "")||"startDate"
|
const startAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:startDate").shift()?.value||"startDate"
|
||||||
const endAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:endDate").shift()?.value.replace("#", "")||"endDate"
|
const endAttribute = note.getAttributes("label").filter(attr => attr.name == "calendar:endDate").shift()?.value||"endDate"
|
||||||
|
|
||||||
attributes.setAttribute(note, "label", startAttribute, startDate);
|
attributes.setAttribute(note, "label", startAttribute, startDate);
|
||||||
attributes.setAttribute(note, "label", endAttribute, endDate);
|
attributes.setAttribute(note, "label", endAttribute, endDate);
|
||||||
@ -326,7 +326,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the user to customize the attribute from which to obtain a particular value. For example, if `customLabelNameAttribute` is `calendar:startDate`
|
* Allows the user to customize the attribute from which to obtain a particular value. For example, if `customLabelNameAttribute` is `calendar:startDate`
|
||||||
* and `defaultLabelName` is `startDate` and the note at hand has `#calendar:startDate=#myStartDate #myStartDate=2025-02-26` then the value returned will
|
* and `defaultLabelName` is `startDate` and the note at hand has `#calendar:startDate=myStartDate #myStartDate=2025-02-26` then the value returned will
|
||||||
* be `2025-02-26`. If there is no custom attribute value, then the value of the default attribute is returned instead (e.g. `#startDate`).
|
* be `2025-02-26`. If there is no custom attribute value, then the value of the default attribute is returned instead (e.g. `#startDate`).
|
||||||
*
|
*
|
||||||
* @param note the note from which to read the values.
|
* @param note the note from which to read the values.
|
||||||
@ -336,8 +336,8 @@ export default class CalendarView extends ViewMode {
|
|||||||
*/
|
*/
|
||||||
static #getCustomisableLabel(note: FNote, defaultLabelName: string, customLabelNameAttribute: string) {
|
static #getCustomisableLabel(note: FNote, defaultLabelName: string, customLabelNameAttribute: string) {
|
||||||
const customAttributeName = note.getLabelValue(customLabelNameAttribute);
|
const customAttributeName = note.getLabelValue(customLabelNameAttribute);
|
||||||
if (customAttributeName?.startsWith("#")) {
|
if (customAttributeName) {
|
||||||
const customValue = note.getLabelValue(customAttributeName.substring(1));
|
const customValue = note.getLabelValue(customAttributeName);
|
||||||
if (customValue) {
|
if (customValue) {
|
||||||
return customValue;
|
return customValue;
|
||||||
}
|
}
|
||||||
@ -347,8 +347,8 @@ export default class CalendarView extends ViewMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async buildEvent(note: FNote, startDate: string, endDate?: string | null) {
|
static async buildEvent(note: FNote, startDate: string, endDate?: string | null) {
|
||||||
const customTitle = note.getLabelValue("calendar:title");
|
const customTitleAttributeName = note.getLabelValue("calendar:title");
|
||||||
const titles = await CalendarView.#parseCustomTitle(customTitle, note);
|
const titles = await CalendarView.#parseCustomTitle(customTitleAttributeName, note);
|
||||||
const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color");
|
const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color");
|
||||||
const events: EventInput[] = [];
|
const events: EventInput[] = [];
|
||||||
|
|
||||||
@ -390,16 +390,13 @@ export default class CalendarView extends ViewMode {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #parseCustomTitle(customTitleValue: string | null, note: FNote, allowRelations = true): Promise<string[]> {
|
static async #parseCustomTitle(customTitlettributeName: string | null, note: FNote, allowRelations = true): Promise<string[]> {
|
||||||
if (customTitleValue) {
|
if (customTitlettributeName) {
|
||||||
const attributeName = customTitleValue.substring(1);
|
const labelValue = note.getAttributeValue("label", customTitlettributeName);
|
||||||
if (customTitleValue.startsWith("#")) {
|
if (labelValue) return [labelValue];
|
||||||
const labelValue = note.getAttributeValue("label", attributeName);
|
|
||||||
if (labelValue) {
|
if (allowRelations) {
|
||||||
return [labelValue];
|
const relations = note.getRelations(customTitlettributeName);
|
||||||
}
|
|
||||||
} else if (allowRelations && customTitleValue.startsWith("~")) {
|
|
||||||
const relations = note.getRelations(attributeName);
|
|
||||||
if (relations.length > 0) {
|
if (relations.length > 0) {
|
||||||
const noteIds = relations.map((r) => r.targetNoteId);
|
const noteIds = relations.map((r) => r.targetNoteId);
|
||||||
const notesFromRelation = await froca.getNotes(noteIds);
|
const notesFromRelation = await froca.getNotes(noteIds);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user