Skip to content

Commit

Permalink
Fixed search filter issue in result list panel
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed Sep 27, 2024
1 parent 3343b9c commit b347254
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
5 changes: 5 additions & 0 deletions angular/src/app/landing/filters/filters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ export class FiltersComponent implements OnInit {
* clear filters
*/
clearFilters() {
this.searchService.setClearAll(true);
setTimeout(() => {
this.searchService.setClearAll(false);
}, 0)

this.filterStrings = {};
this.filterStrings[Collections.DEFAULT] = "";
this.filterStrings[Collections.FORENSICS] = "";
Expand Down
72 changes: 35 additions & 37 deletions angular/src/app/landing/resultlist/resultlist.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ export class ResultlistComponent implements OnInit {
constructor(private searchService: SearchService,
private cfg: AppConfig,
public collectionService: CollectionService,
public gaService: GoogleAnalyticsService) { }
public gaService: GoogleAnalyticsService) {

this.searchService.watchClearAll((clearAll: boolean) => {
if(clearAll) {
this.searchPhases = "";
this.filterResults();
}
});
}

ngOnInit(): void {
this.colorScheme = this.collectionService.getColorScheme(this.collection);
Expand Down Expand Up @@ -292,7 +300,8 @@ export class ResultlistComponent implements OnInit {
let searchWord: string = "";

if(searchPhase != ""){
filteredResults = JSON.parse(JSON.stringify(this.searchResultsOriginal));
// filteredResults = JSON.parse(JSON.stringify(this.searchResultsOriginal));
filteredResults = JSON.parse(JSON.stringify(this.searchResults));

// Restore the contents in quotes
if(searchPhase.indexOf('Quooooote') >= 0) {
Expand All @@ -303,59 +312,48 @@ export class ResultlistComponent implements OnInit {
searchWord = searchPhase.replace(/"/g, '');
}

// Do search
filteredResults = this.filterResultByWord(filteredResults, searchWord);

filteredResults.forEach((object)=>{
finalFilteredResults.push(object);
})

finalFilteredResults.map(item => item["@id"])
.filter((value, index, self) => self.indexOf(value) === index);
// Filter by word
this.filterResultByWord(this.searchResults, searchWord);
}
})

this.searchResults = finalFilteredResults;
}

/**
* Filter search result using searchString
* @param searchResults The result list to be searched
* @param searchString search string
* @returns filtered result list
*/
filterResultByWord(searchResults:any[], searchString: string) {
let retuenVal: any[] = [];
let found: boolean = false;

// Filter by word means only remove items, never add items
for(let object of searchResults) {
found = false;
for(let key of this.searchFields) {
if(Array.isArray(object[key])) {
for(let val of object[key]) {
if(val.toLowerCase().includes(searchString.trim().toLowerCase())) {
if(object.active){
found = false;
for(let key of this.searchFields) {
if(Array.isArray(object[key])) {
for(let val of object[key]) {
if(val.toLowerCase().includes(searchString.trim().toLowerCase())) {
retuenVal.push(object);
found = true;
break;
}
}
}else{
if(object[key].toLowerCase().includes(searchString.toLowerCase())) {
retuenVal.push(object);
found = true;
break;
}
}
}else{
if(object[key].toLowerCase().includes(searchString.toLowerCase())) {
retuenVal.push(object);
found = true;
break;
}
}

if(found) break;
};
}

// Remove items with duplicated @id
retuenVal.map(item => item["@id"])
.filter((value, index, self) => self.indexOf(value) === index);
if(found) break;
};

return retuenVal;
object.active = found;
}
}
}

/**
Expand Down Expand Up @@ -393,9 +391,6 @@ export class ResultlistComponent implements OnInit {
// Reset the search result
this.resetResult(this.filterString=="NoFilter");

// Handle search text box first
this.filterResultByPhase(this.searchPhases);

// Handle filters
if(this.filterString != "noFilter" && this.filterString != ""){
filters = this.filterString.split("&");
Expand Down Expand Up @@ -502,6 +497,9 @@ export class ResultlistComponent implements OnInit {
})
}

// Handle search text box first
this.filterResultByPhase(this.searchPhases);

this.searchResultsForDisplay = [];
this.searchResults.forEach((object) => {
if(object.active) this.searchResultsForDisplay.push(object);
Expand Down
12 changes: 12 additions & 0 deletions angular/src/app/shared/search-service/search-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ export class SearchService {
this.portalBase = cfg.get("locations.portalBase", "/unconfigured");
}

/**
* Signal clear all action.
*/
_clearAll : BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public setClearAll(val : boolean) {
this._clearAll.next(val);
}
public watchClearAll(subscriber) {
this._clearAll.subscribe(subscriber);
}


searchById(searchValue: string, browserside: boolean = false) {
let backend: string = this.rmmBackend

Expand Down

0 comments on commit b347254

Please sign in to comment.