From 4cbaec3667183a8bf68877c24d613cb3a72d883e Mon Sep 17 00:00:00 2001 From: Nikolaos Laskaris Date: Mon, 27 Nov 2017 12:51:20 +0200 Subject: [PATCH] altered the lifecycle of the user login --- dmp-frontend/src/app/app.component.ts | 36 +++++++++++++++ dmp-frontend/src/app/dmps/dmps.html | 2 +- .../googgle-sign-in.component.ts | 46 ++++--------------- .../dmp-detailed/dmp-detailed.component.html | 8 ++-- .../project-detailed.component.html | 6 +-- .../project-detailed.component.ts | 17 ++++++- dmp-frontend/src/assets/custom.js | 28 +++++++++++ 7 files changed, 96 insertions(+), 47 deletions(-) diff --git a/dmp-frontend/src/app/app.component.ts b/dmp-frontend/src/app/app.component.ts index 9bf4b41f0..98d47dd52 100644 --- a/dmp-frontend/src/app/app.component.ts +++ b/dmp-frontend/src/app/app.component.ts @@ -11,6 +11,7 @@ import { BreadcrumbComponent } from './widgets/breadcrumb/breadcrumb.component'; import { AutocompleteRemoteComponent } from './form/fields/autocomplete-remote/autocomplete-remote.component'; +declare const gapi: any; declare var $ :any; @Component({ @@ -36,10 +37,45 @@ export class AppComponent implements OnInit { } ngOnInit() { + //this.initiateExternalProviders(); + } + + initiateExternalProviders(){ + + + //initiate google + var clientId = '1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com'; + var scope = [ + 'profile', + 'email' + ].join(' '); + + if(gapi.auth2 == undefined){ + + gapi.load('auth2', () => { + + gapi.auth2.init({ + client_id: clientId, + cookiepolicy: 'single_host_origin', + scope: scope + }); + + + + //RE-Render the button (due to known issues of google-button with angular's lifecycle) + gapi.signin2.render('googleBtn'); + + //var buttonElement = this.element.nativeElement.querySelector('#googleBtn'); + //this.attachSignin(buttonElement); + + }); + + } } + slideNav(){ $("#appSidebar").toggleClass("expanded"); diff --git a/dmp-frontend/src/app/dmps/dmps.html b/dmp-frontend/src/app/dmps/dmps.html index 23911d5db..d2d9dffef 100644 --- a/dmp-frontend/src/app/dmps/dmps.html +++ b/dmp-frontend/src/app/dmps/dmps.html @@ -68,7 +68,7 @@ {{(dmp?.label?.length > 40) ? (dmp?.label | slice:0:40)+'...':(dmp?.label) }} {{dmp?.version}} - {{dmp?.previous}} + {{(dmp?.previous?.label?.length > 40) ? (dmp?.previous?.label | slice:0:40)+'...':(dmp?.previous?.label) }} {{(dmp?.project?.label?.length > 40) ? (dmp?.project?.label | slice:0:40)+'...':(dmp?.project?.label) }} {{(dmp?.description?.length > 40) ? (dmp?.description | slice:0:40)+'...':(dmp?.description) }} {{dmp?.created | date:'yyyy-MM-dd HH:mm:ss Z'}} diff --git a/dmp-frontend/src/app/login/googgle-sign-in/googgle-sign-in.component.ts b/dmp-frontend/src/app/login/googgle-sign-in/googgle-sign-in.component.ts index 718a431e2..d0f2dca38 100644 --- a/dmp-frontend/src/app/login/googgle-sign-in/googgle-sign-in.component.ts +++ b/dmp-frontend/src/app/login/googgle-sign-in/googgle-sign-in.component.ts @@ -28,48 +28,19 @@ export class GooggleSignInComponent implements OnInit, AfterViewInit, Injectable ngAfterViewInit() { - this.googleInit(); + + //RE-Render the button (due to known issues of google-button with angular's lifecycle) + gapi.signin2.render('googleBtn'); + var buttonElement = this.element.nativeElement.querySelector('#googleBtn'); + this.attachSignin(buttonElement); } - private clientId:string = '1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com'; - - private scope = [ - 'profile', - 'email' - //, - //'https://www.googleapis.com/auth/plus.me', - //'https://www.googleapis.com/auth/contacts.readonly', - //'https://www.googleapis.com/auth/admin.directory.user.readonly' - ].join(' '); - - public auth2: any; - - public googleInit() { - - - gapi.load('auth2', () => { - this.auth2 = gapi.auth2.init({ - client_id: this.clientId, - cookiepolicy: 'single_host_origin', - scope: this.scope - }); - - //RE-Render the button (due to known issues of google-button with angular's lifecycle) - gapi.signin2.render('googleBtn'); - - var buttonElement = this.element.nativeElement.querySelector('#googleBtn'); - this.attachSignin(buttonElement); - - - }); - - - } public attachSignin(element) { - this.auth2.attachClickHandler(element, {}, + + gapi.auth2.getAuthInstance().attachClickHandler(element, {}, (googleUser) => { //simple_notifier("success",null,"Successful login"); let profile = googleUser.getBasicProfile(); @@ -78,7 +49,8 @@ export class GooggleSignInComponent implements OnInit, AfterViewInit, Injectable function (error) { //simple_notifier("danger",null,"Failed to login"); console.log(JSON.stringify(error, undefined, 2)); - }); + } + ); } diff --git a/dmp-frontend/src/app/viewers/dmp-detailed/dmp-detailed.component.html b/dmp-frontend/src/app/viewers/dmp-detailed/dmp-detailed.component.html index baf72769a..f980afb2b 100644 --- a/dmp-frontend/src/app/viewers/dmp-detailed/dmp-detailed.component.html +++ b/dmp-frontend/src/app/viewers/dmp-detailed/dmp-detailed.component.html @@ -4,7 +4,7 @@