Feature/Add date range selector to assistant (#2905)

* Add date range selector including WTD and MTD to assistant

* Update changelog
This commit is contained in:
Cédric Meuter 2024-01-23 11:57:37 +01:00 committed by GitHub
parent 5c23ece62c
commit a5ed49fe4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 14 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Extended the date range support by week to date (`WTD`) and month to date (`MTD`) in the portfolio service - Extended the date range support by week to date (`WTD`) and month to date (`MTD`) in the assistant (experimental)
- Added `healthcheck` for the _Ghostfolio_ service to the `docker-compose` files (`docker-compose.yml` and `docker-compose.build.yml`) - Added `healthcheck` for the _Ghostfolio_ service to the `docker-compose` files (`docker-compose.yml` and `docker-compose.build.yml`)
### Changed ### Changed

View File

@ -1654,19 +1654,22 @@ export class PortfolioService {
case 'mtd': case 'mtd':
portfolioStart = max([ portfolioStart = max([
portfolioStart, portfolioStart,
startOfMonth(new Date().setHours(0, 0, 0, 0)) subDays(startOfMonth(new Date().setHours(0, 0, 0, 0)), 1)
]); ]);
break; break;
case 'wtd': case 'wtd':
portfolioStart = max([ portfolioStart = max([
portfolioStart, portfolioStart,
startOfWeek(new Date().setHours(0, 0, 0, 0), { weekStartsOn: 1 }) subDays(
startOfWeek(new Date().setHours(0, 0, 0, 0), { weekStartsOn: 1 }),
1
)
]); ]);
break; break;
case 'ytd': case 'ytd':
portfolioStart = max([ portfolioStart = max([
portfolioStart, portfolioStart,
startOfYear(new Date().setHours(0, 0, 0, 0)) subDays(startOfYear(new Date().setHours(0, 0, 0, 0)), 1)
]); ]);
break; break;
case '1y': case '1y':
@ -1682,6 +1685,7 @@ export class PortfolioService {
]); ]);
break; break;
} }
return portfolioStart; return portfolioStart;
} }

View File

@ -17,7 +17,6 @@ import {
} from '@angular/core'; } from '@angular/core';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { MatMenuTrigger } from '@angular/material/menu'; import { MatMenuTrigger } from '@angular/material/menu';
import { ToggleComponent } from '@ghostfolio/client/components/toggle/toggle.component';
import { AdminService } from '@ghostfolio/client/services/admin.service'; import { AdminService } from '@ghostfolio/client/services/admin.service';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { User } from '@ghostfolio/common/interfaces'; import { User } from '@ghostfolio/common/interfaces';
@ -92,7 +91,25 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit {
public static readonly SEARCH_RESULTS_DEFAULT_LIMIT = 5; public static readonly SEARCH_RESULTS_DEFAULT_LIMIT = 5;
public dateRangeOptions = ToggleComponent.DEFAULT_DATE_RANGE_OPTIONS; public dateRangeFormControl = new FormControl<string>(undefined);
public readonly dateRangeOptions = [
{ label: $localize`Today`, value: '1d' },
{
label: $localize`Week to date` + ' (' + $localize`WTD` + ')',
value: 'wtd'
},
{
label: $localize`Month to date` + ' (' + $localize`MTD` + ')',
value: 'mtd'
},
{
label: $localize`Year to date` + ' (' + $localize`YTD` + ')',
value: 'ytd'
},
{ label: $localize`1Y`, value: '1y' },
{ label: $localize`5Y`, value: '5y' },
{ label: $localize`Max`, value: 'max' }
];
public isLoading = false; public isLoading = false;
public isOpen = false; public isOpen = false;
public placeholder = $localize`Find holding...`; public placeholder = $localize`Find holding...`;
@ -163,6 +180,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit {
} }
public ngOnChanges() { public ngOnChanges() {
this.dateRangeFormControl.setValue(this.user?.settings?.dateRange ?? null);
this.tagsFormControl.setValue( this.tagsFormControl.setValue(
this.user?.settings?.['filters.tags']?.[0] ?? null this.user?.settings?.['filters.tags']?.[0] ?? null
); );

View File

@ -102,12 +102,17 @@
>Date Range</span >Date Range</span
></ng-template ></ng-template
> >
<div class="d-flex justify-content-center py-3"> <div class="p-3">
<gf-toggle <mat-form-field appearance="outline" class="w-100 without-hint">
[defaultValue]="user?.settings?.dateRange" <mat-select
[options]="dateRangeOptions" [formControl]="dateRangeFormControl"
(change)="onChangeDateRange($event.value)" (selectionChange)="onChangeDateRange($event.value)"
></gf-toggle> >
@for (range of dateRangeOptions; track range) {
<mat-option [value]="range.value">{{ range.label }}</mat-option>
}
</mat-select>
</mat-form-field>
</div> </div>
</mat-tab> </mat-tab>
<mat-tab> <mat-tab>

View File

@ -2,10 +2,11 @@ import { CommonModule } from '@angular/common';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatRadioModule } from '@angular/material/radio'; import { MatRadioModule } from '@angular/material/radio';
import { MatSelectModule } from '@angular/material/select';
import { MatTabsModule } from '@angular/material/tabs'; import { MatTabsModule } from '@angular/material/tabs';
import { RouterModule } from '@angular/router'; import { RouterModule } from '@angular/router';
import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { GfAssistantListItemModule } from './assistant-list-item/assistant-list-item.module'; import { GfAssistantListItemModule } from './assistant-list-item/assistant-list-item.module';
@ -18,9 +19,10 @@ import { AssistantComponent } from './assistant.component';
CommonModule, CommonModule,
FormsModule, FormsModule,
GfAssistantListItemModule, GfAssistantListItemModule,
GfToggleModule,
MatButtonModule, MatButtonModule,
MatFormFieldModule,
MatRadioModule, MatRadioModule,
MatSelectModule,
MatTabsModule, MatTabsModule,
NgxSkeletonLoaderModule, NgxSkeletonLoaderModule,
ReactiveFormsModule, ReactiveFormsModule,