Browse Source

Refactoring

pull/2487/head
Thomas 2 years ago
parent
commit
b41f7219b3
  1. 5
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts
  2. 1
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html
  3. 23
      libs/ui/src/lib/currency-selector/currency-selector.component.ts

5
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts

@ -31,7 +31,6 @@ import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces';
}) })
export class CreateOrUpdateAccountDialog implements OnDestroy { export class CreateOrUpdateAccountDialog implements OnDestroy {
public accountForm: FormGroup; public accountForm: FormGroup;
public accountCurrency: Currency;
public currencies: Currency[] = []; public currencies: Currency[] = [];
public filteredPlatforms: Observable<Platform[]>; public filteredPlatforms: Observable<Platform[]>;
public platforms: Platform[]; public platforms: Platform[];
@ -52,10 +51,6 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
label: currency, label: currency,
value: currency value: currency
})); }));
this.accountCurrency = {
label: this.data.account.currency,
value: this.data.account.currency
};
this.platforms = platforms; this.platforms = platforms;
this.accountForm = this.formBuilder.group({ this.accountForm = this.formBuilder.group({

1
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html

@ -23,7 +23,6 @@
<gf-currency-autocomplete <gf-currency-autocomplete
formControlName="currency" formControlName="currency"
[currencies]="currencies" [currencies]="currencies"
[defaultValue]="accountCurrency"
/> />
</mat-form-field> </mat-form-field>
</div> </div>

23
libs/ui/src/lib/currency-selector/currency-selector.component.ts

@ -9,7 +9,7 @@ import {
OnInit, OnInit,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { FormControl, NgControl } from '@angular/forms'; import { FormControl, FormGroupDirective, NgControl } from '@angular/forms';
import { import {
MatAutocomplete, MatAutocomplete,
MatAutocompleteSelectedEvent MatAutocompleteSelectedEvent
@ -42,7 +42,7 @@ export class CurrencySelectorComponent
implements OnInit, OnDestroy implements OnInit, OnDestroy
{ {
@Input() private currencies: Currency[] = []; @Input() private currencies: Currency[] = [];
@Input() defaultValue: Currency; @Input() private formControlName: string;
@ViewChild(MatInput, { static: false }) private input: MatInput; @ViewChild(MatInput, { static: false }) private input: MatInput;
@ -58,6 +58,7 @@ export class CurrencySelectorComponent
public readonly _elementRef: ElementRef, public readonly _elementRef: ElementRef,
public readonly _focusMonitor: FocusMonitor, public readonly _focusMonitor: FocusMonitor,
public readonly changeDetectorRef: ChangeDetectorRef, public readonly changeDetectorRef: ChangeDetectorRef,
private readonly formGroupDirective: FormGroupDirective,
public readonly ngControl: NgControl public readonly ngControl: NgControl
) { ) {
super(_elementRef, _focusMonitor, ngControl); super(_elementRef, _focusMonitor, ngControl);
@ -65,17 +66,23 @@ export class CurrencySelectorComponent
this.controlType = 'currency-autocomplete'; this.controlType = 'currency-autocomplete';
} }
public ngOnChanges() {
if (this.defaultValue) {
this.value = this.defaultValue;
}
}
public ngOnInit() { public ngOnInit() {
if (this.disabled) { if (this.disabled) {
this.control.disable(); this.control.disable();
} }
const formGroup = this.formGroupDirective.form;
if (formGroup) {
const control = formGroup.get(this.formControlName);
if (control) {
this.value = this.currencies.find(({ value }) => {
return value === control.value;
});
}
}
this.control.valueChanges this.control.valueChanges
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {

Loading…
Cancel
Save