You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
argos/dmp-frontend/src/app/ui/grant/listing/criteria/grant-criteria.component.ts

58 lines
2.0 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 { GrantStateType } from '../../../../core/common/enum/grant-state-type';
import { GrantCriteria } from '../../../../core/query/grant/grant-criteria';
import { BaseCriteriaComponent } from '../../../misc/criteria/base-criteria.component';
import { ErrorStateMatcher } from '@angular/material/core';
@Component({
selector: 'app-grant-criteria-component',
templateUrl: './grant-criteria.component.html',
styleUrls: ['./grant-criteria.component.scss']
})
export class GrantCriteriaComponent extends BaseCriteriaComponent implements OnInit, ErrorStateMatcher {
public GrantStateType = GrantStateType;
public criteria: GrantCriteria = new GrantCriteria();
constructor(
public language: TranslateService,
public formBuilder: FormBuilder
) {
super(new ValidationErrorModel());
}
ngOnInit() {
super.ngOnInit();
if (this.criteria == null) {
this.criteria = new GrantCriteria();
this.criteria.grantStateType = GrantStateType.OnGoing;
}
}
setCriteria(criteria: GrantCriteria): 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)
) {
setTimeout(() => this.refreshCallback(true));
}
}
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));
}
}