parsing and setting isInheritable flag

This commit is contained in:
zadam
2020-07-13 23:27:23 +02:00
parent 5dd73562da
commit 528418aecb
8 changed files with 82 additions and 27 deletions

View File

@@ -19,7 +19,7 @@ class Attribute {
/** @param {int} position */
this.position = row.position;
/** @param {boolean} isInheritable */
this.isInheritable = row.isInheritable;
this.isInheritable = !!row.isInheritable;
}
/** @returns {NoteShort} */

View File

@@ -92,6 +92,15 @@ function lexer(str) {
finishWord(i - 1);
continue;
}
else if (['(', ')'].includes(chr)) {
finishWord(i - 1);
currentWord = chr;
finishWord(i);
continue;
}
else if (previousOperatorSymbol() !== isOperatorSymbol(chr)) {
finishWord(i - 1);
@@ -122,15 +131,30 @@ function parser(tokens, str, allowEmptyRelations = false) {
}
for (let i = 0; i < tokens.length; i++) {
const {text, startIndex, endIndex} = tokens[i];
const {text, startIndex} = tokens[i];
function isInheritable() {
if (tokens.length > i + 3
&& tokens[i + 1].text === '('
&& tokens[i + 2].text === 'inheritable'
&& tokens[i + 3].text === ')') {
i += 3;
return true;
}
else {
return false;
}
}
if (text.startsWith('#')) {
const attr = {
type: 'label',
name: text.substr(1),
isInheritable: false, // FIXME
isInheritable: isInheritable(),
startIndex: startIndex,
endIndex: endIndex
endIndex: tokens[i].endIndex // i could be moved by isInheritable
};
if (i + 1 < tokens.length && tokens[i + 1].text === "=") {
@@ -150,9 +174,9 @@ function parser(tokens, str, allowEmptyRelations = false) {
const attr = {
type: 'relation',
name: text.substr(1),
isInheritable: false, // FIXME
isInheritable: isInheritable(),
startIndex: startIndex,
endIndex: endIndex
endIndex: tokens[i].endIndex // i could be moved by isInheritable
};
attrs.push(attr);

View File

@@ -117,6 +117,8 @@ export default class AttributeDetailWidget extends BasicWidget {
});
this.$attrEditInheritable = this.$widget.find('.attr-edit-inheritable');
this.$attrEditInheritable.on('change', () => this.updateParent());
this.$closeAttrDetailButton = this.$widget.find('.close-attr-detail-button');
this.$attrIsOwnedBy = this.$widget.find('.attr-is-owned-by');
@@ -210,6 +212,8 @@ export default class AttributeDetailWidget extends BasicWidget {
.setSelectedNotePath(attribute.value);
}
this.$attrEditInheritable.prop("checked", !!attribute.isInheritable);
this.$widget.css("left", x - this.$widget.width() / 2);
this.$widget.css("top", y + 30);
this.$widget.show();
@@ -218,6 +222,7 @@ export default class AttributeDetailWidget extends BasicWidget {
updateParent() {
this.attribute.name = this.$attrEditName.val();
this.attribute.value = this.$attrEditValue.val();
this.attribute.isInheritable = this.$attrEditInheritable.is(":checked");
this.triggerCommand('updateAttributeList', { attributes: this.allAttributes });
}

View File

@@ -496,7 +496,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {
this.$inheritedAttributes.empty();
await this.renderAttributesIntoDiv(inheritedAttributes, this.$inheritedAttributes);
await this.renderInheritedAttributes(inheritedAttributes, this.$inheritedAttributes);
this.parseAttributes();
}
@@ -504,7 +504,9 @@ export default class NoteAttributesWidget extends TabAwareWidget {
async renderOwnedAttributes(ownedAttributes) {
const $attributesContainer = $("<div>");
await this.renderAttributesIntoCKEditor(ownedAttributes, $attributesContainer);
for (const attribute of ownedAttributes) {
this.renderAttribute(attribute, $attributesContainer, true);
}
await this.spacedUpdate.allowUpdateWithoutChange(() => {
this.textEditor.setData($attributesContainer.html());
@@ -523,13 +525,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {
});
}
async renderAttributesIntoCKEditor(attributes, $container) {
for (const attribute of attributes) {
this.renderAttribute(attribute, $container);
}
}
renderAttributesIntoDiv(attributes, $container) {
renderInheritedAttributes(attributes, $container) {
for (const attribute of attributes) {
const $span = $("<span>")
.on('click', e => this.attributeDetailWidget.showAttributeDetail({
@@ -546,13 +542,15 @@ export default class NoteAttributesWidget extends TabAwareWidget {
$container.append($span);
this.renderAttribute(attribute, $span);
this.renderAttribute(attribute, $span, false);
}
}
renderAttribute(attribute, $container) {
renderAttribute(attribute, $container, renderIsInheritable) {
const isInheritable = renderIsInheritable && attribute.isInheritable ? `(inheritable)` : '';
if (attribute.type === 'label') {
$container.append(document.createTextNode('#' + attribute.name));
$container.append(document.createTextNode('#' + attribute.name + isInheritable));
if (attribute.value) {
$container.append('=');
@@ -566,7 +564,7 @@ export default class NoteAttributesWidget extends TabAwareWidget {
}
if (attribute.value) {
$container.append(document.createTextNode('~' + attribute.name + "="));
$container.append(document.createTextNode('~' + attribute.name + isInheritable + "="));
$container.append(this.createNoteLink(attribute.value));
$container.append(" ");
} else {