2017-12-14 14:10:56 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-01-24 16:30:23 +01:00
|
|
|
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';
|
2019-08-01 09:54:40 +02:00
|
|
|
import { GrantStateType } from '../../../../core/common/enum/grant-state-type';
|
|
|
|
import { GrantCriteria } from '../../../../core/query/grant/grant-criteria';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { ErrorStateMatcher } from '@angular/material/core';
|
2017-12-14 14:10:56 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-08-01 09:54:40 +02:00
|
|
|
selector: 'app-grant-criteria-component',
|
|
|
|
templateUrl: './grant-criteria.component.html',
|
|
|
|
styleUrls: ['./grant-criteria.component.scss']
|
2017-12-14 14:10:56 +01:00
|
|
|
})
|
2019-08-01 09:54:40 +02:00
|
|
|
export class GrantCriteriaComponent extends BaseCriteriaComponent implements OnInit, ErrorStateMatcher {
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
public GrantStateType = GrantStateType;
|
|
|
|
public criteria: GrantCriteria = new GrantCriteria();
|
2017-12-14 14:10:56 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
public language: TranslateService,
|
2019-09-06 12:00:01 +02:00
|
|
|
public formBuilder: FormBuilder
|
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();
|
2019-05-17 15:29:00 +02:00
|
|
|
if (this.criteria == null) {
|
2019-08-01 09:54:40 +02:00
|
|
|
this.criteria = new GrantCriteria();
|
|
|
|
this.criteria.grantStateType = GrantStateType.OnGoing;
|
2019-03-06 15:19:08 +01:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
setCriteria(criteria: GrantCriteria): void {
|
2017-12-14 14:10:56 +01:00
|
|
|
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
|
|
|
) {
|
2019-05-17 15:29:00 +02:00
|
|
|
setTimeout(() => this.refreshCallback(true));
|
2017-12-18 14:45:36 +01:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
}
|
2019-05-17 15:29:00 +02:00
|
|
|
|
2019-01-24 16:30:23 +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));
|
|
|
|
}
|
2019-05-17 15:29:00 +02:00
|
|
|
}
|