Add persistent search input
This commit is contained in:
parent
c602e75f33
commit
cc07e11f8f
@ -5,6 +5,7 @@ import {objToBase64} from '../../utils/base64conversion';
|
|||||||
import {PresetService} from '../../services/preset.service';
|
import {PresetService} from '../../services/preset.service';
|
||||||
import {Preset} from '../../interfaces/preset.interface';
|
import {Preset} from '../../interfaces/preset.interface';
|
||||||
import {formatDate} from '@angular/common';
|
import {formatDate} from '@angular/common';
|
||||||
|
import {SearchService} from '../../services/search.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search-input',
|
selector: 'app-search-input',
|
||||||
@ -23,7 +24,7 @@ export class SearchInputComponent implements OnInit {
|
|||||||
singlePresetSelection = {};
|
singlePresetSelection = {};
|
||||||
multiPresetSelection = {};
|
multiPresetSelection = {};
|
||||||
|
|
||||||
constructor(private router: Router, private ps: PresetService) {
|
constructor(private router: Router, private ps: PresetService, private ss: SearchService) {
|
||||||
const from = new Date();
|
const from = new Date();
|
||||||
const to = new Date();
|
const to = new Date();
|
||||||
to.setDate(from.getDate() + 7);
|
to.setDate(from.getDate() + 7);
|
||||||
@ -40,8 +41,13 @@ export class SearchInputComponent implements OnInit {
|
|||||||
this.multiPresets = this.ps.multiPresets;
|
this.multiPresets = this.ps.multiPresets;
|
||||||
this.multiPresetsKeys = [...this.multiPresets.keys()];
|
this.multiPresetsKeys = [...this.multiPresets.keys()];
|
||||||
|
|
||||||
for (const preset of this.singlePresets) {
|
const prevInput = this.ss.loadSearchInput();
|
||||||
this.singlePresetSelection[preset.preset_id] = false;
|
|
||||||
|
if (prevInput) {
|
||||||
|
this.from = prevInput.from;
|
||||||
|
this.to = prevInput.to;
|
||||||
|
this.singlePresetSelection = prevInput.singlePresetSelection;
|
||||||
|
this.multiPresetSelection = prevInput.multiPresetSelection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +69,14 @@ export class SearchInputComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ss.saveSearchInput({
|
||||||
|
from: this.from,
|
||||||
|
to: this.to,
|
||||||
|
singlePresetSelection: this.singlePresetSelection,
|
||||||
|
multiPresetSelection: this.multiPresetSelection
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
await this.router.navigate(['/search'], {queryParams: {q: objToBase64(query)}});
|
await this.router.navigate(['/search'], {queryParams: {q: objToBase64(query)}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {Result} from '../../interfaces/result.interface';
|
import {Result} from '../../interfaces/result.interface';
|
||||||
import {DataService} from '../../services/data.service';
|
import {SearchService} from '../../services/search.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-search',
|
selector: 'app-search',
|
||||||
@ -16,7 +16,7 @@ export class SearchComponent implements OnInit {
|
|||||||
@ViewChild('result', {static: false})
|
@ViewChild('result', {static: false})
|
||||||
resultDiv: ElementRef;
|
resultDiv: ElementRef;
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private ds: DataService, private router: Router) {
|
constructor(private route: ActivatedRoute, private ss: SearchService, private router: Router) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async ngOnInit() {
|
async ngOnInit() {
|
||||||
@ -29,7 +29,7 @@ export class SearchComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.results = await this.ds.searchRegions(this.queryString);
|
this.results = await this.ss.executeSearch(this.queryString);
|
||||||
this.resultDiv.nativeElement.scrollIntoView({behavior: 'smooth', block: 'start'});
|
this.resultDiv.nativeElement.scrollIntoView({behavior: 'smooth', block: 'start'});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,10 +8,10 @@ export interface Query {
|
|||||||
sun_hours?: number[];
|
sun_hours?: number[];
|
||||||
alcohol_costs?: number[];
|
alcohol_costs?: number[];
|
||||||
food_costs?: number[];
|
food_costs?: number[];
|
||||||
local_transportation_costs: number[];
|
local_transportation_costs?: number[];
|
||||||
entertainment_costs: number[];
|
entertainment_costs?: number[];
|
||||||
accommodation_costs: number[];
|
accommodation_costs?: number[];
|
||||||
average_per_day_costs: number[];
|
average_per_day_costs?: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum SearchParameter {
|
export enum SearchParameter {
|
||||||
|
|||||||
12
frontend/src/app/services/search.service.spec.ts
Normal file
12
frontend/src/app/services/search.service.spec.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {SearchService} from './search.service';
|
||||||
|
|
||||||
|
describe('SearchService', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const service: SearchService = TestBed.get(SearchService);
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
33
frontend/src/app/services/search.service.ts
Normal file
33
frontend/src/app/services/search.service.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {Injectable} from '@angular/core';
|
||||||
|
import {Result} from '../interfaces/result.interface';
|
||||||
|
import {DataService} from './data.service';
|
||||||
|
|
||||||
|
export interface SearchInput {
|
||||||
|
from: string;
|
||||||
|
to: string;
|
||||||
|
singlePresetSelection: object;
|
||||||
|
multiPresetSelection: object;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class SearchService {
|
||||||
|
|
||||||
|
private searchInput: SearchInput;
|
||||||
|
|
||||||
|
constructor(private ds: DataService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public executeSearch(query: string): Promise<Result[]> {
|
||||||
|
return this.ds.searchRegions(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
public saveSearchInput(input: SearchInput) {
|
||||||
|
this.searchInput = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public loadSearchInput(): SearchInput {
|
||||||
|
return this.searchInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user