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 {
public accountForm: FormGroup;
public accountCurrency: Currency;
public currencies: Currency[] = [];
public filteredPlatforms: Observable<Platform[]>;
public platforms: Platform[];
@ -52,10 +51,6 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
label: currency,
value: currency
}));
this.accountCurrency = {
label: this.data.account.currency,
value: this.data.account.currency
};
this.platforms = platforms;
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
formControlName="currency"
[currencies]="currencies"
[defaultValue]="accountCurrency"
/>
</mat-form-field>
</div>

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

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

Loading…
Cancel
Save