Skip to content

Commit

Permalink
fix: ExtrasEndpointForm
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Nov 15, 2024
1 parent c98bf1c commit 4de1a4c
Show file tree
Hide file tree
Showing 31 changed files with 775 additions and 280 deletions.
324 changes: 219 additions & 105 deletions aasportal.mdx

Large diffs are not rendered by default.

Binary file modified docs/source/images/aas-portal-project.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/source/images/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/aas/aas.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<div class="input-group flex-grow-1 me-2 my-1">
<div class="input-group-text"><i class="bi bi-search"></i></div>
<input #textInput type="text" class="form-control" [value]="searchExpression()"
[placeholder]="'PLACEHOLDER_FILTER' | translate" (input)="searchExpressionChange(textInput.value)">
[placeholder]="'AAS.PLACEHOLDER_SEARCH' | translate" (input)="searchExpressionChange(textInput.value)">
<button type="button" class="btn btn-primary" (click)="aasTree.findNext()">
<i class="bi bi-chevron-down"></i>
</button>
Expand Down
3 changes: 1 addition & 2 deletions projects/aas-portal/src/app/aas/aas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import { DashboardChartType, DashboardPage, DashboardService } from '../dashboar
import { DashboardQuery } from '../types/dashboard-query-params';
import { ToolbarService } from '../toolbar.service';
import { AASStore } from './aas.store';
import { AsyncPipe } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { FormsModule } from '@angular/forms';

Expand All @@ -52,7 +51,7 @@ import { FormsModule } from '@angular/forms';
templateUrl: './aas.component.html',
styleUrls: ['./aas.component.scss'],
standalone: true,
imports: [SecuredImageComponent, AASTreeComponent, AsyncPipe, TranslateModule, FormsModule],
imports: [SecuredImageComponent, AASTreeComponent, TranslateModule, FormsModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AASComponent implements OnInit, OnDestroy, AfterViewInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@
}
</div>
}
} @else {
} @else {
<div class="alert alert-info text-center mt-2" role="alert">{{'INFO_EMPTY_DASHBOARD' | translate}}</div>
}
}
</div>

