104 lines
3.5 KiB
TypeScript
104 lines
3.5 KiB
TypeScript
import { AuthService } from './../../../../shared/services/auth.service';
|
|
import { environment } from './../../../../../environments/environment.prod';
|
|
import { ErrorHandlingService } from './../../../../shared/services/error-handling/error-handling.service';
|
|
import { CategoriesService } from 'src/app/shared/services/administration/categories.service';
|
|
import { Category } from './../../../../shared/models/category.interface';
|
|
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
|
|
import { ConfirmationService, LazyLoadEvent } from 'primeng/api';
|
|
import { Page } from '../../../../shared/models/paging/page.interface';
|
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
|
|
|
|
@Component({
|
|
selector: 'app-categories-search-results',
|
|
templateUrl: './categories-search-results.component.html',
|
|
styleUrls: ['./categories-search-results.component.scss']
|
|
})
|
|
export class CategoriesSearchResultsComponent implements OnInit {
|
|
|
|
@Output() paginationEvent = new EventEmitter<{ page: number, offset: number }>(); // TODO: Use interface.
|
|
@Output() valueChange = new EventEmitter<any>();
|
|
@Input() loading: boolean;
|
|
@Input() set searchResultsPage(results: Page<Category>) {
|
|
|
|
// This setter may be called on page setup without arguments.
|
|
if (!results) {
|
|
return;
|
|
}
|
|
|
|
this._searchResultsPage = results;
|
|
this.totalRecords = results.totalElements;
|
|
}
|
|
|
|
_searchResultsPage: Page<Category>;
|
|
totalRecords: number;
|
|
rows: number = 10;
|
|
header: string;
|
|
|
|
displayEditCategoryDialog: boolean;
|
|
categoryToEdit: Category;
|
|
|
|
constructor(
|
|
private categoriesService: CategoriesService,
|
|
private errorHandlingService: ErrorHandlingService,
|
|
private authService: AuthService,
|
|
private translate: TranslateService,
|
|
private confirmationService: ConfirmationService,
|
|
private notifications: NotificationsHandlingService
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
onLazyLoad(event: LazyLoadEvent) {
|
|
let pageToRequest = Math.floor(event.first / event.rows);
|
|
let pageSize = event.rows;
|
|
this.paginationEvent.emit({ page: pageToRequest, offset: pageSize });
|
|
}
|
|
|
|
edit(category: Category) {
|
|
this.header = this.translate.instant('EDIT-CATEGORY');
|
|
this.categoryToEdit = category;
|
|
this.displayEditCategoryDialog = true;
|
|
}
|
|
|
|
cancelEditCategory() {
|
|
this.displayEditCategoryDialog = false;
|
|
this.categoryToEdit = null;
|
|
}
|
|
|
|
delete(category: Category): void {
|
|
this.confirmationService.confirm({
|
|
accept: () => {
|
|
this.categoriesService.delete(category.id).subscribe((success) => {
|
|
this.valueChange.emit(success);
|
|
this.notifications.showDeleteCategorySuccess();
|
|
},
|
|
err => this.errorHandlingService.showHttpResponseError(err)
|
|
);
|
|
// Actual logic to perform a confirmation
|
|
}, reject: () => {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
/*
|
|
* UserRights-check Methods
|
|
*/
|
|
canEditCategories(): boolean {
|
|
return this.authService.userHasRightForClient(USER_RIGHTS.H03, environment.globalRightsClientID);
|
|
}
|
|
|
|
canDeleteCategories(): boolean {
|
|
return this.authService.userHasRightForClient(USER_RIGHTS.H04, environment.globalRightsClientID);
|
|
}
|
|
|
|
passEvent(passEvent : any) {
|
|
if(passEvent){
|
|
this.valueChange.emit(passEvent);
|
|
}
|
|
}
|
|
}
|