Browse Source

Refactoring

pull/4624/head
Thomas Kaul 4 months ago
parent
commit
97a2374eee
  1. 21
      apps/client/src/app/components/home-watchlist/home-watchlist.component.ts
  2. 6
      apps/client/src/app/components/home-watchlist/home-watchlist.html
  3. 15
      libs/ui/src/lib/benchmark/benchmark.component.html
  4. 10
      libs/ui/src/lib/benchmark/benchmark.component.ts

21
apps/client/src/app/components/home-watchlist/home-watchlist.component.ts

@ -94,20 +94,25 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit {
this.loadWatchlistData(); this.loadWatchlistData();
} }
public ngOnDestroy() { public onWatchlistItemDeleted({
this.unsubscribeSubject.next(); dataSource,
this.unsubscribeSubject.complete(); symbol
} }: AssetProfileIdentifier) {
public onWatchlistItemDeleted(item: AssetProfileIdentifier) {
this.dataService this.dataService
.deleteWatchlistItem(item) .deleteWatchlistItem({ dataSource, symbol })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe({ .subscribe({
next: () => this.loadWatchlistData() next: () => {
return this.loadWatchlistData();
}
}); });
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private loadWatchlistData() { private loadWatchlistData() {
this.dataService this.dataService
.fetchWatchlist() .fetchWatchlist()

6
apps/client/src/app/components/home-watchlist/home-watchlist.html

@ -12,12 +12,10 @@
<gf-benchmark <gf-benchmark
[benchmarks]="watchlist" [benchmarks]="watchlist"
[deviceType]="deviceType" [deviceType]="deviceType"
[hasPermissionToDeleteWatchlistItem]=" [hasPermissionToDeleteItem]="hasPermissionToDeleteWatchlistItem"
hasPermissionToDeleteWatchlistItem
"
[locale]="user?.settings?.locale || undefined" [locale]="user?.settings?.locale || undefined"
[user]="user" [user]="user"
(watchlistItemDeleted)="onWatchlistItemDeleted($event)" (itemDeleted)="onWatchlistItemDeleted($event)"
/> />
</div> </div>
</div> </div>

15
libs/ui/src/lib/benchmark/benchmark.component.html

@ -116,21 +116,26 @@
<ng-container matColumnDef="actions" stickyEnd> <ng-container matColumnDef="actions" stickyEnd>
<th *matHeaderCellDef class="px-1 text-center" mat-header-cell></th> <th *matHeaderCellDef class="px-1 text-center" mat-header-cell></th>
<td *matCellDef="let element" class="px-1 text-center" mat-cell> <td *matCellDef="let element" class="px-1 text-center" mat-cell>
@if (hasPermissionToDeleteWatchlistItem) { @if (hasPermissionToDeleteItem) {
<button <button
class="mx-1 no-min-width px-2" class="mx-1 no-min-width px-2"
mat-button mat-button
[matMenuTriggerFor]="watchlistItemMenu" [matMenuTriggerFor]="benchmarkMenu"
(click)="$event.stopPropagation()" (click)="$event.stopPropagation()"
> >
<ion-icon name="ellipsis-horizontal" /> <ion-icon name="ellipsis-horizontal" />
</button> </button>
} }
<mat-menu #watchlistItemMenu="matMenu" xPosition="before"> <mat-menu #benchmarkMenu="matMenu" xPosition="before">
<button <button
mat-menu-item mat-menu-item
[disabled]="!hasPermissionToDeleteWatchlistItem" [disabled]="!hasPermissionToDeleteItem"
(click)="onDeleteWatchlistItem(element)" (click)="
onDeleteItem({
dataSource: element.dataSource,
symbol: element.symbol
})
"
> >
<span class="align-items-center d-flex"> <span class="align-items-center d-flex">
<ion-icon class="mr-2" name="trash-outline" /> <ion-icon class="mr-2" name="trash-outline" />

10
libs/ui/src/lib/benchmark/benchmark.component.ts

@ -53,11 +53,11 @@ import { BenchmarkDetailDialogParams } from './benchmark-detail-dialog/interface
export class GfBenchmarkComponent implements OnChanges, OnDestroy { export class GfBenchmarkComponent implements OnChanges, OnDestroy {
@Input() benchmarks: Benchmark[]; @Input() benchmarks: Benchmark[];
@Input() deviceType: string; @Input() deviceType: string;
@Input() hasPermissionToDeleteWatchlistItem: boolean; @Input() hasPermissionToDeleteItem: boolean;
@Input() locale = getLocale(); @Input() locale = getLocale();
@Input() user: User; @Input() user: User;
@Output() watchlistItemDeleted = new EventEmitter<AssetProfileIdentifier>(); @Output() itemDeleted = new EventEmitter<AssetProfileIdentifier>();
public displayedColumns = [ public displayedColumns = [
'name', 'name',
@ -113,9 +113,11 @@ export class GfBenchmarkComponent implements OnChanges, OnDestroy {
} }
} }
public onDeleteWatchlistItem({ dataSource, symbol }: Benchmark) { public onDeleteItem({ dataSource, symbol }: AssetProfileIdentifier) {
this.notificationService.confirm({ this.notificationService.confirm({
confirmFn: () => this.watchlistItemDeleted.emit({ dataSource, symbol }), confirmFn: () => {
this.itemDeleted.emit({ dataSource, symbol });
},
confirmType: ConfirmationDialogType.Warn, confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this item?` title: $localize`Do you really want to delete this item?`
}); });

Loading…
Cancel
Save