Skip to content

Commit

Permalink
fix: AASIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Nov 2, 2023
1 parent 1be2351 commit e997636
Show file tree
Hide file tree
Showing 45 changed files with 16,955 additions and 27,605 deletions.
42,418 changes: 15,638 additions & 26,780 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
"./projects/aas-portal"
],
"devDependencies": {
"@babel/plugin-syntax-import-attributes": "^7.22.5",
"@semantic-release/git": "^10.0.1",
"@semantic-release/gitlab": "^12.0.5"
"@babel/plugin-syntax-import-attributes": "^7.22.5"
},
"dependencies": {
"lowdb": "^6.1.1"
}
}
5 changes: 4 additions & 1 deletion projects/aas-lib/src/lib/aas-lib.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { DigitalNameplateComponent } from './digital-nameplate/digital-nameplate
import { messageTableReducer } from './message-table/massage-table.reducer';
import { MessageTableComponent } from './message-table/message-table.component';
import { SecuredImageComponent } from './secured-image/secured-image.component';
import { AASProviderService } from './aas-provider/aas-provider.service';

@NgModule({
declarations: [
Expand Down Expand Up @@ -89,6 +90,8 @@ import { SecuredImageComponent } from './secured-image/secured-image.component';
MessageTableComponent,
SecuredImageComponent
],
providers: []
providers: [
AASProviderService
]
})
export class AASLibModule { }
9 changes: 9 additions & 0 deletions projects/aas-lib/src/lib/aas-provider/aas-provider.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class AASProviderService {

constructor() { }
}
31 changes: 31 additions & 0 deletions projects/aas-lib/src/lib/aas-table/aas-table-api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { AASCursor, AASDocumentPage, aas } from 'common';
import { encodeBase64Url } from '../convert';

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

/**
* Returns a page of documents from the specified cursor.
* @param cursor The current cursor.
* @returns The document page.
*/
public getDocuments(cursor: AASCursor): Observable<AASDocumentPage> {
return this.http.get<AASDocumentPage>(`/api/v1/documents&cursor=${encodeBase64Url(JSON.stringify(cursor))}`);
}

/**
* Loads the element structure of the specified document.
* @param url The URL of the container.
* @param id The identification of the AAS document.
* @returns The root of the element structure.
*/
public getContent(url: string, id: string): Observable<aas.Environment> {
return this.http.get<aas.Environment>(
`/api/v1/containers/${encodeBase64Url(url)}/documents/${encodeBase64Url(id)}/content`);
}
}
45 changes: 39 additions & 6 deletions projects/aas-lib/src/lib/aas-table/aas-table.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
*****************************************************************************/

import { createAction, props } from '@ngrx/store';
import { AASDocument } from 'common';
import { AASDocument, AASDocumentPage, aas } from 'common';
import { SortDirection } from '../sortable-header.directive';
import { AASTableRow } from './aas-table.state';
import { ViewMode } from '../types/view-mode';
import { TypedAction } from '@ngrx/store/src/models';

