Skip to content

Commit

Permalink
fix: update implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Nov 13, 2023
1 parent c8c11e1 commit 8c4f82b
Show file tree
Hide file tree
Showing 46 changed files with 5,498 additions and 5,369 deletions.
8,927 changes: 5,019 additions & 3,908 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,7 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
}
);

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

Expand Down Expand Up @@ -499,15 +496,10 @@ export class AASTreeComponent implements AASTree, OnInit, OnChanges, OnDestroy {
}
}

private createMessage(type: EndpointType, url: string, id: string): WebSocketData {
private createMessage(document: AASDocument): WebSocketData {
return {
type: 'LiveRequest',
data: {
type: type,
url: url,
id: id,
nodes: this.liveNodes
} as LiveRequest
data: { endpoint: document.endpoint, id: document.id, nodes: this.liveNodes } as LiveRequest
};
}

Expand Down
6 changes: 3 additions & 3 deletions projects/aas-lib/src/lib/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export class DownloadService {
/**
* Uploads the specified aasx file.
* @param file A file.
* @param url The URL of the destination.
* @param nme The name of the destination endpoint.
*/
public uploadDocuments(url: string, file: File | File[]): Observable<HttpEvent<object>> {
public uploadDocuments(nme: string, file: File | File[]): Observable<HttpEvent<object>> {
const data = new FormData();
if (Array.isArray(file)) {
file.forEach(item => data.append('file', item));
Expand All @@ -78,7 +78,7 @@ export class DownloadService {
}

return this.http.post(
`/api/v1/containers/${encodeBase64Url(url)}/packages`,
`/api/v1/containers/${encodeBase64Url(nme)}/packages`,
data,
{
reportProgress: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function resolveSemanticId(value: aas.HasSemantic | aas.Reference | strin

return semanticId;

function isReference(value: any): value is aas.Reference {
function isReference(value: unknown): value is aas.Reference {
return Array.isArray((value as aas.Reference).keys);
}
}
9 changes: 1 addition & 8 deletions projects/aas-lib/src/test/assets/test-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { AASDocument, AASContainer, AASWorkspace, aas } from 'common';
import { AASDocument, AASContainer, aas } from 'common';

export function createContainer(url: string, documents: AASDocument[]): AASContainer {
return {
Expand All @@ -17,13 +17,6 @@ export function createContainer(url: string, documents: AASDocument[]): AASConta
};
}

export function createWorkspace(name: string, containers: AASContainer[]): AASWorkspace {
return {
name: name,
containers: containers,
};
}

export function createDocument(name: string, url = 'http://localhost/container1'): AASDocument {
const document: AASDocument = {
id: `http://localhost/aas/${name}`,
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/aas/aas.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
</div>
</div>
<div class="row">
<fhg-aas-tree #aasTree [state]="state | async" [search]="search" [document]="document">
<fhg-aas-tree #aasTree [state]="state" [search]="search" [document]="document">
</fhg-aas-tree>
</div>
</div>

<ng-template #aasToolbar>
<div class="btn-group me-2">
<button type="button" class="btn btn-primary" (click)="play()" [disabled]="(state | async) === 'offline'">
<button type="button" class="btn btn-primary" (click)="play()" [disabled]="state === 'online'">
<i class="bi bi-play-fill"></i>
</button>
<button type="button" class="btn btn-primary" (click)="stop()" [disabled]="(state | async) === 'online'">
<button type="button" class="btn btn-primary" (click)="stop()" [disabled]="state === 'offline'">
<i class="bi bi-stop-fill"></i>
</button>
</div>
Expand Down
27 changes: 14 additions & 13 deletions projects/aas-portal/src/app/aas/aas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { head } from 'lodash-es';
import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, EMPTY, map, mergeMap, Observable, Subscription, from } from 'rxjs';
import { EMPTY, map, mergeMap, Observable, Subscription, from } from 'rxjs';
import * as lib from 'projects/aas-lib/src/public-api';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { Store } from '@ngrx/store';
Expand Down Expand Up @@ -45,8 +45,8 @@ import {
})
export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
private readonly store: Store<State>;
private readonly $state = new BehaviorSubject<lib.OnlineState>('offline');
private readonly subscription = new Subscription();
private _state: lib.OnlineState = 'offline';
private _dashboardPage = '';
private templates: TemplateDescriptor[] = [];
private selectedElements: aas.Referable[] = [];
Expand All @@ -66,7 +66,6 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
private readonly clipboard: lib.ClipboardService
) {
this.store = store as Store<State>;
this.state = this.$state.asObservable();
this.search = this.store.select(AASSelectors.selectSearch);
this.editable = this.store.select(AASSelectors.selectEditable);

Expand All @@ -81,7 +80,9 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {

public document: AASDocument | null = null;

public readonly state: Observable<lib.OnlineState>;
public get state(): lib.OnlineState {
return this._state;
}

public readonly search: Observable<string>;

Expand Down Expand Up @@ -116,7 +117,7 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
}

public get onlineReady(): boolean {
return this.document?.onlineReady ?? false;
return !!this.document?.onlineReady;
}

public get readonly(): boolean {
Expand Down Expand Up @@ -172,10 +173,10 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
} else {
return EMPTY;
}
})
).subscribe({
error: error => this.notify.error(error)
}));
}))
.subscribe({
error: error => this.notify.error(error)
}));

