Files
zitadel/console/src/app/modules/metadata/metadata-dialog/metadata-dialog.component.ts
T
05ad3b4ef0 feat(console): org metadata, mfa i18n, defer load of actions (#4471)
* user metadata refactor

* metadata module, set remove interface

* refresh list

* mfa, passwordless i18n

* i18n, metadata table

Co-authored-by: Livio Spring <[email protected]>
2022-10-04 05:44:43 +00:00

86 lines
2.3 KiB
TypeScript

import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { Buffer } from 'buffer';
import { Timestamp } from 'google-protobuf/google/protobuf/timestamp_pb';
import { Metadata } from 'src/app/proto/generated/zitadel/metadata_pb';
import { ManagementService } from 'src/app/services/mgmt.service';
import { ToastService } from 'src/app/services/toast.service';
@Component({
selector: 'cnsl-metadata-dialog',
templateUrl: './metadata-dialog.component.html',
styleUrls: ['./metadata-dialog.component.scss'],
})
export class MetadataDialogComponent {
public metadata: Partial<Metadata.AsObject>[] = [];
public loading: boolean = false;
public ts!: Timestamp.AsObject | undefined;
constructor(
private toast: ToastService,
public dialogRef: MatDialogRef<MetadataDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any,
) {
this.metadata = data.metadata;
}
public addEntry(): void {
const newGroup = {
key: '',
value: '',
};
this.metadata.push(newGroup);
}
public removeEntry(index: number): void {
const key = this.metadata[index].key;
if (key) {
this.removeMetadata(key).then(() => {
this.metadata.splice(index, 1);
if (this.metadata.length === 0) {
this.addEntry();
}
});
} else {
this.metadata.splice(index, 1);
}
}
public saveElement(index: number): void {
const metadataElement = this.metadata[index];
if (metadataElement.key && metadataElement.value) {
this.setMetadata(metadataElement.key, metadataElement.value as string);
}
}
public setMetadata(key: string, value: string): void {
if (key && value) {
this.data
.setFcn(key, value)
.then(() => {
this.toast.showInfo('METADATA.SETSUCCESS', true);
})
.catch((error: any) => {
this.toast.showError(error);
});
}
}
public removeMetadata(key: string): Promise<void> {
return this.data
.removeFcn(key)
.then((resp: any) => {
this.toast.showInfo('METADATA.REMOVESUCCESS', true);
})
.catch((error: any) => {
this.toast.showError(error);
});
}
closeDialog(): void {
this.dialogRef.close();
}
}