1
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
2
|
import { SearchRequest } from '../../../model/SearchRequest';
|
3
|
import { QueryService } from '../../../services/query/query.service';
|
4
|
import { Router } from '@angular/router';
|
5
|
import { DataHolderService } from '../../../services/data-holder/data-holder.service';
|
6
|
import { Subscription } from 'rxjs';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'app-search-box',
|
10
|
templateUrl: './search-box.component.html',
|
11
|
styleUrls: ['./search-box.component.css']
|
12
|
})
|
13
|
export class SearchBoxComponent implements OnInit, OnDestroy {
|
14
|
enableSpellCheck: boolean;
|
15
|
expression: string;
|
16
|
private queryServiceSubscription$: Subscription;
|
17
|
|
18
|
constructor(private queryService: QueryService, private router: Router, private dataHolderService: DataHolderService) { }
|
19
|
|
20
|
ngOnInit(): void {
|
21
|
this.enableSpellCheck = false;
|
22
|
}
|
23
|
|
24
|
onToggle() {
|
25
|
this.enableSpellCheck = !this.enableSpellCheck;
|
26
|
console.log('kontrola spell check: ' + this.enableSpellCheck);
|
27
|
}
|
28
|
|
29
|
onSubmit(): void {
|
30
|
if (!this.expression) { return; }
|
31
|
|
32
|
const searchRequest: SearchRequest = new SearchRequest(this.expression, new Date(), this.enableSpellCheck);
|
33
|
|
34
|
this.queryServiceSubscription$ = this.queryService.searchPost(searchRequest).subscribe (data => {
|
35
|
this.dataHolderService.setData(data);
|
36
|
if (this.router.url === '/') {
|
37
|
this.router.navigate(['/search']);
|
38
|
}
|
39
|
});
|
40
|
}
|
41
|
|
42
|
ngOnDestroy(): void {
|
43
|
if (this.queryServiceSubscription$ !== undefined) {
|
44
|
this.queryServiceSubscription$.unsubscribe();
|
45
|
}
|
46
|
}
|
47
|
}
|