From 072d4140380c6e2ac08f0ad8b3d926bead0f5233 Mon Sep 17 00:00:00 2001 From: Diamadis Tziotzios Date: Mon, 18 Dec 2017 17:15:39 +0200 Subject: [PATCH] no message --- .../src/app/models/projects/ProjectModel.ts | 21 +++++----- .../app/projects/project-listing.component.ts | 2 +- .../app/services/project/project.service.ts | 9 ++--- .../base-http.service.ts | 39 ++++++++++++------- 4 files changed, 42 insertions(+), 29 deletions(-) diff --git a/dmp-frontend/src/app/models/projects/ProjectModel.ts b/dmp-frontend/src/app/models/projects/ProjectModel.ts index c545e7358..011efbb4c 100644 --- a/dmp-frontend/src/app/models/projects/ProjectModel.ts +++ b/dmp-frontend/src/app/models/projects/ProjectModel.ts @@ -21,26 +21,27 @@ export class ProjectModel implements Serializable { 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 { 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')] }); diff --git a/dmp-frontend/src/app/projects/project-listing.component.ts b/dmp-frontend/src/app/projects/project-listing.component.ts index 4092c408f..c4138f97c 100644 --- a/dmp-frontend/src/app/projects/project-listing.component.ts +++ b/dmp-frontend/src/app/projects/project-listing.component.ts @@ -131,7 +131,7 @@ export class ProjectDataSource extends DataSource { .map(result => { if (!result) { return []; } if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; } - return result.payload.data; + return result.data; }); } diff --git a/dmp-frontend/src/app/services/project/project.service.ts b/dmp-frontend/src/app/services/project/project.service.ts index fb0c115f7..9056f4455 100644 --- a/dmp-frontend/src/app/services/project/project.service.ts +++ b/dmp-frontend/src/app/services/project/project.service.ts @@ -27,17 +27,14 @@ export class ProjectService { } getPaged(dataTableRequest: DataTableRequest): Observable> { - return this.http.post>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }) - .map(item => this.http.handleResponse>(item)); + return this.http.post>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }); } getSingle(id: string): Observable { - return this.http.get>(this.actionUrl + 'getSingle/' + id, { headers: this.headers }) - .map(item => this.http.handleResponse(item)); + return this.http.get(this.actionUrl + 'getSingle/' + id, { headers: this.headers }); } createProject(projectModel: ProjectModel): Observable { - return this.http.post>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }) - .map(item => this.http.handleResponse(item));; + return this.http.post(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }); } } diff --git a/dmp-frontend/src/app/utilities/cite-http-service-module/base-http.service.ts b/dmp-frontend/src/app/utilities/cite-http-service-module/base-http.service.ts index 52a9408f4..9f6554767 100644 --- a/dmp-frontend/src/app/utilities/cite-http-service-module/base-http.service.ts +++ b/dmp-frontend/src/app/utilities/cite-http-service-module/base-http.service.ts @@ -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(response: BaseHttpResponseModel) { - 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(response: BaseHttpResponseModel) { + // 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; + // } + // } }