Skip to content

Commit

Permalink
fix: bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Nov 8, 2024
1 parent b027011 commit 28cdcd9
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 70 deletions.
8 changes: 4 additions & 4 deletions projects/aas-lib/src/lib/index-change.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,22 @@ export class IndexChangeService {
}

private documentAdded(): void {
this.state.update(state => ({ ...state, addedDocuments: state.documentCount + 1 }));
this.state.update(state => ({ ...state, documentCount: state.documentCount + 1 }));
}

private documentRemoved(): void {
this.state.update(state => ({ ...state, removedDocuments: state.documentCount - 1 }));
this.state.update(state => ({ ...state, documentCount: state.documentCount - 1 }));
}

private documentUpdate(): void {
this.state.update(state => ({ ...state, changedDocuments: state.changedDocuments + 1 }));
}

private endpointAdded(): void {
this.state.update(state => ({ ...state, addedEndpoints: state.endpointCount + 1 }));
this.state.update(state => ({ ...state, endpointCount: state.endpointCount + 1 }));
}

private endpointRemoved(): void {
this.state.update(state => ({ ...state, removedEndpoints: state.endpointCount - 1 }));
this.state.update(state => ({ ...state, endpointCount: state.endpointCount - 1 }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="modal-header text-info">
<h4 class="modal-title">
<i class="bi bi-plus-circle"></i>
<span class="ms-2" translate>CAPTION_ADD_ENDPOINT</span>
<span class="ms-2" translate>AddEndpointForm.CAPTION_ADD_ENDPOINT</span>
</h4>
<button type="button" class="btn-close" (click)="cancel()"> </button>
</div>
Expand Down Expand Up @@ -42,44 +42,42 @@ <h4 class="modal-title">
(input)="inputValue()">
</div>
@if (selectedItem().type === 'AAS_API') {
<button type="button" class="btn btn-primary mt-3 mb-2" (click)="collapse.toggle()"
<button type="button" class="btn btn-primary btn-sm mt-4 mb-2" (click)="collapse.toggle()"
[attr.aria-expanded]="isCollapsed() === false" aria-controls="collapseExample" translate>
AddEndpointForm.ADVANCED_SETTINGS
</button>
<div #collapse="ngbCollapse" [(ngbCollapse)]="isCollapsed">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeNever" value="never"
[(ngModel)]="schedule">
<label class="form-check-label" for="scheduleTypeNever">Never</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeOnce" value="once"
[(ngModel)]="schedule">
<label class="form-check-label" for="scheduleTypeOnce">Once</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeEvery" value="every"
[(ngModel)]="schedule">
<label class="form-check-label" for="scheduleTypeEvery">Every</label>
</div>
@if (schedule() === 'every') {
<div class="input-group mt-3">
<input #inputHours type="number" class="form-control awp-number-input" min="0" max="99"
aria-label="Hours" [value]="hours()" (input)="hours.set(inputHours.valueAsNumber)">
<span class="input-group-text" translate>AddEndpointForm.HOURS</span>
<input #inputMinutes type="number" class="form-control awp-number-input" min="0" max="59"
aria-label="Minutes" [value]="minutes()" (input)="minutes.set(inputMinutes.valueAsNumber)">
<span class="input-group-text" translate>AddEndpointForm.MINUTES</span>
<label class="form-lable" for="schedule-options" translate>AddEndpointForm.SCHEDULE</label>
<div class="border border-light-subtle rounded p-2 mb-2" id="schedule-options">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeOnce" value="once"
[(ngModel)]="schedule">
<label class="form-check-label" for="scheduleTypeOnce" translate>AddEndpointForm.ONCE</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="scheduleType" id="scheduleTypeEvery"
value="every" [(ngModel)]="schedule">
<label class="form-check-label" for="scheduleTypeEvery" translate>AddEndpointForm.EVERY</label>
</div>
@if (schedule() === 'every') {
<div class="input-group mt-3">
<input #inputHours type="number" class="form-control awp-number-input" min="0" max="99"
aria-label="Hours" [value]="hours()" (input)="hours.set(inputHours.valueAsNumber)">
<span class="input-group-text" translate>AddEndpointForm.HOURS</span>
<input #inputMinutes type="number" class="form-control awp-number-input" min="0" max="59"
aria-label="Minutes" [value]="minutes()" (input)="minutes.set(inputMinutes.valueAsNumber)">
<span class="input-group-text" translate>AddEndpointForm.MINUTES</span>
</div>
}
</div>
}
<div class="col-12 mt-2" style="max-height: 200px; overflow-y: auto;">
<label class="form-lable" for="http-headers" translate>AddEndpointForm.HEADERS</label>
<div id="http-headers" class="border border-light-subtle rounded p-2 col-12" style="max-height: 200px; overflow-y: auto;">
<table class="table table-sm table-striped table-borderless">
<caption class="caption-top">Headers</caption>
<thead>
<tr>
<th scope="col" class="text-center" [style.width]="'32px'">#</th>
<th scope="col" class="text-center">Header</th>
<th scope="col" class="text-center">Value</th>
<th scope="col" class="text-center">AddEndpointForm.HEADER</th>
<th scope="col" class="text-center">AddEndpointForm.VALUE</th>
</tr>
</thead>
<tbody>
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-portal/src/app/start/favorites.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class FavoritesService {
}
}

return lists;
return [...lists];
}),
mergeMap(lists => {
return this.auth.setCookie('.Favorites', JSON.stringify(lists)).pipe(
Expand All @@ -94,7 +94,7 @@ export class FavoritesService {

lists[i] = list;

return lists;
return [...lists];
}),
mergeMap(lists => {
return this.auth.setCookie('.Favorites', JSON.stringify(lists)).pipe(
Expand Down
14 changes: 11 additions & 3 deletions projects/aas-portal/src/app/start/start-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ export class StartApiService {
}

/**
* Adds a new endpoint to the AASServer configuration.
* @param endpoint The AAS container endpoint.
* Adds a new endpoint.
* @param endpoint The AAS endpoint.
*/
public addEndpoint(endpoint: AASEndpoint): Observable<void> {
return this.http.post<void>(`/api/v1/endpoints/${encodeBase64Url(endpoint.name)}`, endpoint);
}

/**
* Removes the specified endpoint from the AASServer configuration.
* Updates an existing endpoint.
* @param endpoint The AAS endpoint.
*/
public updateEndpoint(endpoint: AASEndpoint): Observable<void> {
return this.http.put<void>(`/api/v1/endpoints/${encodeBase64Url(endpoint.name)}`, endpoint);
}

/**
* Removes the specified endpoint.
* @param name The name of the endpoint.
*/
public removeEndpoint(name: string): Observable<void> {
Expand Down
4 changes: 2 additions & 2 deletions projects/aas-portal/src/app/start/start.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[value]="activeFavorites()" (change)="setActiveFavorites(selectFavorites.value)">
@for (option of favoritesLists(); track option; let i = $index) {
@if (i === 0) {
<option class="fst-italic fw-light" [value]="''" translate>FAVORITES</option>
<option class="fst-italic fw-light" [value]="''" translate>Start.FAVORITES</option>
} @else {
<option class="fst-normal fw-normal" [value]="option">{{option}}</option>
}
Expand Down Expand Up @@ -108,4 +108,4 @@
[placeholder]="'PLACEHOLDER_FILTER' | translate" (change)="setFilter(textInput.value)"
(keydown.enter)="textInput.blur()">
</div>
</ng-template>
</ng-template>
8 changes: 5 additions & 3 deletions projects/aas-portal/src/app/start/start.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*****************************************************************************/

import { Router } from '@angular/router';
import { NgClass } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
Expand Down Expand Up @@ -45,14 +46,13 @@ import { StartApiService } from './start-api.service';
import { FavoritesService } from './favorites.service';
import { FavoritesFormComponent } from './favorites-form/favorites-form.component';
import { StartStore } from './start.store';
import { AsyncPipe, NgClass } from '@angular/common';

@Component({
selector: 'fhg-start',
templateUrl: './start.component.html',
styleUrls: ['./start.component.scss'],
standalone: true,
imports: [AASTableComponent, NgClass, AsyncPipe, TranslateModule, NgbModule],
imports: [AASTableComponent, NgClass, TranslateModule, NgbModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StartComponent implements OnDestroy, AfterViewInit {
Expand Down Expand Up @@ -160,7 +160,9 @@ export class StartComponent implements OnDestroy, AfterViewInit {
}),
mergeMap(modalRef => from<Promise<AASEndpoint | undefined>>(modalRef.result)),
mergeMap(result => {
if (!result) return EMPTY;
if (result === undefined) {
return EMPTY;
}

return this.api.addEndpoint(result);
}),
Expand Down
12 changes: 10 additions & 2 deletions projects/aas-portal/src/app/start/start.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class StartStore {
private readonly _limit = signal(10);
private readonly _previous = signal<AASDocumentId | null>(null);
private readonly _next = signal<AASDocumentId | null>(null);
private _totalCount = 0;
private readonly _documents = signal<AASDocument[]>([], { equal: (a, b) => equalArray(a, b) });
private readonly _activeFavorites = signal('');

Expand Down Expand Up @@ -81,16 +80,25 @@ export class StartStore {

public setFilter(filter: string): void {
this._filterText.set(filter);
if (!this._activeFavorites()) {
this.getFirstPage();
}
}

public getFirstPage(filter?: string, limit?: number): void {
if (!filter) {
if (!this._activeFavorites()) {
filter = this._filterText();
}
}

this.api
.getPage(
{
previous: null,
limit: limit ?? this._limit(),
},
filter ?? this._filterText(),
filter,
this.translate.currentLang,
)
.pipe(mergeMap(page => this.setPageAndLoadContents(page, limit, filter)))
Expand Down
14 changes: 11 additions & 3 deletions projects/aas-portal/src/assets/i18n/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"CAPTION_CREATE_WORKSPACE": "Gruppieren",
"CAPTION_EDIT_WORKSPACE": "Gruppe bearbeiten",
"CAPTION_REMOVE_WORKSPACE": "Gruppe löschen",
"CAPTION_ADD_ENDPOINT": "AAS-Endpunkt hinzufügen",
"CAPTION_REMOVE_ENDPOINT": "AAS-Endpunkt entfernen",
"CAPTION_NEW_ELEMENT": "Neu hinzufügen",
"CAPTION_EDIT_ELEMENT": "Bearbeiten",
Expand Down Expand Up @@ -147,7 +146,6 @@
"ERROR_INVALID_CONTAINER_URL": "'{0}' adressiert eine ungülig oder nicht unterstützte VWS-Ressoure.",
"ERROR_FAVORITES_LIST_NAME_USED_SEVERAL_TIMES": "'{0}' ist mehrfach verwendet.",
"ERROR_INVALID_EMPTY_FAVORITES_LIST_NAME": "Ungültiger leerer Name.",
"FAVORITES": "Favoriten",
"INFO_NEW_PASSWORD_SENT": "Ein neues Passwort wurde an '{0}' gesendet",
"INFO_DOWNLOAD_FILE_SUCCESS": "{0} wurde erfolgreich heruntergeladen.",
"INFO_UPLOAD_AASX_FILE_SUCCESS": "{0} wurde erfolgreich hochgeladen.",
Expand All @@ -174,7 +172,11 @@
"OPTION_BAR_HORIZONTAL_CHART": "Balkendiagramm horizontal",
"TEXT_ADD_FAVORITE": "1 Favorit hinzufügen ({0}).",
"TEXT_ADD_FAVORITES": "{0} Favoriten hinzufügen ({1}).",
"Start": {
"FAVORITES": "Alle Verwaltungsschalen"
},
"AddEndpointForm": {
"CAPTION_ADD_ENDPOINT": "AAS-Endpunkt hinzufügen",
"FileSystem": "Dateisystem",
"AAS_API": "AAS API",
"WebDAV": "WebDAV",
Expand All @@ -187,8 +189,14 @@
"PLACEHOLDER_URL_OPCUA": "opc.tcp://",
"PLACEHOLDER_URL_WEBDAV": "http(s)://",
"ADVANCED_SETTINGS": "Erweiterte Einstellungen",
"SCHEDULE": "Endpunkt durchsuchen",
"ONCE": "einmalig",
"EVERY": "zyklisch",
"MINUTES": "Minuten",
"HOURS": "Stunden"
"HOURS": "Stunden",
"HEADERS": "HTTP-Header-Felder",
"HEADER": "Feld",
"VALUE": "Wert"
},
"CustomerFeedback": {
"OverallRating": "Gesamtbewertung",
Expand Down
14 changes: 11 additions & 3 deletions projects/aas-portal/src/assets/i18n/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"CAPTION_CREATE_WORKSPACE": "Group",
"CAPTION_EDIT_WORKSPACE": "Edit Group",
"CAPTION_REMOVE_WORKSPACE": "Remove Group",
"CAPTION_ADD_ENDPOINT": "Add AAS Endpoint",
"CAPTION_REMOVE_ENDPOINT": "Remove AAS Endpoint",
"CAPTION_NEW_ELEMENT": "Insert New",
"CAPTION_EDIT_ELEMENT": "Edit",
Expand Down Expand Up @@ -149,7 +148,6 @@
"ERROR_INVALID_CONTAINER_URL": "'{0}' addresses an invalid or not supported AAS resource.",
"ERROR_FAVORITES_LIST_NAME_USED_SEVERAL_TIMES": "'{0}' is used several times.",
"ERROR_INVALID_EMPTY_FAVORITES_LIST_NAME": "Invalid empty name.",
"FAVORITES": "Favorites",
"INFO_NEW_PASSWORD_SENT": "A new password was sent to '{0}'.",
"INFO_DOWNLOAD_FILE_SUCCESS": "{0} was downloaded successfully.",
"INFO_UPLOAD_AASX_FILE_SUCCESS": "{0} was uploaded successfully.",
Expand All @@ -175,7 +173,11 @@
"OPTION_BAR_HORIZONTAL_CHART": "Horizontal bar chart",
"TEXT_ADD_FAVORITE": "Add 1 favorite ({0}).",
"TEXT_ADD_FAVORITES": "Add {0} favorites ({1}).",
"Start": {
"FAVORITES": "All shells"
},
"AddEndpointForm": {
"CAPTION_ADD_ENDPOINT": "Add AAS Endpoint",
"FileSystem": "File system",
"AAS_API": "AAS API",
"WebDAV": "WebDAV",
Expand All @@ -188,8 +190,14 @@
"PLACEHOLDER_URL_OPCUA": "opc.tcp://",
"PLACEHOLDER_URL_WEBDAV": "http(s)://",
"ADVANCED_SETTINGS": "Advanced settings",
"SCHEDULE": "Search endpoint",
"ONCE": "once",
"EVERY": "cyclic",
"MINUTES": "Minutes",
"HOURS": "Hours"
"HOURS": "Hours",
"HEADERS": "HTTP headers",
"HEADER": "Header",
"VALUE": "Value"
},
"CustomerFeedback": {
"OverallRating": "Overall rating",
Expand Down
2 changes: 2 additions & 0 deletions projects/aas-server/src/app/aas-index/aas-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export abstract class AASIndex {

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

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

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

public abstract getDocuments(cursor: AASCursor, query?: string, language?: string): Promise<AASPagedResult>;
Expand Down
11 changes: 11 additions & 0 deletions projects/aas-server/src/app/aas-index/lowdb/lowdb-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ export class LowDbIndex extends AASIndex {
await this.db.write();
}

public override async updateEndpoint(endpoint: AASEndpoint): Promise<void> {
await this.promise;
const index = this.db.data.endpoints.findIndex(item => item.name === endpoint.name);
if (index < 0) {
throw new Error(`An endpoint with the name ${name} does not exist.`);
}

this.db.data.endpoints[index] = endpoint;
await this.db.write();
}

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

0 comments on commit 28cdcd9

Please sign in to comment.