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";
|
2024-09-08 21:19:13 +03:00
|
|
|
import { t } from "../services/i18n.js";
|
2021-12-20 17:30:47 +01:00
|
|
|
|
|
|
|
const TPL = `
|
2025-01-23 01:12:05 +02:00
|
|
|
<div class="shared-info-widget alert alert-warning use-tn-links">
|
2021-12-20 17:30:47 +01:00
|
|
|
<style>
|
|
|
|
.shared-info-widget {
|
|
|
|
margin: 10px;
|
|
|
|
contain: none;
|
|
|
|
padding: 10px;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
</style>
|
2025-01-23 01:12:05 +02:00
|
|
|
|
2024-09-08 21:19:13 +03:00
|
|
|
<span class="shared-text"></span> <a class="shared-link external"></a>. ${t("shared_info.help_link")}
|
2021-12-20 17:30:47 +01:00
|
|
|
</div>`;
|
|
|
|
|
|
|
|
export default class SharedInfoWidget extends NoteContextAwareWidget {
|
|
|
|
isEnabled() {
|
2025-01-09 18:07:02 +02:00
|
|
|
return super.isEnabled() && this.noteId !== "_share" && this.note.hasAncestor("_share");
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doRender() {
|
|
|
|
this.$widget = $(TPL);
|
2022-01-14 21:23:10 +01:00
|
|
|
this.$sharedLink = this.$widget.find(".shared-link");
|
|
|
|
this.$sharedText = this.$widget.find(".shared-text");
|
2021-12-20 17:30:47 +01:00
|
|
|
this.contentSized();
|
|
|
|
}
|
|
|
|
|
|
|
|
async refreshWithNote(note) {
|
|
|
|
const syncServerHost = options.get("syncServerHost");
|
|
|
|
let link;
|
|
|
|
|
2022-01-17 23:13:56 +01:00
|
|
|
const shareId = this.getShareId(note);
|
2021-12-22 10:57:02 +01:00
|
|
|
|
2021-12-20 17:30:47 +01:00
|
|
|
if (syncServerHost) {
|
2022-12-21 15:19:05 +01:00
|
|
|
link = `${syncServerHost}/share/${shareId}`;
|
2024-09-08 21:19:13 +03:00
|
|
|
this.$sharedText.text(t("shared_info.shared_publicly"));
|
2025-01-09 18:07:02 +02:00
|
|
|
} else {
|
2023-03-29 23:07:47 +02:00
|
|
|
let host = location.host;
|
2025-01-09 18:07:02 +02:00
|
|
|
if (host.endsWith("/")) {
|
2023-03-29 23:07:47 +02:00
|
|
|
// seems like IE has trailing slash
|
|
|
|
// https://github.com/zadam/trilium/issues/3782
|
|
|
|
host = host.substr(0, host.length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
link = `${location.protocol}//${host}${location.pathname}share/${shareId}`;
|
2024-09-08 21:19:13 +03:00
|
|
|
this.$sharedText.text(t("shared_info.shared_locally"));
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|
|
|
|
|
2022-01-14 21:23:10 +01:00
|
|
|
this.$sharedLink.attr("href", link).text(link);
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|
2021-12-22 10:57:02 +01:00
|
|
|
|
2022-01-17 23:13:56 +01:00
|
|
|
getShareId(note) {
|
2025-01-09 18:07:02 +02:00
|
|
|
if (note.hasOwnedLabel("shareRoot")) {
|
|
|
|
return "";
|
2022-01-17 23:13:56 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
return note.getOwnedLabelValue("shareAlias") || note.noteId;
|
2022-01-17 23:13:56 +01:00
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
entitiesReloadedEvent({ loadResults }) {
|
|
|
|
if (loadResults.getAttributeRows().find((attr) => attr.name.startsWith("_share") && attributeService.isAffecting(attr, this.note))) {
|
2021-12-22 10:57:02 +01:00
|
|
|
this.refresh();
|
2025-01-09 18:07:02 +02:00
|
|
|
} else if (loadResults.getBranchRows().find((branch) => branch.noteId === this.noteId)) {
|
2021-12-22 15:01:54 +01:00
|
|
|
this.refresh();
|
|
|
|
}
|
2021-12-22 10:57:02 +01:00
|
|
|
}
|
2021-12-20 17:30:47 +01:00
|
|
|
}
|