Revize 5849958b
Přidáno uživatelem Ondřej Váně před téměř 5 roky(ů)
fe/fulltextsearch/src/app/app.module.ts | ||
---|---|---|
28 | 28 |
import { LayoutModule } from '@angular/cdk/layout'; |
29 | 29 |
import { MatSidenavModule } from '@angular/material/sidenav'; |
30 | 30 |
import { MatListModule } from '@angular/material/list'; |
31 |
import { DatePipe } from '@angular/common'; |
|
31 | 32 |
|
32 | 33 |
@NgModule({ |
33 | 34 |
declarations: [ |
... | ... | |
62 | 63 |
MatSidenavModule, |
63 | 64 |
MatListModule |
64 | 65 |
], |
65 |
providers: [], |
|
66 |
providers: [DatePipe],
|
|
66 | 67 |
bootstrap: [AppComponent] |
67 | 68 |
}) |
68 | 69 |
export class AppModule { } |
fe/fulltextsearch/src/app/components/pages/browse/browse.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import {DocumentResponse} from '../../../model/DocumentResponse'; |
|
3 |
import {QueryService} from '../../../services/query.service'; |
|
2 |
import { DocumentResponse } from '../../../model/DocumentResponse'; |
|
3 |
import { QueryService } from '../../../services/query/query.service'; |
|
4 |
import { LoggerService } from '../../../services/logger/logger.service'; |
|
4 | 5 |
|
5 | 6 |
@Component({ |
6 | 7 |
selector: 'app-browse', |
... | ... | |
10 | 11 |
export class BrowseComponent implements OnInit { |
11 | 12 |
documents: DocumentResponse[] = null; |
12 | 13 |
|
13 |
constructor( private queryService: QueryService ) { } |
|
14 |
constructor( private queryService: QueryService, private LOGGER: LoggerService ) { }
|
|
14 | 15 |
|
15 | 16 |
ngOnInit(): void { |
17 |
this.LOGGER.info('browse component on init'); |
|
16 | 18 |
this.queryService.getDocuments().subscribe( documents => { |
17 | 19 |
this.documents = documents; |
18 | 20 |
}); |
fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts | ||
---|---|---|
4 | 4 |
import { MatTable } from '@angular/material/table'; |
5 | 5 |
import { TableDataSource } from './table-datasource'; |
6 | 6 |
import { DocumentResponse } from '../../../../model/DocumentResponse'; |
7 |
import {QueryService} from '../../../../services/query.service';
|
|
7 |
import { QueryService } from '../../../../services/query/query.service';
|
|
8 | 8 |
|
9 | 9 |
@Component({ |
10 | 10 |
selector: 'app-table-browse', |
fe/fulltextsearch/src/app/components/pages/help/help.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import { LoggerService } from '../../../services/logger/logger.service'; |
|
2 | 3 |
|
3 | 4 |
@Component({ |
4 | 5 |
selector: 'app-help', |
... | ... | |
7 | 8 |
}) |
8 | 9 |
export class HelpComponent implements OnInit { |
9 | 10 |
|
10 |
constructor() { } |
|
11 |
constructor( private LOGGER: LoggerService ) { }
|
|
11 | 12 |
|
12 | 13 |
ngOnInit(): void { |
14 |
this.LOGGER.info('help component on init'); |
|
13 | 15 |
} |
14 | 16 |
|
15 | 17 |
} |
fe/fulltextsearch/src/app/components/pages/home/home.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import { LoggerService } from '../../../services/logger/logger.service'; |
|
2 | 3 |
|
3 | 4 |
@Component({ |
4 | 5 |
selector: 'app-home', |
... | ... | |
7 | 8 |
}) |
8 | 9 |
export class HomeComponent implements OnInit { |
9 | 10 |
|
11 |
constructor( private LOGGER: LoggerService ) {} |
|
12 |
|
|
10 | 13 |
ngOnInit() { |
14 |
this.LOGGER.info('home component on init'); |
|
11 | 15 |
} |
12 | 16 |
|
13 | 17 |
} |
fe/fulltextsearch/src/app/components/pages/search/search.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import { LoggerService } from '../../../services/logger/logger.service'; |
|
2 | 3 |
|
3 | 4 |
@Component({ |
4 | 5 |
selector: 'app-search', |
... | ... | |
7 | 8 |
}) |
8 | 9 |
export class SearchComponent implements OnInit { |
9 | 10 |
|
10 |
constructor() { } |
|
11 |
constructor( private LOGGER: LoggerService ) { }
|
|
11 | 12 |
|
12 | 13 |
ngOnInit(): void { |
14 |
this.LOGGER.info('search component on init'); |
|
13 | 15 |
} |
14 | 16 |
|
15 | 17 |
} |
fe/fulltextsearch/src/app/components/pages/upload/upload.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 |
import {QueryService} from '../../../services/query.service';
|
|
3 |
import {HttpEventType} from '@angular/common/http';
|
|
2 |
import { QueryService } from '../../../services/query/query.service';
|
|
3 |
import { HttpEventType } from '@angular/common/http';
|
|
4 | 4 |
import Utils from '../../../../Utils'; |
5 |
import { LoggerService } from '../../../services/logger/logger.service'; |
|
5 | 6 |
|
6 | 7 |
@Component({ |
7 | 8 |
selector: 'app-upload', |
... | ... | |
13 | 14 |
resultMessage: string = null; |
14 | 15 |
progress = 0; |
15 | 16 |
|
16 |
constructor( private queryService: QueryService ) { } |
|
17 |
constructor( private queryService: QueryService, private LOGGER: LoggerService ) { }
|
|
17 | 18 |
|
18 | 19 |
ngOnInit(): void { |
20 |
this.LOGGER.info('upload component on init'); |
|
19 | 21 |
} |
20 | 22 |
|
21 | 23 |
onFilesSelected(event) { |
... | ... | |
25 | 27 |
} |
26 | 28 |
|
27 | 29 |
onUpload() { |
28 |
console.log(this.selectedFiles);
|
|
30 |
this.LOGGER.info('Selected files: ' + this.selectedFiles);
|
|
29 | 31 |
|
30 | 32 |
if (!this.checkFiles(this.selectedFiles)) { |
31 |
console.log('Files are not valid');
|
|
33 |
this.LOGGER.warn('Files are not valid');
|
|
32 | 34 |
return; |
33 | 35 |
} |
34 | 36 |
|
... | ... | |
38 | 40 |
} else if (event.type === HttpEventType.Response ) { |
39 | 41 |
this.resultMessage = 'Successfully uploaded ' + this.selectedFiles.length + ' files'; |
40 | 42 |
this.selectedFiles = null; |
43 |
this.LOGGER.info('Files successfully uploaded'); |
|
41 | 44 |
} |
42 | 45 |
}); |
43 | 46 |
} |
fe/fulltextsearch/src/app/components/shared-components/search-box/search-box.component.ts | ||
---|---|---|
1 | 1 |
import { Component, OnInit } from '@angular/core'; |
2 | 2 |
import { SearchRequest } from '../../../model/SearchRequest'; |
3 |
import { QueryService } from '../../../services/query.service'; |
|
3 |
import { QueryService } from '../../../services/query/query.service';
|
|
4 | 4 |
import { Router } from '@angular/router'; |
5 | 5 |
|
6 | 6 |
@Component({ |
fe/fulltextsearch/src/app/services/logger/logger.service.spec.ts | ||
---|---|---|
1 |
import { TestBed } from '@angular/core/testing'; |
|
2 |
|
|
3 |
import { LoggerService } from './logger.service'; |
|
4 |
|
|
5 |
describe('LoggerService', () => { |
|
6 |
let service: LoggerService; |
|
7 |
|
|
8 |
beforeEach(() => { |
|
9 |
TestBed.configureTestingModule({}); |
|
10 |
service = TestBed.inject(LoggerService); |
|
11 |
}); |
|
12 |
|
|
13 |
it('should be created', () => { |
|
14 |
expect(service).toBeTruthy(); |
|
15 |
}); |
|
16 |
}); |
fe/fulltextsearch/src/app/services/logger/logger.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { DatePipe } from '@angular/common'; |
|
3 |
|
|
4 |
@Injectable({ |
|
5 |
providedIn: 'root' |
|
6 |
}) |
|
7 |
export class LoggerService { |
|
8 |
|
|
9 |
// log config |
|
10 |
private dateFormat = 'yyyy-MM-dd HH:mm:ss.SSS'; |
|
11 |
private DEBUG = 'DEBUG'; |
|
12 |
private DEBUG_STYLE = 'color: '; |
|
13 |
private INFO = 'INFO'; |
|
14 |
private INFO_STYLE = 'color: #4CCF27'; |
|
15 |
private WARN = 'WARN'; |
|
16 |
private WARN_STYLE = 'color: #FAC837'; |
|
17 |
private ERROR = 'ERROR'; |
|
18 |
private ERROR_STYLE = 'color: #FA3737'; |
|
19 |
|
|
20 |
constructor(public datePipe: DatePipe) { |
|
21 |
} |
|
22 |
|
|
23 |
private log(message: any, logLevel, style) { |
|
24 |
console.log('%c' + this.getFormattedDate() + '\t\t' + logLevel + '\t' + JSON.stringify(message), style); |
|
25 |
} |
|
26 |
|
|
27 |
private getFormattedDate(): string { |
|
28 |
return this.datePipe.transform(new Date(), this.dateFormat); |
|
29 |
} |
|
30 |
|
|
31 |
info(message: any) { |
|
32 |
this.log(message, this.INFO, this.INFO_STYLE); |
|
33 |
} |
|
34 |
|
|
35 |
debug(message: any) { |
|
36 |
this.log(message, this.DEBUG, this.DEBUG_STYLE); |
|
37 |
} |
|
38 |
|
|
39 |
warn(message: any) { |
|
40 |
this.log(message, this.WARN, this.WARN_STYLE); |
|
41 |
} |
|
42 |
|
|
43 |
error(message: any) { |
|
44 |
this.log(message, this.ERROR, this.ERROR_STYLE); |
|
45 |
} |
|
46 |
} |
fe/fulltextsearch/src/app/services/query.service.spec.ts | ||
---|---|---|
1 |
import { TestBed } from '@angular/core/testing'; |
|
2 |
|
|
3 |
import { QueryService } from './query.service'; |
|
4 |
import {HttpClientModule} from '@angular/common/http'; |
|
5 |
|
|
6 |
describe('QueryService', () => { |
|
7 |
beforeEach(() => TestBed.configureTestingModule({ |
|
8 |
imports: [HttpClientModule] |
|
9 |
})); |
|
10 |
|
|
11 |
it('should be created', () => { |
|
12 |
const service: QueryService = TestBed.get(QueryService); |
|
13 |
expect(service).toBeTruthy(); |
|
14 |
}); |
|
15 |
}); |
fe/fulltextsearch/src/app/services/query.service.ts | ||
---|---|---|
1 |
import {Injectable} from '@angular/core'; |
|
2 |
import {HttpClient, HttpHeaders} from '@angular/common/http'; |
|
3 |
import {Observable} from 'rxjs'; |
|
4 |
import {DocumentResponse} from '../model/DocumentResponse'; |
|
5 |
import {SearchResponse} from '../model/SearchResponse'; |
|
6 |
import {SearchRequest} from '../model/SearchRequest'; |
|
7 |
|
|
8 |
const httpOptions = { |
|
9 |
headers: new HttpHeaders( { |
|
10 |
'Content-Type': 'application/json' |
|
11 |
}) |
|
12 |
}; |
|
13 |
|
|
14 |
@Injectable({ |
|
15 |
providedIn: 'root' |
|
16 |
}) |
|
17 |
export class QueryService { |
|
18 |
|
|
19 |
backendUrl = 'http://localhost:8080/'; |
|
20 |
uploadFileUrl = 'upload'; |
|
21 |
documentsUrl = 'documents'; |
|
22 |
|
|
23 |
constructor(private httpClient: HttpClient) {} |
|
24 |
|
|
25 |
searchPost(searchRequest: SearchRequest): Observable<SearchResponse> { |
|
26 |
return this.httpClient.post<SearchResponse>(this.backendUrl, searchRequest, httpOptions); |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
uploadFile(files: File[]): Observable<any> { |
|
31 |
const formDate = new FormData(); |
|
32 |
for (const file of files) { |
|
33 |
formDate.append('file', file); |
|
34 |
} |
|
35 |
return this.httpClient.post(this.backendUrl + this.uploadFileUrl, formDate, { |
|
36 |
reportProgress: true, |
|
37 |
observe: 'events' |
|
38 |
}); |
|
39 |
} |
|
40 |
|
|
41 |
getDocuments(): Observable<DocumentResponse[]> { |
|
42 |
return this.httpClient.get<DocumentResponse[]>(this.backendUrl + this.documentsUrl, httpOptions); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
} |
fe/fulltextsearch/src/app/services/query/query.service.spec.ts | ||
---|---|---|
1 |
import { TestBed } from '@angular/core/testing'; |
|
2 |
|
|
3 |
import { QueryService } from './query.service'; |
|
4 |
import { HttpClientModule } from '@angular/common/http'; |
|
5 |
|
|
6 |
describe('QueryService', () => { |
|
7 |
beforeEach(() => TestBed.configureTestingModule({ |
|
8 |
imports: [HttpClientModule] |
|
9 |
})); |
|
10 |
|
|
11 |
it('should be created', () => { |
|
12 |
const service: QueryService = TestBed.get(QueryService); |
|
13 |
expect(service).toBeTruthy(); |
|
14 |
}); |
|
15 |
}); |
fe/fulltextsearch/src/app/services/query/query.service.ts | ||
---|---|---|
1 |
import { Injectable } from '@angular/core'; |
|
2 |
import { HttpClient, HttpHeaders } from '@angular/common/http'; |
|
3 |
import { Observable } from 'rxjs'; |
|
4 |
import { DocumentResponse } from '../../model/DocumentResponse'; |
|
5 |
import { SearchResponse } from '../../model/SearchResponse'; |
|
6 |
import { SearchRequest } from '../../model/SearchRequest'; |
|
7 |
|
|
8 |
const httpOptions = { |
|
9 |
headers: new HttpHeaders( { |
|
10 |
'Content-Type': 'application/json' |
|
11 |
}) |
|
12 |
}; |
|
13 |
|
|
14 |
@Injectable({ |
|
15 |
providedIn: 'root' |
|
16 |
}) |
|
17 |
export class QueryService { |
|
18 |
|
|
19 |
backendUrl = 'http://localhost:8080/'; |
|
20 |
uploadFileUrl = 'upload'; |
|
21 |
documentsUrl = 'documents'; |
|
22 |
|
|
23 |
constructor(private httpClient: HttpClient) {} |
|
24 |
|
|
25 |
searchPost(searchRequest: SearchRequest): Observable<SearchResponse> { |
|
26 |
return this.httpClient.post<SearchResponse>(this.backendUrl, searchRequest, httpOptions); |
|
27 |
} |
|
28 |
|
|
29 |
|
|
30 |
uploadFile(files: File[]): Observable<any> { |
|
31 |
const formDate = new FormData(); |
|
32 |
for (const file of files) { |
|
33 |
formDate.append('file', file); |
|
34 |
} |
|
35 |
return this.httpClient.post(this.backendUrl + this.uploadFileUrl, formDate, { |
|
36 |
reportProgress: true, |
|
37 |
observe: 'events' |
|
38 |
}); |
|
39 |
} |
|
40 |
|
|
41 |
getDocuments(): Observable<DocumentResponse[]> { |
|
42 |
return this.httpClient.get<DocumentResponse[]>(this.backendUrl + this.documentsUrl, httpOptions); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
} |
Také k dispozici: Unified diff
Re #7816: Logování ve FE
- přidána service pro logování
- implementovány log levely: INFO, WARN, DEBUG, ERROR
- návod na wiki v záložce Nástroje -> logování FE