Browse Source

feat(lib): add actions column to benchmark

pull/4624/head
KenTandrian 4 months ago
parent
commit
62d8c99149
  1. 28
      libs/ui/src/lib/benchmark/benchmark.component.html
  2. 33
      libs/ui/src/lib/benchmark/benchmark.component.ts

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

@ -113,6 +113,34 @@
</td> </td>
</ng-container> </ng-container>
<ng-container matColumnDef="actions" stickyEnd>
<th *matHeaderCellDef class="px-1 text-center" mat-header-cell></th>
<td *matCellDef="let element" class="px-1 text-center" mat-cell>
@if (hasPermissionToDeleteWatchlistItem) {
<button
class="mx-1 no-min-width px-2"
mat-button
[matMenuTriggerFor]="watchlistItemMenu"
(click)="$event.stopPropagation()"
>
<ion-icon name="ellipsis-horizontal" />
</button>
}
<mat-menu #watchlistItemMenu="matMenu" xPosition="before">
<button
mat-menu-item
[disabled]="!hasPermissionToDeleteWatchlistItem"
(click)="onDeleteWatchlistItem(element)"
>
<span class="align-items-center d-flex">
<ion-icon class="mr-2" name="trash-outline" />
<span i18n>Delete</span>
</span>
</button>
</mat-menu>
</td>
</ng-container>
<tr *matHeaderRowDef="displayedColumns" mat-header-row></tr> <tr *matHeaderRowDef="displayedColumns" mat-header-row></tr>
<tr <tr
*matRowDef="let row; columns: displayedColumns" *matRowDef="let row; columns: displayedColumns"

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

@ -1,3 +1,5 @@
import { ConfirmationDialogType } from '@ghostfolio/client/core/notification/confirmation-dialog/confirmation-dialog.type';
import { NotificationService } from '@ghostfolio/client/core/notification/notification.service';
import { getLocale, resolveMarketCondition } from '@ghostfolio/common/helper'; import { getLocale, resolveMarketCondition } from '@ghostfolio/common/helper';
import { import {
AssetProfileIdentifier, AssetProfileIdentifier,
@ -13,11 +15,15 @@ import {
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
EventEmitter,
Input, Input,
OnChanges, OnChanges,
OnDestroy OnDestroy,
Output
} from '@angular/core'; } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatMenuModule } from '@angular/material/menu';
import { MatTableModule } from '@angular/material/table'; import { MatTableModule } from '@angular/material/table';
import { ActivatedRoute, Router, RouterModule } from '@angular/router'; import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
@ -33,6 +39,8 @@ import { BenchmarkDetailDialogParams } from './benchmark-detail-dialog/interface
CommonModule, CommonModule,
GfTrendIndicatorComponent, GfTrendIndicatorComponent,
GfValueComponent, GfValueComponent,
MatButtonModule,
MatMenuModule,
MatTableModule, MatTableModule,
NgxSkeletonLoaderModule, NgxSkeletonLoaderModule,
RouterModule RouterModule
@ -45,10 +53,19 @@ 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() locale = getLocale(); @Input() locale = getLocale();
@Input() user: User; @Input() user: User;
public displayedColumns = ['name', 'date', 'change', 'marketCondition']; @Output() watchlistItemDeleted = new EventEmitter<AssetProfileIdentifier>();
public displayedColumns = [
'name',
'date',
'change',
'marketCondition',
'actions'
];
public isLoading = true; public isLoading = true;
public isNumber = isNumber; public isNumber = isNumber;
public resolveMarketCondition = resolveMarketCondition; public resolveMarketCondition = resolveMarketCondition;
@ -58,6 +75,7 @@ export class GfBenchmarkComponent implements OnChanges, OnDestroy {
public constructor( public constructor(
private dialog: MatDialog, private dialog: MatDialog,
private notificationService: NotificationService,
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router private router: Router
) { ) {
@ -89,11 +107,20 @@ export class GfBenchmarkComponent implements OnChanges, OnDestroy {
'trend200d', 'trend200d',
'date', 'date',
'change', 'change',
'marketCondition' 'marketCondition',
'actions'
]; ];
} }
} }
public onDeleteWatchlistItem({ dataSource, symbol }: AssetProfileIdentifier) {
this.notificationService.confirm({
confirmFn: () => this.watchlistItemDeleted.emit({ dataSource, symbol }),
confirmType: ConfirmationDialogType.Warn,
title: $localize`Do you really want to delete this item?`
});
}
public onOpenBenchmarkDialog({ dataSource, symbol }: AssetProfileIdentifier) { public onOpenBenchmarkDialog({ dataSource, symbol }: AssetProfileIdentifier) {
this.router.navigate([], { this.router.navigate([], {
queryParams: { dataSource, symbol, benchmarkDetailDialog: true } queryParams: { dataSource, symbol, benchmarkDetailDialog: true }

Loading…
Cancel
Save