mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	chore(ts): start port of widgets/buttons/attachment_actions
This commit is contained in:
		
							parent
							
								
									70756fe795
								
							
						
					
					
						commit
						bf15192b25
					
				@ -8,6 +8,8 @@ import appContext from "../../components/app_context.js";
 | 
				
			|||||||
import openService from "../../services/open.js";
 | 
					import openService from "../../services/open.js";
 | 
				
			||||||
import utils from "../../services/utils.js";
 | 
					import utils from "../../services/utils.js";
 | 
				
			||||||
import { Dropdown } from "bootstrap";
 | 
					import { Dropdown } from "bootstrap";
 | 
				
			||||||
 | 
					import type attachmentsApiRoute from "../../../../routes/api/attachments.js"
 | 
				
			||||||
 | 
					import type FAttachment from "../../entities/fattachment.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const TPL = `
 | 
					const TPL = `
 | 
				
			||||||
<div class="dropdown attachment-actions">
 | 
					<div class="dropdown attachment-actions">
 | 
				
			||||||
@ -79,7 +81,12 @@ const TPL = `
 | 
				
			|||||||
</div>`;
 | 
					</div>`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class AttachmentActionsWidget extends BasicWidget {
 | 
					export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			||||||
    constructor(attachment, isFullDetail) {
 | 
					    $uploadNewRevisionInput!: JQuery<HTMLInputElement>;
 | 
				
			||||||
 | 
					    attachment: FAttachment;
 | 
				
			||||||
 | 
					    isFullDetail: boolean;
 | 
				
			||||||
 | 
					    dropdown!: Dropdown;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constructor(attachment: FAttachment, isFullDetail: boolean) {
 | 
				
			||||||
        super();
 | 
					        super();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.attachment = attachment;
 | 
					        this.attachment = attachment;
 | 
				
			||||||
@ -92,21 +99,22 @@ export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    doRender() {
 | 
					    doRender() {
 | 
				
			||||||
        this.$widget = $(TPL);
 | 
					        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.$widget.on("click", ".dropdown-item", () => this.dropdown.toggle());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input");
 | 
					        this.$uploadNewRevisionInput = this.$widget.find(".attachment-upload-new-revision-input");
 | 
				
			||||||
        this.$uploadNewRevisionInput.on("change", async () => {
 | 
					        this.$uploadNewRevisionInput.on("change", async () => {
 | 
				
			||||||
            const fileToUpload = this.$uploadNewRevisionInput[0].files[0]; // copy to allow reset below
 | 
					
 | 
				
			||||||
 | 
					            const fileToUpload = this.$uploadNewRevisionInput[0].files?.item(0);  // copy to allow reset below
 | 
				
			||||||
            this.$uploadNewRevisionInput.val("");
 | 
					            this.$uploadNewRevisionInput.val("");
 | 
				
			||||||
 | 
					            if (fileToUpload) {
 | 
				
			||||||
                const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
 | 
					                const result = await server.upload(`attachments/${this.attachmentId}/file`, fileToUpload);
 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (result.uploaded) {
 | 
					                if (result.uploaded) {
 | 
				
			||||||
                    toastService.showMessage(t("attachments_actions.upload_success"));
 | 
					                    toastService.showMessage(t("attachments_actions.upload_success"));
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    toastService.showError(t("attachments_actions.upload_failed"));
 | 
					                    toastService.showError(t("attachments_actions.upload_failed"));
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const isElectron = utils.isElectron();
 | 
					        const isElectron = utils.isElectron();
 | 
				
			||||||
@ -122,6 +130,7 @@ export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			|||||||
            const $openAttachmentCustomButton = this.$widget.find("[data-trigger-command='openAttachmentCustom']");
 | 
					            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")));
 | 
					            $openAttachmentCustomButton.addClass("disabled").append($('<span class="bx bx-info-circle disabled-tooltip" />').attr("title", t("attachments_actions.open_custom_client_only")));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async openAttachmentCommand() {
 | 
					    async openAttachmentCommand() {
 | 
				
			||||||
@ -141,7 +150,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async copyAttachmentLinkToClipboardCommand() {
 | 
					    async copyAttachmentLinkToClipboardCommand() {
 | 
				
			||||||
        this.parent.copyAttachmentLinkToClipboard();
 | 
					        //TriliumNextTODO: the parent here is AttachmentDetailWidget
 | 
				
			||||||
 | 
					        this.parent?.copyAttachmentLinkToClipboard();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async deleteAttachmentCommand() {
 | 
					    async deleteAttachmentCommand() {
 | 
				
			||||||
@ -158,7 +168,8 @@ export default class AttachmentActionsWidget extends BasicWidget {
 | 
				
			|||||||
            return;
 | 
					            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 }));
 | 
					        toastService.showMessage(t("attachments_actions.convert_success", { title: this.attachment.title }));
 | 
				
			||||||
        await ws.waitForMaxKnownEntityChangeId();
 | 
					        await ws.waitForMaxKnownEntityChangeId();
 | 
				
			||||||
        await appContext.tabManager.getActiveContext().setNote(newNote.noteId);
 | 
					        await appContext.tabManager.getActiveContext().setNote(newNote.noteId);
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user