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

View File

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

View File

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

View File

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