Skip to content

Commit

Permalink
update LowDbIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Dec 4, 2023
1 parent 537a4da commit 3d458ff
Show file tree
Hide file tree
Showing 31 changed files with 65,593 additions and 662 deletions.
19 changes: 15 additions & 4 deletions projects/aas-lib/src/lib/aas-table/aas-table-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { AASCursor, AASPage, aas } from 'common';
import { AASCursor, AASDocumentNode, AASPage, aas } from 'common';
import { encodeBase64Url } from '../convert';

@Injectable({
Expand Down Expand Up @@ -39,12 +39,23 @@ export class AASTableApiService {

/**
* Loads the element structure of the specified document.
* @param name The URL of the container.
* @param endpointName The URL of the container.
* @param id The identification of the AAS document.
* @returns The root of the element structure.
*/
public getContent(name: string, id: string): Observable<aas.Environment> {
public getContent(endpointName: string, id: string): Observable<aas.Environment> {
return this.http.get<aas.Environment>(
`/api/v1/containers/${encodeBase64Url(name)}/documents/${encodeBase64Url(id)}/content`);
`/api/v1/containers/${encodeBase64Url(endpointName)}/documents/${encodeBase64Url(id)}/content`);
}

/**
*
* @param endpointName
* @param id
* @returns
*/
public getHierarchy(endpointName: string, id: string): Observable<AASDocumentNode[]> {
return this.http.get<AASDocumentNode[]>(
`/api/v1/containers/${encodeBase64Url(endpointName)}/documents/${encodeBase64Url(id)}/hierarchy`);
}
}
46 changes: 36 additions & 10 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,32 +7,47 @@
*****************************************************************************/

import { createAction, props } from '@ngrx/store';
import { AASDocument, AASPage, aas } from 'common';
import { AASDocument, AASDocumentNode, AASPage, aas } from 'common';
import { AASTableRow } from './aas-table.state';
import { TypedAction } from '@ngrx/store/src/models';

export enum AASTableActionType {
INITIALIZE = '[AASTable] initialize',
INIT_LIST_VIEW = '[AASTable] init list view',
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_CONTENT = '[AASTable] set content',
UPDATE_ROWS = '[AASTable] Update Rows',
EXPAND = '[AASTable] Expand',
COLLAPSE = '[AASTable] Collapse',
TOGGLE_SELECTED = '[AASTable] Toggle selected',
TOGGLE_SELECTIONS = '[AASTable] Toggle selections'
UPDATE_ROWS = '[AASTable] update Rows',
EXPAND = '[AASTable] expand',
COLLAPSE = '[AASTable] collapse',
TOGGLE_SELECTED = '[AASTable] toggle selected',
TOGGLE_SELECTIONS = '[AASTable] toggle selections',
ADD_ROOT = '[AASTable] add root',
INIT_TREE_VIEW = '[AASTable] init tree view',
SET_SELECTIONS = '[AASTable] set selections',
}

export interface GetPageAction extends TypedAction<AASTableActionType.GET_FIRST_PAGE> {
export interface GetFirstPageAction extends TypedAction<AASTableActionType.GET_FIRST_PAGE> {
limit: number;
filter?: string;
}

export const initialize = createAction(
AASTableActionType.INITIALIZE);
export interface GetLastPageAction extends TypedAction<AASTableActionType.GET_LAST_PAGE> {
limit: number;
filter?: string;
}

export interface GetPreviousPageAction extends TypedAction<AASTableActionType.GET_PREVIOUS_PAGE> {
limit: number;
filter?: string;
}

export interface GetNextPageAction extends TypedAction<AASTableActionType.GET_NEXT_PAGE> {
limit: number;
filter?: string;
}

export const getFirstPage = createAction(
AASTableActionType.GET_FIRST_PAGE,
Expand Down Expand Up @@ -72,3 +87,14 @@ export const toggleSelected = createAction(

export const toggleSelections = createAction(
AASTableActionType.TOGGLE_SELECTIONS);

export const addRoot = createAction(
AASTableActionType.ADD_ROOT,
props<{ nodes: AASDocumentNode[] }>());

export const initTreeView = createAction(
AASTableActionType.INIT_TREE_VIEW);

export const setSelections = createAction(
AASTableActionType.SET_SELECTIONS,
props<{ documents: AASDocument[] }>());
82 changes: 43 additions & 39 deletions projects/aas-lib/src/lib/aas-table/aas-table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
!
!---------------------------------------------------------------------------->

<table *ngIf="viewMode === 'list'" class="table table-sm table-hover table-striped">
<table *ngIf="viewMode === 'list'; else treeView" class="table table-sm table-hover table-striped">
<thead>
<tr>
<th class="th-w-checkbox">
Expand Down Expand Up @@ -43,44 +43,48 @@
</tr>
</tbody>
</table>
<table *ngIf="viewMode === 'tree'" class="table table-sm table-borderless table-hover table-striped">
<thead>
<tr>
<th class="aas-th-name"></th>
<th class="aas-th-value"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows | async">
<td>
<div class="d-flex" style="overflow-x: hidden">
<div [ngStyle]="{'width': (row.level * 16) + 'px'}"></div>
<a *ngIf="!row.isLeaf && !row.expanded && row.hasChildren" href="javascript:void(0);"
(click)="expand(row)">
<div class="text-dark">
<i class="bi bi-plus-square"></i>

<ng-template #treeView>
<table class="table table-sm table-borderless table-hover table-striped">
<thead>
<tr>
<th class="aas-th-name"></th>
<th class="aas-th-value"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let row of rows | async">
<td>
<div class="d-flex" style="overflow-x: hidden">
<div [ngStyle]="{'width': (row.level * 16) + 'px'}"></div>
<a *ngIf="!row.isLeaf && !row.expanded && row.hasChildren" href="javascript:void(0);"
(click)="expand(row)">
<div class="text-dark">
<i class="bi bi-plus-square"></i>
</div>
</a>
<div *ngIf="!row.isLeaf && !row.expanded && !row.hasChildren" class="text-muted">
<i class="bi bi-square"></i>
</div>
</a>
<div *ngIf="!row.isLeaf && !row.expanded && !row.hasChildren" class="text-muted">
<i class="bi bi-square"></i>
</div>
<a *ngIf="!row.isLeaf && row.expanded" href="javascript:void(0);" (click)="collapse(row)">
<div class="text-dark">
<i class="bi bi-dash-square"></i>
<a *ngIf="!row.isLeaf && row.expanded" href="javascript:void(0);" (click)="collapse(row)">
<div class="text-dark">
<i class="bi bi-dash-square"></i>
</div>
</a>
<div *ngIf="row.isLeaf" class="text-muted wh-4"></div>
<div class="ms-2">
<img class="img-fluid" width="40" height="40" [src]="row.thumbnail" alt="" />
</div>
<div class="ms-2 flex-grow-1">
<a class="text-nowrap" href="javascript:void(0);" (click)="open(row)">{{row.name |
max:60}}</a>
</div>
</a>
<div *ngIf="row.isLeaf" class="text-muted wh-4"></div>
<div class="ms-2">
<img class="img-fluid" width="40" height="40" [src]="row.thumbnail" alt="" />
</div>
<div class="ms-2 flex-grow-1">
<a class="text-nowrap" href="javascript:void(0);" (click)="open(row)">{{row.name | max:60}}</a>
</div>
</div>
</td>
<td>
<div class="text-nowrap" placement="top" [ngbTooltip]="getToolTip(row)">{{row.id | max:80}}</div>
</td>
</tr>
</tbody>
</table>
</td>
<td>
<div class="text-nowrap" placement="top" [ngbTooltip]="getToolTip(row)">{{row.id | max:80}}</div>
</td>
</tr>
</tbody>
</table>
</ng-template>
58 changes: 50 additions & 8 deletions projects/aas-lib/src/lib/aas-table/aas-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { AASDocument } from 'common';
import { Observable, Subscription } from 'rxjs';
import { AASDocument, equalArray } from 'common';
import { Observable, Subscription, first, mergeMap } from 'rxjs';

import { ViewMode } from '../types/view-mode';
import { AASTableRow, AASTableFeatureState } from './aas-table.state';
Expand All @@ -19,6 +19,8 @@ import * as AASTableActions from './aas-table.actions';
import { AASQuery } from '../types/aas-query-params';
import { ClipboardService } from '../clipboard.service';
import { WindowService } from '../window.service';
import { AuthService } from '../auth/auth.service';
import { NotifyService } from '../notify/notify.service';

@Component({
selector: 'fhg-aas-table',
Expand All @@ -30,13 +32,17 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy {
private readonly subscription: Subscription = new Subscription();
private _filter = '';
private _limit = 10;
private _viewMode = ViewMode.List;
private _selected: AASDocument[] = [];
private shiftKey = false;
private altKey = false;

constructor(
private readonly router: Router,
store: Store,
private readonly auth: AuthService,
private readonly clipboard: ClipboardService,
private readonly notify: NotifyService,
private readonly window: WindowService
) {
this.store = store as Store<AASTableFeatureState>;
Expand All @@ -47,15 +53,25 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy {
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()
public viewMode: ViewMode = ViewMode.List;
public get viewMode(): ViewMode {
return this._viewMode;
}

public set viewMode(value: ViewMode) {
if (value !== this._viewMode) {
this._viewMode = value;
if (this._viewMode === ViewMode.List) {
this.store.dispatch(AASTableActions.getFirstPage({ limit: this._limit }));
} else {
this.store.dispatch(AASTableActions.initTreeView())
}
}
}

@Input()
public filter: Observable<string> | null = null;
Expand All @@ -64,7 +80,19 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy {
public limit: Observable<number> | null = null;

@Output()
public selectedChange = new EventEmitter<{ documents: AASDocument[] }>();
public selectedChange = new EventEmitter<AASDocument[]>();

@Input()
public get selected(): AASDocument[] {
return this._selected;
}

public set selected(values: AASDocument[]) {
if (!equalArray(this._selected, values)) {
this._selected = values;
this.store.dispatch(AASTableActions.setSelections({ documents: values }));
}
}

public someSelected: Observable<boolean>;

Expand All @@ -79,7 +107,21 @@ export class AASTableComponent implements OnInit, OnChanges, OnDestroy {
public readonly rows: Observable<AASTableRow[]>;

public ngOnInit(): void {
this.store.dispatch(AASTableActions.initialize());
this.subscription.add(this.store.select(AASTableSelectors.selectSelectedDocuments).pipe()
.subscribe(documents => {
this._selected = documents;
this.selectedChange.emit(documents);
}));

this.store.select(AASTableSelectors.selectViewMode).pipe(
first(viewMode => viewMode === ViewMode.Undefined),
mergeMap(() => this.auth.ready),
first(ready => ready),
first(),
).subscribe({
next: () => this.store.dispatch(AASTableActions.getFirstPage({ limit: this._limit })),
error: error => this.notify.error(error),
});
}

public ngOnChanges(changes: SimpleChanges): void {
Expand Down
Loading

0 comments on commit 3d458ff

Please sign in to comment.