Minor changes

This commit is contained in:
Nikolaos Laskaris 2017-10-27 11:20:35 +03:00
parent b67f77e829
commit 142a0a4bde
6 changed files with 60 additions and 24 deletions

View File

@ -19,7 +19,6 @@ export class GlobalInterceptor implements HttpInterceptor {
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
console.log("logging out");
this.tokenService.logout();
}
}

View File

@ -35,7 +35,7 @@ export class RestBase {
loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/login/";
restBasePath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/"+this.restpath+"/";
restPath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/"+this.restpath+"/";
public login(path : string, data : any){
@ -45,13 +45,13 @@ export class RestBase {
public get(path : string, params? : any){
var options = this.createOptions(params);
return this.http.get<any>(this.restBasePath + path, options);
return this.http.get<any>(this.restPath + path, options);
}
public post(path : string, data : any, params? : any){
var options = this.createOptions(params);
return this.http.post<any>(this.restBasePath + path, JSON.stringify(data), options);
return this.http.post<any>(this.restPath + path, JSON.stringify(data), options);
}

View File

@ -24,6 +24,7 @@ import { TocComponent } from './form/tableOfContents/toc.component';
import { ProjectsModule } from './projects/project.module';
import { PaginationService } from './services/pagination.service';
import { EestoreService } from './services/eestore.service';
import { GlobalInterceptor } from './services/interceptor';
import { DatasetsModule } from './datasets/dataset.module';
import { DmpModule } from './dmps/dmp.module';
import { TabModule } from './tabs/tab.module';
@ -53,7 +54,13 @@ import { TabModule } from './tabs/tab.module';
DataTableModule
],
providers: [ServerService, dataModelBuilder, AuthGuard, PaginationService, TokenService, LocalStorageService, RestBase, EestoreService],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: GlobalInterceptor,
multi: true,
},
ServerService, dataModelBuilder, AuthGuard, PaginationService, TokenService, LocalStorageService, RestBase, EestoreService
],
bootstrap: [AppComponent]
})
export class AppModule {

View File

@ -0,0 +1,30 @@
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse} from '@angular/common/http';
@Injectable()
export class GlobalInterceptor implements HttpInterceptor {
constructor() {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).do((event: HttpEvent<any>) => {
/*
if (event instanceof HttpResponse) {
console.log("response ok");
}
*/
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
if (err.status === 401) {
EDW VALE TO KWDIKA GIA TO LOGOUT
}
}
});
}
}

View File

@ -31,8 +31,8 @@ export class RestBase {
restPath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/rest/";
public proxy_get(path : string){
var options = this.createOptions();
public proxy_get(path : string, params? : any){
var options = this.createOptions(params);
return this.http.get<any>(this.proxyPath +"proxy?url="+ path, options);
}
@ -41,30 +41,29 @@ export class RestBase {
return this.http.post<any>(this.loginPath + path, JSON.stringify(data), options);
}
public get(path : string){
var options = this.createOptions();
public get(path : string, params? : any){
var options = this.createOptions(params);
return this.http.get<any>(this.restPath + path, options);
}
public post(path : string, data : any) {
var options = this.createOptions();
public post(path : string, data : any, params? : any){
var options = this.createOptions(params);
return this.http.post<any>(this.restPath + path, JSON.stringify(data), options);
}
public postWithParams(path : string, data : any, params: HttpParams) {
var options = this.createOptions();
options.params = params;
return this.http.post<any>(this.restPath + path, JSON.stringify(data), options);
}
private createOptions(){
private createOptions(parameters : any){
var token = this.tokenService.getToken();
var provider: TokenProvider = this.tokenService.getProvider();
//var csrfToken : string = this.tokenService.getCSRFToken();
const params = new HttpParams();
var params = new HttpParams();
if(parameters != null){
Object.entries(parameters).forEach( entry => {
params = params.set(entry[0], entry[1]);
});
}
var headers;
if(provider == TokenProvider.google)
headers = new HttpHeaders().set('Content-Type', 'application/json').set("google-token", token);

View File

@ -106,9 +106,10 @@ export class ServerService {
public createDmpForProject2(data:any, projectid: string){
//return this.restBase.post("dmp/createforproject", data);
return this.restBase.postWithParams('dmp/create', data,
new HttpParams().set('id', projectid)
)
return this.restBase.post('dmp/create', data,
{"id":projectid}
//new HttpParams().set('id', projectid)
)
}
public createDmpForProject(data:any){