2018-03-28 10:11:06 +08:00
|
|
|
import utils from "./utils.js";
|
|
|
|
import server from "./server.js";
|
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
class NoteDetailFile {
|
|
|
|
/**
|
2019-05-09 01:55:24 +08:00
|
|
|
* @param {TabContext} ctx
|
2019-05-03 04:24:43 +08:00
|
|
|
*/
|
|
|
|
constructor(ctx) {
|
2019-05-04 03:50:14 +08:00
|
|
|
this.ctx = ctx;
|
2019-05-09 01:55:24 +08:00
|
|
|
this.$component = ctx.$tabContent.find('.note-detail-file');
|
|
|
|
this.$fileNoteId = ctx.$tabContent.find(".file-note-id");
|
|
|
|
this.$fileName = ctx.$tabContent.find(".file-filename");
|
|
|
|
this.$fileType = ctx.$tabContent.find(".file-filetype");
|
|
|
|
this.$fileSize = ctx.$tabContent.find(".file-filesize");
|
|
|
|
this.$previewRow = ctx.$tabContent.find(".file-preview-row");
|
|
|
|
this.$previewContent = ctx.$tabContent.find(".file-preview-content");
|
|
|
|
this.$downloadButton = ctx.$tabContent.find(".file-download");
|
|
|
|
this.$openButton = ctx.$tabContent.find(".file-open");
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
this.$downloadButton.click(() => utils.download(this.getFileUrl()));
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
this.$openButton.click(() => {
|
|
|
|
if (utils.isElectron()) {
|
|
|
|
const open = require("open");
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
open(this.getFileUrl());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
window.location.href = this.getFileUrl();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-12 18:58:55 +08:00
|
|
|
async render() {
|
2019-05-04 03:50:14 +08:00
|
|
|
const attributes = await server.get('notes/' + this.ctx.note.noteId + '/attributes');
|
2019-05-03 04:24:43 +08:00
|
|
|
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
|
|
|
|
|
|
|
|
this.$component.show();
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-04 03:50:14 +08:00
|
|
|
this.$fileNoteId.text(this.ctx.note.noteId);
|
2019-05-03 04:24:43 +08:00
|
|
|
this.$fileName.text(attributeMap.originalFileName || "?");
|
|
|
|
this.$fileSize.text((attributeMap.fileSize || "?") + " bytes");
|
2019-05-04 03:50:14 +08:00
|
|
|
this.$fileType.text(this.ctx.note.mime);
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-04 03:50:14 +08:00
|
|
|
if (this.ctx.note.content) {
|
2019-05-03 04:24:43 +08:00
|
|
|
this.$previewRow.show();
|
2019-05-04 03:50:14 +08:00
|
|
|
this.$previewContent.text(this.ctx.note.content);
|
2019-05-03 04:24:43 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.$previewRow.hide();
|
|
|
|
}
|
2018-11-17 01:40:58 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
// open doesn't work for protected notes since it works through browser which isn't in protected session
|
2019-05-04 03:50:14 +08:00
|
|
|
this.$openButton.toggle(!this.ctx.note.isProtected);
|
2019-02-24 03:33:27 +08:00
|
|
|
}
|
2019-05-03 04:24:43 +08:00
|
|
|
|
|
|
|
getFileUrl() {
|
|
|
|
// electron needs absolute URL so we extract current host, port, protocol
|
2019-05-04 03:50:14 +08:00
|
|
|
return utils.getHost() + "/api/notes/" + this.ctx.note.noteId + "/download";
|
2019-02-24 03:33:27 +08:00
|
|
|
}
|
2019-04-22 21:01:05 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
getContent() {}
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
focus() {}
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
onNoteChange() {}
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
cleanup() {}
|
2018-03-28 10:11:06 +08:00
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
scrollToTop() {}
|
2018-03-28 10:11:06 +08:00
|
|
|
}
|
|
|
|
|
2019-05-03 04:24:43 +08:00
|
|
|
export default NoteDetailFile;
|