Skip to content

Commit

Permalink
fix: filter aas-table favorites updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfaron committed Nov 29, 2024
1 parent a8cebe9 commit 56abb57
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 185 deletions.
4 changes: 3 additions & 1 deletion projects/aas-lib/src/lib/aas-table/aas-table.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
parseDate,
toBoolean,
flat,
getModelTypeFromAbbreviation,
AASAbbreviation,
} from 'aas-core';

export type ElementValueType = 'string' | 'boolean' | 'number' | 'Date' | 'bigint';
Expand Down Expand Up @@ -110,7 +112,7 @@ export class AASTableFilter {
}

private any(element: aas.Referable, query: AASQuery): boolean {
if (element.modelType === query.modelType) {
if (element.modelType === getModelTypeFromAbbreviation(query.modelType as AASAbbreviation)) {
if (this.containsString(element.idShort, query.name)) {
if (!element || !query.value) {
return true;
Expand Down
18 changes: 16 additions & 2 deletions projects/aas-lib/src/lib/aas-table/aas-table.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,27 @@ import { AASDocument } from 'aas-core';
import { ViewMode } from '../types/view-mode';
import { AASTableRow, AASTableTree } from './aas-table-row';

type AASTableState = {
documents: AASDocument[];
totalRows: AASTableRow[];
rows: AASTableRow[];
};

const initialState: AASTableState = {
documents: [],
totalRows: [],
rows: [],
};

@Injectable()
export class AASTableStore {
private readonly _totalRows = signal<AASTableRow[]>([]);
private readonly _rows = signal<AASTableRow[]>([]);
private readonly _totalRows = signal<AASTableRow[]>(initialState.totalRows);
private readonly _rows = signal<AASTableRow[]>(initialState.rows);

public readonly rows = this._rows.asReadonly();

public readonly documents = signal<AASDocument[]>(initialState.documents);

public setSelected(documents: AASDocument[], viewMode: ViewMode): void {
const tree = new AASTableTree(untracked(this._totalRows));
tree.selectedElements = documents;
Expand Down
28 changes: 21 additions & 7 deletions projects/aas-lib/src/lib/aas-tree/aas-tree-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*
*****************************************************************************/

import trim from 'lodash-es/trim';
import { Injectable, untracked } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import trim from 'lodash-es/trim';
import {
aas,
AASAbbreviation,
Expand All @@ -21,20 +21,34 @@ import {

import { normalize } from '../convert';
import { AASTreeRow } from './aas-tree-row';
import { AASTreeService, Operator, SearchQuery, SearchTerm } from './aas-tree.service';
import { AASTreeStore } from './aas-tree.store';

export type Operator = '=' | '<' | '>' | '<=' | '>=' | '!=';

export interface SearchQuery {
modelType: aas.ModelType;
operator?: Operator;
name?: string;
value?: string | boolean;
}

export interface SearchTerm {
text?: string;
query?: SearchQuery;
}

@Injectable()
export class AASTreeSearch {
private readonly loop = true;
private terms: SearchTerm[] = [];

public constructor(
private readonly store: AASTreeService,
private readonly store: AASTreeStore,
private readonly translate: TranslateService,
) {}

public find(referable: aas.Referable): void {
const rows = untracked(this.store.state).rows;
const rows = untracked(this.store.state$).rows;
const index = rows.findIndex(row => row.element === referable);
if (index >= 0) {
this.store.setMatchIndex(index);
Expand Down Expand Up @@ -73,7 +87,7 @@ export class AASTreeSearch {

public findNext(): boolean {
let completed = false;
const state = untracked(this.store.state);
const state = untracked(this.store.state$);
if (state.rows.length > 0 && this.terms.length > 0) {
let match = false;
let i = state.matchIndex < 0 ? 0 : state.matchIndex + 1;
Expand Down Expand Up @@ -106,7 +120,7 @@ export class AASTreeSearch {

public findPrevious(): boolean {
let completed = false;
const state = untracked(this.store.state);
const state = untracked(this.store.state$);
if (state.rows.length > 0 && this.terms.length > 0) {
let match = false;
let i = state.matchIndex <= 0 ? state.rows.length - 1 : state.matchIndex - 1;
Expand Down Expand Up @@ -138,7 +152,7 @@ export class AASTreeSearch {
}

private findFirst(): void {
const state = untracked(this.store.state);
const state = untracked(this.store.state$);
if (state.rows.length > 0 && this.terms.length > 0) {
let match = false;
let i = state.matchIndex < 0 ? 0 : state.matchIndex;
Expand Down
Loading

0 comments on commit 56abb57

Please sign in to comment.