1
|
import { TemplateFormComponent } from './../../forms/template-form/template-form.component';
|
2
|
import { TemplatesService } from 'src/app/shared/services/administration/templates.service';
|
3
|
import { EventEmitter, Input, Output, ViewChild } from '@angular/core';
|
4
|
import { Component, OnInit } from '@angular/core';
|
5
|
import { Template } from 'src/app/shared/models/template.interface';
|
6
|
import { Page } from '../../../../shared/models/paging/page.interface';
|
7
|
import { ErrorHandlingService } from 'src/app/shared/services/error-handling/error-handling.service';
|
8
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
9
|
import { AuthService } from 'src/app/shared/services/auth.service';
|
10
|
import { environment } from 'src/environments/environment';
|
11
|
|
12
|
@Component({
|
13
|
selector: 'app-templates-search',
|
14
|
templateUrl: './templates-search.component.html',
|
15
|
styleUrls: ['./templates-search.component.scss']
|
16
|
})
|
17
|
export class TemplatesSearchComponent implements OnInit {
|
18
|
|
19
|
@ViewChild(TemplateFormComponent) private templateForm: TemplateFormComponent;
|
20
|
|
21
|
@Input() set paginationEventRequest(value: { page: number, offset: number }) {
|
22
|
|
23
|
// This setter may be called on page setup without arguments.
|
24
|
if (!value) {
|
25
|
return;
|
26
|
}
|
27
|
this._value = Object.assign(value);
|
28
|
this.search(value.page, value.offset);
|
29
|
}
|
30
|
|
31
|
@Input() set valueTableChange(results: any) {
|
32
|
if (results) {
|
33
|
this.search(this._value.page,this._value.offset);
|
34
|
}
|
35
|
}
|
36
|
|
37
|
@Output() searchResults = new EventEmitter<Page<Template>>();
|
38
|
@Output() loading = new EventEmitter<boolean>();
|
39
|
@Output() searchInitiated = new EventEmitter<boolean>();
|
40
|
|
41
|
_value : {page: number , offset: number};
|
42
|
|
43
|
// Dictated by the expectations of our backend. TODO: Use interface.
|
44
|
lastSearchCriteria: {
|
45
|
docClassificationId: number;
|
46
|
clientId: string;
|
47
|
categoryName: string;
|
48
|
categoryCode: string;
|
49
|
abbyyTemplate: string;
|
50
|
};
|
51
|
|
52
|
constructor(
|
53
|
private templatesService: TemplatesService,
|
54
|
private authService: AuthService,
|
55
|
private errorHandlingService: ErrorHandlingService
|
56
|
) { }
|
57
|
|
58
|
ngOnInit(): void {
|
59
|
}
|
60
|
|
61
|
clear() {
|
62
|
this.templateForm.resetForm();
|
63
|
}
|
64
|
|
65
|
searchButtonClicked() {
|
66
|
|
67
|
this.searchInitiated.emit(true);
|
68
|
|
69
|
// Remember the search for future pagination/whatever requests.
|
70
|
let templateFormValue: Template = this.templateForm.formValue();
|
71
|
|
72
|
let docClassId = templateFormValue.documentClassification ? templateFormValue.documentClassification.classificationId : null;
|
73
|
let clientId = templateFormValue.client ? templateFormValue.client.id : ''
|
74
|
let catName = templateFormValue.category ? templateFormValue.category.categoryName : '';
|
75
|
let catCode = templateFormValue.category ? templateFormValue.category.categoryCode : '';
|
76
|
let abbyyTempCode = templateFormValue.abbyyTemplate;
|
77
|
|
78
|
this.lastSearchCriteria = {
|
79
|
docClassificationId: docClassId,
|
80
|
clientId: clientId as any,
|
81
|
categoryName: catName,
|
82
|
categoryCode: catCode,
|
83
|
abbyyTemplate: abbyyTempCode
|
84
|
}
|
85
|
|
86
|
// Then actually search.
|
87
|
this.search();
|
88
|
}
|
89
|
|
90
|
search(pageNumber = 0, pageSize = 10) {
|
91
|
this.loading.emit(true);
|
92
|
|
93
|
if (!this.lastSearchCriteria) {
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
this.templatesService.searchByCriteriaPaged(pageNumber, pageSize, this.lastSearchCriteria, 'search').subscribe(
|
98
|
(results: Page<Template>) => {
|
99
|
this.searchResults.emit(results);
|
100
|
this.loading.emit(false);
|
101
|
},
|
102
|
err => {
|
103
|
this.loading.emit(false);
|
104
|
this.errorHandlingService.showHttpResponseError(err);
|
105
|
});
|
106
|
}
|
107
|
|
108
|
canPreviewAllTemplates(): boolean {
|
109
|
return this.authService.userHasRightForClient(USER_RIGHTS.I01, environment.globalRightsClientID);
|
110
|
}
|
111
|
}
|