Fix preset loading

This commit is contained in:
Patrick Gebhardt 2020-06-18 00:52:27 +02:00
parent 25f653008a
commit e706a2633e
4 changed files with 22 additions and 22 deletions

View File

@ -1,5 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {PresetService} from './services/preset.service';
@Component({
selector: 'app-root',
@ -8,10 +7,10 @@ import {PresetService} from './services/preset.service';
})
export class AppComponent implements OnInit {
constructor(private ps: PresetService) {
constructor() {
}
ngOnInit(): void {
this.ps.initialize().catch(e => console.log(e));
}
}

View File

@ -24,26 +24,27 @@ export class SearchInputComponent implements OnInit {
multiPresetSelection = {};
constructor(private router: Router, private ps: PresetService) {
this.presets = ps.presets;
this.singlePresets = ps.singlePresets;
this.multiPresets = ps.multiPresets;
this.multiPresetsKeys = [...ps.multiPresets.keys()];
const from = new Date();
const to = new Date();
to.setDate(from.getDate() + 7);
this.from = formatDate(from, 'yyyy-MM-dd', 'en-GB');
this.to = formatDate(to, 'yyyy-MM-dd', 'en-GB');
}
async ngOnInit() {
await this.ps.initialize();
this.presets = this.ps.presets;
this.singlePresets = this.ps.singlePresets;
this.multiPresets = this.ps.multiPresets;
this.multiPresetsKeys = [...this.multiPresets.keys()];
for (const preset of this.singlePresets) {
this.singlePresetSelection[preset.preset_id] = false;
}
}
ngOnInit() {
}
async onSearch() {
const query: Query = {
from: new Date(this.from).getTime(),

View File

@ -1,7 +1,7 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {Result} from '../../interfaces/result.interface';
import {MOCK_RESULT} from '../../mock/mock-data';
import {DataService} from '../../services/data.service';
@Component({
selector: 'app-search',
@ -16,19 +16,15 @@ export class SearchComponent implements OnInit {
@ViewChild('result', {static: false})
resultDiv: ElementRef;
constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute, private ds: DataService) {
}
ngOnInit() {
this.route.queryParams.subscribe(params => {
async ngOnInit() {
this.route.queryParams.subscribe(async params => {
this.queryString = params.q;
});
// Mock results
setTimeout(() => {
this.results = MOCK_RESULT;
this.results = undefined;
this.results = await this.ds.searchRegions(this.queryString);
this.resultDiv.nativeElement.scrollIntoView({behavior: 'smooth', block: 'start'});
}, 1000);
});
}
}

View File

@ -15,6 +15,10 @@ export class PresetService {
}
async initialize() {
if (this.presets) {
return;
}
this.presets = await this.ds.getAllPresets();
const presetMap = new Map<string, Preset[]>();