Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b9a67499
authored
Oct 13, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
koodit turvaan
1 parent
110ee6a0
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
36 deletions
code/moya-angular/src/app/app.component.html
code/moya-angular/src/app/app.component.ts
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.html
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.ts
code/moya-angular/src/app/shared/services/session-service.service.ts
code/moya-angular/src/app/app.component.html
View file @
b9a6749
...
...
@@ -6,7 +6,7 @@
<div
id=
"contentarea"
>
<div
id=
"topbar"
>
<moya-top-menu></moya-top-menu>
<
button
mat-raised-button
(
click
)="
openLoginDialog
()"
tabindex=
"8"
>
{{ "login.login" | translate}}
</button
>
<
moya-login-dialog></moya-login-dialog
>
<moya-locale></moya-locale>
</div>
<div
id=
"content"
>
...
...
code/moya-angular/src/app/app.component.ts
View file @
b9a6749
...
...
@@ -22,25 +22,5 @@ export class AppComponent {
}
openLoginDialog
():
void
{
let
conf
=
new
MatDialogConfig
();
conf
.
autoFocus
=
true
;
/*conf.height = "800px";
conf.width = "500px";*/
let
dialogRef
=
this
.
dialog
.
open
(
LoginComponent
,
conf
);
dialogRef
.
componentInstance
.
loginEvent
.
subscribe
((
success
)
=>
{
if
(
success
)
{
dialogRef
.
close
();
}
else
{
dialogRef
.
close
();
this
.
router
.
navigateByUrl
(
"/login"
);
}
});
}
}
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.html
View file @
b9a6749
<p>
login-dialog works!
</p>
ei toimi
<button
mat-raised-button
(
click
)="
openLoginDialog
()"
tabindex=
"8"
>
{{ "login.login" | translate}}
</button>
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.ts
View file @
b9a6749
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
Component
,
NgZone
,
OnInit
}
from
'@angular/core'
;
import
{
MatDialog
,
MatDialogConfig
}
from
"@angular/material"
;
import
{
LoginComponent
}
from
"../login-component/login.component"
;
import
{
Router
}
from
"@angular/router"
;
@
Component
({
selector
:
'moya-login-dialog'
,
...
...
@@ -7,9 +10,29 @@ import { Component, OnInit } from '@angular/core';
})
export
class
LoginDialogComponent
implements
OnInit
{
constructor
()
{
}
constructor
(
private
router
:
Router
,
private
dialog
:
MatDialog
)
{
}
ngOnInit
()
{
}
openLoginDialog
():
void
{
let
conf
=
new
MatDialogConfig
();
conf
.
autoFocus
=
true
;
/*conf.height = "800px";
conf.width = "500px";*/
let
dialogRef
=
this
.
dialog
.
open
(
LoginComponent
,
conf
);
dialogRef
.
componentInstance
.
loginEvent
.
subscribe
((
success
)
=>
{
if
(
success
)
{
dialogRef
.
close
();
}
else
{
dialogRef
.
close
();
this
.
router
.
navigateByUrl
(
"/login"
);
}
});
}
}
code/moya-angular/src/app/shared/services/session-service.service.ts
View file @
b9a6749
...
...
@@ -2,10 +2,9 @@ import {Injectable} from '@angular/core';
import
gql
from
'graphql-tag'
;
import
{
Permissions
}
from
'../models/permissions.model'
;
import
{
Apollo
,
QueryRef
}
from
'apollo-angular'
;
import
{
Observable
,
Observer
}
from
'rxjs'
;
import
{
BehaviorSubject
,
Observable
,
Observer
,
Subject
}
from
'rxjs'
;
import
{
MOYA_BASE_URL
,
MOYA_REST_URL
}
from
'../config/moya.config'
;
import
{
map
,
share
}
from
'rxjs/operators'
;
import
{
Vip
}
from
'../../modules/viplist/models/vip.model'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'@angular/common/http'
;
import
{
EventUser
}
from
"../models/event-user.model"
;
...
...
@@ -45,11 +44,11 @@ export class SessionServiceService {
private
permissionsObservable
:
Observable
<
Permissions
>
;
private
permissionsApollo
:
QueryRef
<
ApiPermissionRoot
>
;
private
currentuserObservable
:
Observable
<
EventUser
>
;
private
currentuserObserver
:
Observer
<
EventUser
>
;
private
currentuserSubject
:
BehaviorSubject
<
EventUser
>
;
constructor
(
private
apollo
:
Apollo
,
private
http
:
HttpClient
)
{
// Permissions apollo call.
// rewrite permissions from API -format to moya-angular -format
//
...
...
@@ -64,9 +63,12 @@ export class SessionServiceService {
.
reduce
((
permObject
,
perm
)
=>
(
permObject
[
perm
.
feature
]
=
{
'ADMIN'
:
perm
.
admin
,
'USER'
:
perm
.
user
,
'INFO'
:
perm
.
info
}),
{})
as
Permissions
));
// currentUserObservable
Observable
.
create
()
this
.
currentuserObservable
=
this
.
http
.
get
<
EventUser
>
(
MOYA_REST_URL
+
"/v2/user/current"
).
pipe
(
share
());
// make subject to share the current user.
// This way we can later on update it to everyone who is listening this beautiful observable
this
.
currentuserSubject
=
new
BehaviorSubject
(
null
);
this
.
updateCurrentUser
();
}
...
...
@@ -75,12 +77,27 @@ export class SessionServiceService {
}
public
getCurrentUser
()
{
/**
* Returns observable with current user. If we are not logged in, current user is Anonymous.
*
* If there is any change of user status, new user is automatically pushed into this observable.
*/
public
getCurrentUser
():
Observable
<
EventUser
>
{
return
this
.
currentuserSubject
;
}
/**
* Request update of current user.
*
* This will push currently logged in user into currentUser -observable.
*/
public
updateCurrentUser
()
{
this
.
currentuserObservable
.
this
.
http
.
get
<
EventUser
>
(
MOYA_REST_URL
+
"/v2/user/current"
).
subscribe
(
(
currentUser
)
=>
{
this
.
currentuserSubject
.
next
(
currentUser
);
});
}
...
...
@@ -107,9 +124,11 @@ export class SessionServiceService {
apolloObservable
.
subscribe
((
x
)
=>
{
this
.
permissionsApollo
.
refetch
();
this
.
updateCurrentUser
();
});
return
apolloObservable
;
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment