Merge pull request #4280 from rauenzi/promoted-alias

Add option for promoted aliases
This commit is contained in:
zadam 2023-09-25 23:30:39 +02:00 committed by GitHub
commit 4ac609ff57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 1 deletions

View File

@ -17,6 +17,11 @@ function parse(value) {
defObj.numberPrecision = parseInt(chunks[1]); defObj.numberPrecision = parseInt(chunks[1]);
} }
else if (token.startsWith('alias')) {
const chunks = token.split('=');
defObj.promotedAlias = chunks[1];
}
else if (token.startsWith('inverse')) { else if (token.startsWith('inverse')) {
const chunks = token.split('='); const chunks = token.split('=');

View File

@ -98,6 +98,14 @@ const TPL = `
<th>Promoted:</th> <th>Promoted:</th>
<td><input type="checkbox" class="attr-input-promoted form-control form-control-sm" /></td> <td><input type="checkbox" class="attr-input-promoted form-control form-control-sm" /></td>
</tr> </tr>
<tr class="attr-row-promoted-alias">
<th title="The name to be displayed in the promoted attributes UI.">Alias:</th>
<td>
<div class="input-group">
<input type="text" class="attr-input-promoted-alias form-control" />
</div>
</td>
</tr>
<tr class="attr-row-multiplicity"> <tr class="attr-row-multiplicity">
<th title="Multiplicity defines how many attributes of the same name can be created - at max 1 or more than 1.">Multiplicity:</th> <th title="Multiplicity defines how many attributes of the same name can be created - at max 1 or more than 1.">Multiplicity:</th>
<td> <td>
@ -323,6 +331,10 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
this.$inputPromoted = this.$widget.find('.attr-input-promoted'); this.$inputPromoted = this.$widget.find('.attr-input-promoted');
this.$inputPromoted.on('change', () => this.userEditedAttribute()); this.$inputPromoted.on('change', () => this.userEditedAttribute());
this.$rowPromotedAlias = this.$widget.find('.attr-row-promoted-alias');
this.$inputPromotedAlias = this.$widget.find('.attr-input-promoted-alias');
this.$inputPromotedAlias.on('change', () => this.userEditedAttribute());
this.$rowMultiplicity = this.$widget.find('.attr-row-multiplicity'); this.$rowMultiplicity = this.$widget.find('.attr-row-multiplicity');
this.$inputMultiplicity = this.$widget.find('.attr-input-multiplicity'); this.$inputMultiplicity = this.$widget.find('.attr-input-multiplicity');
this.$inputMultiplicity.on('change', () => this.userEditedAttribute()); this.$inputMultiplicity.on('change', () => this.userEditedAttribute());
@ -453,6 +465,11 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
.prop("checked", !!definition.isPromoted) .prop("checked", !!definition.isPromoted)
.attr('disabled', () => !isOwned); .attr('disabled', () => !isOwned);
this.$rowPromotedAlias.toggle(!!definition.isPromoted);
this.$inputPromotedAlias
.val(definition.promotedAlias)
.attr('disabled', () => !isOwned);
this.$rowMultiplicity.toggle(['label-definition', 'relation-definition'].includes(this.attrType)); this.$rowMultiplicity.toggle(['label-definition', 'relation-definition'].includes(this.attrType));
this.$inputMultiplicity this.$inputMultiplicity
.val(definition.multiplicity) .val(definition.multiplicity)
@ -673,6 +690,10 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
if (this.$inputPromoted.is(":checked")) { if (this.$inputPromoted.is(":checked")) {
props.push("promoted"); props.push("promoted");
if (this.$inputPromotedAlias.val() !== '') {
props.push(`alias=${this.$inputPromotedAlias.val()}`);
}
} }
props.push(this.$inputMultiplicity.val()); props.push(this.$inputMultiplicity.val());
@ -693,6 +714,8 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget {
this.attrType === 'label-definition' this.attrType === 'label-definition'
&& this.$inputLabelType.val() === 'number'); && this.$inputLabelType.val() === 'number');
this.$rowPromotedAlias.toggle(this.$inputPromoted.is(":checked"));
return props.join(","); return props.join(",");
} }

View File

@ -32,6 +32,7 @@ const TPL = `
} }
.promoted-attribute-cell strong { .promoted-attribute-cell strong {
word-break:keep-all; word-break:keep-all;
white-space: nowrap;
} }
</style> </style>
@ -137,7 +138,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
.attr("nowrap", true); .attr("nowrap", true);
const $wrapper = $('<div class="promoted-attribute-cell">') const $wrapper = $('<div class="promoted-attribute-cell">')
.append($("<strong>").text(valueName)) .append($("<strong>").text(definition.promotedAlias ?? valueName))
.append($("<div>").addClass("input-group").append($input)) .append($("<div>").addClass("input-group").append($input))
.append($actionCell) .append($actionCell)
.append($multiplicityCell); .append($multiplicityCell);

View File

@ -17,6 +17,11 @@ function parse(value) {
defObj.numberPrecision = parseInt(chunks[1]); defObj.numberPrecision = parseInt(chunks[1]);
} }
else if (token.startsWith('alias')) {
const chunks = token.split('=');
defObj.promotedAlias = chunks[1];
}
else if (token.startsWith('inverse')) { else if (token.startsWith('inverse')) {
const chunks = token.split('='); const chunks = token.split('=');