reimplementation of frontend's api.addButtonToToolbar() to smoothen the upgrade

This commit is contained in:
zadam
2022-12-17 21:46:51 +01:00
parent 967919b400
commit 5af506e268
14 changed files with 382 additions and 161 deletions

View File

@@ -360,7 +360,7 @@ class Note extends AbstractEntity {
/** @returns {boolean} true if this note is JavaScript (code or attachment) */
isJavaScript() {
return (this.type === "code" || this.type === "file")
return (this.type === "code" || this.type === "file" || this.type === 'launcher')
&& (this.mime.startsWith("application/javascript")
|| this.mime === "application/x-javascript"
|| this.mime === "text/javascript");
@@ -400,6 +400,8 @@ class Note extends AbstractEntity {
* @returns {Attribute[]} all note's attributes, including inherited ones
*/
getAttributes(type, name) {
this.__validateTypeName(type, name);
this.__getAttributes([]);
if (type && name) {
@@ -489,6 +491,19 @@ class Note extends AbstractEntity {
return this.inheritableAttributeCache;
}
__validateTypeName(type, name) {
if (type && type !== 'label' && type !== 'relation') {
throw new Error(`Unrecognized attribute type '${type}'. Only 'label' and 'relation' are possible values.`);
}
if (name) {
const firstLetter = name.charAt(0);
if (firstLetter === '#' || firstLetter === '~') {
throw new Error(`Detect '#' or '~' in the attribute's name. In the API, attribute names should be set without these characters.`);
}
}
}
/**
* @param type
* @param name
@@ -693,10 +708,7 @@ class Note extends AbstractEntity {
* @returns {Attribute[]} note's "owned" attributes - excluding inherited ones
*/
getOwnedAttributes(type = null, name = null, value = null) {
// it's a common mistake to include # or ~ into attribute name
if (name && ["#", "~"].includes(name[0])) {
name = name.substr(1);
}
this.__validateTypeName(type, name);
if (type && name && value !== undefined && value !== null) {
return this.ownedAttributes.filter(attr => attr.type === type && attr.name === name && attr.value === value);