59 lines
2.2 KiB
TypeScript
59 lines
2.2 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import { ValidationErrorModel } from '../../../../common/forms/validation/error-model/validation-error-model';
|
|
import { ProjectStateType } from '../../../../core/common/enum/project-state-type';
|
|
import { ProjectCriteria } from '../../../../core/query/project/project-criteria';
|
|
import { LanguageResolverService } from '../../../../services/language-resolver/language-resolver.service';
|
|
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
|
|
import { ErrorStateMatcher } from '@angular/material';
|
|
|
|
@Component({
|
|
selector: 'app-project-criteria-component',
|
|
templateUrl: './project-criteria.component.html',
|
|
styleUrls: ['./project-criteria.component.scss']
|
|
})
|
|
export class ProjectCriteriaComponent extends BaseCriteriaComponent implements OnInit, ErrorStateMatcher {
|
|
|
|
public ProjectStateType = ProjectStateType;
|
|
public criteria: ProjectCriteria = new ProjectCriteria();
|
|
|
|
constructor(
|
|
public language: TranslateService,
|
|
public formBuilder: FormBuilder,
|
|
public languageResolver: LanguageResolverService
|
|
) {
|
|
super(new ValidationErrorModel());
|
|
}
|
|
|
|
ngOnInit() {
|
|
super.ngOnInit();
|
|
if (this.criteria == null) {
|
|
this.criteria = new ProjectCriteria();
|
|
this.criteria.projectStateType = ProjectStateType.OnGoing;
|
|
}
|
|
}
|
|
|
|
setCriteria(criteria: ProjectCriteria): void {
|
|
this.criteria = criteria;
|
|
}
|
|
|
|
onCallbackError(error: any) {
|
|
this.setErrorModel(error.error);
|
|
}
|
|
|
|
controlModified(): void {
|
|
this.clearErrorModel();
|
|
if (this.refreshCallback != null &&
|
|
(this.criteria.like == null || this.criteria.like.length === 0 || this.criteria.like.length > 2)
|
|
) {
|
|
this.refreshCallback();
|
|
}
|
|
}
|
|
|
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
|
|
const isSubmitted = form && form.submitted;
|
|
const isDateInvalid = this.criteria.periodStart != null && this.criteria.periodEnd != null && this.criteria.periodStart > this.criteria.periodEnd
|
|
return !!(control && isDateInvalid && (control.dirty || control.touched || isSubmitted));
|
|
}
|
|
} |