Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalWebpage
Commits
4d2987ed
Commit
4d2987ed
authored
Nov 29, 2018
by
Lukas Burgey
Browse files
Change the way updates are received
parent
f4622c00
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/app/types/types.module.ts
View file @
4d2987ed
...
...
@@ -114,6 +114,7 @@ export interface State {
export
interface
Update
{
deployment
?:
Deployment
;
deployment_state
?:
DeploymentState
;
error
?:
string
;
}
...
...
src/app/user.service.ts
View file @
4d2987ed
...
...
@@ -11,7 +11,7 @@ import { SnackBarService } from './snackbar.service';
import
{
IdpService
}
from
'
./idp.service
'
;
import
{
VO
,
User
,
Update
,
State
,
Deployment
,
DeploymentState
,
SSHKey
,
NewSSHKey
,
IdP
,
Service
VO
,
User
,
Update
,
State
,
Deployment
,
DeploymentState
,
SSHKey
,
NewSSHKey
,
IdP
,
Service
,
Site
}
from
'
./types/types.module
'
;
...
...
@@ -26,6 +26,9 @@ export class UserService {
private
sshKeys
:
SSHKey
[]
=
new
Array
<
SSHKey
>
();
private
sshKeys$
=
new
BehaviorSubject
<
SSHKey
[]
>
([]);
private
deploymentStates
:
Map
<
number
,
DeploymentState
>
=
new
Map
([]);
private
deploymentStates$
=
new
BehaviorSubject
<
DeploymentState
[]
>
([]);
private
deployments
:
Map
<
number
,
Deployment
>
=
new
Map
([]);
private
deployments$
=
new
BehaviorSubject
<
Deployment
[]
>
([]);
...
...
@@ -75,7 +78,6 @@ export class UserService {
this
.
snackBar
.
open
(
'
Logged in
'
);
}
if
(
newUser
.
id
)
{
this
.
connectLiveUpdates
(
newUser
.
id
);
}
...
...
@@ -92,6 +94,13 @@ export class UserService {
this
.
deployments$
.
next
(
Array
.
from
(
this
.
deployments
.
values
()));
}
if
(
newUser
.
states
)
{
newUser
.
states
.
forEach
((
state
:
DeploymentState
)
=>
{
this
.
deploymentStates
.
set
(
state
.
id
,
state
)
});
this
.
deploymentStates$
.
next
(
Array
.
from
(
this
.
deploymentStates
.
values
()));
}
this
.
loggedIn
=
true
;
this
.
initialized
=
true
;
}
...
...
@@ -103,9 +112,8 @@ export class UserService {
private
connectLiveUpdates
(
userID
:
number
):
void
{
// handle with care
let
login
=
userID
let
passcode
=
this
.
cookieService
.
get
(
'
sessionid
'
);
const
login
=
userID
const
passcode
=
this
.
cookieService
.
get
(
'
sessionid
'
);
const
stompConfig
:
StompConfig
=
{
// Which server?
url
:
'
wss://
'
+
window
.
location
.
host
+
'
/ws
'
,
...
...
@@ -129,10 +137,11 @@ export class UserService {
// Will log diagnostics on console
debug
:
false
,
};
this
.
stompService
.
config
=
stompConfig
;
this
.
stompService
.
initAndConnect
();
le
t
subscription
=
this
.
stompService
.
subscribe
(
cons
t
subscription
=
this
.
stompService
.
subscribe
(
'
/exchange/users/
'
+
userID
.
toString
()
);
...
...
@@ -145,6 +154,10 @@ export class UserService {
this
.
snackBar
.
open
(
update
.
error
);
}
if
(
update
.
deployment_state
)
{
this
.
updateDeploymentState
(
update
.
deployment_state
);
}
if
(
update
.
deployment
)
{
this
.
updateDeployment
(
update
.
deployment
);
}
...
...
@@ -154,12 +167,21 @@ export class UserService {
}
private
updateDeployment
(
dep
:
Deployment
):
void
{
if
(
dep
)
{
if
(
dep
!=
undefined
&&
dep
!=
null
)
{
dep
.
states
.
forEach
((
state
:
DeploymentState
)
=>
this
.
updateDeploymentState
(
state
),
);
this
.
deployments
.
set
(
dep
.
id
,
dep
);
this
.
deployments$
.
next
(
Array
.
from
(
this
.
deployments
.
values
()));
}
}
private
updateDeploymentState
(
ds
:
DeploymentState
):
void
{
if
(
ds
!=
undefined
&&
ds
!=
null
)
{
this
.
deploymentStates
.
set
(
ds
.
id
,
ds
);
this
.
deploymentStates$
.
next
(
Array
.
from
(
this
.
deploymentStates
.
values
()));
}
}
private
updateState
(
update
:
State
):
void
{
if
(
update
)
{
// report an occured error
...
...
@@ -289,13 +311,15 @@ export class UserService {
);
}
public
changeDeployment
(
action
:
string
,
vo
:
VO
):
Observable
<
Deployment
>
{
public
changeDeployment
(
action
:
string
,
vo
:
VO
):
void
{
const
body
=
{
'
type
'
:
action
,
'
vo
'
:
vo
.
id
,
};
return
this
.
http
.
post
<
Deployment
>
(
'
/backend/api/deployments
'
,
body
).
pipe
(
this
.
http
.
post
<
Deployment
>
(
'
/backend/api/deployments
'
,
body
).
pipe
(
catchError
(
this
.
catchError
(
true
,
"
Error changing deployment
"
)),
).
subscribe
(
(
dep
:
Deployment
)
=>
this
.
updateDeployment
(
dep
),
);
}
...
...
@@ -317,6 +341,18 @@ export class UserService {
return
this
.
deployments$
.
asObservable
();
}
public
subscribeDeploymentStates
():
Observable
<
DeploymentState
[]
>
{
return
this
.
deploymentStates$
.
asObservable
();
}
public
subscribeStateFor
(
site
:
Site
,
service
:
Service
):
Observable
<
DeploymentState
>
{
return
this
.
deploymentStates$
.
asObservable
().
pipe
(
map
((
states
:
DeploymentState
[])
=>
states
.
find
(
(
dsi
:
DeploymentState
)
=>
dsi
.
site
.
id
==
site
.
id
&&
dsi
.
service
.
id
==
service
.
id
,
)),
);
}
public
subscribeVOs
():
Observable
<
VO
[]
>
{
let
voSelector
=
(
user
:
User
)
=>
user
?
user
.
vos
:
[];
return
this
.
subscribeSpecific
<
VO
[]
>
(
voSelector
);
...
...
@@ -343,9 +379,4 @@ export class UserService {
),
);
}
public
subscribeDeploymentStates
():
Observable
<
DeploymentState
[]
>
{
let
statesSelector
=
(
user
:
User
)
=>
user
?
user
.
states
:
[];
return
this
.
subscribeSpecific
<
DeploymentState
[]
>
(
statesSelector
);
}
}
src/app/vo-data/vo-data.component.ts
View file @
4d2987ed
...
...
@@ -25,7 +25,6 @@ export class VoDataComponent implements OnInit {
private
sites$
=
new
BehaviorSubject
<
Site
[]
>
([]);
public
sites$$
:
Observable
<
Site
[]
>
;
private
deployment$
=
<
BehaviorSubject
<
Deployment
>>
new
BehaviorSubject
(
undefined
);
public
deployment$$
:
Observable
<
Deployment
>
;
constructor
(
...
...
@@ -58,23 +57,15 @@ export class VoDataComponent implements OnInit {
this
.
sites$
.
next
(
uniqueSites
);
}
);
this
.
userService
.
subscribeVODeployment
(
this
.
vo
).
subscribe
(
(
dep
:
Deployment
)
=>
{
if
(
dep
){
this
.
deployment$
.
next
(
dep
);
}
}
);
this
.
services$$
=
this
.
services$
.
asObservable
();
this
.
sites$$
=
this
.
sites$
.
asObservable
();
this
.
deployment$$
=
this
.
deployment$
.
asObservable
(
);
this
.
deployment$$
=
this
.
userService
.
subscribeVODeployment
(
this
.
vo
);
}
ngOnDestroy
():
void
{
this
.
services$
.
complete
();
this
.
sites$
.
complete
();
this
.
deployment$
.
complete
();
}
public
servicesAtSite
(
site
:
Site
):
Observable
<
Service
[]
>
{
...
...
@@ -88,18 +79,10 @@ export class VoDataComponent implements OnInit {
}
public
subscribeStateItem
(
site
:
Site
,
service
:
Service
):
Observable
<
DeploymentState
>
{
return
this
.
userService
.
subscribeDeploymentStates
().
pipe
(
map
((
states
:
DeploymentState
[])
=>
states
.
find
(
(
dsi
:
DeploymentState
)
=>
dsi
.
site
.
id
==
site
.
id
&&
dsi
.
service
.
id
==
service
.
id
,
)),
);
return
this
.
userService
.
subscribeStateFor
(
site
,
service
);
}
public
changeDeployment
(
action
:
string
):
void
{
this
.
userService
.
changeDeployment
(
action
,
this
.
vo
).
subscribe
(
(
dep
:
Deployment
)
=>
{
this
.
deployment$
.
next
(
dep
);
}
);
this
.
userService
.
changeDeployment
(
action
,
this
.
vo
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment