Skip to content

Commit

Permalink
AASDocument, AASEndpoint updated
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Nov 9, 2023
1 parent 86d537b commit b1d5429
Show file tree
Hide file tree
Showing 85 changed files with 567 additions and 1,160 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"WEB_ROOT": "projects/aas-portal/dist",
"ASSETS": "projects/aas-server/src/assets",
"USER_STORAGE": "mongodb://localhost:27017/aasportal-users",
"ENDPOINTS": "[\"file:///samples?name=Samples\"]"
"ENDPOINTS": "[\"file:///samples?name=Samples\",\"http://localhost:5001?name=AASXServer&type=AasxServer\"]"
}
},
{
Expand Down
7 changes: 4 additions & 3 deletions projects/aas-lib/src/lib/aas-table/aas-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows | async">
<tr *ngFor="let row of rows | async" class="align-middle">
<td>
<input type="checkbox" class="form-check-input" (change)="toggleSelected(row)" [checked]="row.selected"
[name]="row.name" />
</td>
<td>
<img class="img-fluid" width="24" height="24" [src]="getFormatIcon(row)" alt="" />
<img class="img-fluid" width="40" height="40" [src]="row.thumbnail" alt="" />
</td>
<td>
<a class="text-nowrap" href="javascript:void(0);" [name]="row.name" (click)="open(row)">{{row.name |
max:60}}</a>
<td>
<div>{{row.endpoint}}</div>
<div class="text-nowrap" placement="top" [ngbTooltip]="getToolTip(row)">{{row.id | max:80}}</div>
</td>
</tr>
Expand Down Expand Up @@ -70,7 +71,7 @@
</a>
<div *ngIf="row.isLeaf" class="text-muted wh-4"></div>
<div class="ms-2">
<img class="img-fluid" width="24" height="24" [src]="getFormatIcon(row)" alt="" />
<img class="img-fluid" width="40" height="40" [src]="row.thumbnail" alt="" />
</div>
<div class="ms-2 flex-grow-1">
<a class="text-nowrap" href="javascript:void(0);" (click)="open(row)">{{row.name | max:60}}</a>
Expand Down
19 changes: 2 additions & 17 deletions projects/aas-lib/src/lib/aas-table/aas-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class AASTableComponent implements AASTable, OnInit, OnChanges, OnDestroy
public open(row: AASTableRow): void {
const query: AASQuery = {
id: row.document.id,
url: this.getUrl(row.document.container)
url: row.document.endpoint.url,
};

if (this._filter) {
Expand All @@ -140,19 +140,8 @@ export class AASTableComponent implements AASTable, OnInit, OnChanges, OnDestroy
this.router.navigateByUrl('/aas?format=AASQuery', { skipLocationChange: true });
}

public getFormatIcon(row: AASTableRow): string {
switch (row.type) {
case 'opc':
return '/assets/resources/opcua.32.png';
case 'http':
return '/assets/resources/aas.32.png';
default:
return '/assets/resources/aasx.32.png';
}
}

public getToolTip(row: AASTableRow): string {
return `${row.document.container}, ${row.document.endpoint.address}`;
return `${row.document.endpoint.url}, ${row.document.address}`;
}

public toggleSelected(row: AASTableRow): void {
Expand All @@ -162,8 +151,4 @@ export class AASTableComponent implements AASTable, OnInit, OnChanges, OnDestroy
public toggleSelections(): void {
this.store.dispatch(AASTableActions.toggleSelections());
}

private getUrl(url: string): string {
return url.split('?')[0];
}
}
2 changes: 1 addition & 1 deletion projects/aas-lib/src/lib/aas-table/aas-table.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ export class AASTableEffects {
});

private getId(document: AASDocument): AASDocumentId {
return { id: document.id, url: document.container.split('?')[0] };
return { id: document.id, url: document.endpoint.url };
}
}
15 changes: 0 additions & 15 deletions projects/aas-lib/src/lib/aas-table/aas-table.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ function initList(documents: AASDocument[]): AASTableRow[] {
const row = new AASTableRow(
document,
false,
document.idShort,
document.id,
document.endpoint.type,
false,
false,
0,
Expand Down Expand Up @@ -198,9 +195,6 @@ function expandRow(state: AASTableState, row: AASTableRow): AASTableState {
rows[index] = new AASTableRow(
row.document,
false,
row.name,
row.id,
row.type,
true,
row.isLeaf,
row.level,
Expand All @@ -216,9 +210,6 @@ function collapseRow(state: AASTableState, row: AASTableRow): AASTableState {
rows[index] = new AASTableRow(
row.document,
false,
row.name,
row.id,
row.type,
false,
row.isLeaf,
row.level,
Expand All @@ -234,9 +225,6 @@ function toggleSelected(state: AASTableState, row: AASTableRow) {
rows[index] = new AASTableRow(
row.document,
!row.selected,
row.name,
row.id,
row.type,
row.expanded,
row.isLeaf,
row.level,
Expand All @@ -255,9 +243,6 @@ function toggleSelections(state: AASTableState) {
rows[index] = new AASTableRow(
row.document,
!row.selected,
row.name,
row.id,
row.type,
row.expanded,
row.isLeaf,
row.level,
Expand Down
21 changes: 17 additions & 4 deletions projects/aas-lib/src/lib/aas-table/aas-table.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@
*
*****************************************************************************/

import { AASDocument, EndpointType } from "common";
import { AASDocument } from 'common';

export class AASTableRow {
constructor(
public readonly document: AASDocument,
public readonly selected: boolean,
public readonly name: string,
public readonly id: string,
public readonly type: EndpointType,
public readonly expanded: boolean,
public readonly isLeaf: boolean,
public readonly level: number,
public firstChild: number,
public nextSibling: number) {
}

public get id(): string {
return this.document.id;
}

public get name(): string {
return this.document.idShort;
}

public get thumbnail(): string {
return this.document.thumbnail ?? '/assets/resources/aas.32.png';
}

public get endpoint(): string | null {
return this.document.endpoint.name;
}

public get hasChildren(): boolean {
return this.firstChild >= 0;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-lib/src/lib/aas-tree/aas-tree-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AASTreeApiService {
return new Promise<aas.Operation>((result, reject) => {
let data: aas.Operation;
this.http.post<aas.Operation>(
`/api/v1/containers/${encodeBase64Url(document.container)}/documents/${encodeBase64Url(document.id)}`,
`/api/v1/containers/${encodeBase64Url(document.endpoint.url)}/documents/${encodeBase64Url(document.id)}`,
operation).subscribe({
next: (value) => data = value,
complete: () => result(data),
Expand Down
1 change: 0 additions & 1 deletion projects/aas-lib/src/lib/aas-tree/aas-tree.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { createAction, props } from '@ngrx/store';
import { AASDocument } from 'common';
import { AASTreeRow, SearchTerm } from './aas-tree.state';
import { TypedAction } from '@ngrx/store/src/models';

export enum AASTreeActionType {
UPDATE_ROWS = '[AASTree] Update Rows',
Expand Down
26 changes: 19 additions & 7 deletions projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
selectSubmodel,
getIdShortPath,
mimeTypeToExtension,
AASEndpointType,
} from 'common';

import { AASTreeRow, AASTreeFeatureState } from './aas-tree.state';
Expand Down Expand Up @@ -286,7 +287,7 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
template,
submodels: [{
id: this.document.id,
url: this.document.container,
url: this.document.endpoint.url,
idShort: submodel.idShort
}]
};
Expand Down Expand Up @@ -327,11 +328,11 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
await this.showVideoAsync(name, `data:${blob.contentType};base64,${blob.value}`);
}
} else {
const container = encodeBase64Url(this.document.container);
const endpoint = encodeBase64Url(this.document.endpoint.url);
const id = encodeBase64Url(this.document.id);
const smId = encodeBase64Url(blob.parent.keys[0].value);
const path = getIdShortPath(blob);
const url = `/api/v1/containers/${container}/documents/${id}/submodels/${smId}/blobs/${path}/value`;
const url = `/api/v1/containers/${endpoint}/documents/${id}/submodels/${smId}/blobs/${path}/value`;
if (blob.contentType.startsWith('image/')) {
await this.showImageAsync(name, url);
} else if (blob.contentType.startsWith('video/')) {
Expand Down Expand Up @@ -453,12 +454,23 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
);

this.webSocketSubject.next(this.createMessage(
this.document.endpoint.type,
this.document.container,
this.toEndpointType(this.document.endpoint.type),
this.document.endpoint.url,
this.document.id));
}
}

private toEndpointType(type: AASEndpointType): EndpointType {
switch (type) {
case 'OpcuaServer':
return 'opc';
case 'AasxDirectory':
return 'file';
default:
return 'http';
}
}

private stop(): void {
if (this.webSocketSubject) {
this.webSocketSubject.unsubscribe();
Expand Down Expand Up @@ -513,7 +525,7 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
}
}

private onError = (error: any): void => {
private onError = (error: unknown): void => {
this.notify.log(LogType.Error, error);
}

Expand All @@ -525,7 +537,7 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
const smId = encodeBase64Url(submodel.id);
const path = getIdShortPath(file);
value.name = basename(file.value);
const url = encodeBase64Url(this.document.container);
const url = encodeBase64Url(this.document.endpoint.url);
const id = encodeBase64Url(this.document.id);
value.url = `/api/v1/containers/${url}/documents/${id}/submodels/${smId}/submodel-elements/${path}/value`;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-lib/src/lib/aas-tree/aas-tree.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { aas, isSubmodel } from "common";
import { aas, isSubmodel } from 'common';
import { resolveSemanticId, supportedSubmodelTemplates } from '../submodel-template/submodel-template';

export class AASTreeRow {
Expand Down
16 changes: 8 additions & 8 deletions projects/aas-lib/src/test/aas-table/aas-table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ describe('AASTableComponent', () => {
});
});

it('allows switching to viewMode "Tree"', function (done: DoneFn) {
component.viewMode = ViewMode.Tree;
component.ngOnChanges({ viewMode: new SimpleChange(ViewMode.List, ViewMode.Tree, true) });
store.select(selectState).pipe(first()).subscribe(state => {
expect(state.viewMode).toEqual(ViewMode.Tree);
done();
});
});
// it('allows switching to viewMode "Tree"', function (done: DoneFn) {
// component.viewMode = ViewMode.Tree;
// component.ngOnChanges({ viewMode: new SimpleChange(ViewMode.List, ViewMode.Tree, true) });
// store.select(selectState).pipe(first()).subscribe(state => {
// expect(state.viewMode).toEqual(ViewMode.Tree);
// done();
// });
// });

it('allows set a filter', function (done: DoneFn) {
component.filter = of('document');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { AASDocument, aas } from 'common';
import { AASDocument, AASEndpoint, aas } from 'common';
import { AASTreeApiService } from '../../lib/aas-tree/aas-tree-api.service';
import { AuthService } from '../../lib/auth/auth.service';

Expand Down Expand Up @@ -47,7 +47,7 @@ describe('AASTreeApiService', function () {
describe('invoke', function () {
it('invokes an operation', async function () {
const document = jasmine.createSpyObj<AASDocument>({}, {
container: 'http://localhost/container',
endpoint: { url: 'http://localhost/container', name: 'Test', version: '3.0' } as AASEndpoint,
id: 'http://localhost/aas'
});

Expand Down
16 changes: 4 additions & 12 deletions projects/aas-lib/src/test/assets/sample-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2972,12 +2972,8 @@ const technicalData: object = {
export const sampleDocument: AASDocument = {
"id": "http://customer.com/aas/9175_7013_7091_9168",
"idShort": "ExampleMotor",
"container": "file:///samples?name=Samples&type=AasxDirectory",
"endpoint": {
"type": "file",
"address": "ExampleMotor.aasx"
},
"timeStamp": 1675961220599,
"endpoint": { url: "file:///samples", name: 'Samples', type: 'AasxDirectory', version: '3.0' },
"address": "ExampleMotor.aasx",
"modified": false,
"readonly": false,
"onlineReady": false,
Expand All @@ -2987,12 +2983,8 @@ export const sampleDocument: AASDocument = {
export const aasNoTechnicalData: AASDocument = {
"id": "http://customer.com/aas/9175_7013_7091_9168",
"idShort": "ExampleMotor",
"container": "file:///endpoints/samples?name=Samples&type=AasxDirectory",
"endpoint": {
"type": "file",
"address": "ExampleMotor.aasx"
},
"timeStamp": 1675961220599,
"endpoint": { url: "file:///samples", name: 'Samples', type: 'AasxDirectory', version: '3.0' },
"address": "ExampleMotor.aasx",
"modified": false,
"readonly": false,
"onlineReady": false,
Expand Down
13 changes: 6 additions & 7 deletions projects/aas-lib/src/test/assets/test-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export function createContainer(url: string, documents: AASDocument[]): AASConta
return {
documents: documents,
url: url,
name: url
name: url,
type: 'AasxDirectory'
};
}

Expand All @@ -27,9 +28,8 @@ export function createDocument(name: string, url = 'http://localhost/container1'
const document: AASDocument = {
id: `http://localhost/aas/${name}`,
idShort: name,
container: url,
endpoint: { address: '', type: 'file' },
timeStamp: 0,
endpoint: { url, name, type: 'AasxServer', version: '3.0' },
address: '',
modified: false,
readonly: false,
onlineReady: false,
Expand All @@ -43,9 +43,8 @@ export function createDocumentHeader(name: string, url: string): AASDocument {
const document: AASDocument = {
id: `http://localhost/aas/${name}`,
idShort: name,
container: url,
endpoint: { address: '', type: 'file' },
timeStamp: 0,
endpoint: { url, name, type: 'AasxServer', version: '3.0' },
address: '',
modified: false,
readonly: false,
onlineReady: false,
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/aas/aas-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class AASApiService {
const formData = new FormData();
formData.append('content', new Blob([JSON.stringify(document.content)]));
return this.http.put<string[]>(
`/api/v1/containers/${encodeBase64Url(document.container)}/documents/${encodeBase64Url(document.id)}`,
`/api/v1/containers/${encodeBase64Url(document.endpoint.url)}/documents/${encodeBase64Url(document.id)}`,
formData);
}
}
Loading

0 comments on commit b1d5429

Please sign in to comment.