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 @@