diff --git a/erdblick_app/app/jump.service.ts b/erdblick_app/app/jump.service.ts index 8bd1a390..f1432c65 100644 --- a/erdblick_app/app/jump.service.ts +++ b/erdblick_app/app/jump.service.ts @@ -148,7 +148,7 @@ export class JumpTargetService { try { tileId = BigInt(bigintStr); } catch { - valid = false; + return null; } if (quoted1 || unquoted1) { @@ -170,10 +170,10 @@ export class JumpTargetService { } } } else { - valid = false; + return null; } - if (tileId === -1n || !valid) { + if (tileId === -1n) { return null; } @@ -216,6 +216,9 @@ export class JumpTargetService { valid &&= this.validateMapgetTileId(matches[0].toString()); } + else { + valid = false; + } return { icon: "pi-database", @@ -253,7 +256,7 @@ export class JumpTargetService { } } }, - validate: (value: string) => { + validate: (_: string) => { return valid; } } diff --git a/erdblick_app/app/search.panel.component.ts b/erdblick_app/app/search.panel.component.ts index 3b6454e5..62e17df2 100644 --- a/erdblick_app/app/search.panel.component.ts +++ b/erdblick_app/app/search.panel.component.ts @@ -269,7 +269,6 @@ export class SearchPanelComponent implements AfterViewInit { for (let i = 0; i < this.searchItems.length; i++) { // TODO: Introduce a static ID for the action, so we can reference it directly. if (this.searchItems[i].name === "Inspect Tile Layer Source Data") { - console.assert(this.searchItems[i].validate(value)) this.parametersService.setSearchHistoryState([i, value]); break; } diff --git a/erdblick_app/app/sourcedataselection.dialog.component.ts b/erdblick_app/app/sourcedataselection.dialog.component.ts index 72fc3ad3..bfca4987 100644 --- a/erdblick_app/app/sourcedataselection.dialog.component.ts +++ b/erdblick_app/app/sourcedataselection.dialog.component.ts @@ -64,13 +64,16 @@ import {coreLib} from "./wasm"; }) export class SourceDataLayerSelectionDialogComponent { selectedTileId: SourceDataDropdownOption | undefined; - tileIds: SourceDataDropdownOption[] = []; - selectedSourceDataLayer: SourceDataDropdownOption | undefined; - sourceDataLayers: SourceDataDropdownOption[] = []; - sourceDataLayersMap: Map = new Map(); selectedMapId: SourceDataDropdownOption | undefined; - mapIdsMap: Map = new Map(); + selectedSourceDataLayer: SourceDataDropdownOption | undefined; + + tileIds: SourceDataDropdownOption[] = []; mapIds: SourceDataDropdownOption[] = []; + sourceDataLayers: SourceDataDropdownOption[] = []; + + mapIdsPerTileId: Map = new Map(); + sourceDataLayersPerMapId: Map = new Map(); + errorString: string = ""; loading: boolean = true; customTileId: string = ""; @@ -86,42 +89,46 @@ export class SourceDataLayerSelectionDialogComponent { this.load(); }); this.menuService.customTileAndMapId.subscribe(([tileId, mapId]: [string, string]) => { - this.load(tileId.length > 0, tileId, mapId); + this.load(tileId, mapId); this.menuService.tileSourceDataDialogVisible = true; }); } - load(withCustomTileId: boolean = false, customTileId: string = "", customMapId: string = "") { - this.showCustomTileIdInput = withCustomTileId; + load(customTileId: string = "", customMapId: string = "") { + this.showCustomTileIdInput = customTileId.length > 0; this.customTileId = customTileId; this.customMapId = customMapId; this.mapIds = []; this.sourceDataLayers = []; this.loading = false; this.menuService.tileOutiline.next(null); - if (withCustomTileId && customTileId) { - const tileId = BigInt(customTileId); - this.triggerModelChange({id: tileId, name: customTileId}); + + // Special case: There is a custom tile ID. + if (customTileId) { + this.onCustomTileIdChange(customTileId); return; } + // Abort if no Tile IDs were provided by the menu service. if (!this.tileIds.length) { this.selectedTileId = undefined; this.errorString = "No tile IDs available for the clicked position!"; return; } + // Fill map IDs per tile ID. for (let i = 0; i < this.tileIds.length; i++) { const id = this.tileIds[i].id as bigint; const maps = [...this.findMapsForTileId(id)]; this.tileIds[i]["disabled"] = !maps.length; - this.mapIdsMap.set(id, maps); + this.mapIdsPerTileId.set(id, maps); } - this.selectedTileId = this.tileIds.find(element => !element.disabled); - if (this.selectedTileId === undefined) { - return; + + // Pre-select the tile ID. + let tileIdSelection = this.tileIds.find(element => !element.disabled); + if (tileIdSelection) { + this.setCurrentTileId(tileIdSelection); } - this.triggerModelChange(this.selectedTileId); } *findMapsForTileId(tileId: bigint): Generator { @@ -147,28 +154,28 @@ export class SourceDataLayerSelectionDialogComponent { const tileId = BigInt(tileIdString); const maps = [...this.findMapsForTileId(tileId)]; - this.mapIdsMap.set(tileId, maps); - this.triggerModelChange({id: tileId, name: tileIdString}); + this.mapIdsPerTileId.set(tileId, maps); + this.setCurrentTileId({id: tileId, name: tileIdString}); } - private triggerModelChange(tileId: SourceDataDropdownOption) { + private setCurrentTileId(tileId: SourceDataDropdownOption) { + this.selectedTileId = tileId; this.onTileIdChange(tileId); - if (this.customMapId.length) { - const mapId = { id: this.customMapId, name: this.customMapId }; - if (!this.mapIds.includes(mapId)) { - this.mapIds.push(mapId); + + if (this.customMapId) { + let mapSelection = this.mapIds.find(entry => entry.id == this.customMapId); + if (mapSelection) { + this.selectedMapId = mapSelection; } - this.selectedMapId = mapId; - this.findLayersForMapId(mapId.id); - this.onMapIdChange(this.selectedMapId); - if (this.sourceDataLayers.length) { - this.selectedSourceDataLayer = this.sourceDataLayers[0]; - this.onLayerIdChange(this.selectedSourceDataLayer); + else { + this.mapIds.unshift({ id: this.customMapId, name: this.customMapId }); } - return; } + if (this.mapIds.length) { - this.selectedMapId = this.mapIds[0]; + if (!this.selectedMapId) { + this.selectedMapId = this.mapIds[0]; + } this.onMapIdChange(this.selectedMapId); if (this.sourceDataLayers.length) { this.selectedSourceDataLayer = this.sourceDataLayers[0]; @@ -182,14 +189,14 @@ export class SourceDataLayerSelectionDialogComponent { this.selectedSourceDataLayer = undefined; this.sourceDataLayers = []; this.outlineTheTileBox(BigInt(tileId.id), Color.HOTPINK); - const mapIds = this.mapIdsMap.get(tileId.id as bigint); + const mapIds = this.mapIdsPerTileId.get(tileId.id as bigint); if (mapIds !== undefined) { this.mapIds = mapIds.sort((a, b) => a.name.localeCompare(b.name)); for (let i = 0; i < this.mapIds.length; i++) { const id = this.mapIds[i].id as string; const layers = this.findLayersForMapId(id); this.mapIds[i]["disabled"] = !layers.length; - this.sourceDataLayersMap.set(id, layers); + this.sourceDataLayersPerMapId.set(id, layers); } } } @@ -229,7 +236,7 @@ export class SourceDataLayerSelectionDialogComponent { onMapIdChange(mapId: SourceDataDropdownOption) { this.selectedSourceDataLayer = undefined; - const sourceDataLayers = this.sourceDataLayersMap.get(mapId.id as string); + const sourceDataLayers = this.sourceDataLayersPerMapId.get(mapId.id as string); if (sourceDataLayers !== undefined) { this.sourceDataLayers = sourceDataLayers; }