102 lines
3.8 KiB
TypeScript
102 lines
3.8 KiB
TypeScript
import { environment } from './../../../../../environments/environment.prod';
|
|
import { ErrorHandlingService } from './../../../../shared/services/error-handling/error-handling.service';
|
|
import { AuthService } from 'src/app/shared/services/auth.service';
|
|
import { CategoryFormComponent } from './../../forms/category-form/category-form.component';
|
|
import { Category } from './../../../../shared/models/category.interface';
|
|
import { DocumentClassificationsService } from './../../../../shared/services/administration/document-classifications.service';
|
|
import { Component, OnInit, Output, EventEmitter, Input, ViewChild } from '@angular/core';
|
|
import { FormBuilder } from '@angular/forms';
|
|
import { CategoriesService } from 'src/app/shared/services/administration/categories.service';
|
|
import { DocumentClassification } from 'src/app/shared/models/document-classification.interface';
|
|
import { Page } from '../../../../shared/models/paging/page.interface';
|
|
import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum';
|
|
|
|
@Component({
|
|
selector: 'app-categories-search',
|
|
templateUrl: './categories-search.component.html',
|
|
styleUrls: ['./categories-search.component.scss']
|
|
})
|
|
export class CategoriesSearchComponent implements OnInit {
|
|
|
|
@Input() set paginationEventRequest(value: { page: number, offset: number }) {
|
|
|
|
// This setter may be called on page setup without arguments.
|
|
if (!value) {
|
|
return;
|
|
}
|
|
this._value = Object.assign(value);
|
|
this.search(value.page, value.offset);
|
|
}
|
|
|
|
@Input() set valueTableChange(results: any) {
|
|
if (results) {
|
|
this.search(this._value.page, this._value.offset);
|
|
}
|
|
}
|
|
|
|
@Output() searchResults = new EventEmitter<Page<Category>>();
|
|
@Output() loading = new EventEmitter<boolean>();
|
|
@Output() searchInitiated = new EventEmitter<boolean>();
|
|
@Input() passChange: any;
|
|
|
|
@ViewChild(CategoryFormComponent)
|
|
private categoryForm: CategoryFormComponent;
|
|
_value: { page: number, offset: number };
|
|
lastSearchCriteria: { docClassificationId: number | string, categoryName: string, categoryCode: string };
|
|
|
|
constructor(
|
|
private categoriesService: CategoriesService,
|
|
private authService: AuthService,
|
|
private errorHandlingService: ErrorHandlingService
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
}
|
|
|
|
clear() {
|
|
this.categoryForm.resetForm();
|
|
}
|
|
|
|
searchButtonClicked() {
|
|
|
|
// Inform anyone interested there is a new search underway.
|
|
this.searchInitiated.emit(true);
|
|
|
|
// Remember the search for future pagination/whatever requests.
|
|
let categoryFormValue = this.categoryForm.formValue();
|
|
let docClassId = categoryFormValue.documentClassification ? categoryFormValue.documentClassification.classificationId : null;
|
|
let catName = categoryFormValue.categoryName;
|
|
let catCode = categoryFormValue.categoryCode;
|
|
|
|
this.lastSearchCriteria = {
|
|
docClassificationId: docClassId ? docClassId : '',
|
|
categoryName: catName ? catName : '',
|
|
categoryCode: catCode ? catCode : ''
|
|
};
|
|
|
|
// Then actually search.
|
|
this.search();
|
|
}
|
|
|
|
search(pageNumber = 0, pageSize = 10) {
|
|
this.loading.emit(true);
|
|
|
|
// A search may be issued by the paginationEventRequest setter upon setting up the page.
|
|
if (!this.lastSearchCriteria) {
|
|
return;
|
|
}
|
|
|
|
this.categoriesService.searchByCriteriaPaged(pageNumber, pageSize, this.lastSearchCriteria, 'search').subscribe((results: Page<Category>) => {
|
|
this.searchResults.emit(results);
|
|
this.loading.emit(false);
|
|
},err => {
|
|
this.loading.emit(false);
|
|
this.errorHandlingService.showHttpResponseError(err);
|
|
});
|
|
}
|
|
|
|
canPreviewAllCategories(): boolean {
|
|
return this.authService.userHasRightForClient(USER_RIGHTS.H01, environment.globalRightsClientID);
|
|
}
|
|
}
|