This commit is contained in:
annampak 2017-12-18 17:28:16 +02:00
commit e945cda554
4 changed files with 42 additions and 29 deletions

View File

@ -21,26 +21,27 @@ export class ProjectModel implements Serializable<ProjectModel> {
fromJSONObject(item: any): ProjectModel { fromJSONObject(item: any): ProjectModel {
this.id = item.id; this.id = item.id;
this.label = item.label; this.label = item.label;
this.abbreviation = item.abbreviation; this.abbreviation = item.abbreviation;
this.reference = item.reference; this.reference = item.reference;
this.uri = item.uri; this.uri = item.uri;
this.status = item.status; this.status = item.status;
this.startDate = item.startDate; this.startDate = new Date(item.startDate);
this.endDate = item.endDate; this.endDate = new Date(item.endDate);
this.description = item.description; this.description = item.description;
return this; return this;
} }
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup { buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); } if (context == null) { context = this.createValidationContext(); }
const formGroup = new FormBuilder().group({ const formGroup = new FormBuilder().group({
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
abbreviation: [{ value: this.abbreviation, disabled: disabled }, context.getValidation('abbreviation').validators], abbreviation: [{ value: this.abbreviation, disabled: disabled }, context.getValidation('abbreviation').validators],
reference: [{ value: this.reference, disabled: disabled }], reference: [{ value: this.reference, disabled: disabled }],
uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators], uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators],
status: [{ value: this.status}], status: [{ value: this.status, disabled: disabled }, context.getValidation('label').validators],
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
startDate: [{ value: this.startDate, disabled: disabled }, context.getValidation('startDate').validators], startDate: [{ value: this.startDate, disabled: disabled }, context.getValidation('startDate').validators],
endDate: [{ value: this.endDate, disabled: disabled }, context.getValidation('endDate').validators] endDate: [{ value: this.endDate, disabled: disabled }, context.getValidation('endDate').validators]
@ -51,9 +52,11 @@ export class ProjectModel implements Serializable<ProjectModel> {
createValidationContext(): ValidationContext { createValidationContext(): ValidationContext {
const baseContext: ValidationContext = new ValidationContext(); const baseContext: ValidationContext = new ValidationContext();
baseContext.validation.push({ key: 'id', validators: [] });
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] }); baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] });
baseContext.validation.push({ key: 'abbreviation', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'abbreviation')] }); baseContext.validation.push({ key: 'abbreviation', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'abbreviation')] });
baseContext.validation.push({ key: 'uri', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'uri')] }); baseContext.validation.push({ key: 'uri', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'uri')] });
baseContext.validation.push({ key: 'status', validators: [] });
baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] }); baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'description')] });
baseContext.validation.push({ key: 'startDate', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'startDate')] }); baseContext.validation.push({ key: 'startDate', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'startDate')] });
baseContext.validation.push({ key: 'endDate', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'endDate')] }); baseContext.validation.push({ key: 'endDate', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'endDate')] });

View File

@ -131,7 +131,7 @@ export class ProjectDataSource extends DataSource<ProjectListingModel> {
.map(result => { .map(result => {
if (!result) { return []; } if (!result) { return []; }
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; } if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
return result.payload.data; return result.data;
}); });
} }

View File

@ -27,17 +27,14 @@ export class ProjectService {
} }
getPaged(dataTableRequest: DataTableRequest): Observable<DataTableData<ProjectListingModel>> { getPaged(dataTableRequest: DataTableRequest): Observable<DataTableData<ProjectListingModel>> {
return this.http.post<BaseHttpResponseModel<DataTableData<ProjectListingModel>>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }) return this.http.post<DataTableData<ProjectListingModel>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
.map(item => this.http.handleResponse<DataTableData<ProjectListingModel>>(item));
} }
getSingle(id: string): Observable<ProjectModel> { getSingle(id: string): Observable<ProjectModel> {
return this.http.get<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'getSingle/' + id, { headers: this.headers }) return this.http.get<ProjectModel>(this.actionUrl + 'getSingle/' + id, { headers: this.headers });
.map(item => this.http.handleResponse<ProjectModel>(item));
} }
createProject(projectModel: ProjectModel): Observable<ProjectModel> { createProject(projectModel: ProjectModel): Observable<ProjectModel> {
return this.http.post<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }) return this.http.post<ProjectModel>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers });
.map(item => this.http.handleResponse<ProjectModel>(item));;
} }
} }

View File

@ -80,20 +80,33 @@ export class BaseHttpService {
} else { } else {
return Observable.throw(error); return Observable.throw(error);
} }
})
.map(response => {
if (response.statusCode < 200 || response.statusCode >= 300) {
//throw new Error('Request failed');
this.snackBar.openFromComponent(SnackBarNotificationComponent, {
data: { message: 'GENERAL.ERRORS.HTTP-REQUEST-ERROR', language: this.language },
duration: 3000,
extraClasses: ['snackbar-warning']
})
}
else {
return response.payload;
}
}); });
} }
public handleResponse<T>(response: BaseHttpResponseModel<T>) { // public handleResponse<T>(response: BaseHttpResponseModel<T>) {
if (response.statusCode < 200 || response.statusCode >= 300) { // if (response.statusCode < 200 || response.statusCode >= 300) {
//throw new Error('Request failed'); // //throw new Error('Request failed');
this.snackBar.openFromComponent(SnackBarNotificationComponent, { // this.snackBar.openFromComponent(SnackBarNotificationComponent, {
data: { message: 'GENERAL.ERRORS.HTTP-REQUEST-ERROR', language: this.language }, // data: { message: 'GENERAL.ERRORS.HTTP-REQUEST-ERROR', language: this.language },
duration: 3000, // duration: 3000,
extraClasses: ['snackbar-warning'] // extraClasses: ['snackbar-warning']
}) // })
} // }
else { // else {
return response.payload; // return response.payload;
} // }
} // }
} }