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