implemented mirror relations

This commit is contained in:
azivner
2018-11-12 23:34:22 +01:00
parent e7cea59ba7
commit 21d3b0c9d8
13 changed files with 164 additions and 31 deletions
@@ -71,6 +71,7 @@ function AttributesModel() {
attr.relationDefinition = (attr.type === 'relation-definition' && attr.value) ? attr.value : {
multiplicityType: "singlevalue",
mirrorRelation: "",
isPromoted: true
};
@@ -189,6 +190,7 @@ function AttributesModel() {
},
relationDefinition: {
multiplicityType: "singlevalue",
mirrorRelation: "",
isPromoted: true
}
}));
+12 -9
View File
@@ -60,7 +60,7 @@ async function showAttributes() {
const $inputCell = $("<td>").append($("<div>").addClass("input-group").append($input));
const $actionCell = $("<td>");
const $multiplicityCell = $("<td>");
const $multiplicityCell = $("<td>").addClass("multiplicity");
$tr
.append($labelCell)
@@ -148,9 +148,14 @@ async function showAttributes() {
// ideally we'd use link instead of button which would allow tooltip preview, but
// we can't guarantee updating the link in the a element
const $openButton = $("<button>").addClass("btn btn-sm").text("Open").click(() => {
const notePath = $input.prop("data-selected-path");
const notePath = $input.getSelectedPath();
treeService.activateNote(notePath);
if (notePath) {
treeService.activateNote(notePath);
}
else {
console.log("Empty note path, nothing to open.");
}
});
$actionCell.append($openButton);
@@ -162,7 +167,7 @@ async function showAttributes() {
if (definition.multiplicityType === "multivalue") {
const addButton = $("<span>")
.addClass("glyphicon glyphicon-plus pointer")
.addClass("jam jam-plus pointer")
.prop("title", "Add new attribute")
.click(async () => {
const $new = await createRow(definitionAttr, {
@@ -178,7 +183,7 @@ async function showAttributes() {
});
const removeButton = $("<span>")
.addClass("glyphicon glyphicon-trash pointer")
.addClass("jam jam-trash pointer")
.prop("title", "Remove this attribute")
.click(async () => {
if (valueAttr.attributeId) {
@@ -269,11 +274,9 @@ async function promotedAttributeChanged(event) {
value = $attr.is(':checked') ? "true" : "false";
}
else if ($attr.prop("attribute-type") === "relation") {
const selectedPath = $attr.prop("data-selected-path");
const selectedPath = $attr.getSelectedPath();
if (selectedPath) {
value = treeUtils.getNoteIdFromNotePath(selectedPath);
}
value = selectedPath ? treeUtils.getNoteIdFromNotePath(selectedPath) : "";
}
else {
value = $attr.val();
@@ -54,24 +54,34 @@ function initNoteAutocomplete($el) {
$el.prop("data-selected-path", suggestion.path);
});
$el.getSelectedPath = () => $el.prop("data-selected-path");
$el.on('autocomplete:closed', () => {
$el.prop("data-selected-path", "");
});
}
return $el;
}
$.fn.getSelectedPath = function() {
if (!$(this).val().trim()) {
return "";
}
else {
return $(this).prop("data-selected-path");
}
};
ko.bindingHandlers.noteAutocomplete = {
init: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
initNoteAutocomplete($(element));
$(element).on('autocomplete:selected', function(event, suggestion, dataset) {
bindingContext.$data.selectedPath = suggestion.path;
bindingContext.$data.selectedPath = $(element).val().trim() ? suggestion.path : '';
});
}
};
export default {
initNoteAutocomplete,
autocompleteSource,
showRecentNotes
}
+6 -1
View File
@@ -152,6 +152,11 @@ async function getRunPath(notePath) {
if (childNoteId !== null) {
const child = await treeCache.getNote(childNoteId);
if (!child) {
console.log("Can't find " + childNoteId);
}
const parents = await child.getParentNotes();
if (!parents) {
@@ -609,7 +614,7 @@ $(window).bind('hashchange', function() {
const notePath = getNotePathFromAddress();
if (getCurrentNotePath() !== notePath) {
console.log("Switching to " + notePath + " because of hash change");
console.debug("Switching to " + notePath + " because of hash change");
activateNote(notePath);
}
@@ -57,7 +57,7 @@ class TreeCache {
return noteIds.map(noteId => {
if (!this.notes[noteId] && !silentNotFoundError) {
messagingService.logError(`Can't find note ${noteId}`);
messagingService.logError(`Can't find note "${noteId}"`);
return null;
}