From d342ebb2470a5ab49ee53270915ae889f5a2cc6e Mon Sep 17 00:00:00 2001 From: annampak Date: Thu, 19 Oct 2017 17:33:12 +0300 Subject: [PATCH] login - create new project --- dmp-frontend/src/app/login/login-page.html | 3 +- dmp-frontend/src/app/login/login-page.ts | 97 +++++++++++-------- dmp-frontend/src/app/projects/project.html | 78 +++++++++++++-- .../app/services/dataModelBuilder.service.ts | 2 +- dmp-frontend/src/app/services/rest-base.ts | 2 +- dmp-frontend/src/index.html | 4 +- 6 files changed, 133 insertions(+), 53 deletions(-) diff --git a/dmp-frontend/src/app/login/login-page.html b/dmp-frontend/src/app/login/login-page.html index 748752031..56caf9983 100644 --- a/dmp-frontend/src/app/login/login-page.html +++ b/dmp-frontend/src/app/login/login-page.html @@ -27,7 +27,8 @@
Sign in with
- + +
diff --git a/dmp-frontend/src/app/login/login-page.ts b/dmp-frontend/src/app/login/login-page.ts index 8d0b83416..3300ffafb 100644 --- a/dmp-frontend/src/app/login/login-page.ts +++ b/dmp-frontend/src/app/login/login-page.ts @@ -1,23 +1,24 @@ -import { Component, OnInit, NgZone } from '@angular/core'; -import {GoogleSignInSuccess} from 'angular-google-signin'; +import { Component, OnInit, NgZone, AfterViewInit, ElementRef } from '@angular/core'; +import { GoogleSignInSuccess } from 'angular-google-signin'; import { Router, ActivatedRoute } from '@angular/router'; import { TokenService, TokenProvider } from '../services/token.service'; @Component({ selector: 'login-page', templateUrl: './login-page.html', - providers: [] + providers: [] }) -export class LoginComponent implements OnInit{ +export class LoginComponent implements OnInit, AfterViewInit { returnUrl: string; + token: any; - - constructor( + constructor( private route: ActivatedRoute, private router: Router, private ngZone: NgZone, - private tokenService : TokenService - ){ + private tokenService: TokenService, + private element: ElementRef + ) { } @@ -26,41 +27,61 @@ export class LoginComponent implements OnInit{ //this.authenticationService.logout(); // get return url from route parameters or default to '/' - this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; -} - private myClientId: string = '524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com'; + + //this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; + } + //private myClientId: string = '524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com'; + private myClientId: string = '1010962018903-glegmqudqtl1lub0150vacopbu06lgsg.apps.googleusercontent.com'; - onGoogleSignInSuccess(event: GoogleSignInSuccess) { - let googleUser: gapi.auth2.GoogleUser = event.googleUser; - let id: string = googleUser.getId(); - let profile: gapi.auth2.BasicProfile = googleUser.getBasicProfile(); - this.tokenService.setToken(googleUser.getAuthResponse().id_token); + public auth2: any; - console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. - console.log('Name: ' + profile.getName()); - console.log('token: ' + this.tokenService.getToken()); - - this.tokenService.setProvider(TokenProvider.google); - this.tokenService.setLoggedIn(true); - this.tokenService.setEmail(profile.getEmail()); - this.tokenService.setUsername(profile.getName()); + private scope = [ + 'profile', + 'email' + ].join(' '); - localStorage.setItem('currentUser', this.tokenService.getToken()); - /* AYTA FEYGOUN, xanontai me to refresh tis selidas - - localStorage.setItem('currentUser', JSON.stringify(googleUser)); - var currentUser = JSON.parse(localStorage.getItem('currentUser')); - console.log('current user local storage:' +currentUser) - */ + public googleInit() { - // STO LOGOUT, KATHARIZEIS TO tokenService (apo opoudipote... e;inai apo pantou prosvasimo, kai den xanei tis times toy oso exeis to browser anoixto.) + gapi.load('auth2', () => {debugger; + this.auth2 = gapi.auth2.init({ + client_id: this.myClientId, + cookie_policy: 'single_host_origin', + scope: this.scope + }); + var buttonElement = this.element.nativeElement.querySelector('#googleBtn'); + this.attachSignin(buttonElement); + }); + } + + public attachSignin(element) {debugger; + this.auth2.attachClickHandler(element, {}, + (googleUser) => { + this.token = googleUser.getAuthResponse().id_token; + + 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()); + + this.ngZone.run(() => this.router.navigateByUrl('projects')); + + window.location.reload(); + + }, function (error) { + console.log(JSON.stringify(error, undefined, 2)); + }); + + + + } + + ngAfterViewInit() { + this.googleInit(); + } - - //this.router.navigateByUrl('dynamic-form'); - this.ngZone.run(() => this.router.navigateByUrl('projects')); - //this.router.navigate(['/projects']); - } - } diff --git a/dmp-frontend/src/app/projects/project.html b/dmp-frontend/src/app/projects/project.html index 5d533459d..63571923c 100644 --- a/dmp-frontend/src/app/projects/project.html +++ b/dmp-frontend/src/app/projects/project.html @@ -1,4 +1,3 @@ -
- + Dmp Id - - + + {{ item.dmp.id }} {{item.dmp.id}} - + @@ -32,11 +31,20 @@ - + - + - + + +
@@ -44,7 +52,57 @@ No item selected
- +
- + + +Sign out + \ No newline at end of file diff --git a/dmp-frontend/src/app/services/dataModelBuilder.service.ts b/dmp-frontend/src/app/services/dataModelBuilder.service.ts index 4e5eccff8..8dc60fbba 100644 --- a/dmp-frontend/src/app/services/dataModelBuilder.service.ts +++ b/dmp-frontend/src/app/services/dataModelBuilder.service.ts @@ -78,7 +78,7 @@ export class dataModelBuilder { newfield = new CheckBoxField({ label: element.title.__cdata, key: element._id, - value: element.value, + value: false, order: element._ordinal, rules: element.visible.rule != undefined ? element.visible.rule : rule, visible: element._defaultVisibility, diff --git a/dmp-frontend/src/app/services/rest-base.ts b/dmp-frontend/src/app/services/rest-base.ts index 9d8e3ae84..1e4cd8eb7 100644 --- a/dmp-frontend/src/app/services/rest-base.ts +++ b/dmp-frontend/src/app/services/rest-base.ts @@ -18,7 +18,7 @@ export class RestBase { protocol: string = "http"; hostname: string ="dl010.madgik.di.uoa.gr" ;//"localhost";//"dl010.madgik.di.uoa.gr";// port: number = 8080;//8080;// - webappname: string = "dmp-backend";//"dmp-backend-new";// + webappname: string = "dmp-backend-1";//"dmp-backend-new";// proxyPath : string = this.protocol+"://"+this.hostname+":"+this.port+"/"+this.webappname+"/proxy/"; diff --git a/dmp-frontend/src/index.html b/dmp-frontend/src/index.html index 00b6f0c31..0f41afc37 100644 --- a/dmp-frontend/src/index.html +++ b/dmp-frontend/src/index.html @@ -9,7 +9,7 @@ - Digital Management Plans - Manager + Data Management Plans - Manager @@ -32,7 +32,7 @@
-

Digital Management Plan

+

Data Management Plan