Merge branch 'Development' of https://gitlab.eudat.eu/dmp/OpenAIRE-EUDAT-DMP-service-pilot into Development
This commit is contained in:
commit
8572bd14bd
|
@ -46,7 +46,6 @@ export class DatasetListingComponent implements OnInit, AfterViewInit {
|
|||
setTimeout(() => {
|
||||
this.criteria.setRefreshCallback(() => this.refresh());
|
||||
this.criteria.setCriteria(this.getDefaultCriteria());
|
||||
this.criteria.controlModified();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
export enum Status {
|
||||
Active = 0,
|
||||
Inactive = 1
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
export interface BaseHttpResponseModel<T> {
|
||||
statusCode: number;
|
||||
message: String;
|
||||
payload: T;
|
||||
}
|
|
@ -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<ProjectModel> {
|
||||
public id: String;
|
||||
|
@ -10,7 +11,7 @@ export class ProjectModel implements Serializable<ProjectModel> {
|
|||
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<ProjectModel> {
|
|||
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]
|
||||
|
|
|
@ -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<DataTableData<ProjectListingModel>> {
|
||||
return this.http.post<DataTableData<ProjectListingModel>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers });
|
||||
return this.http.post<BaseHttpResponseModel<DataTableData<ProjectListingModel>>>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers })
|
||||
.map(item => this.http.handleResponse<DataTableData<ProjectListingModel>>(item));
|
||||
}
|
||||
|
||||
getSingle(id: string): Observable<ProjectModel> {
|
||||
return this.http.get<ProjectModel>(this.actionUrl + id, { headers: this.headers });
|
||||
return this.http.get<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'getSingle/' + id, { headers: this.headers })
|
||||
.map(item => this.http.handleResponse<ProjectModel>(item));
|
||||
}
|
||||
|
||||
createProject(projectModel: ProjectModel): Observable<ProjectModel> {
|
||||
return this.http.post<ProjectModel>(this.actionUrl + 'add', projectModel, { headers: this.headers });
|
||||
return this.http.post<BaseHttpResponseModel<ProjectModel>>(this.actionUrl + 'createOrUpdate', projectModel, { headers: this.headers })
|
||||
.map(item => this.http.handleResponse<ProjectModel>(item));;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue