Skip to content

Commit 91a6f6f

Browse files
committed
Update regular search type to correctly use a SearchFilterObject and set the localOnly parameter as intended
1 parent 8159bc7 commit 91a6f6f

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/app/common/shared/item-manager.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export class ItemManagerService {
4444

4545
fetchListOfData = async (itemType: ItemType, orgMrn: string, pageNumber: number, elementsPerPage: number, secomSearchFilterobj?: SearchFilterObject): Promise<FetchedItems> => {
4646
let page;
47-
console.log('Fetching data for', itemType, 'Page:', pageNumber, 'Elements per page:', elementsPerPage);
4847

4948
if(itemType === ItemType.Instance) {
5049
page = await firstValueFrom(this.instanceService.getInstances(pageNumber, elementsPerPage, [], 'response'));
@@ -56,7 +55,6 @@ export class ItemManagerService {
5655

5756
} else if(itemType === ItemType.SearchObjectResult && secomSearchFilterobj) {
5857

59-
6058
page = await firstValueFrom(this.secomService.search(secomSearchFilterobj, pageNumber, elementsPerPage, 'response'));
6159
const totalElements = parseInt(page.headers.get('X-Total-Count')!) || 10;
6260
return { data: (page.body?.services! as SearchObjectResult[]).map(i => preprocess(i, itemType)),

src/app/pages/sr-search/sr-search.component.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { Component, ElementRef, ViewChild } from '@angular/core';
1818
import { InputGeometryComponent } from "../../components/input-geometry/input-geometry.component";
1919
import { ComponentsModule } from 'src/app/components/components.module';
2020
import { SvcSearchInputComponent } from "../../components/svc-search-input/svc-search-input.component";
21-
import { SearchObjectResult, SearchParameters, SECOMService } from 'src/app/backend-api/secom';
21+
import {SearchFilterObject, SearchObjectResult, SearchParameters, SECOMService} from 'src/app/backend-api/secom';
2222
import { InstanceInfo, ItemType } from 'src/app/common/menuType';
2323
import { ColumnForResource } from 'src/app/common/columnForMenu';
2424
import { InstanceControllerService, InstanceDto } from 'src/app/backend-api/service-registry';
@@ -72,6 +72,7 @@ export class SrSearchComponent {
7272
showPanel = false;
7373
selectedInstance: any = {};
7474
instanceType = ItemType.Instance;
75+
localOnly : boolean = true;
7576

7677
constructor(
7778
private router: Router,
@@ -107,14 +108,14 @@ export class SrSearchComponent {
107108
fetchData = async (itemType: ItemType, pageNumber: number, elementsPerPage: number) => {
108109
try {
109110
console.debug("Call fetch data with params:", this.searchParams, this.queryGeometry);
110-
const secomSearchParam = this.buildSearchParam(this.searchParams, Object.keys(this.queryGeometry).length > 0 ? JSON.stringify(this.queryGeometry) : ''); //geojsonToWKT(this.queryGeometry) : '');
111+
const secomSearchFilterObj = this.buildSearchFilterObject(this.searchParams, Object.keys(this.queryGeometry).length > 0 ? JSON.stringify(this.queryGeometry) : '', this.localOnly); //geojsonToWKT(this.queryGeometry) : '');
111112
if (this.freetext === '' && Object.keys(this.searchParams).length === 0 && Object.keys(this.queryGeometry).length === 0) {
112113
return [];
113114
}
114115
// a bit of hack to deal with the fact that the search service does not support total number of elements....
115116
let fetchedItems;
116117
try {
117-
fetchedItems = await this.itemManagerService.fetchListOfData(itemType, this.orgMrn, pageNumber, 100, secomSearchParam);
118+
fetchedItems = await this.itemManagerService.fetchListOfData(itemType, this.orgMrn, pageNumber, 100, secomSearchFilterObj);
118119
} catch (error) {
119120
console.error('Error fetching items:', error);
120121
this.notifier.notify('error.search.general', (error as any).message);
@@ -139,20 +140,23 @@ export class SrSearchComponent {
139140
}
140141
}
141142

142-
buildSearchParam = (searchParams: SearchParameters, geojsonString?: string): object => {
143-
const queryObject: any = {};
143+
buildSearchFilterObject = (searchParams: SearchParameters, geojsonString?: string, localOnly? : boolean): object => {
144+
let searchFilterObj: SearchFilterObject = {
145+
};
144146

145147
// Only add the query section if it has data
146148
if (searchParams && Object.keys(searchParams).length > 0) {
147-
queryObject["query"] = searchParams;
149+
searchFilterObj.query = searchParams;
148150
}
149151

150152
// Add geometry only if provided
151153
if (geojsonString) {
152-
queryObject["geometry"] = geojsonString;
154+
searchFilterObj.geometry = geojsonString;
153155
}
154156

155-
return queryObject;
157+
searchFilterObj.localOnly = localOnly;
158+
159+
return searchFilterObj;
156160
};
157161

158162
onUpdateGeometry = (event: any) => {
@@ -175,7 +179,7 @@ export class SrSearchComponent {
175179

176180
search = (searchParams: SearchParameters, geojsonString?: string) => {
177181
this.isLoading = true;
178-
const queryObject = this.buildSearchParam(searchParams, geojsonString);
182+
const queryObject = this.buildSearchFilterObject(searchParams, geojsonString, this.localOnly);
179183
this.secomSearchController.search(queryObject).subscribe(res => {
180184
this.instances = res.services;
181185
this.refreshData(this.instances);
@@ -198,7 +202,14 @@ export class SrSearchComponent {
198202
if (this.geometryMap) {
199203
this.geometryMap.clearMap();
200204
}
201-
console.debug("Noermal search with params:", this.searchParams);
205+
206+
if (payload.scope === 'global') {
207+
this.localOnly = false;
208+
} else {
209+
this.localOnly = true;
210+
}
211+
212+
202213
this.smartTable.loadData();
203214
}
204215

0 commit comments

Comments
 (0)