This commit is contained in:
annampak 2017-12-18 16:28:24 +02:00
commit 58ab138fe0
13 changed files with 53 additions and 149 deletions

View File

@ -97,7 +97,7 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest(startIndex, this._paginator.pageSize);
request.criteria = this._criteria.getFormData();
request.criteria = this._criteria.criteria;
return this._service.getPaged(request);
})
.catch((error: any) => {
@ -106,7 +106,7 @@ export class DatasetDataSource extends DataSource<DatasetListingModel> {
duration: 3000,
extraClasses: ['snackbar-warning']
});
this._criteria.onCallbackError(error);
//this._criteria.criteria.onCallbackError(error);
return Observable.of(null);
})
.map(result => {

View File

@ -42,11 +42,7 @@ export class DataManagementPlanListingComponent implements OnInit, AfterViewInit
}
ngAfterViewInit() {
setTimeout(() => {
this.criteria.setRefreshCallback(() => this.refresh());
this.criteria.setCriteria(this.getDefaultCriteria());
this.criteria.controlModified();
});
this.criteria.setRefreshCallback(() => this.refresh());
}
refresh() {
@ -61,19 +57,6 @@ export class DataManagementPlanListingComponent implements OnInit, AfterViewInit
const defaultCriteria = new DataManagementPlanCriteria();
return defaultCriteria;
}
// canShowOwner(): boolean {
// const principal: Principal = this.authentication.current();
// if (principal) {
// const principalRoles = principal.appRoles;
// for (let i = 0; i < principalRoles.length; i++) {
// if (principalRoles[i] === Principal.AppRole.Admin || principalRoles[i] === Principal.AppRole.BudgetManager) {
// return true;
// }
// }
// }
// return false;
// }
}
export class DataManagementPlanDataSource extends DataSource<DataManagementPlanListingModel> {
@ -115,7 +98,7 @@ export class DataManagementPlanDataSource extends DataSource<DataManagementPlanL
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest(startIndex, this._paginator.pageSize);
request.criteria = this._criteria.getFormData();
request.criteria = this._criteria.criteria;
return this._service.getPaged(request);
})
.catch((error: any) => {
@ -124,7 +107,7 @@ export class DataManagementPlanDataSource extends DataSource<DataManagementPlanL
duration: 3000,
extraClasses: ['snackbar-warning']
});
this._criteria.onCallbackError(error);
//this._criteria.onCallbackError(error);
return Observable.of(null);
})
.map(result => {

View File

@ -1,3 +1,6 @@
import { FormGenerator } from "../../utilities/forms/FormGenerator";
import { BaseCriteriaErrorModel } from "./BaseCriteriaErrorModel";
export class BaseCriteria {
public Like: string;
public like: string;
}

View File

@ -1,3 +1,3 @@
export class BaseCriteriaErrorModel {
public Like: String;
public like: String;
}

View File

@ -1,6 +1,6 @@
import { BaseCriteria } from "../BaseCriteria";
export class ProjectCriteria extends BaseCriteria {
public PeriodStart: Date;
public PeriodEnd: Date;
public periodStart: Date;
public periodEnd: Date;
}

View File

@ -20,7 +20,7 @@ import { SnackBarNotificationComponent } from "../shared/components/notificaiton
providers: [ProjectService],
encapsulation: ViewEncapsulation.None
})
export class ProjectListingComponent implements OnInit, AfterViewInit {
export class ProjectListingComponent implements OnInit {
@ViewChild(MatPaginator) _paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
@ -39,19 +39,13 @@ export class ProjectListingComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
}
ngAfterViewInit() {
setTimeout(() => {
this.criteria.setRefreshCallback(() => this.refresh());
this.criteria.setCriteria(this.getDefaultCriteria());
this.criteria.controlModified();
});
this.criteria.setCriteria(this.getDefaultCriteria());
this.refresh();
this.criteria.setRefreshCallback(() => this.refresh());
}
refresh() {
this.dataSource = new ProjectDataSource(this.projectService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, );
this.dataSource = new ProjectDataSource(this.projectService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria );
}
rowClick(rowId: String) {
@ -116,7 +110,7 @@ export class ProjectDataSource extends DataSource<ProjectListingModel> {
});
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
const request = new DataTableRequest(startIndex, this._paginator.pageSize);
request.criteria = this._criteria.getFormData();
request.criteria = this._criteria.criteria;
return this._service.getPaged(request);
})
.catch((error: any) => {

View File

@ -90,7 +90,7 @@ export class AutocompleteComponent implements OnInit {
inputOnChange(term: string) {
//this.form.patchValue({ value: null, description: '', text: '' });
//this.form.updateValueAndValidity();
this.configuration.criteria.Like = term;
this.configuration.criteria.like = term;
this.configuration.callback(this.configuration.criteria)
.map((res: any) => this.mapper(res))
.subscribe(

View File

@ -13,7 +13,6 @@ import { BaseCriteriaErrorModel } from '../../../../models/criteria/BaseCriteria
export class BaseCriteriaComponent implements OnInit {
public refreshCallback: Function = null;
public formGroup: FormGroup = null;
public errorModel: BaseCriteriaErrorModel = new BaseCriteriaErrorModel();
constructor(errorModel: BaseCriteriaErrorModel) {
@ -23,69 +22,10 @@ export class BaseCriteriaComponent implements OnInit {
ngOnInit() {
}
controlModified(): void {
this.clearErrorModel();
if (!this.isFormValid()) { return; }
if (this.refreshCallback != null) { this.refreshCallback(); }
}
public isFormValid(): boolean {
this.touchAllFormFields(this.formGroup);
this.validateAllFormFields(this.formGroup);
return this.formGroup.valid;
}
public getFormData(): any {
return this.formGroup.value;
}
public getFormControl(controlName: string): AbstractControl {
return this.formGroup.get(controlName);
}
public disableFormFields(formControl: AbstractControl) {
formControl.disable();
}
public validateAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.updateValueAndValidity({ emitEvent: false })
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.validateAllFormFields(control);
})
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.validateAllFormFields(item);
})
}
}
public touchAllFormFields(formControl: AbstractControl) {
if (formControl instanceof FormControl) {
formControl.markAsTouched();
} else if (formControl instanceof FormGroup) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
this.touchAllFormFields(control);
})
} else if (formControl instanceof FormArray) {
formControl.controls.forEach(item => {
this.touchAllFormFields(item);
})
}
}
setRefreshCallback(callback: Function): void {
this.refreshCallback = callback;
}
onCallbackError(error: any) {
this.setErrorModel(error.error);
this.validateAllFormFields(this.formGroup);
}
public setErrorModel(errorModel: BaseCriteriaErrorModel) {
Object.keys(errorModel).forEach(item => {
(<any>this.errorModel)[item] = (<any>errorModel)[item];

View File

@ -31,12 +31,10 @@ export class DataManagementPlanCriteriaComponent extends BaseCriteriaComponent i
ngOnInit() {
super.ngOnInit();
if (this.criteria == null) { this.criteria = new DataManagementPlanCriteria(); }
if (this.formGroup == null) { this.formGroup = this.buildForm(); }
}
setCriteria(criteria: DataManagementPlanCriteria): void {
this.criteria = criteria;
this.formGroup = this.buildForm();
}
public fromJSONObject(item: any): DataManagementPlanCriteria {

View File

@ -1,34 +1,31 @@
<form class="form-criteria">
<div class="project-criteria">
<mat-card class="mat-card">
<div class="row">
<div class="col-sm-6 col-md-2">
<div class="col-md-4">
<mat-form-field>
<input matInput
(focus)="periodStartPicker.open()"
(click)="periodStartPicker.open()"
placeholder=" {{'CRITERIA.FORMS.PERIOD-FROM'| translate}}"
[matDatepicker]="periodStartPicker"
name="projectCriteriaPeriodStart"
[ngModel]="this.criteria.PeriodStart" (ngModelChange)="controlModified()">
<mat-error *ngIf="getFormControl('periodStart').errors?.backendError">{{baseErrorModel['Criteria.PeriodStart']}}</mat-error>
<input matInput placeholder=" {{'CRITERIA.PROJECTS.LIKE'| translate}}" name="projectCriteriaLike" [(ngModel)]="criteria.like"
(ngModelChange)="controlModified()">
<mat-error *ngIf="baseErrorModel?.like">{{baseErrorModel['Criteria.like']}}</mat-error>
</mat-form-field>
</div>
<div class="col-md-4">
<mat-form-field>
<input matInput (focus)="periodStartPicker.open()" (click)="periodStartPicker.open()" placeholder=" {{'CRITERIA.PROJECTS.PERIOD-FROM'| translate}}"
[matDatepicker]="periodStartPicker" name="projectCriteriaPeriodStart" [(ngModel)]="criteria.periodStart" (ngModelChange)="controlModified()">
<mat-error *ngIf="baseErrorModel?.periodStart">{{baseErrorModel['Criteria.periodStart']}}</mat-error>
<mat-datepicker-toggle matSuffix [for]="periodStartPicker"></mat-datepicker-toggle>
<mat-datepicker #periodStartPicker></mat-datepicker>
</mat-form-field>
</div>
<div class="col-sm-6 col-md-2">
<div class="col-md-4">
<mat-form-field>
<input matInput
(focus)="periodEndPicker.open()"
(click)="periodEndPicker.open()"
name="projectCriteriaPeriodEnd"
placeholder=" {{'CRITERIA.FORMS.PERIOD-TO'| translate}}"
[matDatepicker]="periodEndPicker"
[ngModel]="this.criteria.PeriodEnd" (ngModelChange)="controlModified()">
<mat-error *ngIf="getFormControl('periodEnd').errors?.backendError">{{baseErrorModel['Criteria.PeriodEnd']}}</mat-error>
<input matInput (focus)="periodEndPicker.open()" (click)="periodEndPicker.open()" name="projectCriteriaPeriodEnd" placeholder=" {{'CRITERIA.PROJECTS.PERIOD-TO'| translate}}"
[matDatepicker]="periodEndPicker" [(ngModel)]="criteria.periodEnd" (ngModelChange)="controlModified()">
<mat-error *ngIf="baseErrorModel?.periodEnd">{{baseErrorModel['Criteria.periodEnd']}}</mat-error>
<mat-datepicker-toggle matSuffix [for]="periodEndPicker"></mat-datepicker-toggle>
<mat-datepicker #periodEndPicker></mat-datepicker>
</mat-form-field>
</div>
</div>
</mat-card>
</form>
</div>

View File

@ -1,4 +1,4 @@
.form-criteria {
.project-criteria {
mat-form-field {
padding-bottom: 5px;
width: 100%;

View File

@ -31,38 +31,22 @@ export class ProjectCriteriaComponent extends BaseCriteriaComponent implements O
ngOnInit() {
super.ngOnInit();
if (this.criteria == null) { this.criteria = new ProjectCriteria(); }
if (this.formGroup == null) { this.formGroup = this.buildForm(); }
}
setCriteria(criteria: ProjectCriteria): void {
this.criteria = criteria;
this.formGroup = this.buildForm();
}
public fromJSONObject(item: any): ProjectCriteria {
this.criteria = new ProjectCriteria();
this.criteria.PeriodStart = new Date(item.PeriodStart);
this.criteria.PeriodEnd = new Date(item.PeriodEnd);
return this.criteria;
onCallbackError(error: any) {
this.setErrorModel(error.error);
}
buildForm(): FormGroup {
const context: ValidationContext = this.createValidationContext();
return this.formBuilder.group({
periodStart: [this.criteria.PeriodStart, context.getValidation('periodStart').validators],
periodEnd: [this.criteria.PeriodEnd, context.getValidation('periodEnd').validators],
});
}
createValidationContext(): ValidationContext {
const validationContext: ValidationContext = new ValidationContext();
const validationArray: Validation[] = new Array<Validation>();
validationArray.push({ key: 'periodStart', validators: [BackendErrorValidator(this.errorModel, 'Criteria.PeriodStart')] }); //must add 'Criteria.' because the criteria validator is inside the request validator
validationArray.push({ key: 'periodEnd', validators: [BackendErrorValidator(this.errorModel, 'Criteria.PeriodEnd')] });
validationContext.validation = validationArray;
return validationContext;
controlModified(): void {
this.clearErrorModel();
if (this.refreshCallback != null &&
(this.criteria.like == null || this.criteria.like.length == 0 || this.criteria.like.length > 2)
) {
this.refreshCallback();
}
}
}

View File

@ -76,10 +76,15 @@
}
},
"CRITERIA": {
"FORMS": {
"PROJECTS": {
"LIKE": "Search",
"PERIOD-FROM": "Project Start",
"PERIOD-TO": "Project End"
},
"DATA-SETS": {
"LIKE": "Search",
"PERIOD-FROM": "Start",
"PERIOD-TO": "End",
"NAME": "Name",
"STATUS": "Status"
}
}