Browse Source

Add unit to value component

pull/2042/head
Thomas 2 years ago
parent
commit
ffdb76bbb6
  1. 10
      apps/api/src/app/portfolio/portfolio.controller.ts
  2. 24
      apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts
  3. 4
      apps/client/src/app/pages/portfolio/analysis/analysis-page.html
  4. 2
      libs/ui/src/lib/i18n.ts
  5. 6
      libs/ui/src/lib/value/value.component.html
  6. 1
      libs/ui/src/lib/value/value.component.ts

10
apps/api/src/app/portfolio/portfolio.controller.ts

@ -280,7 +280,10 @@ export class PortfolioController {
investment: item.investment / maxInvestment investment: item.investment / maxInvestment
})); }));
streaks = nullifyValuesInObject(streaks, ['current', 'longest']); streaks = nullifyValuesInObject(streaks, [
'currentStreak',
'longestStreak'
]);
} }
if ( if (
@ -291,7 +294,10 @@ export class PortfolioController {
return nullifyValuesInObject(item, ['investment']); return nullifyValuesInObject(item, ['investment']);
}); });
streaks = nullifyValuesInObject(streaks, ['current', 'longest']); streaks = nullifyValuesInObject(streaks, [
'currentStreak',
'longestStreak'
]);
} }
return { investments, streaks }; return { investments, streaks };

24
apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts

@ -60,9 +60,9 @@ export class AnalysisPageComponent implements OnDestroy, OnInit {
public placeholder = ''; public placeholder = '';
public portfolioEvolutionDataLabel = $localize`Deposit`; public portfolioEvolutionDataLabel = $localize`Deposit`;
public streaks: PortfolioInvestments['streaks']; public streaks: PortfolioInvestments['streaks'];
public subLabelCurrentStreak: string;
public subLabelLongestStreak: string;
public top3: Position[]; public top3: Position[];
public unitCurrentStreak: string;
public unitLongestStreak: string;
public user: User; public user: User;
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
@ -249,14 +249,22 @@ export class AnalysisPageComponent implements OnDestroy, OnInit {
.subscribe(({ investments, streaks }) => { .subscribe(({ investments, streaks }) => {
this.investmentsByGroup = investments; this.investmentsByGroup = investments;
this.streaks = streaks; this.streaks = streaks;
this.subLabelCurrentStreak = this.unitCurrentStreak =
this.mode === 'year' this.mode === 'year'
? `(${translate('YEARS')})` ? this.streaks.currentStreak === 1
: `(${translate('MONTHS')})`; ? translate('YEAR')
this.subLabelLongestStreak = : translate('YEARS')
: this.streaks.currentStreak === 1
? translate('MONTH')
: translate('MONTHS');
this.unitLongestStreak =
this.mode === 'year' this.mode === 'year'
? `(${translate('YEARS')})` ? this.streaks.longestStreak === 1
: `(${translate('MONTHS')})`; ? translate('YEAR')
: translate('YEARS')
: this.streaks.longestStreak === 1
? translate('MONTH')
: translate('MONTHS');
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });

4
apps/client/src/app/pages/portfolio/analysis/analysis-page.html

@ -182,7 +182,7 @@
<gf-value <gf-value
i18n i18n
size="large" size="large"
[subLabel]="subLabelCurrentStreak" [unit]="unitCurrentStreak"
[value]="streaks?.currentStreak" [value]="streaks?.currentStreak"
>Current Streak</gf-value >Current Streak</gf-value
> >
@ -191,7 +191,7 @@
<gf-value <gf-value
i18n i18n
size="large" size="large"
[subLabel]="subLabelLongestStreak" [unit]="unitLongestStreak"
[value]="streaks?.longestStreak" [value]="streaks?.longestStreak"
>Longest Streak</gf-value >Longest Streak</gf-value
> >

2
libs/ui/src/lib/i18n.ts

@ -13,6 +13,7 @@ const locales = {
HIGHER_RISK: $localize`Higher Risk`, HIGHER_RISK: $localize`Higher Risk`,
IMPORT_ACTIVITY_ERROR_IS_DUPLICATE: $localize`This activity already exists.`, IMPORT_ACTIVITY_ERROR_IS_DUPLICATE: $localize`This activity already exists.`,
LOWER_RISK: $localize`Lower Risk`, LOWER_RISK: $localize`Lower Risk`,
MONTH: $localize`Month`,
MONTHS: $localize`Months`, MONTHS: $localize`Months`,
OTHER: $localize`Other`, OTHER: $localize`Other`,
RETIREMENT_PROVISION: $localize`Retirement Provision`, RETIREMENT_PROVISION: $localize`Retirement Provision`,
@ -20,6 +21,7 @@ const locales = {
SECURITIES: $localize`Securities`, SECURITIES: $localize`Securities`,
SYMBOL: $localize`Symbol`, SYMBOL: $localize`Symbol`,
TAG: $localize`Tag`, TAG: $localize`Tag`,
YEAR: $localize`Year`,
YEARS: $localize`Years`, YEARS: $localize`Years`,
// enum AssetClass // enum AssetClass

6
libs/ui/src/lib/value/value.component.html

@ -35,9 +35,15 @@
<small *ngIf="currency && size === 'medium'" class="ml-1"> <small *ngIf="currency && size === 'medium'" class="ml-1">
{{ currency }} {{ currency }}
</small> </small>
<small *ngIf="unit && size === 'medium'" class="ml-1">
{{ unit }}
</small>
<div *ngIf="currency && size !== 'medium'" class="ml-1"> <div *ngIf="currency && size !== 'medium'" class="ml-1">
{{ currency }} {{ currency }}
</div> </div>
<div *ngIf="unit && size !== 'medium'" class="ml-1">
{{ unit }}
</div>
</ng-container> </ng-container>
<ng-container *ngIf="isString"> <ng-container *ngIf="isString">
<div <div

1
libs/ui/src/lib/value/value.component.ts

@ -26,6 +26,7 @@ export class ValueComponent implements OnChanges {
@Input() precision: number | undefined; @Input() precision: number | undefined;
@Input() size: 'large' | 'medium' | 'small' = 'small'; @Input() size: 'large' | 'medium' | 'small' = 'small';
@Input() subLabel = ''; @Input() subLabel = '';
@Input() unit = '';
@Input() value: number | string = ''; @Input() value: number | string = '';
public absoluteValue = 0; public absoluteValue = 0;

Loading…
Cancel
Save