1
|
import { AuthService } from './../../../../shared/services/auth.service';
|
2
|
import { TemplatesService } from 'src/app/shared/services/administration/templates.service';
|
3
|
import { Template } from './../../../../shared/models/template.interface';
|
4
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
5
|
import { ConfirmationService, LazyLoadEvent } from 'primeng/api';
|
6
|
import { Page } from '../../../../shared/models/paging/page.interface';
|
7
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
8
|
import { environment } from 'src/environments/environment';
|
9
|
import { TranslateService } from '@ngx-translate/core';
|
10
|
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
|
11
|
|
12
|
@Component({
|
13
|
selector: 'app-templates-search-results',
|
14
|
templateUrl: './templates-search-results.component.html',
|
15
|
styleUrls: ['./templates-search-results.component.scss']
|
16
|
})
|
17
|
export class TemplatesSearchResultsComponent implements OnInit {
|
18
|
|
19
|
@Output() paginationEvent = new EventEmitter<{ page: number, offset: number }>(); // TODO: Use interface.
|
20
|
@Output() valueChange = new EventEmitter<any>();
|
21
|
@Input() loading: boolean;
|
22
|
@Input() set searchResultsPage(results: Page<Template>) {
|
23
|
|
24
|
// This setter may be called on page setup without arguments.
|
25
|
if (!results) {
|
26
|
return;
|
27
|
}
|
28
|
|
29
|
this._searchResultsPage = results;
|
30
|
this.totalRecords = results.totalElements;
|
31
|
}
|
32
|
|
33
|
_searchResultsPage: Page<Template>;
|
34
|
totalRecords: number;
|
35
|
rows: number = 10;
|
36
|
header: string;
|
37
|
|
38
|
displayEditTemplateDialog: boolean;
|
39
|
templateToEdit: Template;
|
40
|
|
41
|
constructor(
|
42
|
private templatesService: TemplatesService,
|
43
|
private authService: AuthService,
|
44
|
private translate: TranslateService,
|
45
|
private confirmationService: ConfirmationService,
|
46
|
private notificationHandling: NotificationsHandlingService
|
47
|
) { }
|
48
|
|
49
|
ngOnInit(): void {
|
50
|
}
|
51
|
|
52
|
onLazyLoad(event: LazyLoadEvent) {
|
53
|
let pageToRequest = Math.floor(event.first / event.rows);
|
54
|
let pageSize = event.rows;
|
55
|
|
56
|
this.paginationEvent.emit({ page: pageToRequest, offset: pageSize });
|
57
|
}
|
58
|
|
59
|
edit(template: Template) {
|
60
|
this.header = this.translate.instant('EDIT-TEMPLATE');
|
61
|
this.templateToEdit = template;
|
62
|
this.displayEditTemplateDialog = true;
|
63
|
}
|
64
|
|
65
|
cancelEditTemplate() {
|
66
|
this.displayEditTemplateDialog = false;
|
67
|
this.templateToEdit = null;
|
68
|
}
|
69
|
|
70
|
delete(template: Template): void {
|
71
|
this.confirmationService.confirm({
|
72
|
accept: () => {
|
73
|
this.templatesService.delete(template.id).subscribe((success) => {
|
74
|
this.valueChange.emit(success);
|
75
|
this.notificationHandling.showDeleteTemplateSuccess();
|
76
|
},
|
77
|
|
78
|
(error) => console.error(error)
|
79
|
);
|
80
|
// Actual logic to perform a confirmation
|
81
|
}, reject: () => {
|
82
|
|
83
|
}
|
84
|
});
|
85
|
}
|
86
|
|
87
|
/*
|
88
|
* UserRights-check Methods
|
89
|
*/
|
90
|
canEditTemplates(): boolean {
|
91
|
return this.authService.userHasRightForClient(USER_RIGHTS.I03, environment.globalRightsClientID);
|
92
|
}
|
93
|
|
94
|
canDeleteTemplates(): boolean {
|
95
|
return this.authService.userHasRightForClient(USER_RIGHTS.I04, environment.globalRightsClientID);
|
96
|
}
|
97
|
|
98
|
passEvent(passEvent : any) {
|
99
|
if(passEvent){
|
100
|
this.valueChange.emit(passEvent);
|
101
|
}
|
102
|
}
|
103
|
}
|