<ng-template #dashboardToolbar>
<div class="input-group me-2 my-1">
<select #select class="form-select" [value]="activePage()" (change)="setPage(pages()[select.selectedIndex])">
@for (page of pages(); track page) {
@for (page of pages(); track page.name) {
<option [ngValue]="page">{{page.name}}</option>
}
</select>
Expand Down
6 changes: 3 additions & 3 deletions projects/aas-portal/src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import 'chart.js/auto';
import { WebSocketSubject } from 'rxjs/webSocket';
import { ActivatedRoute } from '@angular/router';
import { AsyncPipe, NgClass } from '@angular/common';
import { NgClass } from '@angular/common';
import { FormsModule } from '@angular/forms';
import {
AfterViewInit,
Expand Down Expand Up @@ -79,7 +79,7 @@ interface TimeSeries {
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss'],
standalone: true,
imports: [NgClass, AsyncPipe, FormsModule, TranslateModule],
imports: [NgClass, FormsModule, TranslateModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit {
Expand Down Expand Up @@ -148,7 +148,7 @@ export class DashboardComponent implements OnInit, OnDestroy, AfterViewInit {

public get selectedItem(): DashboardItem | null {
if (this.selections.size === 1) {
return this.findItem(this.selections.values().next().value) ?? null;
return this.findItem(this.selections.values().next().value!) ?? null;
}

return null;
Expand Down
21 changes: 14 additions & 7 deletions projects/aas-portal/src/app/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ export class DashboardService {
zip(this.auth.getCookie('.DashboardPage'), this.auth.getCookie('.DashboardPages')).pipe(
map(([value, data]) => {
const pages: DashboardPage[] = data ? JSON.parse(data) : [];
this._state.set({
pages,
index: Math.max(
pages.findIndex(page => page.name === value),
0,
),
});
if (pages.length === 0) {
pages.push({ name: this.createPageName(), items: [], requests: [] });
}

if (value === undefined) {
value = pages[0].name;
}

const index = Math.max(
pages.findIndex(page => page.name === value),
0,
);

this._state.set({ pages, index });
}),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!-----------------------------------------------------------------------------
!
! Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo,
! eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
! zur Foerderung der angewandten Forschung e.V.
!
!---------------------------------------------------------------------------->

<form (ngSubmit)="submit()">
<div class="modal-header text-info">
<h4 class="modal-title">
<i class="bi bi-gear"></i>
<span class="ms-2" translate>ExtrasEndpointForm.CAPTION</span>
</h4>
<button type="button" class="btn-close" (click)="submit()"> </button>
</div>
<div class="modal-body">
@for (message of messages(); track message) {
<ngb-toast [autohide]="false" class="bg-danger w-100 mb-3">
<div class="d-flex">
<div class="flex-grow-1">{{ message }}</div>
</div>
</ngb-toast>
}
<table class="table table-sm">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col" translate>ExtrasEndpointForm.NAME</th>
<th scope="col" translate>ExtrasEndpointForm.COUNT</th>
<th scope="col" translate>ExtrasEndpointForm.UPDATE</th>
</tr>
</thead>
<tbody>
@for (item of endpoints(); track item.name; let index = $index) {
<tr class="align-middle">
<th scope="row">{{index + 1}}</th>
<td>
<div class="d-flex flex-column flex-grow-1">
<div>{{item.name}}</div>
<div class="ts-small">{{item.url}}</div>
</div>
</td>
<td>{{item.count}}</td>
@if (item.schedule === 'manual') {
<td><a href="javascript:void(0);" (click)="scan(item.name)">{{'ExtrasEndpointForm.'+item.schedule |
translate}}</a></td>
} @else {
<td>{{'ExtrasEndpointForm.' + item.schedule | translate}}</td>
}
</tr>
}
</tbody>
</table>
<button type="button" class="btn btn-secondary" (click)="collapse.toggle()" [attr.aria-expanded]="!isCollapsed"
aria-controls="collapseReset">
<span translate>ExtrasEndpointForm.RESET</span><span>...</span>
</button>
<div #collapse="ngbCollapse" class="mt-2" [(ngbCollapse)]="isCollapsed">
<div class="card">
<div class="card-body">
<p class="card-text" translate>ExtrasEndpointForm.CONFIRM_RESET_CONFIGURATION</p>
<button type="button" class="btn btn-danger" (click)="reset()"
translate>ExtrasEndpointForm.RESET</button>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" translate>ExtrasEndpointForm.CLOSE</button>
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/******************************************************************************
*
* Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/******************************************************************************
*
* Copyright (c) 2019-2024 Fraunhofer IOSB-INA Lemgo,
* eine rechtlich nicht selbstaendige Einrichtung der Fraunhofer-Gesellschaft
* zur Foerderung der angewandten Forschung e.V.
*
*****************************************************************************/

import { Component, Signal, signal, computed } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal, NgbCollapse, NgbToast } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { AASEndpointScheduleType, convertToString } from 'aas-core';
import { ExtrasEndpointService } from './extras-endpoint.service';
import { toSignal } from '@angular/core/rxjs-interop';
import { from, map, mergeMap, toArray } from 'rxjs';

export type ExtrasEndpointItem = {
name: string;
url: string;
count: number;
schedule: AASEndpointScheduleType;
};

@Component({
selector: 'fhg-extras-endpoint',
standalone: true,
imports: [FormsModule, NgbToast, NgbCollapse, TranslateModule],
providers: [ExtrasEndpointService],
templateUrl: './extras-endpoint-form.component.html',
styleUrl: './extras-endpoint-form.component.scss',
})
export class ExtrasEndpointFormComponent {
private readonly _messages = signal<string[]>([]);
private readonly _endpoints: Signal<ExtrasEndpointItem[]>;

public constructor(
private readonly modal: NgbActiveModal,
private readonly translate: TranslateService,
private readonly api: ExtrasEndpointService,
) {
this._endpoints = toSignal(
api.getEndpoints().pipe(
mergeMap(values =>
from(values).pipe(
mergeMap(value =>
this.api.getDocumentCount(value.name).pipe(
map(
count =>
({
name: value.name,
url: value.url,
count,
schedule: value.schedule?.type || 'every',
}) as ExtrasEndpointItem,
),
),
),
),
),
toArray(),
),
{ initialValue: [] as ExtrasEndpointItem[] },
);
}

public readonly messages = this._messages.asReadonly();

public readonly endpoints = computed(() => this._endpoints().map(item => item));

public readonly isCollapsed = signal(true);

public submit(): void {
this.modal.close();
}

public reset(): void {
this.api
.reset()
.pipe()
.subscribe({
next: () => this.modal.close(),
error: error =>
this._messages.update(state => [...state, convertToString(error, this.translate.currentLang)]),
});
}

public scan(endpointName: string): void {
this.api
.scan(endpointName)
.pipe()
.subscribe({
next: () => this.modal.close(),
error: error =>
this._messages.update(state => [...state, convertToString(error, this.translate.currentLang)]),
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/******************************************************************************
*
* Copyright (c) 2019-2024 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 { map, Observable } from 'rxjs';
import { AASEndpoint } from 'aas-core';
import { encodeBase64Url } from 'aas-lib';

@Injectable()
export class ExtrasEndpointService {
public constructor(private readonly http: HttpClient) {}

/**
* Returns all configured AAS endpoints.
* @returns An array of `AASContainer`.
**/
public getEndpoints(): Observable<AASEndpoint[]> {
return this.http.get<AASEndpoint[]>('/api/v1/endpoints');
}

/**
* Restores the default AAS endpoint configuration.
**/
public reset(): Observable<void> {
return this.http.delete<void>('/api/v1/endpoints');
}

/**
* Gets the total amount of documents contained in the endpoint with the specified name.
* @param endpointName The name of the endpoint.
**/
public getDocumentCount(endpointName: string): Observable<number> {
return this.http
.get<{ count: number }>(`/api/v1/endpoints/${encodeBase64Url(endpointName)}/documents/count`)
.pipe(map(value => value.count));
}

/**
* Starts an update of the endpoint index.
* @param endpointName The name of the endpoint.
**/
public scan(endpointName: string): Observable<void> {
return this.http.put<void>(`/api/v1/endpoints/${encodeBase64Url(endpointName)}/scan`, null);
}
}
Loading

0 comments on commit 4de1a4c

Please sign in to comment.