Skip to content

Build your personal knowledge base with Trilium Notes

add support for number precision in promoted attributes, closes #245

azivnerba7c8e77e557
diff --git a/db/demo.tar b/db/demo.tar
index 43a3a8609d..19f0c04157 100644
Binary files a/db/demo.tar and b/db/demo.tar differ
diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js
index dde933b045..b742829df9 100644
--- a/src/public/javascripts/dialogs/attributes.js
+++ b/src/public/javascripts/dialogs/attributes.js
@@ -67,7 +67,8 @@ function AttributesModel() {
attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : {
labelType: "text",
multiplicityType: "singlevalue",
- isPromoted: true
+ isPromoted: true,
+ numberPrecision: 0
};
attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? attr.value : {
@@ -187,7 +188,8 @@ function AttributesModel() {
labelDefinition: {
labelType: "text",
multiplicityType: "singlevalue",
- isPromoted: true
+ isPromoted: true,
+ numberPrecision: 0
},
relationDefinition: {
multiplicityType: "singlevalue",
diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js
index 893e73a5cd..3b184a9176 100644
--- a/src/public/javascripts/services/attributes.js
+++ b/src/public/javascripts/services/attributes.js
@@ -3,9 +3,7 @@ import utils from "./utils.js";
import messagingService from "./messaging.js";
import treeUtils from "./tree_utils.js";
import noteAutocompleteService from "./note_autocomplete.js";
-import treeService from "./tree.js";
import linkService from "./link.js";
-import infoService from "./info.js";
import noteDetailService from "./note_detail.js";
const $attributeList = $("#attribute-list");
@@ -163,6 +161,14 @@ async function createPromotedAttributeRow(definitionAttr, valueAttr) {
}
else if (definition.labelType === 'number') {
$input.prop("type", "number");
+
+ let step = 1;
+
+ for (let i = 0; i < (definition.numberPrecision || 0) && i < 10; i++) {
+ step /= 10;
+ }
+
+ $input.prop("step", step);
}
else if (definition.labelType === 'boolean') {
$input.prop("type", "checkbox");
diff --git a/src/views/dialogs/attributes.ejs b/src/views/dialogs/attributes.ejs
index 8d91ea044a..204d1d594b 100644
--- a/src/views/dialogs/attributes.ejs
+++ b/src/views/dialogs/attributes.ejs
@@ -64,6 +64,11 @@
data-bind="checked: labelDefinition.isPromoted"/>
Promoted
</label>
+
+ <div data-bind="visible: labelDefinition.labelType === 'number'"
+ title="Precision of floating point numbers - 0 means effectively integer, 2 allows entering e.g. 1.23">
+ Number precision: <input type="number" min="0" max="9" data-bind="value: labelDefinition.numberPrecision" style="width: 50px;"/>
+ </div>
</div>
<div data-bind="visible: type == 'relation-definition'">