From e88b2353974477a73a54d9a5d1294cc43948d779 Mon Sep 17 00:00:00 2001 From: lcdr Date: Thu, 9 Nov 2023 18:13:05 +0100 Subject: [PATCH] Use SQL query API in item list component --- .../gui/item-list/item-list.component.html | 18 ++- src/app/gui/item-list/item-list.component.ts | 110 ++---------------- 2 files changed, 26 insertions(+), 102 deletions(-) diff --git a/src/app/gui/item-list/item-list.component.html b/src/app/gui/item-list/item-list.component.html index 562f394..a4eab7d 100644 --- a/src/app/gui/item-list/item-list.component.html +++ b/src/app/gui/item-list/item-list.component.html @@ -1,4 +1,14 @@ -
- -
\ No newline at end of file +
+ +
diff --git a/src/app/gui/item-list/item-list.component.ts b/src/app/gui/item-list/item-list.component.ts index f2a1932..6e59d5b 100644 --- a/src/app/gui/item-list/item-list.component.ts +++ b/src/app/gui/item-list/item-list.component.ts @@ -1,106 +1,20 @@ -import { Component, ComponentRef, createComponent, EnvironmentInjector, Input, OnInit, ViewContainerRef } from '@angular/core'; -import { Observable, ReplaySubject } from 'rxjs'; -import { first, map, shareReplay, switchMap } from 'rxjs/operators'; -import { DB_ComponentsRegistry, DB_RenderComponent } from '../../../defs/cdclient'; -import { RENDER_COMPONENT_ID } from '../../../defs/components'; -import { mapRec, mapToDict, mapToMultiDict, pick, values } from '../../../defs/rx'; -import { LuCoreDataService } from '../../services'; -import { ItemTooltipComponent } from '../item-tooltip/item-tooltip.component'; - -interface DB_Objects_Ref { - id: number; - name?: string; - displayName?: string; -} - -const OBJECT_KEYS: Array = [ - "id", - "name", - "displayName", -]; - -class GameObject { - tooltipComponentRef: ComponentRef; - - constructor( - public id: number, - public $table: Observable, - public $renderComponent: Observable, - environmentInjector: EnvironmentInjector, - ) { - this.tooltipComponentRef = createComponent(ItemTooltipComponent, { environmentInjector }) - this.tooltipComponentRef.instance.id = id; - this.$table.pipe(first()).subscribe(o => { - let title = o?.displayName || o?.name || "Object #" + this.id; - this.tooltipComponentRef.instance.title = title; - this.tooltipComponentRef.changeDetectorRef.detectChanges(); - }) - } -} - -const COMPONENTS_REGISTRY_KEYS: Array = [ - "id", - "component_type", - "component_id", -]; - -interface DB_RenderComponent_Ref { - id: number; - icon_asset: string, - IconID: string, -} - -const RENDER_COMPONENT_KEYS: Array = [ - "id", - "icon_asset", - "IconID", -]; +import { Component, Input } from "@angular/core"; @Component({ - selector: 'lux-item-list', - templateUrl: './item-list.component.html', - styleUrls: ['./item-list.component.css'] + selector: "lux-item-list", + templateUrl: "./item-list.component.html", + styleUrls: ["./item-list.component.css"] }) -export class ItemListComponent implements OnInit { +export class ItemListComponent { @Input() - ids: number[]; - - $ids: ReplaySubject; - objects: GameObject[]; - - constructor( - private luCoreData: LuCoreDataService, - private environmentInjector: EnvironmentInjector, - ) { - this.$ids = new ReplaySubject(1); + set ids(value: number[]) { + this._where = "c.id in (" + value + ")"; } - ngOnInit(): void { - const cd = this.luCoreData; - let $table = cd.queryTableEntries("Objects", this.ids, OBJECT_KEYS).pipe( - mapToDict("id"), - shareReplay(1) - ); - let $renderComponentIds = cd.queryTableEntries("ComponentsRegistry", this.ids, COMPONENTS_REGISTRY_KEYS).pipe( - mapToMultiDict("id"), - mapRec(v => v.find(x => x.component_type == RENDER_COMPONENT_ID)?.component_id), - shareReplay(1), - ); - let $renderComponents = $renderComponentIds.pipe( - values(), - cd.queryTableEntries$("RenderComponent", RENDER_COMPONENT_KEYS), - mapToDict("id"), - shareReplay(1), - ); - this.objects = Array.from(this.ids, id => { - let $rcId = $renderComponentIds.pipe(pick(id)); - let $rc = $rcId.pipe(switchMap(rcId => $renderComponents.pipe(pick(rcId)))); - return new GameObject( - id, - $table.pipe(pick(id)), - $rc, - this.environmentInjector, - ) - }) + @Input() + set where(value: string) { + this._where = value; } + + _where: string = ""; }