mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fix showing promoted notes, closes #944
This commit is contained in:
parent
b1bed18331
commit
dfb97d64f7
@ -27,6 +27,15 @@ class Attribute {
|
|||||||
return await this.treeCache.getNote(this.noteId);
|
return await this.treeCache.getNote(this.noteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get jsonValue() {
|
||||||
|
try {
|
||||||
|
return JSON.parse(this.value);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get toString() {
|
get toString() {
|
||||||
return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
|
return `Attribute(attributeId=${this.attributeId}, type=${this.type}, name=${this.name}, value=${this.value})`;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import treeService from "./tree.js";
|
import treeService from "./tree.js";
|
||||||
import linkService from "./link.js";
|
import linkService from "./link.js";
|
||||||
import treeCache from "./tree_cache.js";
|
import treeCache from "./tree_cache.js";
|
||||||
|
import utils from "./utils.js";
|
||||||
|
|
||||||
function setupGlobalTooltip() {
|
function setupGlobalTooltip() {
|
||||||
$(document).on("mouseenter", "a", mouseEnterHandler);
|
$(document).on("mouseenter", "a", mouseEnterHandler);
|
||||||
@ -74,13 +75,18 @@ async function renderTooltip(note, noteComplement) {
|
|||||||
return '<div>Note has been deleted.</div>';
|
return '<div>Note has been deleted.</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributes = await note.getAttributes();
|
const attributes = note.getAttributes();
|
||||||
|
|
||||||
let content = '';
|
let content = '';
|
||||||
const promoted = attributes.filter(attr =>
|
|
||||||
(attr.type === 'label-definition' || attr.type === 'relation-definition')
|
const promoted = attributes
|
||||||
&& !attr.name.startsWith("child:")
|
.filter(attr => attr.type === 'label-definition' || attr.type === 'relation-definition')
|
||||||
&& attr.value.isPromoted);
|
.filter(attr => !attr.name.startsWith("child:"))
|
||||||
|
.filter(attr => {
|
||||||
|
const json = attr.jsonValue;
|
||||||
|
|
||||||
|
return json && json.isPromoted;
|
||||||
|
});
|
||||||
|
|
||||||
if (promoted.length > 0) {
|
if (promoted.length > 0) {
|
||||||
const $table = $("<table>").addClass("promoted-attributes-in-tooltip");
|
const $table = $("<table>").addClass("promoted-attributes-in-tooltip");
|
||||||
@ -116,12 +122,12 @@ async function renderTooltip(note, noteComplement) {
|
|||||||
content += $table.prop('outerHTML');
|
content += $table.prop('outerHTML');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.type === 'text') {
|
if (note.type === 'text' && !utils.isHtmlEmpty(noteComplement.content)) {
|
||||||
// surround with <div> for a case when note's content is pure text (e.g. "[protected]") which
|
// surround with <div> for a case when note's content is pure text (e.g. "[protected]") which
|
||||||
// then fails the jquery non-empty text test
|
// then fails the jquery non-empty text test
|
||||||
content += '<div>' + noteComplement.content + '</div>';
|
content += '<div>' + noteComplement.content + '</div>';
|
||||||
}
|
}
|
||||||
else if (note.type === 'code') {
|
else if (note.type === 'code' && noteComplement.content && noteComplement.content.trim()) {
|
||||||
content += $("<pre>")
|
content += $("<pre>")
|
||||||
.text(noteComplement.content)
|
.text(noteComplement.content)
|
||||||
.prop('outerHTML');
|
.prop('outerHTML');
|
||||||
@ -133,10 +139,6 @@ async function renderTooltip(note, noteComplement) {
|
|||||||
}
|
}
|
||||||
// other types of notes don't have tooltip preview
|
// other types of notes don't have tooltip preview
|
||||||
|
|
||||||
if (!$(content).text().trim() && note.type !== 'image') {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ export default class AttributesWidget extends CollapsibleWidget {
|
|||||||
.attr("href", "javascript:")
|
.attr("href", "javascript:")
|
||||||
.text("+show inherited")
|
.text("+show inherited")
|
||||||
.on('click', async () => {
|
.on('click', async () => {
|
||||||
const attributes = await note.getAttributes();
|
const attributes = note.getAttributes();
|
||||||
const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.noteId);
|
const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.noteId);
|
||||||
|
|
||||||
if (inheritedAttributes.length === 0) {
|
if (inheritedAttributes.length === 0) {
|
||||||
|
@ -40,10 +40,14 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
|
|||||||
|
|
||||||
const attributes = note.getAttributes();
|
const attributes = note.getAttributes();
|
||||||
|
|
||||||
const promoted = attributes.filter(attr =>
|
const promoted = attributes
|
||||||
(attr.type === 'label-definition' || attr.type === 'relation-definition')
|
.filter(attr => attr.type === 'label-definition' || attr.type === 'relation-definition')
|
||||||
&& !attr.name.startsWith("child:")
|
.filter(attr => !attr.name.startsWith("child:"))
|
||||||
&& attr.value.isPromoted);
|
.filter(attr => {
|
||||||
|
const json = attr.jsonValue;
|
||||||
|
|
||||||
|
return json && json.isPromoted;
|
||||||
|
});
|
||||||
|
|
||||||
const hidePromotedAttributes = attributes.some(attr => attr.type === 'label' && attr.name === 'hidePromotedAttributes');
|
const hidePromotedAttributes = attributes.some(attr => attr.type === 'label' && attr.name === 'hidePromotedAttributes');
|
||||||
|
|
||||||
@ -89,7 +93,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async createPromotedAttributeRow(definitionAttr, valueAttr) {
|
async createPromotedAttributeRow(definitionAttr, valueAttr) {
|
||||||
const definition = definitionAttr.value;
|
const definition = definitionAttr.jsonValue;
|
||||||
const $tr = $("<tr>");
|
const $tr = $("<tr>");
|
||||||
const $labelCell = $("<th>").append(valueAttr.name);
|
const $labelCell = $("<th>").append(valueAttr.name);
|
||||||
const $input = $("<input>")
|
const $input = $("<input>")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user