Browse Source

Improve usability

pull/1779/head
Thomas 3 years ago
parent
commit
ab7ced441b
  1. 10
      apps/client/src/app/pages/portfolio/fire/fire-page.component.ts
  2. 2
      apps/client/src/app/pages/portfolio/fire/fire-page.html
  3. 11
      libs/ui/src/lib/fire-calculator/fire-calculator.component.html
  4. 27
      libs/ui/src/lib/fire-calculator/fire-calculator.component.scss
  5. 51
      libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

10
apps/client/src/app/pages/portfolio/fire/fire-page.component.ts

@ -1,5 +1,6 @@
import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
import { UserService } from '@ghostfolio/client/services/user/user.service'; import { UserService } from '@ghostfolio/client/services/user/user.service';
import { PortfolioReportRule, User } from '@ghostfolio/common/interfaces'; import { PortfolioReportRule, User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { hasPermission, permissions } from '@ghostfolio/common/permissions';
@ -20,6 +21,7 @@ export class FirePageComponent implements OnDestroy, OnInit {
public deviceType: string; public deviceType: string;
public feeRules: PortfolioReportRule[]; public feeRules: PortfolioReportRule[];
public fireWealth: Big; public fireWealth: Big;
public hasImpersonationId: boolean;
public hasPermissionToCreateOrder: boolean; public hasPermissionToCreateOrder: boolean;
public hasPermissionToUpdateUserSettings: boolean; public hasPermissionToUpdateUserSettings: boolean;
public isLoading = false; public isLoading = false;
@ -33,6 +35,7 @@ export class FirePageComponent implements OnDestroy, OnInit {
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService, private dataService: DataService,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private impersonationStorageService: ImpersonationStorageService,
private userService: UserService private userService: UserService
) {} ) {}
@ -70,6 +73,13 @@ export class FirePageComponent implements OnDestroy, OnInit {
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
}); });
this.impersonationStorageService
.onChangeHasImpersonation()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((impersonationId) => {
this.hasImpersonationId = !!impersonationId;
});
this.userService.stateChanged this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((state) => { .subscribe((state) => {

2
apps/client/src/app/pages/portfolio/fire/fire-page.html

@ -16,7 +16,7 @@
[currency]="user?.settings?.baseCurrency" [currency]="user?.settings?.baseCurrency"
[deviceType]="deviceType" [deviceType]="deviceType"
[fireWealth]="fireWealth?.toNumber()" [fireWealth]="fireWealth?.toNumber()"
[hasPermissionToUpdateUserSettings]="hasPermissionToUpdateUserSettings" [hasPermissionToUpdateUserSettings]="!hasImpersonationId && hasPermissionToUpdateUserSettings"
[locale]="user?.settings?.locale" [locale]="user?.settings?.locale"
[projectedTotalAmount]="user?.settings?.projectedTotalAmount" [projectedTotalAmount]="user?.settings?.projectedTotalAmount"
[retirementDate]="user?.settings?.retirementDate" [retirementDate]="user?.settings?.retirementDate"

11
libs/ui/src/lib/fire-calculator/fire-calculator.component.html

@ -30,20 +30,27 @@
<mat-form-field appearance="outline" class="w-100"> <mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Retirement Date</mat-label> <mat-label i18n>Retirement Date</mat-label>
<div>
{{
calculatorForm.controls['retirementDate'].value
| date : 'MMMM YYYY'
}}
</div>
<input <input
class="d-none"
formControlName="retirementDate" formControlName="retirementDate"
matInput matInput
[matDatepicker]="datepicker" [matDatepicker]="datepicker"
/> />
<mat-datepicker-toggle <mat-datepicker-toggle
matIconSuffix matIconSuffix
[disabled]="false" [disabled]="hasPermissionToUpdateUserSettings !== true"
[for]="datepicker" [for]="datepicker"
></mat-datepicker-toggle> ></mat-datepicker-toggle>
<mat-datepicker <mat-datepicker
#datepicker #datepicker
startView="multi-year" startView="multi-year"
[disabled]="false" [disabled]="hasPermissionToUpdateUserSettings !== true"
(monthSelected)="setMonthAndYear($event, datepicker)" (monthSelected)="setMonthAndYear($event, datepicker)"
> >
</mat-datepicker> </mat-datepicker>

27
libs/ui/src/lib/fire-calculator/fire-calculator.component.scss

@ -8,4 +8,31 @@
height: 100%; height: 100%;
} }
} }
::ng-deep {
.mdc-text-field--disabled {
.mdc-floating-label,
.mdc-text-field__input {
color: inherit;
}
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
border-color: rgba(var(--dark-disabled-text));
}
}
}
}
:host-context(.is-dark-theme) {
::ng-deep {
.mdc-text-field--disabled {
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
border-color: rgba(var(--dark-disabled-text));
}
}
}
} }

