mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-06 07:32:17 +08:00
feat(note_language): allow removing language tag
This commit is contained in:
parent
598586f735
commit
bb42b5fb19
@ -23,6 +23,28 @@ async function removeAttributeById(noteId: string, attributeId: string) {
|
|||||||
await server.remove(`notes/${noteId}/attributes/${attributeId}`);
|
await server.remove(`notes/${noteId}/attributes/${attributeId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the attribute of the given note to the provided value if its truthy, or removes the attribute if the value is falsy.
|
||||||
|
* For an attribute with an empty value, pass an empty string instead.
|
||||||
|
*
|
||||||
|
* @param note the note to set the attribute to.
|
||||||
|
* @param type the type of attribute (label or relation).
|
||||||
|
* @param name the name of the attribute to set.
|
||||||
|
* @param value the value of the attribute to set.
|
||||||
|
*/
|
||||||
|
async function setAttribute(note: FNote, type: "label" | "relation", name: string, value: string | null | undefined) {
|
||||||
|
if (value) {
|
||||||
|
// Create or update the attribute.
|
||||||
|
await server.put(`notes/${note.noteId}/set-attribute`, { type, name, value });
|
||||||
|
} else {
|
||||||
|
// Remove the attribute if it exists on the server but we don't define a value for it.
|
||||||
|
const attributeId = note.getAttribute(type, name)?.attributeId;
|
||||||
|
if (attributeId) {
|
||||||
|
await server.remove(`notes/${note.noteId}/attributes/${attributeId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns - returns true if this attribute has the potential to influence the note in the argument.
|
* @returns - returns true if this attribute has the potential to influence the note in the argument.
|
||||||
* That can happen in multiple ways:
|
* That can happen in multiple ways:
|
||||||
@ -66,6 +88,7 @@ function isAffecting(attrRow: AttributeRow, affectedNote: FNote | null | undefin
|
|||||||
export default {
|
export default {
|
||||||
addLabel,
|
addLabel,
|
||||||
setLabel,
|
setLabel,
|
||||||
|
setAttribute,
|
||||||
removeAttributeById,
|
removeAttributeById,
|
||||||
isAffecting
|
isAffecting
|
||||||
};
|
};
|
||||||
|
@ -76,9 +76,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (languageId) {
|
attributes.setAttribute(this.note, "label", "language", languageId);
|
||||||
attributes.setLabel(this.note.noteId, "language", languageId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note: FNote) {
|
async refreshWithNote(note: FNote) {
|
||||||
|
@ -229,8 +229,8 @@ export default class CalendarView extends ViewMode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CalendarView.#setAttribute(note, "label", "startDate", startDate);
|
attributes.setAttribute(note, "label", "startDate", startDate);
|
||||||
CalendarView.#setAttribute(note, "label", "endDate", endDate);
|
attributes.setAttribute(note, "label", "endDate", endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
|
onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
@ -435,20 +435,6 @@ export default class CalendarView extends ViewMode {
|
|||||||
return [ note.title ];
|
return [ note.title ];
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #setAttribute(note: FNote, type: "label" | "relation", name: string, value: string | null | undefined) {
|
|
||||||
if (value) {
|
|
||||||
// Create or update the attribute.
|
|
||||||
await server.put(`notes/${note.noteId}/set-attribute`, { type, name, value });
|
|
||||||
} else {
|
|
||||||
// Remove the attribute if it exists on the server but we don't define a value for it.
|
|
||||||
const attributeId = note.getAttribute(type, name)?.attributeId;
|
|
||||||
if (attributeId) {
|
|
||||||
await server.remove(`notes/${note.noteId}/attributes/${attributeId}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await ws.waitForMaxKnownEntityChangeId();
|
|
||||||
}
|
|
||||||
|
|
||||||
static #formatDateToLocalISO(date: Date | null | undefined) {
|
static #formatDateToLocalISO(date: Date | null | undefined) {
|
||||||
if (!date) {
|
if (!date) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user