mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
chore(client/ts): port file_properties
This commit is contained in:
parent
48e9e30efe
commit
a2b6bb7ecf
@ -5,6 +5,7 @@ import openService from "../../services/open.js";
|
|||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import protectedSessionHolder from "../../services/protected_session_holder.js";
|
import protectedSessionHolder from "../../services/protected_session_holder.js";
|
||||||
import { t } from "../../services/i18n.js";
|
import { t } from "../../services/i18n.js";
|
||||||
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="file-properties-widget">
|
<div class="file-properties-widget">
|
||||||
@ -66,6 +67,16 @@ const TPL = `
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
||||||
|
|
||||||
|
private $fileNoteId!: JQuery<HTMLElement>;
|
||||||
|
private $fileName!: JQuery<HTMLElement>;
|
||||||
|
private $fileType!: JQuery<HTMLElement>;
|
||||||
|
private $fileSize!: JQuery<HTMLElement>;
|
||||||
|
private $downloadButton!: JQuery<HTMLElement>;
|
||||||
|
private $openButton!: JQuery<HTMLElement>;
|
||||||
|
private $uploadNewRevisionButton!: JQuery<HTMLElement>;
|
||||||
|
private $uploadNewRevisionInput!: JQuery<HTMLFormElement>;
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return "fileProperties";
|
return "fileProperties";
|
||||||
}
|
}
|
||||||
@ -99,8 +110,8 @@ export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
|||||||
this.$uploadNewRevisionButton = this.$widget.find(".file-upload-new-revision");
|
this.$uploadNewRevisionButton = this.$widget.find(".file-upload-new-revision");
|
||||||
this.$uploadNewRevisionInput = this.$widget.find(".file-upload-new-revision-input");
|
this.$uploadNewRevisionInput = this.$widget.find(".file-upload-new-revision-input");
|
||||||
|
|
||||||
this.$downloadButton.on("click", () => openService.downloadFileNote(this.noteId));
|
this.$downloadButton.on("click", () => this.noteId && openService.downloadFileNote(this.noteId));
|
||||||
this.$openButton.on("click", () => openService.openNoteExternally(this.noteId, this.note.mime));
|
this.$openButton.on("click", () => this.noteId && this.note && openService.openNoteExternally(this.noteId, this.note.mime));
|
||||||
|
|
||||||
this.$uploadNewRevisionButton.on("click", () => {
|
this.$uploadNewRevisionButton.on("click", () => {
|
||||||
this.$uploadNewRevisionInput.trigger("click");
|
this.$uploadNewRevisionInput.trigger("click");
|
||||||
@ -122,16 +133,20 @@ export default class FilePropertiesWidget extends NoteContextAwareWidget {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async refreshWithNote(note) {
|
async refreshWithNote(note: FNote) {
|
||||||
this.$widget.show();
|
this.$widget.show();
|
||||||
|
|
||||||
|
if (!this.note) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.$fileNoteId.text(note.noteId);
|
this.$fileNoteId.text(note.noteId);
|
||||||
this.$fileName.text(note.getLabelValue("originalFileName") || "?");
|
this.$fileName.text(note.getLabelValue("originalFileName") || "?");
|
||||||
this.$fileType.text(note.mime);
|
this.$fileType.text(note.mime);
|
||||||
|
|
||||||
const blob = await this.note.getBlob();
|
const blob = await this.note.getBlob();
|
||||||
|
|
||||||
this.$fileSize.text(utils.formatSize(blob.contentLength));
|
this.$fileSize.text(utils.formatSize(blob?.contentLength ?? 0));
|
||||||
|
|
||||||
// open doesn't work for protected notes since it works through a browser which isn't in protected session
|
// open doesn't work for protected notes since it works through a browser which isn't in protected session
|
||||||
this.$openButton.toggle(!note.isProtected);
|
this.$openButton.toggle(!note.isProtected);
|
Loading…
x
Reference in New Issue
Block a user