2021-12-20 17:30:47 +01:00
|
|
|
import NoteContextAwareWidget from "./note_context_aware_widget.js";
|
|
|
|
import options from "../services/options.js";
|
2021-12-22 10:57:02 +01:00
|
|
|
import attributeService from "../services/attributes.js";
|
2021-12-20 17:30:47 +01:00
|
|
|
|
|
|
|
const TPL = `
|
|
|
|
<div class="shared-info-widget alert alert-warning">
|
|
|
|
<style>
|
|
|
|
.shared-info-widget {
|
|
|
|
margin: 10px;
|
|
|
|
contain: none;
|
|
|
|
padding: 10px;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<span class="share-text"></span> <a class="share-link external"></a>. For help visit <a href="https://github.com/zadam/trilium/wiki/Sharing">wiki</a>.
|
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class SharedInfoWidget extends NoteContextAwareWidget {
|
|
|
|
isEnabled() {
|
|
|
|
return super.isEnabled() && this.note.hasAncestor('share');
|
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
|
|
|
this.$shareLink = this.$widget.find(".share-link");
|
|
|
|
this.$shareText = this.$widget.find(".share-text");
|
|
|
|
this.contentSized();
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshWithNote(note) {
|
|
|
|
const syncServerHost = options.get("syncServerHost");
|
|
|
|
let link;
|
|
|
|
|
2021-12-22 10:57:02 +01:00
|
|
|
const shareId = note.getOwnedLabelValue('shareAlias') || note.noteId;
|
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
if (syncServerHost) {
|
2021-12-22 10:57:02 +01:00
|
|
|
link = syncServerHost + "/share/" + shareId;
|
2021-12-20 17:30:47 +01:00
|
|
|
this.$shareText.text("This note is shared publicly on");
|
|
|
|
}
|
|
|
|
else {
|
2021-12-22 10:57:02 +01:00
|
|
|
link = location.protocol + '//' + location.host + location.pathname + "share/" + shareId;
|
2021-12-20 17:30:47 +01:00
|
|
|
this.$shareText.text("This note is shared locally on");
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$shareLink.attr("href", link).text(link);
|
|
|
|
}
|
2021-12-22 10:57:02 +01:00
|
|
|
|
|
|
|
entitiesReloadedEvent({loadResults}) {
|
|
|
|
if (loadResults.getAttributes().find(attr => attr.name.startsWith("share") && attributeService.isAffecting(attr, this.note))) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
}
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|