diff --git a/package.json b/package.json
index c8e139134..870cf47be 100644
--- a/package.json
+++ b/package.json
@@ -42,7 +42,7 @@
"express-session": "1.17.1",
"file-type": "14.6.2",
"fs-extra": "9.0.1",
- "helmet": "3.23.2",
+ "helmet": "3.23.3",
"html": "1.0.0",
"html2plaintext": "2.1.2",
"http-proxy-agent": "4.0.1",
diff --git a/src/public/app/widgets/attribute_detail.js b/src/public/app/widgets/attribute_detail.js
new file mode 100644
index 000000000..1366bcae4
--- /dev/null
+++ b/src/public/app/widgets/attribute_detail.js
@@ -0,0 +1,162 @@
+import server from "../services/server.js";
+import treeCache from "../services/tree_cache.js";
+import treeService from "../services/tree.js";
+import linkService from "../services/link.js";
+import BasicWidget from "./basic_widget.js";
+
+const TPL = `
+
+
+
+
Label detail
+
+
+
+
+
+
+
+
+
+
+
`;
+
+
+const DISPLAYED_NOTES = 10;
+
+export default class AttributeDetailWidget extends BasicWidget {
+ doRender() {
+ this.$widget = $(TPL);
+ this.$relatedNotesTitle = this.$widget.find('.related-notes-tile');
+ this.$relatedNotesList = this.$widget.find('.related-notes-list');
+ this.$relatedNotesMoreNotes = this.$widget.find('.related-notes-more-notes');
+ this.$attrEditName = this.$widget.find('.attr-edit-name');
+ this.$attrEditValue = this.$widget.find('.attr-edit-value');
+ this.$attrEditInheritable = this.$widget.find('.attr-edit-inheritable');
+
+ return this.$widget;
+ }
+
+ async showAttributeDetail(attr, x, y) {
+ if (!attr) {
+ this.hide();
+
+ return;
+ }
+
+ this.toggleInt(true);
+
+ let {results, count} = await server.post('search-related', attr);
+
+ for (const res of results) {
+ res.noteId = res.notePathArray[res.notePathArray.length - 1];
+ }
+
+ results = results.filter(({noteId}) => noteId !== this.noteId);
+
+ if (results.length === 0) {
+ this.$relatedNotesTitle.hide();
+ }
+ else {
+ this.$relatedNotesTitle.text(`Other notes with ${attr.type} name "${attr.name}"`);
+ }
+
+ this.$relatedNotesList.empty();
+
+ const displayedResults = results.length <= DISPLAYED_NOTES ? results : results.slice(0, DISPLAYED_NOTES);
+ const displayedNotes = await treeCache.getNotes(displayedResults.map(res => res.noteId));
+
+ for (const note of displayedNotes) {
+ const notePath = treeService.getSomeNotePath(note);
+ const $noteLink = await linkService.createNoteLink(notePath, {showNotePath: true});
+
+ this.$relatedNotesList.append(
+ $("").append($noteLink)
+ );
+ }
+
+ if (results.length > DISPLAYED_NOTES) {
+ this.$relatedNotesMoreNotes.show().text(`... and ${count - DISPLAYED_NOTES} more.`);
+ }
+ else {
+ this.$relatedNotesMoreNotes.hide();
+ }
+
+ this.$attrEditName.val(attr.name);
+ this.$attrEditValue.val(attr.value);
+
+ this.$widget.css("left", x - this.$widget.width() / 2);
+ this.$widget.css("top", y + 30);
+ this.$widget.show();
+ }
+
+ hide() {
+ this.toggleInt(false);
+ }
+
+ createNoteLink(noteId) {
+ return $("", {
+ href: '#' + noteId,
+ class: 'reference-link',
+ 'data-note-path': noteId
+ });
+ }
+}
diff --git a/src/public/app/widgets/basic_widget.js b/src/public/app/widgets/basic_widget.js
index b5d81142b..f1e4f98b2 100644
--- a/src/public/app/widgets/basic_widget.js
+++ b/src/public/app/widgets/basic_widget.js
@@ -46,9 +46,9 @@ class BasicWidget extends Component {
}
render() {
- const $widget = this.doRender();
+ this.doRender();
- $widget.addClass('component')
+ this.$widget.addClass('component')
.prop('component', this);
this.toggleInt(this.isEnabled());
@@ -56,28 +56,28 @@ class BasicWidget extends Component {
if (this.cssEl) {
const css = this.cssEl.trim().startsWith('`;
- $widget.append(css);
+ this.$widget.append(css);
}
for (const key in this.attrs) {
if (key === 'style') {
if (this.attrs[key]) {
- let style = $widget.attr('style');
+ let style = this.$widget.attr('style');
style = style ? `${style}; ${this.attrs[key]}` : this.attrs[key];
- $widget.attr(key, style);
+ this.$widget.attr(key, style);
}
}
else {
- $widget.attr(key, this.attrs[key]);
+ this.$widget.attr(key, this.attrs[key]);
}
}
for (const className of this.classes) {
- $widget.addClass(className);
+ this.$widget.addClass(className);
}
- return $widget;
+ return this.$widget;
}
isEnabled() {
diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js
index a23245b30..af7beda7e 100644
--- a/src/public/app/widgets/note_attributes.js
+++ b/src/public/app/widgets/note_attributes.js
@@ -6,8 +6,7 @@ import server from "../services/server.js";
import ws from "../services/ws.js";
import SpacedUpdate from "../services/spaced_update.js";
import attributesParser from "../services/attribute_parser.js";
-import linkService from "../services/link.js";
-import treeService from "../services/tree.js";
+import AttributeDetailWidget from "./attribute_detail.js";
const mentionSetup = {
feeds: [
@@ -74,110 +73,36 @@ const mentionSetup = {
const TPL = `
-
-
-
-