Skip to content

Commit

Permalink
Add UI and IPC for nested search
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Jan 8, 2025
1 parent 93060ae commit 2320787
Show file tree
Hide file tree
Showing 16 changed files with 428 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class SessionSearch {
return this.managers.search.run(filters);
}

public searchNestedMatch(filter: IFilter, from: number): Promise<number | undefined> {
return this.session.searchNestedMatch(filter, from);
}

public values(filters: string[]): ICancelablePromise<void> {
return this.managers.values.run(filters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export enum Type {
export enum Source {
Assign = 'Assign',
Search = 'Search',
SearchNested = 'SearchNested',
SearchValues = 'SearchValues',
GetMap = 'GetMap',
ExtractMatchesValues = 'ExtractMatchesValues',
Expand Down Expand Up @@ -90,7 +91,9 @@ export class NativeError extends Error {
}
if (smth instanceof Buffer || smth instanceof Uint8Array) {
try {
const err = protocol.decodeComputationError(smth);
const err = protocol.decodeComputationError(
smth instanceof Buffer ? Uint8Array.from(smth) : smth,
);
if (err === null) {
return new NativeError(
new Error(`Fail decode error`),
Expand Down
37 changes: 37 additions & 0 deletions application/apps/rustcore/ts-bindings/src/native/native.session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export abstract class RustSession extends RustSessionRequiered {

public abstract isRawExportAvailable(): Promise<boolean>;

public abstract searchNestedMatch(filter: IFilter, from: number): Promise<number | undefined>;

public abstract search(filters: IFilter[], operationUuid: string): Promise<void>;

public abstract searchValues(filters: string[], operationUuid: string): Promise<void>;
Expand Down Expand Up @@ -282,6 +284,16 @@ export abstract class RustSessionNative {
operationUuid: string,
): Promise<void>;

public abstract searchNestedMatch(
filter: {
value: string;
is_regex: boolean;
ignore_case: boolean;
is_word: boolean;
},
from: number,
): Promise<number | undefined>;

public abstract applySearchValuesFilters(
filters: string[],
operationUuid: string,
Expand Down Expand Up @@ -826,6 +838,31 @@ export class RustSessionWrapper extends RustSession {
});
}

public searchNestedMatch(filter: IFilter, from: number): Promise<number | undefined> {
return new Promise((resolve, reject) => {
try {
this._native
.searchNestedMatch(
{
value: filter.filter,
is_regex: filter.flags.reg,
ignore_case: !filter.flags.cases,
is_word: filter.flags.word,
},
from,
)
.then(resolve)
.catch((err: Error) => {
reject(NativeError.from(err));
});
} catch (err) {
return reject(
new NativeError(NativeError.from(err), Type.Other, Source.SearchNested),
);
}
});
}

public searchValues(filters: string[], operationUuid: string): Promise<void> {
return new Promise((resolve, reject) => {
try {
Expand Down
22 changes: 22 additions & 0 deletions application/client/src/app/service/session/dependencies/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ export class Search extends Subscriber {
});
}

public searchNextNested(): Promise<number | undefined> {
const filter = this.state().getNested();
if (filter === undefined) {
return Promise.resolve(undefined);
}
return new Promise((resolve, reject) => {
Requests.IpcRequest.send(
Requests.Search.NextNested.Response,
new Requests.Search.NextNested.Request({
session: this._uuid,
filter,
from: this.state().getNestedPos(),
}),
)
.then((response) => {
this.state().setNestedPos(response.pos === undefined ? 0 : response.pos);
resolve(response.pos);
})
.catch(reject);
});
}

public extract(filters: string[]): Promise<void> {
return new Promise((resolve, reject) => {
Requests.IpcRequest.send(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class State {

private _controller: Search;
private _active: IFilter | undefined;
private _nested: { filter: IFilter | undefined; from: number } = { filter: undefined, from: 0 };
private _hash: {
search: string | undefined;
charts: string | undefined;
Expand Down Expand Up @@ -113,6 +114,28 @@ export class State {
});
}

public setNested(filter: IFilter): void {
this._nested.filter = obj.clone(filter);
this._nested.from = 0;
}

public setNestedPos(pos: number): void {
this._nested.from = pos;
}

public getNested(): IFilter | undefined {
return this._nested.filter;
}

public getNestedPos(): number {
return this._nested.from;
}

public dropNested(): void {
this._nested.filter = undefined;
this._nested.from = 0;
}

public filters(): Promise<void> {
if (this._active !== undefined) {
return Promise.resolve();
Expand Down
5 changes: 3 additions & 2 deletions application/client/src/app/ui/views/toolbar/search/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CommonModule } from '@angular/common';
import { ViewSearch } from './component';
import { ViewSearchInput } from './input/component';
import { ViewSearchResults } from './results/component';
import { ViewSearchNested } from './nested/component';
import { ScrollAreaModule } from '@elements/scrollarea/module';
import { ContainersModule } from '@elements/containers/module';
import { AppDirectiviesModule } from '@directives/module';
Expand All @@ -16,7 +17,7 @@ import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

const entryComponents = [ViewSearch, ViewSearchInput, ViewSearchResults];
const entryComponents = [ViewSearch, ViewSearchInput, ViewSearchNested, ViewSearchResults];
const components = [ViewSearch, ...entryComponents];

@NgModule({
Expand All @@ -36,6 +37,6 @@ const components = [ViewSearch, ...entryComponents];
ReactiveFormsModule,
],
declarations: [...components],
exports: [...components, ScrollAreaModule]
exports: [...components, ScrollAreaModule],
})
export class SearchModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
Component,
OnDestroy,
ViewChild,
Input,
AfterContentInit,
AfterViewInit,
ChangeDetectorRef,
ElementRef,
ViewEncapsulation,
} from '@angular/core';
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { Session } from '@service/session';
import { Ilc, IlcInterface } from '@env/decorators/component';
import { SearchInput } from '../input/input';
import { List } from '@env/storages/recent/list';
import { ChangesDetector } from '@ui/env/extentions/changes';
import { ISearchFinishEvent } from '@service/session/dependencies/search/state';
import { Notification } from '@ui/service/notifications';
import { IFilter } from '@platform/types/filter';

@Component({
selector: 'app-views-search-nested',
templateUrl: './template.html',
styleUrls: ['./styles.less'],
encapsulation: ViewEncapsulation.None,
})
@Ilc()
export class ViewSearchNested
extends ChangesDetector
implements AfterViewInit, AfterContentInit, OnDestroy
{
@Input() public session!: Session;

@ViewChild('searchinput') searchInputRef!: ElementRef<HTMLInputElement>;
@ViewChild(MatAutocompleteTrigger) recentPanelRef!: MatAutocompleteTrigger;

public readonly input = new SearchInput();
public readonly recent: List;
public readonly progress: boolean = false;

constructor(chRef: ChangeDetectorRef) {
super(chRef);
this.recent = new List(this.input.control, 'RecentNestedFilters', 'recent_nested_filters');
}

public ngOnDestroy(): void {
this.session.search.state().nonActive = this.input.getNonActive();
this.input.destroy();
}

public ngAfterContentInit(): void {
const filter = this.session.search.state().getNested();
this.input.set().value(filter ? filter : '');
}

public ngAfterViewInit(): void {
this.input.bind(this.searchInputRef.nativeElement, this.recentPanelRef);
this.input.actions.accept.subscribe(() => {
if (this.input.value.trim() !== '') {
const filter = this.input.asFilter();
this.recent.update(filter.filter);
this.session.search.state().setNested(filter);
this.session.search
.searchNextNested()
.then((pos: number | undefined) => {
console.log(`>>>>>>>>>>>>>>>>>>>>> next: ${pos}`);
})
.catch((err: Error) => {
this.log().error(`Fail apply nested search: ${err.message}`);
});
} else {
this.drop();
}
});
this.input.actions.drop.subscribe(() => {
this.drop();
});
this.input.actions.edit.subscribe(() => {
console.log('>>>>>>>>>>>>>>>> Edit');
// this.input.set().value(this.active.filter);
// this.drop();
this.detectChanges();
});
this.input.actions.recent.subscribe(() => {
this.detectChanges();
});
this.input.focus();
}

public drop() {
this.session.search.state().dropNested();
}
}
export interface ViewSearchNested extends IlcInterface {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@import '../../../../styles/variables.less';

app-views-search-nested {
display: flex;
position: relative;
flex-direction: row;
height: 32px;
width: 250px;
background: @scheme-color-5;
overflow: hidden;
justify-content: center;
align-items: center;
div.input {
display: block;
flex: auto;
height: 24px;
overflow: hidden;
align-items: center;
padding-left: 6px;
}
div.flags,
div.extantions {
display: flex;
padding: 0px 8px 0 8px;
& span {
display: inline-block;
height: 24px;
width: 24px;
color: @scheme-color-0;
text-align: center;
padding-top: 4px;
box-sizing: border-box;
&:hover{
background: @scheme-color-4;
}
&.active{
background: @scheme-color-active;
}
&.invalid {
color: @scheme-color-error;
}
}
}
div.summary {
position: relative;
display: flex;
flex-direction: row;
align-items: center;
padding: 0 6px 0 0;
margin-right: 12px;
white-space: nowrap;
& mat-spinner {
margin-left: 6px;
}
& span.error {
display: flex;
align-items: center;
padding-right: 6px;
& span.message {
color: @scheme-color-error;
max-width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
& mat-icon {
color: @scheme-color-error;
height: 16px;
width: 16px;
font-size: 16px;
margin: 0 6px 0 1px;
line-height: 16px;
}
}
}
& span.small-icon-button.occupied {
font-size: 13px;
line-height: 13px;
padding-top: 6px;
}

}
Loading

0 comments on commit 2320787

Please sign in to comment.