mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-17 07:12:30 +08:00
chore(client/ts): port inherited_attribute_list
This commit is contained in:
parent
bd06d1d7b2
commit
c27d5afdf2
@ -288,7 +288,7 @@ const ATTR_HELP: Record<string, Record<string, string>> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface AttributeDetailOpts {
|
interface AttributeDetailOpts {
|
||||||
allAttributes: Attribute[];
|
allAttributes?: Attribute[];
|
||||||
attribute: Attribute;
|
attribute: Attribute;
|
||||||
isOwned: boolean;
|
isOwned: boolean;
|
||||||
x: number;
|
x: number;
|
||||||
@ -338,7 +338,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
private relatedNotesSpacedUpdate!: SpacedUpdate;
|
private relatedNotesSpacedUpdate!: SpacedUpdate;
|
||||||
private attribute!: Attribute;
|
private attribute!: Attribute;
|
||||||
private allAttributes!: Attribute[];
|
private allAttributes?: Attribute[];
|
||||||
private attrType!: ReturnType<AttributeDetailWidget["getAttrType"]>;
|
private attrType!: ReturnType<AttributeDetailWidget["getAttrType"]>;
|
||||||
|
|
||||||
async refresh() {
|
async refresh() {
|
||||||
@ -434,7 +434,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
this.attribute.value = pathChunks[pathChunks.length - 1]; // noteId
|
this.attribute.value = pathChunks[pathChunks.length - 1]; // noteId
|
||||||
|
|
||||||
this.triggerCommand("updateAttributeList", { attributes: this.allAttributes });
|
this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] });
|
||||||
this.updateRelatedNotes();
|
this.updateRelatedNotes();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -454,7 +454,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
|
|||||||
this.$deleteButton = this.$widget.find(".attr-delete-button");
|
this.$deleteButton = this.$widget.find(".attr-delete-button");
|
||||||
this.$deleteButton.on("click", async () => {
|
this.$deleteButton.on("click", async () => {
|
||||||
await this.triggerCommand("updateAttributeList", {
|
await this.triggerCommand("updateAttributeList", {
|
||||||
attributes: this.allAttributes.filter((attr) => attr !== this.attribute)
|
attributes: (this.allAttributes || []).filter((attr) => attr !== this.attribute)
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.triggerCommand("saveAttributes");
|
await this.triggerCommand("saveAttributes");
|
||||||
@ -714,7 +714,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
|
|||||||
this.attribute.value = String(this.$inputValue.val());
|
this.attribute.value = String(this.$inputValue.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.triggerCommand("updateAttributeList", { attributes: this.allAttributes });
|
this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
buildDefinitionValue() {
|
buildDefinitionValue() {
|
||||||
|
@ -3,6 +3,8 @@ import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";
|
|||||||
import attributeRenderer from "../../services/attribute_renderer.js";
|
import attributeRenderer from "../../services/attribute_renderer.js";
|
||||||
import attributeService from "../../services/attributes.js";
|
import attributeService from "../../services/attributes.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
import type { EventData } from "../../components/app_context.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="inherited-attributes-widget">
|
<div class="inherited-attributes-widget">
|
||||||
@ -23,6 +25,11 @@ const TPL = `
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
|
private attributeDetailWidget: AttributeDetailWidget;
|
||||||
|
|
||||||
|
private $container!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return "inheritedAttributes";
|
return "inheritedAttributes";
|
||||||
}
|
}
|
||||||
@ -34,7 +41,6 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/** @type {AttributeDetailWidget} */
|
|
||||||
this.attributeDetailWidget = new AttributeDetailWidget().contentSized().setParent(this);
|
this.attributeDetailWidget = new AttributeDetailWidget().contentSized().setParent(this);
|
||||||
|
|
||||||
this.child(this.attributeDetailWidget);
|
this.child(this.attributeDetailWidget);
|
||||||
@ -42,7 +48,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
getTitle() {
|
getTitle() {
|
||||||
return {
|
return {
|
||||||
show: !this.note.isLaunchBarConfig(),
|
show: !this.note?.isLaunchBarConfig(),
|
||||||
title: t("inherited_attribute_list.title"),
|
title: t("inherited_attribute_list.title"),
|
||||||
icon: "bx bx-list-plus"
|
icon: "bx bx-list-plus"
|
||||||
};
|
};
|
||||||
@ -56,7 +62,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
this.$widget.append(this.attributeDetailWidget.render());
|
this.$widget.append(this.attributeDetailWidget.render());
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note: FNote) {
|
||||||
this.$container.empty();
|
this.$container.empty();
|
||||||
|
|
||||||
const inheritedAttributes = this.getInheritedAttributes(note);
|
const inheritedAttributes = this.getInheritedAttributes(note);
|
||||||
@ -90,7 +96,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getInheritedAttributes(note) {
|
getInheritedAttributes(note: FNote) {
|
||||||
const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId);
|
const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId);
|
||||||
|
|
||||||
attrs.sort((a, b) => {
|
attrs.sort((a, b) => {
|
||||||
@ -105,7 +111,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget {
|
|||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedEvent({ loadResults }) {
|
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
|
||||||
if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) {
|
if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user