export enum AASTableActionType {
INITIALIZE = '[AASTable] initialize',
GET_FIRST_PAGE = '[AASTable] get first page',
GET_NEXT_PAGE = '[AASTable] get next page',
GET_PREVIOUS_PAGE = '[AASTable] previous next page',
SET_PAGE = '[AASTable] set page',
GET_LAST_PAGE = '[AASTable] get last page',
SET_DOCUMENT_CONTENT = '[AASTable] set document content',

UPDATE_ROWS = '[AASTable] Update Rows',
SET_VIEW_MODE = '[AASTable] Set view mode',
SET_SHOW_ALL = '[AASTable] Set show all',
SET_SORT_PARAMETER = '[AASTable] Set sort parameter',
SET_FILTER = '[AASTable] Set filter',
EXPAND = '[AASTable] Expand',
Expand All @@ -24,6 +32,35 @@ export enum AASTableActionType {
TOGGLE_SELECTIONS = '[AASTable] Toggle selections'
}

export interface ApplyDocumentAction extends TypedAction<AASTableActionType.GET_FIRST_PAGE> {
filter?: string;
}

export const initialize = createAction(
AASTableActionType.INITIALIZE);

export const getFirstPage = createAction(
AASTableActionType.GET_FIRST_PAGE,
props<{ filter?: string }>());

export const getNextPage = createAction(
AASTableActionType.GET_NEXT_PAGE);

export const getPreviousPage = createAction(
AASTableActionType.GET_PREVIOUS_PAGE);

export const getLastPage = createAction(
AASTableActionType.GET_LAST_PAGE);


export const setPage = createAction(
AASTableActionType.SET_PAGE,
props<{ page: AASDocumentPage }>());

export const setDocumentContent = createAction(
AASTableActionType.SET_DOCUMENT_CONTENT,
props<{ document: AASDocument; content?: aas.Environment }>());

export const updateRows = createAction(
AASTableActionType.UPDATE_ROWS,
props<{ documents: AASDocument[] }>());
Expand All @@ -32,10 +69,6 @@ export const setViewMode = createAction(
AASTableActionType.SET_VIEW_MODE,
props<{ documents: AASDocument[]; viewMode: ViewMode }>());

export const setShowAll = createAction(
AASTableActionType.SET_SHOW_ALL,
props<{ documents: AASDocument[]; showAll: boolean }>());

export const setFilter = createAction(
AASTableActionType.SET_FILTER,
props<{ filter?: string }>());
Expand Down
6 changes: 3 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 @@ -13,13 +13,13 @@
<input id="aas-table-checkbox" type="checkbox" class="form-check-input" (change)="toggleSelections()"
[checked]="someSelections | async">
</th>
<th scope="col" sortable="type" (sort)="onSort($event)" class="th-w-icon">
<th scope="col" class="th-w-icon">
<i class="bi bi-tag"></i>
</th>
<th scope="col" sortable="name" (sort)="onSort($event)">
<th scope="col">
<div class="me-1" translate>COLUMN_NAME</div>
</th>
<th scope="col" sortable="id" (sort)="onSort($event)">
<th scope="col">
<div class="me-1" translate>COLUMN_ID</div>
</th>
</tr>
Expand Down
81 changes: 49 additions & 32 deletions projects/aas-lib/src/lib/aas-table/aas-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*
*****************************************************************************/

import { Component, Input, OnChanges, OnDestroy, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { AASDocument } from 'common';
import { first, Observable, Subscription } from 'rxjs';
import { Observable, Subscription } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';

import { ViewMode } from '../types/view-mode';
Expand All @@ -22,13 +22,15 @@ import { AASQuery } from '../types/aas-query-params';
import { NotifyService } from '../notify/notify.service';
import { ClipboardService } from '../clipboard.service';
import { SortEvent, SortableHeaderDirective } from '../sortable-header.directive';
import { AASTableApiService } from './aas-table-api.service';

@Component({
selector: 'fhg-aas-table',
templateUrl: './aas-table.component.html',
styleUrls: ['./aas-table.component.scss']
styleUrls: ['./aas-table.component.scss'],
providers: [AASTableApiService]
})
export class AASTableComponent implements AASTable, OnChanges, OnDestroy {
export class AASTableComponent implements AASTable, OnInit, OnChanges, OnDestroy {
private readonly store: Store<AASTableFeatureState>;
private readonly subscription: Subscription = new Subscription();
private _filter = '';
Expand All @@ -37,13 +39,19 @@ export class AASTableComponent implements AASTable, OnChanges, OnDestroy {
private readonly router: Router,
translate: TranslateService,
store: Store,
private readonly api: AASTableApiService,
private readonly notify: NotifyService,
private readonly clipboard: ClipboardService
) {
this.store = store as Store<AASTableFeatureState>;
this.selectedDocuments = this.store.select(AASTableSelectors.selectSelectedDocuments);
this.someSelections = this.store.select(AASTableSelectors.selectSomeSelections);
this.rows = this.store.select(AASTableSelectors.selectRows(translate));
this.rows = this.store.select(AASTableSelectors.selectRows);

this.canSkipStart = this.store.select(AASTableSelectors.selectAtStart);
this.canSkipBackward = this.store.select(AASTableSelectors.selectAtStart);
this.canSkipForward = this.store.select(AASTableSelectors.selectAtEnd);
this.canSkipEnd = this.store.select(AASTableSelectors.selectAtEnd);
}

@ViewChildren(SortableHeaderDirective)
Expand All @@ -52,55 +60,64 @@ export class AASTableComponent implements AASTable, OnChanges, OnDestroy {
@Input()
public viewMode: ViewMode = ViewMode.List;

@Input()
public showAll = false;

@Input()
public filter: Observable<string> | null = null;

@Input()
public documents: Observable<AASDocument[]> | null = null;
public readonly canSkipStart: Observable<boolean>;

public readonly canSkipBackward: Observable<boolean>;

public readonly canSkipForward: Observable<boolean>;

public readonly canSkipEnd: Observable<boolean>;

public rows: Observable<AASTableRow[]>;

public readonly selectedDocuments: Observable<AASDocument[]>;

public readonly someSelections: Observable<boolean>;

public ngOnChanges(changes: SimpleChanges): void {
if (changes['documents']) {
this.documents?.subscribe(documents => this.documentsChanged(documents));
}
public ngOnInit(): void {
this.store.dispatch(AASTableActions.initialize());
}

public ngOnChanges(changes: SimpleChanges): void {
if (changes['filter'] && this.filter) {
this.subscription.add(this.filter.subscribe(filter => {
this.store.dispatch(AASTableActions.setFilter({ filter }));
this.store.dispatch(AASTableActions.getFirstPage({ filter }));
}));
}

const showAllChange = changes['showAll'];
if (showAllChange && this.showAll !== showAllChange.previousValue) {
this.documents?.pipe(first())
.subscribe(documents => this.store.dispatch(AASTableActions.setShowAll({
documents,
showAll: this.showAll
})));
}

const viewModeChange = changes['viewMode'];
if (viewModeChange && this.viewMode !== viewModeChange.previousValue) {
this.documents?.pipe(first())
.subscribe(documents => this.store.dispatch(AASTableActions.setViewMode({
documents,
viewMode: this.viewMode
})));
}
// const viewModeChange = changes['viewMode'];
// if (viewModeChange && this.viewMode !== viewModeChange.previousValue) {
// this.documents?.pipe(first())
// .subscribe(documents => this.store.dispatch(AASTableActions.setViewMode({
// documents,
// viewMode: this.viewMode
// })));
// }
}

public ngOnDestroy(): void {
this.subscription.unsubscribe();
}

public skipStart(): void {
this.store.dispatch(AASTableActions.getFirstPage({}));
}

public skipBackward(): void {
this.store.dispatch(AASTableActions.getPreviousPage())
}

public skipForward(): void {
this.store.dispatch(AASTableActions.getNextPage())
}

public skipEnd(): void {
this.store.dispatch(AASTableActions.getLastPage())
}

public expand(row: AASTableRow): void {
if (this.viewMode === ViewMode.Tree) {
this.store.dispatch(AASTableActions.expandRow({ row }));
Expand Down
48 changes: 48 additions & 0 deletions projects/aas-lib/src/lib/aas-table/aas-table.effects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
*
* 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 { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { AASCursor, AASWorkspace } from 'common';
import { catchError, EMPTY, exhaustMap, from, map, merge, mergeMap, Observable, of, skipWhile, zip } from 'rxjs';

import * as AASTableActions from './aas-table.actions';
import * as AASTableSelectors from './aas-table.selectors';
import { AASTableApiService } from './aas-table-api.service';
import { AASTableFeatureState } from './aas-table.state';

@Injectable()
export class AASTableEffects {
private readonly store: Store<AASTableFeatureState>;

constructor(
private readonly actions: Actions,
store: Store,
private readonly api: AASTableApiService
) {
this.store = store as Store<AASTableFeatureState>;
}

public initialize = createEffect(() => {
return this.actions.pipe(
ofType(AASTableActions.AASTableActionType.INITIALIZE),
exhaustMap(() => this.store.select(AASTableSelectors.selectState)),
mergeMap(state => {
if (state.initialized) {
return EMPTY;
}

return this.api.getDocuments({ previous: null, limit: state.cursor.limit });
}),
mergeMap(page => from(page.documents)),
skipWhile(document => document.content != null),
mergeMap(document => zip(of(document), this.api.getContent(document.container, document.id))),
map(tuple => AASTableActions.setDocumentContent({ document: tuple[0], content: tuple[1] })));
});
}
Loading

0 comments on commit e997636

Please sign in to comment.