|
|
@ -1,4 +1,13 @@ |
|
|
|
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; |
|
|
|
import { CreatePlatformDto } from '@ghostfolio/api/app/platform/create-platform.dto'; |
|
|
|
import { validateObjectForForm } from '@ghostfolio/client/util/form.util'; |
|
|
|
|
|
|
|
import { |
|
|
|
ChangeDetectionStrategy, |
|
|
|
Component, |
|
|
|
Inject, |
|
|
|
OnDestroy |
|
|
|
} from '@angular/core'; |
|
|
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|
|
|
import { Subject } from 'rxjs'; |
|
|
|
|
|
|
@ -11,13 +20,38 @@ import { CreateOrUpdatePlatformDialogParams } from './interfaces/interfaces'; |
|
|
|
styleUrls: ['./create-or-update-platform-dialog.scss'], |
|
|
|
templateUrl: 'create-or-update-platform-dialog.html' |
|
|
|
}) |
|
|
|
export class CreateOrUpdatePlatformDialog { |
|
|
|
export class CreateOrUpdatePlatformDialog implements OnDestroy { |
|
|
|
public platformForm: FormGroup; |
|
|
|
private unsubscribeSubject = new Subject<void>(); |
|
|
|
|
|
|
|
public constructor( |
|
|
|
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdatePlatformDialogParams, |
|
|
|
public dialogRef: MatDialogRef<CreateOrUpdatePlatformDialog> |
|
|
|
) {} |
|
|
|
public dialogRef: MatDialogRef<CreateOrUpdatePlatformDialog>, |
|
|
|
private formBuilder: FormBuilder |
|
|
|
) { |
|
|
|
this.platformForm = this.formBuilder.group({ |
|
|
|
name: [this.data.platform.name, Validators.required], |
|
|
|
url: [this.data.platform.url, Validators.required] |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public async onSubmit() { |
|
|
|
try { |
|
|
|
const platform: CreatePlatformDto = { |
|
|
|
name: this.platformForm.get('name')?.value, |
|
|
|
url: this.platformForm.get('url')?.value |
|
|
|
}; |
|
|
|
|
|
|
|
await validateObjectForForm({ |
|
|
|
classDto: CreatePlatformDto, |
|
|
|
form: this.platformForm, |
|
|
|
object: platform |
|
|
|
}); |
|
|
|
this.dialogRef.close(platform); |
|
|
|
} catch (error) { |
|
|
|
console.error(error); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public onCancel() { |
|
|
|
this.dialogRef.close(); |
|
|
|