no message

This commit is contained in:
Diamantis Tziotzios 2017-12-18 17:15:39 +02:00
parent 2352c759ed
commit 072d414038
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 {
this.id = item.id;
this.label = item.label;
this.abbreviation = item.abbreviation;
this.reference = item.reference;
this.uri = item.uri;
this.status = item.status;
this.startDate = item.startDate;
this.endDate = item.endDate;
this.description = item.description;
this.abbreviation = item.abbreviation;
this.reference = item.reference;
this.uri = item.uri;
this.status = item.status;
this.startDate = new Date(item.startDate);
this.endDate = new Date(item.endDate);
this.description = item.description;
return this;
}
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
if (context == null) { context = this.createValidationContext(); }
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],
abbreviation: [{ value: this.abbreviation, disabled: disabled }, context.getValidation('abbreviation').validators],
reference: [{ value: this.reference, disabled: disabled }],
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],
startDate: [{ value: this.startDate, disabled: disabled }, context.getValidation('startDate').validators],
endDate: [{ value: this.endDate, disabled: disabled }, context.getValidation('endDate').validators]
@ -51,9 +52,11 @@ export class ProjectModel implements Serializable<ProjectModel> {
createValidationContext(): 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: 'abbreviation', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'abbreviation')] });
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: 'startDate', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'startDate')] });
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 => {
if (!result) { return []; }
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>> {
return this.http.post<BaseHttpResponseModel<DataTableData<ProjectListingModel>>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers })
.map(item => this.http.handleResponse<DataTableData<ProjectListingModel>>(item));
return this.http.post<DataTableData<ProjectListingModel>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
}
getSingle(id: string): Observable<ProjectModel> {
return this.http.get<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'getSingle/' + id, { headers: this.headers })
.map(item => this.http.handleResponse<ProjectModel>(item));
return this.http.get<ProjectModel>(this.actionUrl + 'getSingle/' + id, { headers: this.headers });
}
createProject(projectModel: ProjectModel): Observable<ProjectModel> {
return this.http.post<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers })
.map(item => this.http.handleResponse<ProjectModel>(item));;
return this.http.post<ProjectModel>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers });
}
}

View File

@ -80,20 +80,33 @@ export class BaseHttpService {
} else {
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>) {
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>) {
// 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;
// }
// }
}