Browse Source

review changes

- remove Platform interface and use existing one in prisma/client
- several small adjustments
- bugfix: on item select, check if value is string
pull/2429/head
Kevin Lien 2 years ago
committed by Thomas
parent
commit
d1ec42ed5b
  1. 37
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts
  2. 2
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html
  3. 2
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts
  4. 5
      apps/client/src/app/pages/accounts/create-or-update-account-dialog/interfaces/interfaces.ts

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

@ -18,10 +18,8 @@ import { DataService } from '@ghostfolio/client/services/data.service';
import { Observable, Subject } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import {
CreateOrUpdateAccountDialogParams,
Platform
} from './interfaces/interfaces';
import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces';
import { Platform } from '@prisma/client';
@Component({
host: { class: 'h-100' },
@ -33,8 +31,8 @@ import {
export class CreateOrUpdateAccountDialog implements OnDestroy {
public accountForm: FormGroup;
public currencies: string[] = [];
public platforms: Platform[];
public filteredPlatforms: Observable<Platform[]>;
public platforms: Platform[];
private unsubscribeSubject = new Subject<void>();
@ -49,7 +47,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
const { currencies, platforms } = this.dataService.fetchInfo();
this.currencies = currencies;
this.platforms = platforms;
this.platforms = platforms.map((platform) => {
return { ...platform, url: '' };
});
this.accountForm = this.formBuilder.group({
accountId: [{ disabled: true, value: this.data.account.id }],
@ -59,9 +59,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
isExcluded: [this.data.account.isExcluded],
name: [this.data.account.name, Validators.required],
platformId: [
this.platforms.find(
(platform) => platform.id === this.data.account.platformId
),
this.platforms.find(({ id }) => {
return id === this.data.account.platformId;
}),
this._autocompleteObjectValidator()
]
});
@ -106,22 +106,23 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
public autoCompleteCheck() {
const inputValue = this.accountForm.controls['platformId'].value;
const matchingEntry = this.platforms.find(
(platform) => platform.name === inputValue
);
this.accountForm.controls['platformId'].setValue(matchingEntry);
if (typeof inputValue === 'string') {
const matchingEntry = this.platforms.find(({ name }) => {
return name === inputValue;
});
this.accountForm.controls['platformId'].setValue(matchingEntry);
}
}
displayFn(platform: Platform) {
return platform && platform.name ? platform.name : '';
return platform?.name ? platform.name : '';
}
private _filter(value: string): Platform[] {
const filterValue = value.toLowerCase();
return this.platforms.filter((platformEntry) =>
platformEntry.name.toLowerCase().includes(filterValue)
);
return this.platforms.filter(({ name }) => {
return name.toLowerCase().includes(filterValue);
});
}
private _autocompleteObjectValidator(): ValidatorFn {

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

@ -56,7 +56,7 @@
*ngFor="let platformEntry of filteredPlatforms | async"
[value]="platformEntry"
>
{{platformEntry.name}}
{{ platformEntry.name }}
</mat-option>
</mat-autocomplete>
</mat-form-field>

2
apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.module.ts

@ -16,13 +16,13 @@ import { CreateOrUpdateAccountDialog } from './create-or-update-account-dialog.c
imports: [
CommonModule,
FormsModule,
MatAutocompleteModule,
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatAutocompleteModule,
ReactiveFormsModule
]
})

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

@ -3,8 +3,3 @@ import { Account } from '@prisma/client';
export interface CreateOrUpdateAccountDialogParams {
account: Account;
}
export interface Platform {
id: string;
name: string;
}

Loading…
Cancel
Save