argos/dmp-frontend/src/app/ui/project/listing/criteria/project-criteria.component.ts

59 lines
2.2 KiB
TypeScript
Raw Normal View History

2017-12-14 14:10:56 +01:00
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms';
2019-01-18 18:03:45 +01:00
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';
2018-03-28 15:24:47 +02:00
import { LanguageResolverService } from '../../../../services/language-resolver/language-resolver.service';
2019-01-18 18:03:45 +01:00
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
import { ErrorStateMatcher } from '@angular/material';
2017-12-14 14:10:56 +01:00
@Component({
2019-01-18 18:03:45 +01:00
selector: 'app-project-criteria-component',
templateUrl: './project-criteria.component.html',
styleUrls: ['./project-criteria.component.scss']
2017-12-14 14:10:56 +01:00
})
export class ProjectCriteriaComponent extends BaseCriteriaComponent implements OnInit, ErrorStateMatcher {
2017-12-14 14:10:56 +01:00
2018-08-24 17:21:02 +02:00
public ProjectStateType = ProjectStateType;
2017-12-14 14:10:56 +01:00
public criteria: ProjectCriteria = new ProjectCriteria();
constructor(
public language: TranslateService,
2018-03-28 15:24:47 +02:00
public formBuilder: FormBuilder,
public languageResolver: LanguageResolverService
2017-12-14 14:10:56 +01:00
) {
2019-01-18 18:03:45 +01:00
super(new ValidationErrorModel());
2017-12-14 14:10:56 +01:00
}
ngOnInit() {
super.ngOnInit();
if (this.criteria == null) {
this.criteria = new ProjectCriteria();
this.criteria.projectStateType = ProjectStateType.OnGoing;
}
2017-12-14 14:10:56 +01:00
}
setCriteria(criteria: ProjectCriteria): void {
this.criteria = criteria;
}
2017-12-18 14:45:36 +01:00
onCallbackError(error: any) {
this.setErrorModel(error.error);
2017-12-14 14:10:56 +01:00
}
2017-12-18 14:45:36 +01:00
controlModified(): void {
this.clearErrorModel();
if (this.refreshCallback != null &&
2018-10-05 17:00:54 +02:00
(this.criteria.like == null || this.criteria.like.length === 0 || this.criteria.like.length > 2)
2017-12-18 14:45:36 +01:00
) {
this.refreshCallback();
}
2017-12-14 14:10:56 +01:00
}
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));
}
}