X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/400481f862c9de54569daabf9de167601dc887bc..d366e025618106edb2419941a041cd0f4214b245:/src/services/search-service/search-service.ts diff --git a/src/services/search-service/search-service.ts b/src/services/search-service/search-service.ts index f9392c237a..84d120a89c 100644 --- a/src/services/search-service/search-service.ts +++ b/src/services/search-service/search-service.ts @@ -2,31 +2,37 @@ // // SPDX-License-Identifier: AGPL-3.0 +import { SearchBarAdvanceFormData } from '~/models/search-bar'; + export class SearchService { - private recentQueries: string[] = this.getRecentQueries(); - private savedQueries: string[] = this.getSavedQueries(); + private recentQueries = this.getRecentQueries(); + private savedQueries: SearchBarAdvanceFormData[] = this.getSavedQueries(); saveRecentQuery(query: string) { if (this.recentQueries.length >= MAX_NUMBER_OF_RECENT_QUERIES) { this.recentQueries.shift(); - this.recentQueries.push(query); - } else { - this.recentQueries.push(query); } + this.recentQueries.push(query); localStorage.setItem('recentQueries', JSON.stringify(this.recentQueries)); } - getRecentQueries() { - return JSON.parse(localStorage.getItem('recentQueries') || '[]') as string[]; + getRecentQueries(): string[] { + return JSON.parse(localStorage.getItem('recentQueries') || '[]'); + } + + saveQuery(data: SearchBarAdvanceFormData) { + this.savedQueries.push({...data}); + localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries)); } - saveQuery(query: string) { - this.savedQueries.push(query); + editSavedQueries(data: SearchBarAdvanceFormData) { + const itemIndex = this.savedQueries.findIndex(item => item.queryName === data.queryName); + this.savedQueries[itemIndex] = {...data}; localStorage.setItem('savedQueries', JSON.stringify(this.savedQueries)); } getSavedQueries() { - return JSON.parse(localStorage.getItem('savedQueries') || '[]') as string[]; + return JSON.parse(localStorage.getItem('savedQueries') || '[]') as SearchBarAdvanceFormData[]; } deleteSavedQuery(id: number) { @@ -35,4 +41,4 @@ export class SearchService { } } -const MAX_NUMBER_OF_RECENT_QUERIES = 5; \ No newline at end of file +const MAX_NUMBER_OF_RECENT_QUERIES = 5;