From 5e39e9643d7ca763bb88d119eaea37409d3eb861 Mon Sep 17 00:00:00 2001 From: Diamadis Tziotzios Date: Mon, 18 Dec 2017 16:58:13 +0200 Subject: [PATCH] no message --- .../app/datasets_new/dataset-listing.component.ts | 1 - dmp-frontend/src/app/models/Status.ts | 4 ++++ .../src/app/models/http/BaseHttpResponseModel.ts | 5 +++++ .../src/app/models/projects/ProjectModel.ts | 4 +++- .../src/app/services/project/project.service.ts | 11 +++++++---- .../datasets/datasets-criteria.component.ts | 2 -- .../cite-http-service-module/base-http.service.ts | 15 +++++++++++++++ 7 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 dmp-frontend/src/app/models/Status.ts create mode 100644 dmp-frontend/src/app/models/http/BaseHttpResponseModel.ts diff --git a/dmp-frontend/src/app/datasets_new/dataset-listing.component.ts b/dmp-frontend/src/app/datasets_new/dataset-listing.component.ts index 6d9e0bfd0..c4e41dc1c 100644 --- a/dmp-frontend/src/app/datasets_new/dataset-listing.component.ts +++ b/dmp-frontend/src/app/datasets_new/dataset-listing.component.ts @@ -46,7 +46,6 @@ export class DatasetListingComponent implements OnInit, AfterViewInit { setTimeout(() => { this.criteria.setRefreshCallback(() => this.refresh()); this.criteria.setCriteria(this.getDefaultCriteria()); - this.criteria.controlModified(); }); } diff --git a/dmp-frontend/src/app/models/Status.ts b/dmp-frontend/src/app/models/Status.ts new file mode 100644 index 000000000..888f52a39 --- /dev/null +++ b/dmp-frontend/src/app/models/Status.ts @@ -0,0 +1,4 @@ +export enum Status { + Active = 0, + Inactive = 1 +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/http/BaseHttpResponseModel.ts b/dmp-frontend/src/app/models/http/BaseHttpResponseModel.ts new file mode 100644 index 000000000..8a95259f6 --- /dev/null +++ b/dmp-frontend/src/app/models/http/BaseHttpResponseModel.ts @@ -0,0 +1,5 @@ +export interface BaseHttpResponseModel { + statusCode: number; + message: String; + payload: T; +} \ No newline at end of file diff --git a/dmp-frontend/src/app/models/projects/ProjectModel.ts b/dmp-frontend/src/app/models/projects/ProjectModel.ts index 622f80428..c545e7358 100644 --- a/dmp-frontend/src/app/models/projects/ProjectModel.ts +++ b/dmp-frontend/src/app/models/projects/ProjectModel.ts @@ -3,6 +3,7 @@ import { ValidationContext } from "../../utilities/validators/ValidationContext" import { FormGroup, FormBuilder, FormControl, Validators } from "@angular/forms"; import { BackendErrorValidator } from "../../utilities/validators/BackendErrorValidator"; import { BaseErrorModel } from "../error/BaseErrorModel"; +import { Status } from "../Status"; export class ProjectModel implements Serializable { public id: String; @@ -10,7 +11,7 @@ export class ProjectModel implements Serializable { public abbreviation: String; public reference: String; public uri: String; - public status: String; + public status: Status; public startDate: Date; public endDate: Date; public description: String; @@ -39,6 +40,7 @@ export class ProjectModel implements Serializable { 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}], 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] diff --git a/dmp-frontend/src/app/services/project/project.service.ts b/dmp-frontend/src/app/services/project/project.service.ts index f22ee93ac..fb0c115f7 100644 --- a/dmp-frontend/src/app/services/project/project.service.ts +++ b/dmp-frontend/src/app/services/project/project.service.ts @@ -8,6 +8,7 @@ import { DataTableRequest } from '../../models/data-table/DataTableRequest'; import { DataTableData } from '../../models/data-table/DataTableData'; import { ProjectListingModel } from '../../models/projects/ProjectListingModel'; import { ProjectModel } from '../../models/projects/ProjectModel'; +import { BaseHttpResponseModel } from '../../models/http/BaseHttpResponseModel'; @Injectable() @@ -26,15 +27,17 @@ export class ProjectService { } getPaged(dataTableRequest: DataTableRequest): Observable> { - return this.http.post>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }); + return this.http.post>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }) + .map(item => this.http.handleResponse>(item)); } getSingle(id: string): Observable { - return this.http.get(this.actionUrl + id, { headers: this.headers }); + return this.http.get>(this.actionUrl + 'getSingle/' + id, { headers: this.headers }) + .map(item => this.http.handleResponse(item)); } createProject(projectModel: ProjectModel): Observable { - return this.http.post(this.actionUrl + 'add', projectModel, { headers: this.headers }); + return this.http.post>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers }) + .map(item => this.http.handleResponse(item));; } - } diff --git a/dmp-frontend/src/app/shared/components/criteria/datasets/datasets-criteria.component.ts b/dmp-frontend/src/app/shared/components/criteria/datasets/datasets-criteria.component.ts index a47ecc2fb..7bcd9cd49 100644 --- a/dmp-frontend/src/app/shared/components/criteria/datasets/datasets-criteria.component.ts +++ b/dmp-frontend/src/app/shared/components/criteria/datasets/datasets-criteria.component.ts @@ -31,12 +31,10 @@ export class DatasetCriteriaComponent extends BaseCriteriaComponent implements O ngOnInit() { super.ngOnInit(); if (this.criteria == null) { this.criteria = new DatasetCriteria(); } - if (this.formGroup == null) { this.formGroup = this.buildForm(); } } setCriteria(criteria: DatasetCriteria): void { this.criteria = criteria; - this.formGroup = this.buildForm(); } public fromJSONObject(item: any): DatasetCriteria { 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 e08c3458f..52a9408f4 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 @@ -7,6 +7,7 @@ import { TranslateService } from '@ngx-translate/core'; import { HttpClient } from '@angular/common/http'; import { AuthService } from '../../services/auth/auth.service'; import { SnackBarNotificationComponent } from '../../shared/components/notificaiton/snack-bar-notification.component'; +import { BaseHttpResponseModel } from '../../models/http/BaseHttpResponseModel'; @Injectable() export class BaseHttpService { @@ -81,4 +82,18 @@ export class BaseHttpService { } }); } + + 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; + } + } }