this.subscription.add(this.store.select(AASSelectors.selectTemplates).pipe()
.subscribe(templates => {
Expand Down Expand Up @@ -203,13 +204,13 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
}

public play(): void {
if (this.onlineReady && this.$state.value === 'offline') {
this.$state.next('online');
if (this.onlineReady && this._state === 'offline') {
this._state = 'online';
}
}

public stop(): void {
this.$state.next('offline');
this._state = 'offline';
}

public canAddToDashboard(): boolean {
Expand Down Expand Up @@ -396,7 +397,7 @@ export class AASComponent implements OnInit, OnDestroy, AfterViewInit {

return false;
}

// Hack, Hack
private isTimeSeries(element: aas.Referable): boolean {
return isBlob(element) &&
Expand Down
8 changes: 3 additions & 5 deletions projects/aas-portal/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { AASLibModule } from 'projects/aas-lib/src/public-api';
import { EffectsModule } from '@ngrx/effects';
import { FormsModule } from '@angular/forms';

import { AppRoutingModule } from './app-routing.module';
Expand All @@ -34,11 +33,11 @@ import { UploadFormComponent } from './start/upload-form/upload-form.component';
import { ViewComponent } from './view/view.component';
import { viewReducer } from './view/view.reducer';
import { AddEndpointFormComponent } from './start/add-endpoint-form/add-endpoint-form.component';
import { projectReducer } from './project/project.reducer';
import { ProjectEffects } from './project/project.effects';
import { HttpLoaderFactory } from './http-loader-factory';
import { httpInterceptorProviders } from './index';
import { EffectsModule } from '@ngrx/effects';
import { AASEffects } from './aas/aas.effects';
import { ViewEffects } from './view/view.effects';

@NgModule({
declarations: [
Expand Down Expand Up @@ -68,9 +67,8 @@ import { AASEffects } from './aas/aas.effects';
aas: aasReducer,
view: viewReducer,
dashboard: dashboardReducer,
project: projectReducer
}),
EffectsModule.forRoot([ProjectEffects, AASEffects]),
EffectsModule.forRoot([AASEffects, ViewEffects]),
TranslateModule.forRoot({
defaultLanguage: 'en-us',
loader: {
Expand Down
6 changes: 2 additions & 4 deletions projects/aas-portal/src/app/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,7 @@ export class DashboardService {
} else {
nodes = [];
page.requests.push({
type: this.toEndpointType(document.endpoint.type),
url: document.endpoint.url,
endpoint: document.endpoint,
id: document.id,
nodes: nodes
});
Expand Down Expand Up @@ -378,10 +377,9 @@ export class DashboardService {

private indexOfRequest(page: DashboardPage, document: AASDocument): number {
const url = document.endpoint.url;
const type = this.toEndpointType(document.endpoint.type);
const id = document.id;
return page.requests.findIndex(item => {
return item.url === url && (type === 'opc' || item.id === id);
return item.endpoint.url === url && (item.endpoint.type === 'OpcuaServer' || item.id === id);
});
}

Expand Down
32 changes: 32 additions & 0 deletions projects/aas-portal/src/app/main/main-api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/******************************************************************************
*
* Copyright (c) 2019-2023 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { Injectable } from '@angular/core';
import { HttpClient, } from '@angular/common/http';
import { AASDocument, AASEndpoint } from 'common';
import { Observable } from 'rxjs';
import { encodeBase64Url } from 'projects/aas-lib/src/public-api';

/** The client side AAS provider service. */
@Injectable({
providedIn: 'root'
})
export class MainApiService {
constructor(
private readonly http: HttpClient,
) { }

/**
* Gets the first AAS with the specified identifier.
* @param id The identification or name of the document.
* @returns The AAS document.
*/
public getDocument(id: string): Observable<AASDocument> {
return this.http.get<AASDocument>(`/api/v1/documents/${encodeBase64Url(id)}`);
}
}
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Component, OnDestroy, OnInit, TemplateRef, ViewChild, ViewContainerRef
import { Router } from '@angular/router';
import { Observable, Subscription, first, map } from 'rxjs';
import { ClipboardService, WindowService, AASQuery } from 'projects/aas-lib/src/public-api';
import { ProjectService } from '../project/project.service';
import { ToolbarService } from '../toolbar.service';
import { MainApiService } from './main-api.service';

export enum LinkId {
START = 0,
Expand Down Expand Up @@ -55,7 +55,7 @@ export class MainComponent implements OnInit, OnDestroy {
constructor(
private readonly router: Router,
private readonly window: WindowService,
private readonly project: ProjectService,
private readonly api: MainApiService,
private readonly clipboard: ClipboardService,
private readonly viewContainer: ViewContainerRef,
private readonly toolbar: ToolbarService) {
Expand All @@ -78,7 +78,7 @@ export class MainComponent implements OnInit, OnDestroy {
const params = this.window.getQueryParams();
const id = params.get('id');
if (id) {
this.project.findDocument(id).pipe(first()).subscribe(document => {
this.api.getDocument(id).pipe(first()).subscribe(document => {
if (document) {
this.clipboard.set('AASQuery', { id: document.id } as AASQuery);
this.router.navigateByUrl('/aas?format=AASQuery');
Expand Down
Loading

0 comments on commit 8c4f82b

Please sign in to comment.