Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(ts): start port of widgets/buttons/attachment_actions
Panagiotis Papadopoulosbf15192b2521
diff --git a/src/public/app/widgets/buttons/attachments_actions.js b/src/public/app/widgets/buttons/attachments_actions.tssimilarity index 86%rename from src/public/app/widgets/buttons/attachments_actions.jsrename to src/public/app/widgets/buttons/attachments_actions.tsindex 5ee51b9d96..f25e9c376b 100644--- a/src/public/app/widgets/buttons/attachments_actions.js+++ b/src/public/app/widgets/buttons/attachments_actions.ts@@ -8,6 +8,8 @@ import appContext from "../../components/app_context.js";import openService from "../../services/open.js";import utils from "../../services/utils.js";import { Dropdown } from "bootstrap";+import type attachmentsApiRoute from "../../../../routes/api/attachments.js"+import type FAttachment from "../../entities/fattachment.js";const TPL = `<div class="dropdown attachment-actions">@@ -79,7 +81,12 @@ const TPL = `</div>`;export default class AttachmentActionsWidget extends BasicWidget {- constructor(attachment, isFullDetail) {+ $uploadNewRevisionInput!: JQuery<HTMLInputElement>;+ attachment: FAttachment;+ isFullDetail: boolean;+ dropdown!: Dropdown;++ constructor(attachment: FAttachment, isFullDetail: boolean) {super();this.attachment = attachment;@@ -92,20 +99,21 @@ export default class AttachmentActionsWidget extends BasicWidget {doRender() {this.$widget = $(TPL);- this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']"));+ this.dropdown = Dropdown.getOrCreateInstance(this.$widget.find("[data-bs-toggle='dropdown']")[0]);this.$widget.on("click", ".dropdown-item", () => this.dropdown.toggle());this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input");this.$uploadNewRevisionInput.on("change", async () => {- const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below- this.$uploadNewRevisionInput.val("");-- const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);- if (result.uploaded) {- toastService.showMessage(t("attachments_actions.upload_success"));- } else {- toastService.showError(t("attachments_actions.upload_failed"));+ const fileToUpload = this.$uploadNewRevisionInput[0].files?.item(0); // copy to allow reset below+ this.$uploadNewRevisionInput.val("");+ if (fileToUpload) {+ const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);+ if (result.uploaded) {+ toastService.showMessage(t("attachments_actions.upload_success"));+ } else {+ toastService.showError(t("attachments_actions.upload_failed"));+ }}});@@ -122,6 +130,7 @@ export default class AttachmentActionsWidget extends BasicWidget {const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");$openAttachmentCustomButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_custom_client_only")));}+}async openAttachmentCommand() {@@ -141,7 +150,8 @@ export default class AttachmentActionsWidget extends BasicWidget {}async copyAttachmentLinkToClipboardCommand() {- this.parent.copyAttachmentLinkToClipboard();+ //TriliumNextTODO: the parent here is AttachmentDetailWidget+ this.parent?.copyAttachmentLinkToClipboard();}async deleteAttachmentCommand() {@@ -158,7 +168,8 @@ export default class AttachmentActionsWidget extends BasicWidget {return;}- const { note: newNote } = await server.post(`attachments/${this.attachmentId}/convert-to-note`);++ const { note: newNote } = await server.post<ReturnType<typeof attachmentsApiRoute.convertAttachmentToNote>>(`attachments/${this.attachmentId}/convert-to-note`);toastService.showMessage(t("attachments_actions.convert_success", { title: this.attachment.title }));await ws.waitForMaxKnownEntityChangeId();await appContext.tabManager.getActiveContext().setNote(newNote.noteId);