fix relations in attributes

This commit is contained in:
azivner 2018-08-06 11:30:37 +02:00
parent a55d3530e9
commit 49989695ff
3 changed files with 12 additions and 7 deletions

View File

@ -1,6 +1,8 @@
import noteDetailService from '../services/note_detail.js'; import noteDetailService from '../services/note_detail.js';
import server from '../services/server.js'; import server from '../services/server.js';
import infoService from "../services/info.js"; import infoService from "../services/info.js";
import treeUtils from "../services/tree_utils.js";
import linkService from "../services/link.js";
const $dialog = $("#attributes-dialog"); const $dialog = $("#attributes-dialog");
const $saveAttributesButton = $("#save-attributes-button"); const $saveAttributesButton = $("#save-attributes-button");
@ -53,10 +55,10 @@ function AttributesModel() {
}); });
}; };
function prepareAttributes(attributes) { async function showAttributes(attributes) {
for (const attr of attributes) { for (const attr of attributes) {
attr.labelValue = attr.type === 'label' ? attr.value : ''; attr.labelValue = attr.type === 'label' ? attr.value : '';
attr.relationValue = attr.type === 'relation' ? attr.value : ''; attr.relationValue = attr.type === 'relation' ? (await treeUtils.getNoteTitle(attr.value) + " (" + attr.value + ")") : '';
attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : { attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : {
labelType: "text", labelType: "text",
multiplicityType: "singlevalue", multiplicityType: "singlevalue",
@ -80,7 +82,7 @@ function AttributesModel() {
const attributes = await server.get('notes/' + noteId + '/attributes'); const attributes = await server.get('notes/' + noteId + '/attributes');
prepareAttributes(attributes); await showAttributes(attributes);
// attribute might not be rendered immediatelly so could not focus // attribute might not be rendered immediatelly so could not focus
setTimeout(() => $(".attribute-name:last").focus(), 100); setTimeout(() => $(".attribute-name:last").focus(), 100);
@ -139,7 +141,7 @@ function AttributesModel() {
attr.value = attr.labelValue; attr.value = attr.labelValue;
} }
else if (attr.type === 'relation') { else if (attr.type === 'relation') {
attr.value = attr.relationValue; attr.value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel(attr.relationValue));
} }
else if (attr.type === 'label-definition') { else if (attr.type === 'label-definition') {
attr.value = attr.labelDefinition; attr.value = attr.labelDefinition;
@ -156,7 +158,7 @@ function AttributesModel() {
const attributes = await server.put('notes/' + noteId + '/attributes', attributesToSave); const attributes = await server.put('notes/' + noteId + '/attributes', attributesToSave);
prepareAttributes(attributes); await showAttributes(attributes);
infoService.showMessage("Attributes have been saved."); infoService.showMessage("Attributes have been saved.");

View File

@ -263,7 +263,7 @@ async function loadAttributes() {
$attributeListInner.append(utils.formatLabel(attribute) + " "); $attributeListInner.append(utils.formatLabel(attribute) + " ");
} }
else if (attribute.type === 'relation') { else if (attribute.type === 'relation') {
$attributeListInner.append(attribute.name + " = "); $attributeListInner.append(attribute.name + "=");
$attributeListInner.append(await linkService.createNoteLink(attribute.value)); $attributeListInner.append(await linkService.createNoteLink(attribute.value));
$attributeListInner.append(" "); $attributeListInner.append(" ");
} }

View File

@ -2,6 +2,7 @@ import utils from "./utils.js";
import Branch from "../entities/branch.js"; import Branch from "../entities/branch.js";
import NoteShort from "../entities/note_short.js"; import NoteShort from "../entities/note_short.js";
import infoService from "./info.js"; import infoService from "./info.js";
import messagingService from "./messaging.js";
import server from "./server.js"; import server from "./server.js";
class TreeCache { class TreeCache {
@ -48,7 +49,9 @@ class TreeCache {
return noteIds.map(noteId => { return noteIds.map(noteId => {
if (!this.notes[noteId]) { if (!this.notes[noteId]) {
throw new Error(`Can't find note ${noteId}`); messagingService.logError(`Can't find note ${noteId}`);
return `[unknown ${noteId}]`;
} }
else { else {
return this.notes[noteId]; return this.notes[noteId];