mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
28 changed files with 451 additions and 114 deletions
@ -0,0 +1,79 @@ |
|||||
|
import { Rule } from '@ghostfolio/api/models/rule'; |
||||
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; |
||||
|
import { UserSettings } from '@ghostfolio/common/interfaces'; |
||||
|
|
||||
|
import { Settings } from './interfaces/rule-settings.interface'; |
||||
|
|
||||
|
export class RegionalMarketClusterRiskEmergingMarkets extends Rule<Settings> { |
||||
|
private currentValueInBaseCurrency: number; |
||||
|
private emergingMarketsValueInBaseCurrency: number; |
||||
|
|
||||
|
public constructor( |
||||
|
protected exchangeRateDataService: ExchangeRateDataService, |
||||
|
currentValueInBaseCurrency: number, |
||||
|
emergingMarketsValueInBaseCurrency: number |
||||
|
) { |
||||
|
super(exchangeRateDataService, { |
||||
|
key: RegionalMarketClusterRiskEmergingMarkets.name, |
||||
|
name: 'Emerging Markets' |
||||
|
}); |
||||
|
|
||||
|
this.currentValueInBaseCurrency = currentValueInBaseCurrency; |
||||
|
this.emergingMarketsValueInBaseCurrency = |
||||
|
emergingMarketsValueInBaseCurrency; |
||||
|
} |
||||
|
|
||||
|
public evaluate(ruleSettings: Settings) { |
||||
|
const emergingMarketsValueRatio = this.currentValueInBaseCurrency |
||||
|
? this.emergingMarketsValueInBaseCurrency / |
||||
|
this.currentValueInBaseCurrency |
||||
|
: 0; |
||||
|
|
||||
|
if (emergingMarketsValueRatio > ruleSettings.thresholdMax) { |
||||
|
return { |
||||
|
evaluation: `The Emerging Markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) exceeds ${( |
||||
|
ruleSettings.thresholdMax * 100 |
||||
|
).toPrecision(3)}%`,
|
||||
|
value: false |
||||
|
}; |
||||
|
} else if (emergingMarketsValueRatio < ruleSettings.thresholdMin) { |
||||
|
return { |
||||
|
evaluation: `The Emerging Markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) is below ${( |
||||
|
ruleSettings.thresholdMin * 100 |
||||
|
).toPrecision(3)}%`,
|
||||
|
value: false |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
evaluation: `The Emerging Markets contribution of your current investment (${(emergingMarketsValueRatio * 100).toPrecision(3)}%) is within the range of ${( |
||||
|
ruleSettings.thresholdMin * 100 |
||||
|
).toPrecision( |
||||
|
3 |
||||
|
)}% and ${(ruleSettings.thresholdMax * 100).toPrecision(3)}%`,
|
||||
|
value: true |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public getConfiguration() { |
||||
|
return { |
||||
|
threshold: { |
||||
|
max: 1, |
||||
|
min: 0, |
||||
|
step: 0.01, |
||||
|
unit: '%' |
||||
|
}, |
||||
|
thresholdMax: true, |
||||
|
thresholdMin: true |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public getSettings({ baseCurrency, xRayRules }: UserSettings): Settings { |
||||
|
return { |
||||
|
baseCurrency, |
||||
|
isActive: xRayRules?.[this.getKey()]?.isActive ?? true, |
||||
|
thresholdMax: xRayRules?.[this.getKey()]?.thresholdMax ?? 0.12, |
||||
|
thresholdMin: xRayRules?.[this.getKey()]?.thresholdMin ?? 0.08 |
||||
|
}; |
||||
|
} |
||||
|
} |
@ -1 +0,0 @@ |
|||||
// import '!style-loader!css-loader!sass-loader!../../../apps/client/src/styles.scss';
|
|
@ -1,32 +1,60 @@ |
|||||
<mat-form-field appearance="outline" class="w-100 without-hint"> |
<div class="row"> |
||||
<mat-label i18n>Tags</mat-label> |
<div class="col"> |
||||
<mat-chip-grid #tagsChipList> |
@if (readonly) { |
||||
@for (tag of tagsSelected(); track tag.id) { |
<div class="h5" i18n>Tags</div> |
||||
<mat-chip-row |
@if (tags?.length > 0) { |
||||
matChipRemove |
<mat-chip-listbox> |
||||
[removable]="true" |
@for (tag of tags; track tag) { |
||||
(removed)="onRemoveTag(tag)" |
<mat-chip-option disabled>{{ tag.name }}</mat-chip-option> |
||||
> |
} |
||||
{{ tag.name }} |
</mat-chip-listbox> |
||||
<ion-icon matChipTrailingIcon name="close-outline" /> |
} @else { |
||||
</mat-chip-row> |
<div>-</div> |
||||
|
} |
||||
|
} @else { |
||||
|
<mat-form-field appearance="outline" class="w-100 without-hint"> |
||||
|
<mat-label i18n>Tags</mat-label> |
||||
|
<mat-chip-grid #tagsChipList> |
||||
|
@for (tag of tagsSelected(); track tag.id) { |
||||
|
<mat-chip-row |
||||
|
matChipRemove |
||||
|
[removable]="true" |
||||
|
(removed)="onRemoveTag(tag)" |
||||
|
> |
||||
|
{{ tag.name }} |
||||
|
<ion-icon matChipTrailingIcon name="close-outline" /> |
||||
|
</mat-chip-row> |
||||
|
} |
||||
|
<input |
||||
|
#tagInput |
||||
|
[formControl]="tagInputControl" |
||||
|
[matAutocomplete]="autocompleteTags" |
||||
|
[matChipInputFor]="tagsChipList" |
||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" |
||||
|
/> |
||||
|
</mat-chip-grid> |
||||
|
<mat-autocomplete |
||||
|
#autocompleteTags="matAutocomplete" |
||||
|
(optionSelected)="onAddTag($event)" |
||||
|
> |
||||
|
@for (tag of filteredOptions | async; track tag.id) { |
||||
|
<mat-option [value]="tag.id"> |
||||
|
{{ tag.name }} |
||||
|
</mat-option> |
||||
|
} |
||||
|
|
||||
|
@if (hasPermissionToCreateTags && tagInputControl.value) { |
||||
|
<mat-option [value]="tagInputControl.value.trim()"> |
||||
|
<span class="align-items-center d-flex"> |
||||
|
<ion-icon class="mr-2" name="add-circle-outline" /> |
||||
|
<ng-container i18n>Create</ng-container> "{{ |
||||
|
tagInputControl.value.trim() |
||||
|
}}" |
||||
|
</span> |
||||
|
</mat-option> |
||||
|
} |
||||
|
</mat-autocomplete> |
||||
|
</mat-form-field> |
||||
} |
} |
||||
<input |
</div> |
||||
#tagInput |
</div> |
||||
[formControl]="tagInputControl" |
|
||||
[matAutocomplete]="autocompleteTags" |
|
||||
[matChipInputFor]="tagsChipList" |
|
||||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" |
|
||||
/> |
|
||||
</mat-chip-grid> |
|
||||
<mat-autocomplete |
|
||||
#autocompleteTags="matAutocomplete" |
|
||||
(optionSelected)="onAddTag($event)" |
|
||||
> |
|
||||
@for (tag of filteredOptions | async; track tag.id) { |
|
||||
<mat-option [value]="tag.id"> |
|
||||
{{ tag.name }} |
|
||||
</mat-option> |
|
||||
} |
|
||||
</mat-autocomplete> |
|
||||
</mat-form-field> |
|
||||
|
@ -0,0 +1,95 @@ |
|||||
|
import { CommonModule } from '@angular/common'; |
||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
||||
|
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular'; |
||||
|
|
||||
|
import { GfTagsSelectorComponent } from './tags-selector.component'; |
||||
|
|
||||
|
export default { |
||||
|
title: 'Tags Selector', |
||||
|
component: GfTagsSelectorComponent, |
||||
|
decorators: [ |
||||
|
moduleMetadata({ |
||||
|
imports: [CommonModule, NoopAnimationsModule] |
||||
|
}) |
||||
|
] |
||||
|
} as Meta<GfTagsSelectorComponent>; |
||||
|
|
||||
|
type Story = StoryObj<GfTagsSelectorComponent>; |
||||
|
|
||||
|
const OPTIONS = [ |
||||
|
{ |
||||
|
id: '3ef7e6d9-4598-4eb2-b0e8-00e61cfc0ea6', |
||||
|
name: 'Gambling', |
||||
|
userId: 'c6a71541-d0e3-4e22-ae83-b5e5611b6695' |
||||
|
}, |
||||
|
{ |
||||
|
id: 'EMERGENCY_FUND', |
||||
|
name: 'Emergency Fund', |
||||
|
userId: null |
||||
|
}, |
||||
|
{ |
||||
|
id: 'RETIREMENT_FUND', |
||||
|
name: 'Retirement Fund', |
||||
|
userId: null |
||||
|
} |
||||
|
]; |
||||
|
|
||||
|
export const Default: Story = { |
||||
|
args: { |
||||
|
tags: [ |
||||
|
{ |
||||
|
id: 'EMERGENCY_FUND', |
||||
|
name: 'Emergency Fund', |
||||
|
userId: null |
||||
|
} |
||||
|
], |
||||
|
tagsAvailable: OPTIONS |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export const CreateCustomTags: Story = { |
||||
|
args: { |
||||
|
hasPermissionToCreateTags: true, |
||||
|
tags: [ |
||||
|
{ |
||||
|
id: 'EMERGENCY_FUND', |
||||
|
name: 'Emergency Fund', |
||||
|
userId: null |
||||
|
} |
||||
|
], |
||||
|
tagsAvailable: OPTIONS |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export const Readonly: Story = { |
||||
|
args: { |
||||
|
readonly: true, |
||||
|
tags: [ |
||||
|
{ |
||||
|
id: 'EMERGENCY_FUND', |
||||
|
name: 'Emergency Fund', |
||||
|
userId: null |
||||
|
}, |
||||
|
{ |
||||
|
id: 'RETIREMENT_FUND', |
||||
|
name: 'Retirement Fund', |
||||
|
userId: null |
||||
|
} |
||||
|
], |
||||
|
tagsAvailable: OPTIONS |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export const WithoutValue: Story = { |
||||
|
args: { |
||||
|
tags: [], |
||||
|
tagsAvailable: OPTIONS |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
export const WithoutOptions: Story = { |
||||
|
args: { |
||||
|
tags: [], |
||||
|
tagsAvailable: [] |
||||
|
} |
||||
|
}; |
Loading…
Reference in new issue