Skip to content

Commit

Permalink
fix: AASPropertyGridComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Aug 12, 2024
1 parent bf51d1e commit c90e8f0
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 236 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
<p>aas-property-grid works!</p>
@if (referable()) {
<table>
@for (item of items(); track item.name) {
<tr>
<td>{{item.name}}</td>
<td>{{item.value}}</td>
</tr>
}
</table>
} @else {
<div class="alert alert-info text-center mt-2" role="alert">{{'INFO_NO_REFERABLE_SELECTED' | translate}}</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*****************************************************************************/

import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { aas } from 'aas-core';

export interface PropertyValueItem {
Expand All @@ -20,7 +21,7 @@ export interface PropertyValueItem {
templateUrl: './aas-property-grid.component.html',
styleUrl: './aas-property-grid.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [],
imports: [TranslateModule],
})
export class AASPropertyGridComponent {
public readonly referable = input<aas.Referable>();
Expand All @@ -36,6 +37,8 @@ export class AASPropertyGridComponent {
const value = (referable as unknown as { [key: string]: unknown })[name];
if (typeof value === 'string') {
items.push({ name, value });
} else if (typeof value === 'object') {
items.push({ name, value: 'ToDo...' });
}
}

Expand Down
173 changes: 0 additions & 173 deletions projects/aas-lib/src/lib/aas-tree/aas-tree-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,15 @@ import isEqual from 'lodash-es/isEqual';
import {
AASDocument,
aas,
convertToString,
getAbbreviation,
getLocaleValue,
isAssetAdministrationShell,
isBooleanType,
isHasSemantics,
isIdentifiable,
isMultiLanguageProperty,
isSubmodel,
isSubmodelElement,
mimeTypeToExtension,
selectReferable,
toBoolean,
toLocale,
} from 'aas-core';

import { resolveSemanticId, supportedSubmodelTemplates } from '../submodel-template/submodel-template';
import { Tree, TreeNode } from '../tree';
import { basename, normalize } from '../convert';

export class AASTreeRow extends TreeNode<aas.Referable> {
public constructor(
Expand All @@ -40,8 +30,6 @@ export class AASTreeRow extends TreeNode<aas.Referable> {
level: number,
public readonly abbreviation: string,
public readonly name: string,
public readonly typeInfo: string,
public readonly value: string | boolean | undefined,
public readonly isLeaf: boolean,
parent: number,
firstChild: number,
Expand All @@ -63,44 +51,6 @@ export class AASTreeRow extends TreeNode<aas.Referable> {

return false;
}

public get annotatedRelationship(): aas.AnnotatedRelationshipElement | undefined {
return this.element.modelType === 'AnnotatedRelationshipElement'
? (this.element as aas.AnnotatedRelationshipElement)
: undefined;
}

public get blob(): aas.Blob | undefined {
return this.element.modelType === 'Blob' ? (this.element as aas.Blob) : undefined;
}

public get entity(): aas.Entity | undefined {
return this.element.modelType === 'Entity' ? (this.element as aas.Entity) : undefined;
}

public get file(): aas.File | undefined {
return this.element.modelType === 'File' ? (this.element as aas.File) : undefined;
}

public get operation(): aas.Operation | undefined {
return this.element.modelType === 'Operation' ? (this.element as aas.Operation) : undefined;
}

public get property(): aas.Property | undefined {
return this.element.modelType === 'Property' ? (this.element as aas.Property) : undefined;
}

public get reference(): aas.ReferenceElement | undefined {
return this.element.modelType === 'ReferenceElement' ? (this.element as aas.ReferenceElement) : undefined;
}

public get relationship(): aas.RelationshipElement | undefined {
return this.element.modelType === 'RelationshipElement' ? (this.element as aas.RelationshipElement) : undefined;
}

public get submodel(): aas.Submodel | undefined {
return this.element.modelType === 'Submodel' ? (this.element as aas.Submodel) : undefined;
}
}

class TreeInitialize {
Expand Down Expand Up @@ -153,8 +103,6 @@ class TreeInitialize {
level,
getAbbreviation(element.modelType) ?? '',
element.idShort,
this.getTypeInfo(element),
this.getValue(element, this.language),
isLeaf,
parent,
-1,
Expand Down Expand Up @@ -257,44 +205,6 @@ class TreeInitialize {
return { type: 'ModelReference', keys };
}

private getValue(referable: aas.Referable | null, localeId: string): boolean | string | undefined {
if (!referable) {
return '';
}

switch (referable.modelType) {
case 'Blob': {
const blob = referable as aas.Blob;
const extension = mimeTypeToExtension(blob.contentType);
return `${blob.idShort}${extension}`;
}
case 'Entity':
return (referable as aas.Entity).globalAssetId ?? '-';
case 'File': {
const file = referable as aas.File;
return file.value ? basename(normalize(file.value)) : '-';
}
case 'MultiLanguageProperty':
return getLocaleValue((referable as aas.MultiLanguageProperty).value, localeId) ?? '-';
case 'Operation':
return `${referable.idShort}()`;
case 'Property':
return this.getPropertyValue(referable as aas.Property, localeId);
case 'Range': {
const range = referable as aas.Range;
return `${convertToString(range.min, localeId)} ... ${convertToString(range.max, localeId)}`;
}
case 'ReferenceElement':
return this.referenceToString((referable as aas.ReferenceElement).value);
case 'SubmodelElementCollection':
return (referable as aas.SubmodelElementCollection).value?.length.toString() ?? '0';
case 'SubmodelElementList':
return (referable as aas.SubmodelElementList).value?.length.toString() ?? '0';
default:
return '';
}
}

private hasChildren(referable: aas.Referable): boolean {
switch (referable.modelType) {
case 'AssetAdministrationShell': {
Expand Down Expand Up @@ -341,87 +251,6 @@ class TreeInitialize {
return false;
}
}

private getPropertyValue(property: aas.Property, localeId: string): string | boolean | undefined {
if (isBooleanType(property.valueType)) {
return toBoolean(property.value);
} else {
return toLocale(property.value, property.valueType, localeId);
}
}

private getTypeInfo(referable: aas.Referable | null): string {
if (!referable) {
return '-';
}

if (isAssetAdministrationShell(referable)) {
return referable.id;
}

if (isMultiLanguageProperty(referable)) {
let value = '';
if (referable && Array.isArray(referable.value)) {
value += `${referable.value.map(item => item.language).join(', ')}`;
}

return value;
}

let value = '';
if (isHasSemantics(referable)) {
const a = this.getSemanticId(referable);
value = `Semantic ID: ${a}`;
}

switch (referable.modelType) {
case 'AnnotatedRelationshipElement':
value = (referable as aas.AnnotatedRelationshipElement).annotations?.length.toString() ?? '-';
break;
case 'Blob': {
const contentType = (referable as aas.Blob).contentType;
if (contentType) {
value += ', ' + contentType;
}

break;
}
case 'File': {
const contentType = (referable as aas.File).contentType;
if (contentType) {
value += ', ' + contentType;
}

break;
}
case 'Property': {
const valueType = (referable as aas.Property).valueType;
if (valueType) {
value += ', ' + (valueType.startsWith('xs:') ? valueType.substring(3) : valueType);
}

break;
}
case 'Range': {
const valueType = (referable as aas.Range).valueType;
if (valueType) {
value += ', ' + (valueType.startsWith('xs:') ? valueType.substring(3) : valueType);
}

break;
}
}

return value;
}

private getSemanticId(hasSematics: aas.HasSemantics): string {
return this.referenceToString(hasSematics?.semanticId);
}

private referenceToString(reference: aas.Reference | undefined): string {
return reference?.keys.map(key => key.value).join('/') ?? '-';
}
}

export class AASTree extends Tree<aas.Referable, AASTreeRow> {
Expand Down Expand Up @@ -463,8 +292,6 @@ export class AASTree extends Tree<aas.Referable, AASTreeRow> {
node.level,
node.abbreviation,
node.name,
node.typeInfo,
node.value,
node.isLeaf,
node.parent,
node.firstChild,
Expand Down
31 changes: 28 additions & 3 deletions projects/aas-lib/src/lib/aas-tree/aas-tree-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ export class AASTreeSearch {
} else if (term.text) {
match =
row.name.toLocaleLowerCase(this.translate.currentLang).indexOf(term.text) >= 0 ||
row.typeInfo.toLocaleLowerCase(this.translate.currentLang).indexOf(term.text) >= 0 ||
(typeof row.value === 'string' &&
row.value.toLocaleLowerCase(this.translate.currentLang).indexOf(term.text) >= 0);
this.contains(row.element, term.text);
}

if (match) {
Expand All @@ -276,6 +274,33 @@ export class AASTreeSearch {
return match;
}

private contains(referable: aas.Referable, text: string): boolean {
const stack = [referable as unknown as { [key: string]: unknown }];
while (stack.length > 0) {
const obj = stack.pop();
if (!obj) {
break;
}

for (const name in obj) {
if (name.indexOf(text) >= 0) {
return true;
}

const value = obj[name];
if (typeof value === 'string') {
if (value.indexOf(text) >= 0) {
return true;
}
} else if (typeof value === 'object') {
stack.push(value as { [key: string]: unknown });
}
}
}

return false;
}

private containsString(a: string, b?: string): boolean {
return b == null || a.toLowerCase().indexOf(b.toLowerCase()) >= 0;
}
Expand Down
Loading

0 comments on commit c90e8f0

Please sign in to comment.