51
libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

@ -1,7 +1,6 @@
import 'chartjs-adapter-date-fns'; import 'chartjs-adapter-date-fns';
import { import {
AfterViewInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
@ -49,9 +48,7 @@ import { FireCalculatorService } from './fire-calculator.service';
styleUrls: ['./fire-calculator.component.scss'], styleUrls: ['./fire-calculator.component.scss'],
templateUrl: './fire-calculator.component.html' templateUrl: './fire-calculator.component.html'
}) })
export class FireCalculatorComponent export class FireCalculatorComponent implements OnChanges, OnDestroy {
implements AfterViewInit, OnChanges, OnDestroy
{
@Input() annualInterestRate = 5; @Input() annualInterestRate = 5;
@Input() colorScheme: ColorScheme; @Input() colorScheme: ColorScheme;
@Input() currency: string; @Input() currency: string;
@ -145,47 +142,9 @@ export class FireCalculatorComponent
}); });
} }
public ngAfterViewInit() {
if (isNumber(this.fireWealth) && this.fireWealth >= 0) {
setTimeout(() => {
// Wait for the chartCanvas
this.calculatorForm.patchValue(
{
annualInterestRate: this.annualInterestRate,
paymentPerPeriod: this.getPMT(),
principalInvestmentAmount: this.getP(),
projectedTotalAmount:
Number(this.getProjectedTotalAmount().toFixed(0)) ?? 0,
retirementDate:
this.getRetirementDate() ?? this.DEFAULT_RETIREMENT_DATE
},
{
emitEvent: false
}
);
this.calculatorForm.get('principalInvestmentAmount').disable();
this.changeDetectorRef.markForCheck();
});
}
if (this.hasPermissionToUpdateUserSettings === true) {
this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false });
this.calculatorForm
.get('projectedTotalAmount')
.enable({ emitEvent: false });
} else {
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false });
this.calculatorForm
.get('projectedTotalAmount')
.disable({ emitEvent: false });
}
this.calculatorForm.get('retirementDate').disable({ emitEvent: false });
}
public ngOnChanges() { public ngOnChanges() {
this.periodsToRetire = this.getPeriodsToRetire(); this.periodsToRetire = this.getPeriodsToRetire();
if (isNumber(this.fireWealth) && this.fireWealth >= 0) { if (isNumber(this.fireWealth) && this.fireWealth >= 0) {
setTimeout(() => { setTimeout(() => {
// Wait for the chartCanvas // Wait for the chartCanvas
@ -210,11 +169,17 @@ export class FireCalculatorComponent
} }
if (this.hasPermissionToUpdateUserSettings === true) { if (this.hasPermissionToUpdateUserSettings === true) {
this.calculatorForm
.get('annualInterestRate')
.enable({ emitEvent: false });
this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false }); this.calculatorForm.get('paymentPerPeriod').enable({ emitEvent: false });
this.calculatorForm this.calculatorForm
.get('projectedTotalAmount') .get('projectedTotalAmount')
.enable({ emitEvent: false }); .enable({ emitEvent: false });
} else { } else {
this.calculatorForm
.get('annualInterestRate')
.disable({ emitEvent: false });
this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false }); this.calculatorForm.get('paymentPerPeriod').disable({ emitEvent: false });
this.calculatorForm this.calculatorForm
.get('projectedTotalAmount') .get('projectedTotalAmount')

Loading…
Cancel
Save