fix: refresh idp list on delete, add (#2596)

This commit is contained in:
Max Peintner
2021-11-09 11:35:59 +01:00
committed by GitHub
parent 685ffc5dc7
commit b1ef990785

View File

@@ -23,30 +23,24 @@ export class LoginPolicyIdpsComponent implements OnInit {
public IDPStylingType: any = IDPStylingType; public IDPStylingType: any = IDPStylingType;
constructor( constructor(private toast: ToastService, private dialog: MatDialog) {}
private toast: ToastService,
private dialog: MatDialog,
) { }
ngOnInit(): void { ngOnInit(): void {
this.getIdps().then(resp => { this.getIdps().then((resp) => {
this.idps = resp; this.idps = resp;
console.log(this.idps);
}); });
} }
private async getIdps(): Promise<IDPLoginPolicyLink.AsObject[]> { private async getIdps(): Promise<IDPLoginPolicyLink.AsObject[]> {
switch (this.serviceType) { switch (this.serviceType) {
case PolicyComponentServiceType.MGMT: case PolicyComponentServiceType.MGMT:
return (this.service as ManagementService).listLoginPolicyIDPs() return (this.service as ManagementService).listLoginPolicyIDPs().then((resp) => {
.then((resp) => { return resp.resultList;
return resp.resultList; });
});
case PolicyComponentServiceType.ADMIN: case PolicyComponentServiceType.ADMIN:
return (this.service as AdminService).listLoginPolicyIDPs() return (this.service as AdminService).listLoginPolicyIDPs().then((providers) => {
.then((providers) => { return providers.resultList;
return providers.resultList; });
});
} }
} }
@@ -67,16 +61,20 @@ export class LoginPolicyIdpsComponent implements OnInit {
width: '400px', width: '400px',
}); });
dialogRef.afterClosed().subscribe(resp => { dialogRef.afterClosed().subscribe((resp) => {
if (resp && resp.idp && resp.type) { if (resp && resp.idp && resp.type) {
this.addIdp(resp.idp, resp.type).then(() => { this.addIdp(resp.idp, resp.type)
this.loading = true; .then(() => {
setTimeout(() => { this.loading = true;
this.getIdps(); setTimeout(() => {
}, 1000); this.getIdps().then((resp) => {
}).catch(error => { this.idps = resp;
this.toast.showError(error); });
}); }, 1000);
})
.catch((error) => {
this.toast.showError(error);
});
} }
}); });
} }
@@ -84,24 +82,28 @@ export class LoginPolicyIdpsComponent implements OnInit {
public removeIdp(idp: IDPLoginPolicyLink.AsObject): void { public removeIdp(idp: IDPLoginPolicyLink.AsObject): void {
switch (this.serviceType) { switch (this.serviceType) {
case PolicyComponentServiceType.MGMT: case PolicyComponentServiceType.MGMT:
(this.service as ManagementService).removeIDPFromLoginPolicy(idp.idpId).then(() => { (this.service as ManagementService).removeIDPFromLoginPolicy(idp.idpId).then(
const index = this.idps.findIndex(temp => temp === idp); () => {
if (index > -1) { this.getIdps().then((resp) => {
this.idps.splice(index, 1); this.idps = resp;
} });
}, error => { },
this.toast.showError(error); (error) => {
}); this.toast.showError(error);
},
);
break; break;
case PolicyComponentServiceType.ADMIN: case PolicyComponentServiceType.ADMIN:
(this.service as AdminService).removeIDPFromLoginPolicy(idp.idpId).then(() => { (this.service as AdminService).removeIDPFromLoginPolicy(idp.idpId).then(
const index = this.idps.findIndex(temp => temp === idp); () => {
if (index > -1) { this.getIdps().then((resp) => {
this.idps.splice(index, 1); this.idps = resp;
} });
}, error => { },
this.toast.showError(error); (error) => {
}); this.toast.showError(error);
},
);
break; break;
} }
} }