Commit 0d0c1d84 authored by Lukas Burgey's avatar Lukas Burgey

Make use of new rest interface

parent e4d11b39
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
</span> </span>
</div> </div>
<div [ngSwitch]="(deployment$ | async)?.state_target"> <div [ngSwitch]="(deployment$ | async)?.state_target">
<button *ngSwitchCase="'not_deployed'" (click)="changeDeployment('add')" mat-raised-button color="primary" matTooltip="Deploy credentials to these services"> <button *ngSwitchCase="'not_deployed'" (click)="changeDeployment('deployed')" mat-raised-button color="primary" matTooltip="Deploy credentials to these services">
Deploy my credentials Deploy my credentials
</button> </button>
<button *ngSwitchCase="'deployed'" (click)="changeDeployment('remove')" mat-raised-button color="primary" matTooltip="Remove credentials from these services"> <button *ngSwitchCase="'deployed'" (click)="changeDeployment('not_deployed')" mat-raised-button color="primary" matTooltip="Remove credentials from these services">
Remove my credentials Remove my credentials
</button> </button>
<button *ngSwitchDefault (click)="changeDeployment('add')" mat-raised-button color="primary" matTooltip="Deploy credentials these services"> <button *ngSwitchDefault (click)="changeDeployment('deployed')" mat-raised-button color="primary" matTooltip="Deploy credentials these services">
Deploy my credentials Deploy my credentials
</button> </button>
</div> </div>
...@@ -23,11 +23,14 @@ export class DeploymentActionRowComponent implements OnInit { ...@@ -23,11 +23,14 @@ export class DeploymentActionRowComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
public changeDeployment(action: string): void { public changeDeployment(stateTarget: string): void {
if (this.vo != undefined) { if (this.vo != undefined) {
this.userService.changeVODeployment(action, this.vo); this.userService.patchDeployment('vo', stateTarget, this.vo.id);
} else if (this.service != undefined) { return
this.userService.changeServiceDeployment(action, this.service); }
if (this.service != undefined) {
this.userService.patchDeployment('service', stateTarget, this.service.id);
return
} }
} }
} }
...@@ -31,11 +31,4 @@ export class ServiceComponent implements OnInit { ...@@ -31,11 +31,4 @@ export class ServiceComponent implements OnInit {
(dep: Deployment) => dep.service ? dep.service.id == this.service.id : false (dep: Deployment) => dep.service ? dep.service.id == this.service.id : false
); );
} }
ngOnDestroy() {
}
changeDeployment(action: string): void {
this.userService.changeServiceDeployment(action, this.service);
}
} }
...@@ -328,20 +328,6 @@ export class UserService { ...@@ -328,20 +328,6 @@ export class UserService {
); );
} }
public sentQuestionnaire(stateItemID: number, answers: JSONObject) {
return this.http.patch<DeploymentState>(
`/rest/dep-state?id=${ stateItemID }`,
{
'answers': answers,
},
).pipe(
catchError(this.handleError(true, "Error submitting answers")),
).subscribe(
(state: DeploymentState) => this.updateDeploymentState(state),
this.logErrorAndFetch,
);
}
public deleteUser() { public deleteUser() {
return this.http.delete('/rest/user').pipe( return this.http.delete('/rest/user').pipe(
catchError(this.handleError(true, "Error deleting user")), catchError(this.handleError(true, "Error deleting user")),
...@@ -355,7 +341,10 @@ export class UserService { ...@@ -355,7 +341,10 @@ export class UserService {
} }
public uploadSshKey(name: string, key: string | ArrayBuffer): void { public uploadSshKey(name: string, key: string | ArrayBuffer): void {
this.http.post<SSHKey>('/rest/ssh-keys', {'name': name, 'key': key}).pipe( this.http.post<SSHKey>(
'/rest/ssh-keys',
{'name': name, 'key': key},
).pipe(
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(newKey: SSHKey) => { (newKey: SSHKey) => {
...@@ -368,7 +357,9 @@ export class UserService { ...@@ -368,7 +357,9 @@ export class UserService {
public removeSshKey(key: SSHKey) { public removeSshKey(key: SSHKey) {
console.log('Deleting key:', key); console.log('Deleting key:', key);
return this.http.delete('/rest/ssh-key?id='+key.id.toString()).pipe( return this.http.delete(
`/rest/ssh-key/${ key.id.toString() }`,
).pipe(
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
_ => { _ => {
...@@ -379,27 +370,26 @@ export class UserService { ...@@ -379,27 +370,26 @@ export class UserService {
); );
} }
public changeVODeployment(action: string, vo: VO): void { public patchDeployment(depType: string, stateTarget: string, id: number): void {
const body = { this.http.patch<Deployment>(
'type': action, `/rest/deployment/${ depType }/${ id.toString() }`,
'vo': vo.id, {'state_target': stateTarget},
}; ).pipe(
this.http.post<Deployment>('/backend/api/deployments', body).pipe(
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(dep: Deployment) => this.updateDeployment(dep), (dep: Deployment) => this.updateDeployment(dep),
); );
} }
public changeServiceDeployment(action: string, service: Service): void { public sentQuestionnaire(stateItemID: number, answers: JSONObject) {
const body = { return this.http.patch<DeploymentState>(
'type': action, `/rest/state/${ stateItemID }`,
'service': service.id, {'answers': answers},
}; ).pipe(
this.http.post<Deployment>('/backend/api/deployments', body).pipe( catchError(this.handleError(true, "Error submitting answers")),
catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(dep: Deployment) => this.updateDeployment(dep), (state: DeploymentState) => this.updateDeploymentState(state),
this.logErrorAndFetch,
); );
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment