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

Make use of new rest interface

parent e4d11b39
......@@ -7,13 +7,13 @@
</span>
</div>
<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
</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
</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
</button>
</div>
......@@ -23,11 +23,14 @@ export class DeploymentActionRowComponent implements OnInit {
ngOnInit() {
}
public changeDeployment(action: string): void {
public changeDeployment(stateTarget: string): void {
if (this.vo != undefined) {
this.userService.changeVODeployment(action, this.vo);
} else if (this.service != undefined) {
this.userService.changeServiceDeployment(action, this.service);
this.userService.patchDeployment('vo', stateTarget, this.vo.id);
return
}
if (this.service != undefined) {
this.userService.patchDeployment('service', stateTarget, this.service.id);
return
}
}
}
......@@ -31,11 +31,4 @@ export class ServiceComponent implements OnInit {
(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 {
);
}
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() {
return this.http.delete('/rest/user').pipe(
catchError(this.handleError(true, "Error deleting user")),
......@@ -355,7 +341,10 @@ export class UserService {
}
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")),
).subscribe(
(newKey: SSHKey) => {
......@@ -368,7 +357,9 @@ export class UserService {
public removeSshKey(key: SSHKey) {
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")),
).subscribe(
_ => {
......@@ -379,27 +370,26 @@ export class UserService {
);
}
public changeVODeployment(action: string, vo: VO): void {
const body = {
'type': action,
'vo': vo.id,
};
this.http.post<Deployment>('/backend/api/deployments', body).pipe(
public patchDeployment(depType: string, stateTarget: string, id: number): void {
this.http.patch<Deployment>(
`/rest/deployment/${ depType }/${ id.toString() }`,
{'state_target': stateTarget},
).pipe(
catchError(this.handleError(true, "Error changing deployment")),
).subscribe(
(dep: Deployment) => this.updateDeployment(dep),
);
}
public changeServiceDeployment(action: string, service: Service): void {
const body = {
'type': action,
'service': service.id,
};
this.http.post<Deployment>('/backend/api/deployments', body).pipe(
catchError(this.handleError(true, "Error changing deployment")),
public sentQuestionnaire(stateItemID: number, answers: JSONObject) {
return this.http.patch<DeploymentState>(
`/rest/state/${ stateItemID }`,
{'answers': answers},
).pipe(
catchError(this.handleError(true, "Error submitting answers")),
).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