Skip to content

Commit

Permalink
fix: zoneless completed
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Jun 23, 2024
1 parent 072e460 commit 3e81684
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ASSETS": "projects/aas-server/src/assets",
// "USER_STORAGE": "mongodb://localhost:27017/aasportal-users",
// "TEMPLATE_STORAGE": "http://localhost:8080/templates",
// "AAS_INDEX": "mysql://localhost:3306",
"AAS_INDEX": "mysql://localhost:3306",
"ENDPOINTS": "[\"file:///endpoints/samples?name=Samples\"]",
}
},
Expand Down
14 changes: 13 additions & 1 deletion projects/aas-portal/src/app/aas/aas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
*
*****************************************************************************/

import { AfterViewInit, Component, OnDestroy, OnInit, TemplateRef, ViewChild, computed, signal } from '@angular/core';
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
OnDestroy,
OnInit,
TemplateRef,
ViewChild,
computed,
signal,
} from '@angular/core';

import { ActivatedRoute, Router } from '@angular/router';
import { EMPTY, map, mergeMap, Observable, from, of, catchError, first } from 'rxjs';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
Expand Down Expand Up @@ -42,6 +53,7 @@ import { FormsModule } from '@angular/forms';
styleUrls: ['./aas.component.scss'],
standalone: true,
imports: [SecuredImageComponent, AASTreeComponent, AsyncPipe, TranslateModule, FormsModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
public constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { Component, computed, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { NgbActiveModal, NgbToast } from '@ng-bootstrap/ng-bootstrap';
import { TemplateService } from 'aas-lib';
import { TemplateDescriptor, aas, getChildren, isEnvironment } from 'common';
Expand All @@ -21,6 +21,7 @@ import { ModelType } from 'projects/common/dist/types/aas';
styleUrls: ['./new-element-form.component.scss'],
standalone: true,
imports: [NgbToast, FormsModule, AsyncPipe, TranslateModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NewElementFormComponent {
private readonly _messages = signal<string[]>([]);
Expand Down
10 changes: 5 additions & 5 deletions projects/aas-portal/src/app/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ <h1>AASPortal</h1>
<p>Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo, eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
zur Foerderung der angewandten Forschung e.V.</p>
<p>
<span>Internet:&nbsp;</span><a [href]="homepage" target="_blank">{{homepage}}</a><br>
<span>Internet:&nbsp;</span><a [href]="homepage()" target="_blank">{{homepage()}}</a><br>
</p>
<h2>AASPortal</h2>
<p>Version: {{version}}</p>
<p>Version: {{version()}}</p>
<h2>AAS-Server</h2>
<p>Version: {{serverVersion}}</p>
<p>Version: {{serverVersion()}}</p>
<h2>Third-party Libraries</h2>
<p>The application is based on some third-party libraries for which specific copyright statements and licenses
apply.</p>
<fhg-library-table [collection]="libraries"></fhg-library-table>
<fhg-library-table [collection]="libraries()"></fhg-library-table>
<h2>Server Messages</h2>
<fhg-message-table [collection]="messages"></fhg-message-table>
<fhg-message-table [collection]="messages()"></fhg-message-table>
</div>

<ng-template #aboutToolbar></ng-template>
40 changes: 25 additions & 15 deletions projects/aas-portal/src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
*
*****************************************************************************/

import { Component, OnDestroy, OnInit, TemplateRef, ViewChild, AfterViewInit } from '@angular/core';
import {
Component,
OnDestroy,
OnInit,
TemplateRef,
ViewChild,
AfterViewInit,
signal,
ChangeDetectionStrategy,
} from '@angular/core';
import { Library, Message } from 'common';
import { LibraryTableComponent, MessageTableComponent } from 'aas-lib';
import { ServerApiService } from './server-api.service';
Expand All @@ -19,39 +28,40 @@ import { environment } from '../../environments/environment';
styleUrls: ['./about.component.scss'],
standalone: true,
imports: [LibraryTableComponent, MessageTableComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AboutComponent implements OnInit, OnDestroy, AfterViewInit {
private readonly _serverVersion = signal('');
private readonly _libraries = signal<Library[]>([]);
private readonly _messages = signal<Message[]>([]);

public constructor(
private serverApi: ServerApiService,
private toolbar: ToolbarService,
) {
this.author = environment.author;
this.version = environment.version;
this.homepage = environment.homepage;
}
) {}

@ViewChild('aasToolbar', { read: TemplateRef })
public aboutToolbar: TemplateRef<unknown> | null = null;

public version = '';
public readonly version = signal(environment.author).asReadonly();

public serverVersion = '';
public readonly serverVersion = this._serverVersion.asReadonly();

public author = '';
public readonly author = signal(environment.author).asReadonly();

public homepage = '';
public readonly homepage = signal(environment.homepage).asReadonly();

public libraries: Library[] = [];
public readonly libraries = this._libraries.asReadonly();

public messages: Message[] = [];
public readonly messages = this._messages.asReadonly();

public ngOnInit(): void {
this.serverApi.getInfo().subscribe(info => {
this.serverVersion = info.version;
this.libraries = info.libraries ?? [];
this._serverVersion.set(info.version);
this._libraries.set(info.libraries ?? []);
});

this.serverApi.getMessages().subscribe(messages => (this.messages = messages));
this.serverApi.getMessages().subscribe(messages => this._messages.set(messages));
}

public ngAfterViewInit(): void {
Expand Down
7 changes: 3 additions & 4 deletions projects/aas-portal/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { Component } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MainComponent } from './main/main.component';

@Component({
Expand All @@ -15,7 +15,6 @@ import { MainComponent } from './main/main.component';
styleUrls: ['./app.component.scss'],
standalone: true,
imports: [MainComponent],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent {
public title = 'AASPortal';
}
export class AppComponent {}
3 changes: 2 additions & 1 deletion projects/aas-portal/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { Component, OnInit, TemplateRef, ViewChild, model, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit, TemplateRef, ViewChild, model, signal } from '@angular/core';
import { Router, RouterLink, RouterOutlet } from '@angular/router';
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import { first } from 'rxjs';
Expand Down Expand Up @@ -46,6 +46,7 @@ export interface LinkDescriptor {
LocalizeComponent,
AuthComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MainComponent implements OnInit {
public constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*****************************************************************************/

import { Component, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal, NgbToast } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
Expand All @@ -24,16 +24,18 @@ export interface EndpointItem {
styleUrls: ['./add-endpoint-form.component.scss'],
standalone: true,
imports: [NgbToast, TranslateModule, FormsModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AddEndpointFormComponent {
private readonly endpoints = signal<AASEndpoint[]>([]);
public readonly _messages = signal<string[]>([]);

public constructor(
private modal: NgbActiveModal,
private translate: TranslateService,
) {}

public readonly endpoints = signal<AASEndpoint[]>([]);

public readonly messages = signal<string[]>([]);
public readonly messages = this._messages.asReadonly();

public readonly name = signal('');

Expand Down Expand Up @@ -64,6 +66,10 @@ export class AddEndpointFormComponent {

public readonly item = signal(this.items()[0]);

public initialize(endpoints: AASEndpoint[]): void {
this.endpoints.set(endpoints);
}

public setItem(value: EndpointItem): void {
this.item.set(value);
this.clearMessages();
Expand All @@ -88,20 +94,20 @@ export class AddEndpointFormComponent {
}

private clearMessages(): void {
if (this.messages.length > 0) {
this.messages.set([]);
if (this._messages.length > 0) {
this._messages.set([]);
}
}

private validateName(): string | undefined {
let name: string | undefined = this.name().trim();
if (!name) {
this.messages.update(messages => [...messages, this.createMessage('ERROR_EMPTY_ENDPOINT_NAME')]);
this._messages.update(messages => [...messages, this.createMessage('ERROR_EMPTY_ENDPOINT_NAME')]);
name = undefined;
} else {
for (const endpoint of this.endpoints()) {
if (endpoint.name.toLocaleLowerCase() === name.toLocaleLowerCase()) {
this.messages.update(messages => [
this._messages.update(messages => [
...messages,
this.createMessage('ERROR_ENDPOINT_ALREADY_EXIST', name),
]);
Expand Down Expand Up @@ -134,7 +140,11 @@ export class AddEndpointFormComponent {

return url;
} catch (error) {
this.messages.update(messages => [...messages, this.createMessage('ERROR_INVALID_URL', this.item().value)]);
this._messages.update(messages => [
...messages,
this.createMessage('ERROR_INVALID_URL', this.item().value),
]);

return undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class StartComponent implements OnDestroy, AfterViewInit {
mergeMap(() => this.api.getEndpoints()),
map(endpoints => {
const modalRef = this.modal.open(AddEndpointFormComponent, { backdrop: 'static' });
modalRef.componentInstance.endpoints = endpoints;
modalRef.componentInstance.initialize(endpoints);
return modalRef;
}),
mergeMap(modalRef => from<Promise<AASEndpoint | undefined>>(modalRef.result)),
Expand Down
6 changes: 0 additions & 6 deletions projects/aas-portal/src/test/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,4 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

it(`should have as title 'AASPortal'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('AASPortal');
});
});
4 changes: 3 additions & 1 deletion projects/aas-server/src/app/aas-index/aas-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export abstract class AASIndex {

public abstract getEndpoint(name: string): Promise<AASEndpoint>;

public abstract hasEndpoint(name: string): Promise<boolean>;

public abstract addEndpoint(endpoint: AASEndpoint): Promise<void>;

public abstract removeEndpoint(name: string): Promise<boolean>;
public abstract removeEndpoint(endpointName: string): Promise<boolean>;

public abstract getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPage>;

Expand Down
18 changes: 16 additions & 2 deletions projects/aas-server/src/app/aas-index/lowdb/lowdb-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ export class LowDbIndex extends AASIndex {
return endpoint;
}

public override async hasEndpoint(name: string): Promise<boolean> {
await this.promise;
return this.db.data.endpoints.find(endpoint => endpoint.name === name) !== undefined;
}

public override async addEndpoint(endpoint: AASEndpoint): Promise<void> {
await this.promise;
if (this.db.data.endpoints.some(item => item.name === endpoint.name)) {
Expand All @@ -68,12 +73,13 @@ export class LowDbIndex extends AASIndex {
await this.db.write();
}

public override async removeEndpoint(name: string): Promise<boolean> {
public override async removeEndpoint(endpointName: string): Promise<boolean> {
await this.promise;
const index = this.db.data.endpoints.findIndex(endpoint => endpoint.name === name);
const index = this.db.data.endpoints.findIndex(endpoint => endpoint.name === endpointName);
if (index < 0) return false;

this.db.data.endpoints.splice(index, 1);
this.removeDocuments(endpointName);
await this.db.write();
return true;
}
Expand Down Expand Up @@ -180,6 +186,14 @@ export class LowDbIndex extends AASIndex {
await this.db.write();
}

private removeDocuments(endpoint: string) {
const documents = this.db.data.documents.filter(document => document.endpoint === endpoint);
this.db.data.documents = this.db.data.documents.filter(document => document.endpoint !== endpoint);
for (const document of documents) {
this.db.data.elements = this.db.data.elements.filter(element => element.uuid !== document.uuid);
}
}

private toDocument(item: LowDbDocument): AASDocument {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { uuid, ...document } = item;
Expand Down
Loading

0 comments on commit 3e81684

Please sign in to comment.