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 { Observable, Subject } from 'rxjs';
import { map, startWith } from 'rxjs/operators'; import { map, startWith } from 'rxjs/operators';
import { import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces';
CreateOrUpdateAccountDialogParams, import { Platform } from '@prisma/client';
Platform
} from './interfaces/interfaces';
@Component({ @Component({
host: { class: 'h-100' }, host: { class: 'h-100' },
@ -33,8 +31,8 @@ import {
export class CreateOrUpdateAccountDialog implements OnDestroy { export class CreateOrUpdateAccountDialog implements OnDestroy {
public accountForm: FormGroup; public accountForm: FormGroup;
public currencies: string[] = []; public currencies: string[] = [];
public platforms: Platform[];
public filteredPlatforms: Observable<Platform[]>; public filteredPlatforms: Observable<Platform[]>;
public platforms: Platform[];
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
@ -49,7 +47,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
const { currencies, platforms } = this.dataService.fetchInfo(); const { currencies, platforms } = this.dataService.fetchInfo();
this.currencies = currencies; this.currencies = currencies;
this.platforms = platforms; this.platforms = platforms.map((platform) => {
return { ...platform, url: '' };
});
this.accountForm = this.formBuilder.group({ this.accountForm = this.formBuilder.group({
accountId: [{ disabled: true, value: this.data.account.id }], accountId: [{ disabled: true, value: this.data.account.id }],
@ -59,9 +59,9 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
isExcluded: [this.data.account.isExcluded], isExcluded: [this.data.account.isExcluded],
name: [this.data.account.name, Validators.required], name: [this.data.account.name, Validators.required],
platformId: [ platformId: [
this.platforms.find( this.platforms.find(({ id }) => {
(platform) => platform.id === this.data.account.platformId return id === this.data.account.platformId;
), }),
this._autocompleteObjectValidator() this._autocompleteObjectValidator()
] ]
}); });
@ -106,22 +106,23 @@ export class CreateOrUpdateAccountDialog implements OnDestroy {
public autoCompleteCheck() { public autoCompleteCheck() {
const inputValue = this.accountForm.controls['platformId'].value; const inputValue = this.accountForm.controls['platformId'].value;
const matchingEntry = this.platforms.find( if (typeof inputValue === 'string') {
(platform) => platform.name === inputValue const matchingEntry = this.platforms.find(({ name }) => {
); return name === inputValue;
this.accountForm.controls['platformId'].setValue(matchingEntry); });
this.accountForm.controls['platformId'].setValue(matchingEntry);
}
} }
displayFn(platform: Platform) { displayFn(platform: Platform) {
return platform && platform.name ? platform.name : ''; return platform?.name ? platform.name : '';
} }
private _filter(value: string): Platform[] { private _filter(value: string): Platform[] {
const filterValue = value.toLowerCase(); const filterValue = value.toLowerCase();
return this.platforms.filter(({ name }) => {
return this.platforms.filter((platformEntry) => return name.toLowerCase().includes(filterValue);
platformEntry.name.toLowerCase().includes(filterValue) });
);
} }
private _autocompleteObjectValidator(): ValidatorFn { 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" *ngFor="let platformEntry of filteredPlatforms | async"
[value]="platformEntry" [value]="platformEntry"
> >
{{platformEntry.name}} {{ platformEntry.name }}
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </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: [ imports: [
CommonModule, CommonModule,
FormsModule, FormsModule,
MatAutocompleteModule,
MatButtonModule, MatButtonModule,
MatCheckboxModule, MatCheckboxModule,
MatDialogModule, MatDialogModule,
MatFormFieldModule, MatFormFieldModule,
MatInputModule, MatInputModule,
MatSelectModule, MatSelectModule,
MatAutocompleteModule,
ReactiveFormsModule 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 { export interface CreateOrUpdateAccountDialogParams {
account: Account; account: Account;
} }
export interface Platform {
id: string;
name: string;
}

Loading…
Cancel
Save