mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-05-04 11:19:27 -05:00
promoted relation attributes now work correctly, refactoring of note autocomplete code
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import server from "./server.js";
|
||||
|
||||
async function initNoteAutocomplete($el) {
|
||||
if (!$el.hasClass("ui-autocomplete-input")) {
|
||||
const $showRecentNotesButton = $("<span>")
|
||||
.addClass("input-group-addon show-recent-notes-button")
|
||||
.prop("title", "Show recent notes");
|
||||
|
||||
$el.after($showRecentNotesButton);
|
||||
|
||||
$showRecentNotesButton.click(() => $el.autocomplete("search", ""));
|
||||
|
||||
await $el.autocomplete({
|
||||
appendTo: $el.parent().parent(),
|
||||
source: async function (request, response) {
|
||||
const result = await server.get('autocomplete?query=' + encodeURIComponent(request.term));
|
||||
|
||||
if (result.length > 0) {
|
||||
response(result.map(row => {
|
||||
return {
|
||||
label: row.label,
|
||||
value: row.label + ' (' + row.value + ')'
|
||||
}
|
||||
}));
|
||||
}
|
||||
else {
|
||||
response([{
|
||||
label: "No results",
|
||||
value: "No results"
|
||||
}]);
|
||||
}
|
||||
},
|
||||
minLength: 0,
|
||||
change: function (event, ui) {
|
||||
$el.trigger("change");
|
||||
},
|
||||
select: function (event, ui) {
|
||||
if (ui.item.value === 'No results') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ko.bindingHandlers.noteAutocomplete = {
|
||||
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
|
||||
initNoteAutocomplete($(element));
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
initNoteAutocomplete
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import noteDetailFile from './note_detail_file.js';
|
||||
import noteDetailSearch from './note_detail_search.js';
|
||||
import noteDetailRender from './note_detail_render.js';
|
||||
import bundleService from "./bundle.js";
|
||||
import noteAutocompleteService from "./note_autocomplete.js";
|
||||
|
||||
const $noteTitle = $("#note-title");
|
||||
|
||||
@@ -250,7 +251,7 @@ async function loadAttributes() {
|
||||
.addClass("form-control")
|
||||
.addClass("promoted-attribute-input");
|
||||
|
||||
const $inputCell = $("<td>").append($input);
|
||||
const $inputCell = $("<td>").append($("<div>").addClass("input-group").append($input));
|
||||
|
||||
const $actionCell = $("<td>");
|
||||
const $multiplicityCell = $("<td>");
|
||||
@@ -295,6 +296,17 @@ async function loadAttributes() {
|
||||
messagingService.logError("Unknown labelType=" + definitionAttr.labelType);
|
||||
}
|
||||
}
|
||||
else if (valueAttr.type === 'relation') {
|
||||
if (valueAttr.value) {
|
||||
$input.val((await treeUtils.getNoteTitle(valueAttr.value) + " (" + valueAttr.value + ")"));
|
||||
}
|
||||
|
||||
await noteAutocompleteService.initNoteAutocomplete($input);
|
||||
}
|
||||
else {
|
||||
messagingService.logError("Unknown attribute type=" + valueAttr.type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (definition.multiplicityType === "multivalue") {
|
||||
const addButton = $("<span>")
|
||||
@@ -455,6 +467,11 @@ $promotedAttributesContainer.on('change', '.promoted-attribute-input', async eve
|
||||
if ($attr.prop("type") === "checkbox") {
|
||||
value = $attr.is(':checked') ? "true" : "false";
|
||||
}
|
||||
else if ($attr.prop("attribute-type") === "relation") {
|
||||
if ($attr.val()) {
|
||||
value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel($attr.val()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = $attr.val();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ function isElectron() {
|
||||
function assertArguments() {
|
||||
for (const i in arguments) {
|
||||
if (!arguments[i]) {
|
||||
throw new Error(`Argument idx#${i} should not be falsy: ${arguments[i]}`);
|
||||
console.trace(`Argument idx#${i} should not be falsy: ${arguments[i]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user