diff --git a/dmp-admin/src/app/app.component.ts b/dmp-admin/src/app/app.component.ts
index a09dc5f19..ae78b858b 100644
--- a/dmp-admin/src/app/app.component.ts
+++ b/dmp-admin/src/app/app.component.ts
@@ -2,8 +2,7 @@ import { Component } from '@angular/core';
import { TokenService, TokenProvider } from './services/login/token.service';
import {Router} from '@angular/router';
-import '../assets/custom.js';
-declare function sign_out_google(): any;
+
@Component({
selector: 'app-root',
@@ -24,31 +23,9 @@ export class AppComponent {
showLogin : boolean = false;
- authenticateToServer(tokenInfo){
-
- console.log("Running authenticateToServer");
- console.log(tokenInfo);
-
- //backendURL, token
- //return this.tokenService.authenticate_backend(backendURL, token);
- }
-
-
-
+
logout(){
- //set the log out actions here
- this.tokenService.setLoggedIn(false);
- this.tokenService.setEmail(null);
- this.tokenService.setUsername(null);
- this.tokenService.setToken(null);
-
- if(this.tokenService.getProvider() == TokenProvider.google){
- sign_out_google();
- }
-
-
- this.tokenService.setProvider(null);
-
+ this.tokenService.logout();
}
diff --git a/dmp-admin/src/app/app.module.ts b/dmp-admin/src/app/app.module.ts
index ad2600e98..487ae7c5f 100644
--- a/dmp-admin/src/app/app.module.ts
+++ b/dmp-admin/src/app/app.module.ts
@@ -24,9 +24,11 @@ import { OrganisationService } from './services/organisation-service';
import { DmpProfileService } from './services/dmpprofile-service';
import { RegistryService } from './services/registry-service';
import { DatarepoService } from './services/datarepo-service';
+import { GlobalInterceptor } from './services/interceptor';
import { Toolbox } from './services/toolbox';
import { DataFilterPipe } from './pipes/data-filter.pipe';
+import { DatasetProfileTableFilterPipe } from './pipes/datasetprofile-table-filter.pipe';
import { DmpTableFilterPipe } from './pipes/dmp-table-filter.pipe';
import { ServiceTableFilterPipe } from './pipes/service-table-filter.pipe';
import { DmpProfileTableFilterPipe } from './pipes/dmp-profile-table-filter.pipe';
@@ -56,6 +58,7 @@ import { RegistryEditorComponent } from './managers/registry-editor/registry-edi
import { ServiceEditorComponent } from './managers/service-editor/service-editor.component';
import { ResearcherEditorComponent } from './managers/researcher-editor/researcher-editor.component';
import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos-editor.component';
+import { DatasetprofileEditorComponent } from './managers/datasetprofile-editor/datasetprofile-editor.component';
@@ -64,6 +67,7 @@ import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos-
DataFilterPipe,
DmpTableFilterPipe,
DmpProfileTableFilterPipe,
+ DatasetProfileTableFilterPipe,
ProjectTableFilterPipe,
OrganisationTableFilterPipe,
RegistryTableFilterPipe,
@@ -87,7 +91,8 @@ import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos-
ServiceEditorComponent,
MainSignInComponent,
ResearcherEditorComponent,
- DatareposEditorComponent
+ DatareposEditorComponent,
+ DatasetprofileEditorComponent
],
imports: [
BrowserModule,
@@ -101,7 +106,12 @@ import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos-
NgbModule.forRoot(),
AppRouting
],
- providers: [ DatasetsServiceService, TokenService, DmpsServiceService, ResearcherService,
+ providers: [{
+ provide: HTTP_INTERCEPTORS,
+ useClass: GlobalInterceptor,
+ multi: true,
+ },
+ DatasetsServiceService, TokenService, DmpsServiceService, ResearcherService,
DialogService, DatasetProfileService, ProjectService, OrganisationService, DatarepoService,
DmpProfileService, RegistryService, ServiceService, NativeLoginService, HttpModule, Toolbox, HttpClient, RestBase],
bootstrap: [AppComponent]
diff --git a/dmp-admin/src/app/bootstrap/new-dataset/new-dataset.component.ts b/dmp-admin/src/app/bootstrap/new-dataset/new-dataset.component.ts
index 07c59a012..544165408 100644
--- a/dmp-admin/src/app/bootstrap/new-dataset/new-dataset.component.ts
+++ b/dmp-admin/src/app/bootstrap/new-dataset/new-dataset.component.ts
@@ -42,7 +42,6 @@ export class NewDatasetComponent implements OnInit {
}
this.datasetsService.setDataset(this.newdatasetform.value).subscribe(
(data) => {
- console.log("Created a new dataset with id: "+data.json().objID);
jQuery("#newdataset-modal-container").modal("hide");
this.idSender.emit(data.json().objID);
}
diff --git a/dmp-admin/src/app/bootstrap/profile-editor/profile-editor.component.ts b/dmp-admin/src/app/bootstrap/profile-editor/profile-editor.component.ts
index da554ad26..2e510c887 100644
--- a/dmp-admin/src/app/bootstrap/profile-editor/profile-editor.component.ts
+++ b/dmp-admin/src/app/bootstrap/profile-editor/profile-editor.component.ts
@@ -68,7 +68,7 @@ export class ProfileEditorComponent implements OnInit {
if(fieldName == 'ruleset-label') database_profile.ruleset.label = this.profile.ruleset.label;
if(fieldName == 'ruleset-definition') database_profile.ruleset.definition = this.profile.ruleset.definition;
//save back
- this.datasetProfileService.setDatasetProfile(database_profile);
+ this.datasetProfileService.updateDatasetProfile(database_profile);
simple_notifier("success",null,"Updated value of field");
});
}
diff --git a/dmp-admin/src/app/datasets-viewer/datasets-viewer.component.ts b/dmp-admin/src/app/datasets-viewer/datasets-viewer.component.ts
index d64583558..bb29b39b3 100644
--- a/dmp-admin/src/app/datasets-viewer/datasets-viewer.component.ts
+++ b/dmp-admin/src/app/datasets-viewer/datasets-viewer.component.ts
@@ -116,16 +116,35 @@ export class DatasetsViewerComponent implements OnInit, AfterViewInit {
onFocusOutProfileWin($event, value:string) {
this.nullSafeProfile();
if(this.haveChanges){
+
+ //delete this.profile.id;
+ //delete this.profile.ruleset.id;
+ //delete this.profile.viewstyle.id;
+
+ delete this.profile.dataset;
+ delete this.profile.ruleset.datasetProfile;
+ delete this.profile.viewstyle.datasetProfile;
+
console.log("Saving profile: "+JSON.stringify(this.profile));
+
+ //save back
+ this.datasetProfileService.createDatasetProfile(this.profile).subscribe(
+ response => {
+ simple_notifier("success",null,"Saved Dataset Profile");
+ console.log(response);
+ },
+ err => {
+ simple_notifier("danger",null,"Could not save Dataset Profile");
+ console.log(err);
+ }
+ );
+
+ /*
//save back
if(this.profile.id == null){ //if profile is new
//create profile and a) assign it on data[] and on current profile b) assign it to dataset
- this.datasetProfileService.setDatasetProfile(this.profile).subscribe((resp) => {
+ this.datasetProfileService.createDatasetProfile(this.profile).subscribe((resp) => {
-
- console.log("SERVICE RESPONSE: ");
- console.log(resp);
- console.log(resp.json());
this.datasetsService.getDatasetById(this.clickedDatasetID).subscribe( (dataset) => {
if(dataset.profile != null){
@@ -152,11 +171,10 @@ export class DatasetsViewerComponent implements OnInit, AfterViewInit {
console.log("this.profile")
console.log(this.profile)
- console.log(this.profile)
- this.profile.dataset = {"id": this.profile.dataset};
+ //this.profile.dataset = {"id": this.profile.dataset};
- this.datasetProfileService.setDatasetProfile(this.profile).subscribe(
+ this.datasetProfileService.updateDatasetProfile(this.profile).subscribe(
response => {
simple_notifier("success",null,"Saved DMP Profile");
console.log(response);
@@ -168,53 +186,13 @@ export class DatasetsViewerComponent implements OnInit, AfterViewInit {
);
}
+ */
}
}
- /*
- onFocusOutProfileWin($event, value:string){
- if(this.haveChanges){
- console.log("Saving profile: "+JSON.stringify(this.profile));
- //save back
- if(this.profile.id == null){ //if profile is new
- console.log("================CH 1 =======================");
- simple_notifier("info",null,"Dataset didn't have a profile. Created and associated a new one");
- //get the appropriate dataset, and add the new profile
- this.datasetsService.getDatasetById(this.clickedDatasetID).subscribe( (dataset) => {
- console.log("================CH 2 =======================");
- if(dataset.profile != null){
- this.profile.id = dataset.profile.id;
- console.log("================CH 3 =======================");
- }
- dataset.profile = this.profile;
-
- console.log("SAVING DATASET: "+JSON.stringify(dataset));
-
- this.datasetsService.setDataset(dataset).subscribe( (resp) => {
- console.log("================CH 4 =======================");
- //console.log(resp);
- simple_notifier("success",null,"Updated profile element");
- });
- });
- }
- else{
- console.log("================CH 5 =======================");
- this.datasetProfileService.setDatasetProfile(this.profile).subscribe((resp) => {
- console.log("================CH 6 =======================");
- console.log(resp.status);
- simple_notifier("success",null,"Updated profile element");
- });
-
- }
-
- }
-
- }
- */
-
nullSafeProfile(){
if(this.profile==null){
console.log("BEFORE:");
diff --git a/dmp-admin/src/app/login/googgle-sign-in/googgle-sign-in.component.ts b/dmp-admin/src/app/login/googgle-sign-in/googgle-sign-in.component.ts
index 1ccc3c0e2..dac20db7a 100644
--- a/dmp-admin/src/app/login/googgle-sign-in/googgle-sign-in.component.ts
+++ b/dmp-admin/src/app/login/googgle-sign-in/googgle-sign-in.component.ts
@@ -4,6 +4,8 @@ import {Router} from '@angular/router';
declare const gapi: any;
+import '../../../assets/custom.js';
+declare function simple_notifier(type: string, title: string, message:string): any;
@Component({
selector: 'googgle-sign-in',
@@ -12,7 +14,7 @@ declare const gapi: any;
})
export class GooggleSignInComponent implements OnInit, AfterViewInit {
- token:any;
+ //token:any;
constructor(private element: ElementRef, private tokenService : TokenService, private router : Router) {
@@ -50,19 +52,11 @@ export class GooggleSignInComponent implements OnInit, AfterViewInit {
public attachSignin(element) {
this.auth2.attachClickHandler(element, {},
(googleUser) => {
- this.token = googleUser.getAuthResponse().id_token;
-
+ simple_notifier("success",null,"Successful login");
let profile = googleUser.getBasicProfile();
-
- this.tokenService.setLoggedIn(true);
- this.tokenService.setToken(this.token);
- this.tokenService.setProvider(TokenProvider.google);
- this.tokenService.setUsername(profile.getName());
- this.tokenService.setEmail(profile.getEmail());
-
- window.location.reload();
-
+ this.tokenService.login(googleUser.getAuthResponse().id_token, TokenProvider.google, profile.getName(), profile.getEmail());
}, function (error) {
+ simple_notifier("danger",null,"Failed to login");
console.log(JSON.stringify(error, undefined, 2));
});
diff --git a/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts b/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts
index 2881383f1..3879e22fe 100644
--- a/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts
+++ b/dmp-admin/src/app/login/main-sign-in/main-sign-in.component.ts
@@ -48,13 +48,7 @@ export class MainSignInComponent implements OnInit {
simple_notifier("success",null,"Successful login");
- this.tokenService.setLoggedIn(true);
- this.tokenService.setToken(response['token']);
- this.tokenService.setProvider(TokenProvider.native);
- this.tokenService.setUsername(this.creds.username);
- this.tokenService.setEmail(response['email']);
-
- window.location.reload();
+ this.tokenService.login(response['token'], TokenProvider.native, this.creds.username, response['email']);
},
err => {
diff --git a/dmp-admin/src/app/main-window/main-window.component.html b/dmp-admin/src/app/main-window/main-window.component.html
index 7749f27fb..bc10eb217 100644
--- a/dmp-admin/src/app/main-window/main-window.component.html
+++ b/dmp-admin/src/app/main-window/main-window.component.html
@@ -12,7 +12,7 @@
diff --git a/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.css b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.css
new file mode 100644
index 000000000..e69de29bb
diff --git a/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.html b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.html
new file mode 100644
index 000000000..f600a06d3
--- /dev/null
+++ b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+
+ Manage Dataset Profiles
+
+
+
+ Create Dataset profile
+
+
+ Edit this Dataset profile
+
+
+ Delete this
+
+
+
+ Show full tree connections
+
+
+
\ No newline at end of file
diff --git a/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.spec.ts b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.spec.ts
new file mode 100644
index 000000000..3b9452101
--- /dev/null
+++ b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { DatasetprofileEditorComponent } from './datasetprofile-editor.component';
+
+describe('DatasetprofileEditorComponent', () => {
+ let component: DatasetprofileEditorComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ DatasetprofileEditorComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(DatasetprofileEditorComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should be created', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.ts b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.ts
new file mode 100644
index 000000000..1afa960e0
--- /dev/null
+++ b/dmp-admin/src/app/managers/datasetprofile-editor/datasetprofile-editor.component.ts
@@ -0,0 +1,135 @@
+import { Component, OnInit, ViewChild } from '@angular/core';
+import { DatasetProfileService } from '../../services/dataset-profile.service';
+import { ContextMenuComponent } from 'ngx-contextmenu';
+import { ReactiveFormsModule } from '@angular/forms';
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+
+import '../../../assets/custom.js';
+declare function simple_notifier(type: string, title: string, message:string): any;
+
+
+@Component({
+ selector: 'app-datasetprofile-editor',
+ templateUrl: './datasetprofile-editor.component.html',
+ styleUrls: ['./datasetprofile-editor.component.css']
+})
+export class DatasetprofileEditorComponent implements OnInit {
+
+
+ constructor(private datasetProfileService : DatasetProfileService, private fb: FormBuilder) {
+
+ }
+
+ //whole dmp data model
+ tableData : any[] = new Array();
+
+ //DatasetProfile editor data model
+ editingDatasetProfile: any = {};
+ datasetProfileEditorForm : any;
+
+ //required by the table
+ public filterQuery = "";
+ public rowsOnPage = 10;
+ //public sortBy = "email";
+ public sortOrder = "asc";
+
+ //visibility rules for containers
+ tableVisible: boolean = true;
+ editorVisible: boolean = false;
+
+
+ // for tableIds
+ showIDs : boolean = false;
+
+
+
+
+ ngOnInit() {
+ this.getAllDatasetProfiles(false);
+ this.createDatasetProfileEditorForm();
+ }
+
+ createDatasetProfileEditorForm(){
+ this.datasetProfileEditorForm = this.fb.group({
+ id: '',
+ label: ['', Validators.required ],
+ ruleset: '',
+ viewstyle: '',
+ definition: ''
+ });
+
+ }
+
+ switchToTable(){
+ this.tableVisible = true;
+ this.editorVisible = false;
+ }
+
+ switchToEditor(datasetProfileID){
+ this.tableVisible = false;
+ this.editorVisible = true;
+ if(datasetProfileID == null){
+ this.editingDatasetProfile = {id: null, label: "", ruleset: "", viewstyle: "", definition: "" };
+ }
+ else{
+ this.editingDatasetProfile = this.tableData.filter((datasetProfile) => datasetProfile.id === datasetProfileID)[0];
+ }
+ }
+
+
+ getAllDatasetProfiles(showNotification : boolean){
+ this.datasetProfileService.fetchAllDatasetProfiles().subscribe( (data) => {
+ this.tableData = data;
+ if(showNotification)
+ simple_notifier("info",null,"Refreshed the table");
+ });
+ }
+
+
+ edit(data){
+ this.switchToEditor(data);
+ }
+
+ new(){
+ this.switchToEditor(null);
+ }
+
+
+
+ save(mouseEvent){
+ this.datasetProfileService.createDatasetProfile(this.datasetProfileEditorForm.value).subscribe(
+ response => {
+ simple_notifier("success",null,"Saved dataset Profile");
+ this.getAllDatasetProfiles(false);
+ this.switchToTable();
+ },
+ err => {
+ simple_notifier("danger",null,"Could not save dataset Profile");
+ }
+ );
+ }
+
+ delete(data){
+ console.log(data);
+ this.datasetProfileService.delete(data).subscribe(
+ (response) => {
+ simple_notifier("success",null,"Deleted dataset profile");
+ this.getAllDatasetProfiles(false);
+ this.switchToTable();
+ },
+ (err) => {
+ simple_notifier("danger",null,"Could not delete dataset profile");
+ }
+ )
+ }
+
+
+
+ refreshTable($event){
+ this.getAllDatasetProfiles(true);
+ }
+
+
+ @ViewChild(ContextMenuComponent) public basicMenu: ContextMenuComponent;
+
+}
diff --git a/dmp-admin/src/app/managers/service-editor/service-editor.component.ts b/dmp-admin/src/app/managers/service-editor/service-editor.component.ts
index e83441fdb..1aa8e7de2 100644
--- a/dmp-admin/src/app/managers/service-editor/service-editor.component.ts
+++ b/dmp-admin/src/app/managers/service-editor/service-editor.component.ts
@@ -102,6 +102,7 @@ export class ServiceEditorComponent implements OnInit {
response => {
simple_notifier("success",null,"Saved service");
this.getAllServices(false);
+ this.switchToTable();
},
err => {
simple_notifier("danger",null,"Could not save service");
@@ -113,6 +114,8 @@ export class ServiceEditorComponent implements OnInit {
this.serviceService.delete(service).subscribe(
(response) => {
simple_notifier("success",null,"Deleted service");
+ this.getAllServices(false);
+ this.switchToTable();
},
(err) => {
diff --git a/dmp-admin/src/app/pipes/datasetprofile-table-filter.pipe.ts b/dmp-admin/src/app/pipes/datasetprofile-table-filter.pipe.ts
new file mode 100644
index 000000000..b7f2f979d
--- /dev/null
+++ b/dmp-admin/src/app/pipes/datasetprofile-table-filter.pipe.ts
@@ -0,0 +1,25 @@
+import * as _ from "lodash";
+import {Pipe, PipeTransform} from "@angular/core";
+
+@Pipe({
+ name: "datasetProfileTableFilter"
+})
+export class DatasetProfileTableFilterPipe implements PipeTransform {
+
+ transform(array: any[], query: string): any {
+
+ if (query) {
+
+ return _.filter(array, row => {
+ if (row.label == null) row.label = "";
+ if (row.id == null) row.id = "";
+ return (
+ row.label.indexOf(query) > -1 ||
+ row.id.indexOf(query) > -1
+ )
+ });
+
+ }
+ return array;
+ }
+}
\ No newline at end of file
diff --git a/dmp-admin/src/app/routes.ts b/dmp-admin/src/app/routes.ts
index 10bfb4add..bf966523e 100644
--- a/dmp-admin/src/app/routes.ts
+++ b/dmp-admin/src/app/routes.ts
@@ -12,7 +12,7 @@ import { RegistryEditorComponent } from './managers/registry-editor/registry-edi
import { OrganisationEditorComponent } from './managers/organisation-editor/organisation-editor.component';
import { ResearcherEditorComponent } from './managers/researcher-editor/researcher-editor.component';
import { DatareposEditorComponent } from './managers/datarepos-editor/datarepos-editor.component';
-
+import { DatasetprofileEditorComponent } from './managers/datasetprofile-editor/datasetprofile-editor.component';
import { MainWindowComponent } from './main-window/main-window.component';
@@ -30,6 +30,10 @@ export const routes: Routes = [
path: 'datasets',
component: DatasetsViewerComponent
},
+ {
+ path: 'datasetprofiles',
+ component: DatasetprofileEditorComponent
+ },
{
path: 'datarepos',
component: DatareposEditorComponent
diff --git a/dmp-admin/src/app/services/dataset-profile.service.ts b/dmp-admin/src/app/services/dataset-profile.service.ts
index 761b4e12d..cdae154de 100644
--- a/dmp-admin/src/app/services/dataset-profile.service.ts
+++ b/dmp-admin/src/app/services/dataset-profile.service.ts
@@ -16,17 +16,25 @@ export class DatasetProfileService implements OnInit {
}
-
+ fetchAllDatasetProfiles(){
+ return this.restBase.get("datasetprofile/getAll");
+ }
getDatasetProfileById(datasetProfileID){
return this.restBase.get("datasetprofile/"+datasetProfileID);
- //.map((response: Response) => response.json());
}
- setDatasetProfile(datasetProfile){
- return this.restBase.post("datasetprofile/set", datasetProfile);
+ createDatasetProfile(datasetProfile){
+ return this.restBase.post("datasetprofile/create", datasetProfile);
}
+ updateDatasetProfile(datasetProfile){
+ return this.restBase.post("datasetprofile/update", datasetProfile);
+ }
+
+ delete(datasetProfile){
+ return this.restBase.post("datasetprofile/delete", datasetProfile);
+ }
}
\ No newline at end of file
diff --git a/dmp-admin/src/app/services/datasets-service.service.ts b/dmp-admin/src/app/services/datasets-service.service.ts
index af5b8eb5e..87ce6773a 100644
--- a/dmp-admin/src/app/services/datasets-service.service.ts
+++ b/dmp-admin/src/app/services/datasets-service.service.ts
@@ -19,26 +19,26 @@ export class DatasetsServiceService implements OnInit {
getDatasetById(datasetID){
- return this.restBase.get("dataset/"+datasetID);
+ return this.restBase.get("datasets/"+datasetID);
}
fetchAllDatasets(){
- return this.restBase.get("getAllDatasets");
+ return this.restBase.get("dataset/getAll");
}
setDataset(fullDataset){
- return this.restBase.post("setDataset", fullDataset);
+ return this.restBase.post("dataset/create", fullDataset);
}
deleteDataset(dataset){
- return this.restBase.post("deleteDataset", dataset);
+ return this.restBase.post("dataset/delete", dataset);
}
assignDMPToDataset(datasetID, dmpID){
- return this.restBase.get("assignDMPToDataset" +"?datasetID="+datasetID+"&dmpID="+dmpID);
+ return this.restBase.get("dataset/assignDMPToDataset" +"?datasetID="+datasetID+"&dmpID="+dmpID);
}
}
diff --git a/dmp-admin/src/app/services/interceptor.ts b/dmp-admin/src/app/services/interceptor.ts
new file mode 100644
index 000000000..8bf83e057
--- /dev/null
+++ b/dmp-admin/src/app/services/interceptor.ts
@@ -0,0 +1,31 @@
+import {Injectable} from '@angular/core';
+import {Observable} from 'rxjs/Observable';
+import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse, HttpErrorResponse} from '@angular/common/http';
+import { TokenService } from './login/token.service';
+
+@Injectable()
+export class GlobalInterceptor implements HttpInterceptor {
+
+ constructor(public tokenService: TokenService) {}
+
+ intercept(req: HttpRequest, next: HttpHandler): Observable> {
+
+ return next.handle(req).do((event: HttpEvent) => {
+ /*
+ if (event instanceof HttpResponse) {
+ console.log("response ok");
+ }
+ */
+ }, (err: any) => {
+ if (err instanceof HttpErrorResponse) {
+ if (err.status === 401) {
+ console.log("logging out");
+ this.tokenService.logout();
+ }
+ }
+ });
+
+
+ //return next.handle(req);
+ }
+}
\ No newline at end of file
diff --git a/dmp-admin/src/app/services/login/token.service.ts b/dmp-admin/src/app/services/login/token.service.ts
index 5b2bd7897..b8f58541b 100644
--- a/dmp-admin/src/app/services/login/token.service.ts
+++ b/dmp-admin/src/app/services/login/token.service.ts
@@ -6,6 +6,9 @@ import { DOCUMENT } from '@angular/platform-browser';
declare var jQuery : any;
+import '../../../assets/custom.js';
+declare function sign_out_google(): any;
+
@Injectable()
export class TokenService {
@@ -66,6 +69,34 @@ export class TokenService {
}
+ login(token: string, provider: TokenProvider, username: string, email: string){
+
+ this.setLoggedIn(true);
+ this.setToken(token);
+ this.setProvider(provider);
+ this.setUsername(username);
+ this.setEmail(email);
+
+ window.location.reload();
+
+ }
+
+
+ logout(){
+ //set the log out actions here
+ this.setLoggedIn(false);
+ this.setEmail(null);
+ this.setUsername(null);
+ this.setToken(null);
+
+ if(this.getProvider() == TokenProvider.google){
+ sign_out_google();
+ }
+
+ this.setProvider(null);
+ }
+
+
}
export enum TokenProvider {
diff --git a/dmp-admin/src/app/services/rest-base.ts b/dmp-admin/src/app/services/rest-base.ts
index 1ca5fb519..2a056841a 100644
--- a/dmp-admin/src/app/services/rest-base.ts
+++ b/dmp-admin/src/app/services/rest-base.ts
@@ -15,12 +15,24 @@ export class RestBase {
this.xml2jsonOBJ = new X2JS();
}
+ /*
+ */
protocol: string = "http";
- hostname: string = "dionysus.di.uoa.gr";//"dl010.madgik.di.uoa.gr";//
- port: number = 7070;//8080;//
- webappname: string = "dmp-backend";//"dmp-backend-new";//
+ hostname: string = "dionysus.di.uoa.gr";
+ port: number = 7070;
+ webappname: string = "dmp-backend";
restpath: string = "rest";
+/*
+ protocol: string = "http";
+ hostname: string = "dl010.madgik.di.uoa.gr";
+ port: number = 8080;
+ webappname: string = "dmp-backend";
+ restpath: string = "rest";
+*/
+
+
+
loginPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/login/";
restBasePath: string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/"+this.restpath+"/";
@@ -31,24 +43,32 @@ export class RestBase {
return this.http.post(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(this.restBasePath + 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(this.restBasePath + 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('X-CSRF-Token', csrfToken).set("google-token", token);
@@ -58,7 +78,7 @@ export class RestBase {
return options;
}
-
+
}
\ No newline at end of file
diff --git a/dmp-admin/src/app/services/service-service.ts b/dmp-admin/src/app/services/service-service.ts
index 68567daa8..1c51557c2 100644
--- a/dmp-admin/src/app/services/service-service.ts
+++ b/dmp-admin/src/app/services/service-service.ts
@@ -34,7 +34,8 @@ export class ServiceService implements OnInit {
create(service){
return this.restBase.post("service/create", service);
}
-
+
+
delete(serviceID){
var service = {"id": serviceID};
return this.restBase.post("service/delete", service);
diff --git a/dmp-admin/src/app/services/token.service.ts b/dmp-admin/src/app/services/token.service.ts
deleted file mode 100644
index 8eec8b727..000000000
--- a/dmp-admin/src/app/services/token.service.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import { Injectable, } from '@angular/core';
-import { Observable } from 'rxjs';
-import {LocalStorageService} from 'ngx-webstorage';
-import 'rxjs/add/operator/map';
-
-
-@Injectable()
-export class TokenService {
-
-
- constructor (private storage : LocalStorageService) {
-
- }
-
- getProvider(){
- return this.storage.retrieve('provider');
- }
-
- setProvider(provider : TokenProvider){
- this.storage.store('provider',provider);
- }
-
- getToken(){
- return this.storage.retrieve('token');
- }
-
- setToken(token){
- this.storage.store('token',token);
- }
-
- isLoggedIn(){
- return this.storage.retrieve('loggedIn');
- }
-
- setLoggedIn(boolStatus){
- this.storage.store('loggedIn',boolStatus);
- }
-
- getEmail(){
- return this.storage.retrieve('email');
- }
-
- setEmail(email){
- this.storage.store('email',email);
- }
-
- getUsername(){
- return this.storage.retrieve('username');
- }
-
- setUsername(username){
- this.storage.store('username',username);
- }
-
-
-}
-
-export enum TokenProvider {
- native,
- google
-}
-
-
-