From caf721f651097f0861a57351fab21902b6b20045 Mon Sep 17 00:00:00 2001 From: Ralf Aron Date: Sun, 19 Nov 2023 18:51:32 +0100 Subject: [PATCH] fix: update aas-table, aas-tree --- .../src/lib/aas-table/aas-table.actions.ts | 2 +- .../lib/aas-table/aas-table.component.html | 4 +- .../src/lib/aas-table/aas-table.component.ts | 38 +++-- .../src/lib/aas-table/aas-table.reducer.ts | 95 +++++++++--- .../src/lib/aas-table/aas-table.selectors.ts | 13 +- .../src/lib/aas-tree/aas-tree.actions.ts | 5 +- .../src/lib/aas-tree/aas-tree.component.html | 7 +- .../src/lib/aas-tree/aas-tree.component.ts | 26 +++- .../src/lib/aas-tree/aas-tree.reducer.ts | 135 ++++++++---------- .../src/lib/aas-tree/aas-tree.selectors.ts | 7 +- projects/aas-lib/src/lib/convert.ts | 10 +- projects/aas-lib/src/lib/window.service.ts | 18 ++- .../src/app/start/start.component.html | 8 +- .../src/app/aas-provider/aas-provider.ts | 66 ++++----- 14 files changed, 269 insertions(+), 165 deletions(-) diff --git a/projects/aas-lib/src/lib/aas-table/aas-table.actions.ts b/projects/aas-lib/src/lib/aas-table/aas-table.actions.ts index 53756967..934defb4 100644 --- a/projects/aas-lib/src/lib/aas-table/aas-table.actions.ts +++ b/projects/aas-lib/src/lib/aas-table/aas-table.actions.ts @@ -64,7 +64,7 @@ export const collapseRow = createAction( export const toggleSelected = createAction( AASTableActionType.TOGGLE_SELECTED, - props<{ row: AASTableRow }>()); + props<{ row: AASTableRow, altKey: boolean, shiftKey: boolean }>()); export const toggleSelections = createAction( AASTableActionType.TOGGLE_SELECTIONS); diff --git a/projects/aas-lib/src/lib/aas-table/aas-table.component.html b/projects/aas-lib/src/lib/aas-table/aas-table.component.html index 805582c4..f5a0ca61 100644 --- a/projects/aas-lib/src/lib/aas-table/aas-table.component.html +++ b/projects/aas-lib/src/lib/aas-table/aas-table.component.html @@ -10,8 +10,8 @@ - + diff --git a/projects/aas-lib/src/lib/aas-table/aas-table.component.ts b/projects/aas-lib/src/lib/aas-table/aas-table.component.ts index 6980d4bd..de043703 100644 --- a/projects/aas-lib/src/lib/aas-table/aas-table.component.ts +++ b/projects/aas-lib/src/lib/aas-table/aas-table.component.ts @@ -11,16 +11,14 @@ import { Router } from '@angular/router'; import { Store } from '@ngrx/store'; import { AASDocument } from 'common'; import { Observable, Subscription } from 'rxjs'; -import { TranslateService } from '@ngx-translate/core'; import { ViewMode } from '../types/view-mode'; import { AASTableRow, AASTableFeatureState } from './aas-table.state'; import * as AASTableSelectors from './aas-table.selectors'; import * as AASTableActions from './aas-table.actions'; import { AASQuery } from '../types/aas-query-params'; -import { NotifyService } from '../notify/notify.service'; import { ClipboardService } from '../clipboard.service'; -import { AASTableApiService } from './aas-table-api.service'; +import { WindowService } from '../window.service'; @Component({ selector: 'fhg-aas-table', @@ -32,23 +30,27 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy { private readonly subscription: Subscription = new Subscription(); private _filter = ''; private _limit = 10; + private shiftKey = false; + private altKey = false; constructor( private readonly router: Router, - translate: TranslateService, store: Store, - private readonly api: AASTableApiService, - private readonly notify: NotifyService, - private readonly clipboard: ClipboardService + private readonly clipboard: ClipboardService, + private readonly window: WindowService ) { this.store = store as Store; - this.someSelections = this.store.select(AASTableSelectors.selectSomeSelections); this.rows = this.store.select(AASTableSelectors.selectRows); this.isFirstPage = this.store.select(AASTableSelectors.selectIsFirstPage); this.isLastPage = this.store.select(AASTableSelectors.selectIsLastPage); + this.everySelected = this.store.select(AASTableSelectors.selectEverySelected); + this.someSelected = this.store.select(AASTableSelectors.selectSomeSelected); this.subscription.add(this.store.select(AASTableSelectors.selectSelectedDocuments).pipe() .subscribe(documents => this.selectedChange.emit({ documents }))); + + this.window.addEventListener('keyup', this.keyup); + this.window.addEventListener('keydown', this.keydown); } @Input() @@ -63,14 +65,16 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy { @Output() public selectedChange = new EventEmitter<{ documents: AASDocument[] }>(); + public someSelected: Observable; + + public everySelected: Observable; + public readonly isFirstPage: Observable; public readonly isLastPage: Observable; public readonly rows: Observable; - public readonly someSelections: Observable; - public ngOnInit(): void { this.store.dispatch(AASTableActions.initialize()); } @@ -97,6 +101,8 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy { public ngOnDestroy(): void { this.subscription.unsubscribe(); + this.window.removeEventListener('keyup', this.keyup); + this.window.removeEventListener('keydown', this.keydown); } public skipStart(): void { @@ -146,10 +152,20 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy { } public toggleSelected(row: AASTableRow): void { - this.store.dispatch(AASTableActions.toggleSelected({ row })); + this.store.dispatch(AASTableActions.toggleSelected({ row, altKey: this.altKey, shiftKey: this.shiftKey })); } public toggleSelections(): void { this.store.dispatch(AASTableActions.toggleSelections()); } + + private keyup = () => { + this.shiftKey = false; + this.altKey = false; + }; + + private keydown = (event: KeyboardEvent) => { + this.shiftKey = event.shiftKey; + this.altKey = event.altKey; + }; } \ No newline at end of file diff --git a/projects/aas-lib/src/lib/aas-table/aas-table.reducer.ts b/projects/aas-lib/src/lib/aas-table/aas-table.reducer.ts index fd4d9faa..ab49b2f9 100644 --- a/projects/aas-lib/src/lib/aas-table/aas-table.reducer.ts +++ b/projects/aas-lib/src/lib/aas-table/aas-table.reducer.ts @@ -40,7 +40,7 @@ export const aasTableReducer = createReducer( ), on( AASTableActions.toggleSelected, - (state, { row }) => toggleSelected(state, row) + (state, { row, altKey, shiftKey }) => toggleSelected(state, row, altKey, shiftKey) ), on( AASTableActions.toggleSelections, @@ -219,37 +219,88 @@ function collapseRow(state: AASTableState, row: AASTableRow): AASTableState { return { ...state, rows }; } -function toggleSelected(state: AASTableState, row: AASTableRow) { - const rows = [...state.rows]; - const index = rows.indexOf(row); - rows[index] = new AASTableRow( - row.document, - !row.selected, - row.expanded, - row.isLeaf, - row.level, - row.firstChild, - row.nextSibling); +// function toggleSelected(state: AASTableState, row: AASTableRow) { +// const rows = [...state.rows]; +// const index = rows.indexOf(row); +// rows[index] = new AASTableRow( +// row.document, +// !row.selected, +// row.expanded, +// row.isLeaf, +// row.level, +// row.firstChild, +// row.nextSibling); - return { ...state, rows } +// return { ...state, rows } +// } + +function toggleSelected( + state: AASTableState, + row: AASTableRow, + altKey: boolean, + shiftKey: boolean, +): AASTableState { + let rows: AASTableRow[]; + if (altKey) { + rows = state.rows.map(item => + item === row ? clone(row, !row.selected) : (item.selected ? clone(item, false) : item) + ); + } else if (shiftKey) { + const index = state.rows.indexOf(row); + let begin = index; + let end = index; + const selection = state.rows.map(row => row.selected); + const last = selection.lastIndexOf(true); + if (last >= 0) { + if (last > index) { + begin = index; + end = selection.indexOf(true); + } else if (last < index) { + begin = last; + end = index; + } + } + + rows = []; + for (let i = 0, n = state.rows.length; i < n; i++) { + const row = state.rows[i]; + if (i < begin || i > end) { + rows.push(row.selected ? clone(row, false) : row); + } else { + rows.push(row.selected ? row : clone(row, true)); + } + } + } else { + const i = state.rows.indexOf(row); + rows = [...state.rows]; + rows[i] = clone(row, !row.selected); + } + + return { ...state, rows }; } function toggleSelections(state: AASTableState) { - const value = !state.rows.some(row => row.selected); + const value = state.rows.length > 0 && state.rows.some(row => row.selected) && + !state.rows.every(row => row.selected); + const rows = [...state.rows]; for (let index = 0; index < rows.length; ++index) { const row = rows[index]; if (row.selected !== value) { - rows[index] = new AASTableRow( - row.document, - !row.selected, - row.expanded, - row.isLeaf, - row.level, - row.firstChild, - row.nextSibling); + rows[index] = clone(row, value); } } return { ...state, rows } } + +function clone(row: AASTableRow, selected: boolean): AASTableRow { + return new AASTableRow( + row.document, + selected, + row.expanded, + row.isLeaf, + row.level, + row.firstChild, + row.nextSibling) +} diff --git a/projects/aas-lib/src/lib/aas-table/aas-table.selectors.ts b/projects/aas-lib/src/lib/aas-table/aas-table.selectors.ts index 6fa0d997..4ac3d186 100644 --- a/projects/aas-lib/src/lib/aas-table/aas-table.selectors.ts +++ b/projects/aas-lib/src/lib/aas-table/aas-table.selectors.ts @@ -21,14 +21,21 @@ export const selectSelectedDocuments = createSelector( return rows.filter(row => row.selected).map(row => row.document); }); -export const selectSomeSelections = createSelector( +export const selectSomeSelected = createSelector( getRows, (rows: AASTableRow[]): boolean => { - return rows.some(row => row.selected); + return rows.length > 0 && rows.some(row => row.selected) && !rows.every(row => row.selected); + }); + + +export const selectEverySelected = createSelector( + getRows, + (rows: AASTableRow[]): boolean => { + return rows.length > 0 && rows.every(row => row.selected); }); export const selectRows = createSelector(getState, state => { - return state.rows; + return state.rows; }); export const selectIsFirstPage = createSelector( diff --git a/projects/aas-lib/src/lib/aas-tree/aas-tree.actions.ts b/projects/aas-lib/src/lib/aas-tree/aas-tree.actions.ts index d811ceaa..b127dca7 100644 --- a/projects/aas-lib/src/lib/aas-tree/aas-tree.actions.ts +++ b/projects/aas-lib/src/lib/aas-tree/aas-tree.actions.ts @@ -39,11 +39,10 @@ export const collapse = createAction( export const toggleSelected = createAction( AASTreeActionType.TOGGLE_SELECTED, - props<{ row: AASTreeRow }>()); + props<{ row: AASTreeRow, altKey: boolean, shiftKey: boolean }>()); export const toggleSelections = createAction( - AASTreeActionType.TOGGLE_SELECTIONS, - props<{ document: AASDocument | null }>()); + AASTreeActionType.TOGGLE_SELECTIONS); export const setSearchText = createAction( AASTreeActionType.SET_SEARCH_TEXT, diff --git a/projects/aas-lib/src/lib/aas-tree/aas-tree.component.html b/projects/aas-lib/src/lib/aas-tree/aas-tree.component.html index 99604b5d..8698d95b 100644 --- a/projects/aas-lib/src/lib/aas-tree/aas-tree.component.html +++ b/projects/aas-lib/src/lib/aas-tree/aas-tree.component.html @@ -11,7 +11,8 @@ + [disabled]="state === 'online'" [indeterminate]="someSelected | async" + [checked]="everySelected | async"> @@ -24,8 +25,8 @@ - +
diff --git a/projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts b/projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts index f17adab2..326a37fa 100644 --- a/projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts +++ b/projects/aas-lib/src/lib/aas-tree/aas-tree.component.ts @@ -64,6 +64,8 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { private readonly liveNodes: LiveNode[] = []; private readonly map = new Map(); private readonly subscription = new Subscription(); + private shiftKey = false; + private altKey = false; private webSocketSubject?: WebSocketSubject; @@ -79,14 +81,18 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { private readonly translate: TranslateService, private readonly notify: NotifyService, private readonly webSocketFactory: WebSocketFactoryService, - private readonly clipboard: ClipboardService + private readonly clipboard: ClipboardService, ) { this.store = store as Store; this.nodes = this.store.select(AASTreeSelectors.selectNodes); this.someSelected = this.store.select(AASTreeSelectors.selectSomeSelected); + this.everySelected = this.store.select(AASTreeSelectors.selectEverySelected); this.subscription.add(this.store.select(AASTreeSelectors.selectSelectedElements).pipe() .subscribe(elements => this.selectedChange.emit({ elements }))); + + this.window.addEventListener('keyup', this.keyup); + this.window.addEventListener('keydown', this.keydown); } @Input() @@ -115,6 +121,8 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { public someSelected: Observable; + public everySelected: Observable; + public nodes: Observable; public ngOnInit(): void { @@ -175,6 +183,8 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { this.subscription.unsubscribe(); this.webSocketSubject?.unsubscribe(); this.searching?.destroy(); + this.window.removeEventListener('keyup', this.keyup); + this.window.removeEventListener('keydown', this.keydown); } public visualState(node: AASTreeRow): string { @@ -225,11 +235,11 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { } public toggleSelections(): void { - this.store.dispatch(AASTreeActions.toggleSelections({ document: this.document })); + this.store.dispatch(AASTreeActions.toggleSelections()); } public toggleSelection(node: AASTreeRow): void { - this.store.dispatch(AASTreeActions.toggleSelected({ row: node })); + this.store.dispatch(AASTreeActions.toggleSelected({ row: node, altKey: this.altKey, shiftKey: this.shiftKey })); } public open(node: AASTreeRow): void { @@ -523,6 +533,16 @@ export class AASTreeComponent implements OnInit, OnChanges, OnDestroy { this.notify.log(LogType.Error, error); } + private keyup = () => { + this.shiftKey = false; + this.altKey = false; + }; + + private keydown = (event: KeyboardEvent) => { + this.shiftKey = event.shiftKey; + this.altKey = event.altKey; + }; + private resolveFile(file: aas.File): { url?: string, name?: string } { const value: { url?: string, name?: string } = {}; if (this.document?.content && file.value) { diff --git a/projects/aas-lib/src/lib/aas-tree/aas-tree.reducer.ts b/projects/aas-lib/src/lib/aas-tree/aas-tree.reducer.ts index 8ebaef71..3f13e358 100644 --- a/projects/aas-lib/src/lib/aas-tree/aas-tree.reducer.ts +++ b/projects/aas-lib/src/lib/aas-tree/aas-tree.reducer.ts @@ -59,11 +59,11 @@ export const aasTreeReducer = createReducer( ), on( AASTreeActions.toggleSelected, - (state, { row }) => toggleSelected(state, row) + (state, { row, altKey, shiftKey }) => toggleSelected(state, row, altKey, shiftKey) ), on( AASTreeActions.toggleSelections, - (state, { document }) => toggleSelections(state, document) + (state) => toggleSelections(state) ), on( AASTreeActions.updateRows, @@ -263,11 +263,11 @@ function updateRows(state: AASTreeState, document: AASDocument | null, localeId: function expandRow(state: AASTreeState, arg: number | AASTreeRow): AASTreeState { const rows = [...state.rows]; const ancestors: AASTreeRow[] = []; - let row = typeof arg === 'number' ? state.rows[arg] : arg; + let row = typeof arg === 'number' ? state.rows[arg] : arg; if (!row.expanded) { expand(row); } - + let parentRow = row.parent >= 0 ? state.rows[row.parent] : null; while (parentRow) { if (parentRow.expanded) { @@ -287,7 +287,7 @@ function expandRow(state: AASTreeState, arg: number | AASTreeRow): AASTreeState expand(row); } - + return { ...state, rows, error: null }; function expand(row: AASTreeRow) { @@ -380,14 +380,66 @@ function collapse(state: AASTreeState): AASTreeState { return { ...state, rows, error: null }; } -function toggleSelected(state: AASTreeState, row: AASTreeRow): AASTreeState { +function toggleSelected(state: AASTreeState, row: AASTreeRow, altKey: boolean, shiftKey: boolean): AASTreeState { + let rows: AASTreeRow[]; + if (altKey) { + rows = state.rows.map(item => + item === row ? clone(row, !row.selected) : (item.selected ? clone(item, false) : item), + ); + } else if (shiftKey) { + const index = state.rows.indexOf(row); + let begin = index; + let end = index; + const selection = state.rows.map(row => row.selected); + const last = selection.lastIndexOf(true); + if (last >= 0) { + if (last > index) { + begin = index; + end = selection.indexOf(true); + } else if (last < index) { + begin = last; + end = index; + } + } + + rows = []; + for (let i = 0, n = state.rows.length; i < n; i++) { + const row = state.rows[i]; + if (i < begin || i > end) { + rows.push(row.selected ? clone(row, false) : row); + } else { + rows.push(row.selected ? row : clone(row, true)); + } + } + } else { + const i = state.rows.indexOf(row); + rows = [...state.rows]; + rows[i] = clone(row, !row.selected); + } + + return { ...state, rows, error: null }; +} + +function toggleSelections(state: AASTreeState): AASTreeState { + const value = state.rows.length > 0 && state.rows.some(row => row.selected) && + !state.rows.every(row => row.selected); + const rows = [...state.rows]; - const index = rows.indexOf(row); - rows[index] = new AASTreeRow( + for (let index = 0; index < rows.length; ++index) { + const row = rows[index]; + if (row.selected !== value) { + rows[index] = clone(row, value); + } + } + return { ...state, rows, error: null }; +} + +function clone(row: AASTreeRow, selected: boolean): AASTreeRow { + return new AASTreeRow( row.id, row.element, row.expanded, - !row.selected, + selected, row.highlighted, row.level, row.abbreviation, @@ -399,61 +451,6 @@ function toggleSelected(state: AASTreeState, row: AASTreeRow): AASTreeState { row.parent, row.firstChild, row.nextSibling); - - return { ...state, rows, error: null }; -} - -function toggleSelections(state: AASTreeState, document: AASDocument | null): AASTreeState { - const value = !state.rows.some(row => row.selected); - const rows = state.rows.map(row => { - if (value) { - if (!row.selected && isSelectable(row, document)) { - return new AASTreeRow( - row.id, - row.element, - row.expanded, - true, - row.highlighted, - row.level, - row.abbreviation, - row.name, - row.typeInfo, - row.value, - row.displayType, - row.isLeaf, - row.parent, - row.firstChild, - row.nextSibling); - } - } else if (row.selected) { - return new AASTreeRow( - row.id, - row.element, - row.expanded, - false, - row.highlighted, - row.level, - row.abbreviation, - row.name, - row.typeInfo, - row.value, - row.displayType, - row.isLeaf, - row.parent, - row.firstChild, - row.nextSibling); - } - - return row; - }); - - return { ...state, rows, error: null }; - - function isSelectable(row: AASTreeRow, document: AASDocument | null): boolean { - return document != null && - (!document.readonly || - !document.modified && row.element.modelType === 'Property'); - } } function getTypeInfo(referable: aas.Referable | null): string { @@ -588,16 +585,6 @@ function getValue(referable: aas.Referable | null, localeId: string): boolean | const second = relationship.second.keys.map(key => key.value).join('/'); return `1. ${first}; 2. ${second}`; } - - function isDate(valueType: aas.DataTypeDefXsd): boolean { - switch (valueType) { - case 'xs:date': - case 'xs:dateTime': - return true; - default: - return false; - } - } } function setSearchText(state: AASTreeState, terms: SearchTerm[]): AASTreeState { diff --git a/projects/aas-lib/src/lib/aas-tree/aas-tree.selectors.ts b/projects/aas-lib/src/lib/aas-tree/aas-tree.selectors.ts index 543a8aae..33127955 100644 --- a/projects/aas-lib/src/lib/aas-tree/aas-tree.selectors.ts +++ b/projects/aas-lib/src/lib/aas-tree/aas-tree.selectors.ts @@ -43,7 +43,12 @@ export const selectSelectedElements = createSelector( export const selectSomeSelected = createSelector( getRows, - rows => rows.some(row => row.selected) + rows => rows.length > 0 && rows.some(row => row.selected) && !rows.every(row => row.selected) +); + +export const selectEverySelected = createSelector( + getRows, + rows => rows.length > 0 && rows.every(row => row.selected) ); export const selectSelectedRows = createSelector( diff --git a/projects/aas-lib/src/lib/convert.ts b/projects/aas-lib/src/lib/convert.ts index 08d29619..980ffcc0 100644 --- a/projects/aas-lib/src/lib/convert.ts +++ b/projects/aas-lib/src/lib/convert.ts @@ -17,7 +17,7 @@ import { noop, toString } from 'lodash-es'; * @param translate The translate service. * @returns The message as localized text. */ -export function messageToString(message: any, translate: TranslateService): string { +export function messageToString(message: unknown, translate: TranslateService): string { let text: string; if (message instanceof ApplicationError) { text = format(message.message, message.name, message.args); @@ -26,6 +26,7 @@ export function messageToString(message: any, translate: TranslateService): stri } else if (typeof message === 'string') { text = message; } else if (message instanceof HttpErrorResponse) { + if (isErrorData(message.error)) { text = format(message.error.message, message.error.name, message.error.args); } else { @@ -39,11 +40,12 @@ export function messageToString(message: any, translate: TranslateService): stri return text; - function isErrorData(value: object): value is ErrorData { - return typeof value === 'object' && 'message' in value && 'name' in value && 'type' in value; + function isErrorData(value: unknown): value is ErrorData { + const errorData = value as ErrorData; + return errorData.message != null && errorData.name != null && errorData.type != null; } - function format(message: string, name: string, args: any[]): string { + function format(message: string, name: string, args: unknown[]): string { if (name) { return stringFormat(translate.instant(name), args); } diff --git a/projects/aas-lib/src/lib/window.service.ts b/projects/aas-lib/src/lib/window.service.ts index 4882142d..b51edfcc 100644 --- a/projects/aas-lib/src/lib/window.service.ts +++ b/projects/aas-lib/src/lib/window.service.ts @@ -31,7 +31,7 @@ export class WindowService { public confirm(message: string): boolean | undefined { return window.confirm(message); } - + public getQueryParams(): URLSearchParams { return new URLSearchParams(window.location.search); } @@ -51,4 +51,20 @@ export class WindowService { public clearLocalStorage(): void { window.localStorage.clear(); } + + public addEventListener( + type: K, + listener: (this: Window, ev: WindowEventMap[K]) => unknown, + options?: boolean | AddEventListenerOptions + ): void { + window.addEventListener(type, listener, options) + } + + public removeEventListener( + type: K, + listener: (this: Window, ev: WindowEventMap[K]) => unknown, + options?: boolean | EventListenerOptions + ): void { + window.removeEventListener(type, listener, options) + } } \ No newline at end of file diff --git a/projects/aas-portal/src/app/start/start.component.html b/projects/aas-portal/src/app/start/start.component.html index bbd6fbb5..5c3bfaec 100644 --- a/projects/aas-portal/src/app/start/start.component.html +++ b/projects/aas-portal/src/app/start/start.component.html @@ -15,19 +15,19 @@
diff --git a/projects/aas-server/src/app/aas-provider/aas-provider.ts b/projects/aas-server/src/app/aas-provider/aas-provider.ts index a80f939e..b97e4cd7 100644 --- a/projects/aas-server/src/app/aas-provider/aas-provider.ts +++ b/projects/aas-server/src/app/aas-provider/aas-provider.ts @@ -84,38 +84,38 @@ export class AASProvider { public async getDocumentAsync(id: string, url?: string): Promise { const document = await this.index.get(url, id); - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); + await resource.openAsync(); if (!document.content) { - document.content = await source.createPackage(document.address).readEnvironmentAsync(); + document.content = await resource.createPackage(document.address).readEnvironmentAsync(); } return document; } finally { - await source.closeAsync(); + await resource.closeAsync(); } } public async getContentAsync(url: string, id: string): Promise { const document: AASDocument = await this.index.get(url, id); - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); - return await source.createPackage(document.address).readEnvironmentAsync(); + await resource.openAsync(); + return await resource.createPackage(document.address).readEnvironmentAsync(); } finally { - await source.closeAsync(); + await resource.closeAsync(); } } public async getThumbnailAsync(url: string, id: string): Promise { const document: AASDocument = await this.index.get(url, id); - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); - return await source.createPackage(document.address).getThumbnailAsync(id); + await resource.openAsync(); + return await resource.createPackage(document.address).getThumbnailAsync(id); } finally { - await source.closeAsync(); + await resource.closeAsync(); } } @@ -128,10 +128,10 @@ export class AASProvider { ): Promise { const document = await this.index.get(url, id); let stream: NodeJS.ReadableStream; - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); - const pkg = source.createPackage(document.address); + await resource.openAsync(); + const pkg = resource.createPackage(document.address); if (!document.content) { document.content = await pkg.readEnvironmentAsync(); } @@ -156,7 +156,7 @@ export class AASProvider { } } } else if (dataElement.modelType === 'Blob') { - const value = await source.getBlobValueAsync(document.content, smId, path); + const value = await resource.getBlobValueAsync(document.content, smId, path); const readable = new Readable(); readable.push(value); readable.push(null); @@ -165,7 +165,7 @@ export class AASProvider { throw new Error('Not implemented'); } } finally { - await source.closeAsync(); + await resource.closeAsync(); } return stream; @@ -239,10 +239,10 @@ export class AASProvider { throw new Error(`The destination document ${id} is not available.`); } - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); - const pkg = source.createPackage(document.address); + await resource.openAsync(); + const pkg = resource.createPackage(document.address); if (!document.content) { document.content = await pkg.readEnvironmentAsync(); } @@ -250,7 +250,7 @@ export class AASProvider { return await pkg.commitDocumentAsync(document, content); } finally { - await source.closeAsync(); + await resource.closeAsync(); } } @@ -260,14 +260,14 @@ export class AASProvider { * @param url The source URL. * @returns A readable stream. */ - public async getPackageAsync(id: string, url: string): Promise { + public async getPackageAsync(url: string, id: string): Promise { const document = await this.index.get(url, id); - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.openAsync(); - return await source.getPackageAsync(id, document.address); + await resource.openAsync(); + return await resource.getPackageAsync(id, document.address); } finally { - await source.closeAsync(); + await resource.closeAsync(); } } @@ -298,19 +298,19 @@ export class AASProvider { /** * Deletes an AASX package from an endpoint. - * @param url The container URL. + * @param url The endpoint URL. * @param id The AAS identification. */ public async deletePackageAsync(url: string, id: string): Promise { const document = await this.index.get(url, id); if (document) { - const source = this.resourceFactory.create(document.endpoint); + const resource = this.resourceFactory.create(document.endpoint); try { - await source.deletePackageAsync(document.id, document.address); + await resource.deletePackageAsync(document.id, document.address); await this.index.remove(url, id); this.notify({ type: 'Removed', document: { ...document, content: null } }); } finally { - await source.closeAsync(); + await resource.closeAsync(); } } } @@ -361,14 +361,14 @@ export class AASProvider { }; private async createSubscription(message: LiveRequest, client: SocketClient): Promise { - const source = this.resourceFactory.create(message.endpoint); + const resource = this.resourceFactory.create(message.endpoint); const env = await this.getContentAsync(message.endpoint.url, message.id); if (!env) { throw new Error('Invalid operation.'); } - await source.openAsync(); - return source.createSubscription(client, message, env); + await resource.openAsync(); + return resource.createSubscription(client, message, env); } private startScan = async (): Promise => {