mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.7 KiB
101 lines
2.7 KiB
import { UpdateUserSettingDto } from '@ghostfolio/api/app/user/update-user-setting.dto';
|
|
import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface';
|
|
import {
|
|
PortfolioReportRule,
|
|
XRayRulesSettings
|
|
} from '@ghostfolio/common/interfaces';
|
|
|
|
import {
|
|
ChangeDetectionStrategy,
|
|
Component,
|
|
EventEmitter,
|
|
Input,
|
|
OnInit,
|
|
Output
|
|
} from '@angular/core';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { addIcons } from 'ionicons';
|
|
import {
|
|
checkmarkCircleOutline,
|
|
ellipsisHorizontal,
|
|
removeCircleOutline,
|
|
warningOutline
|
|
} from 'ionicons/icons';
|
|
import { DeviceDetectorService } from 'ngx-device-detector';
|
|
import { Subject, takeUntil } from 'rxjs';
|
|
|
|
import { IRuleSettingsDialogParams } from './rule-settings-dialog/interfaces/interfaces';
|
|
import { GfRuleSettingsDialogComponent } from './rule-settings-dialog/rule-settings-dialog.component';
|
|
|
|
@Component({
|
|
selector: 'gf-rule',
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
templateUrl: './rule.component.html',
|
|
styleUrls: ['./rule.component.scss'],
|
|
standalone: false
|
|
})
|
|
export class RuleComponent implements OnInit {
|
|
@Input() hasPermissionToUpdateUserSettings: boolean;
|
|
@Input() isLoading: boolean;
|
|
@Input() rule: PortfolioReportRule;
|
|
@Input() settings: XRayRulesSettings['AccountClusterRiskCurrentInvestment'];
|
|
|
|
@Output() ruleUpdated = new EventEmitter<UpdateUserSettingDto>();
|
|
|
|
private deviceType: string;
|
|
private unsubscribeSubject = new Subject<void>();
|
|
|
|
public constructor(
|
|
private deviceService: DeviceDetectorService,
|
|
private dialog: MatDialog
|
|
) {
|
|
addIcons({
|
|
checkmarkCircleOutline,
|
|
ellipsisHorizontal,
|
|
removeCircleOutline,
|
|
warningOutline
|
|
});
|
|
}
|
|
|
|
public ngOnInit() {
|
|
this.deviceType = this.deviceService.getDeviceInfo().deviceType;
|
|
}
|
|
|
|
public onCustomizeRule(rule: PortfolioReportRule) {
|
|
const dialogRef = this.dialog.open(GfRuleSettingsDialogComponent, {
|
|
data: {
|
|
rule,
|
|
settings: this.settings
|
|
} as IRuleSettingsDialogParams,
|
|
width: this.deviceType === 'mobile' ? '100vw' : '50rem'
|
|
});
|
|
|
|
dialogRef
|
|
.afterClosed()
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
.subscribe((settings: RuleSettings) => {
|
|
if (settings) {
|
|
this.ruleUpdated.emit({
|
|
xRayRules: {
|
|
[rule.key]: settings
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
public onUpdateRule(rule: PortfolioReportRule) {
|
|
const settings: UpdateUserSettingDto = {
|
|
xRayRules: {
|
|
[rule.key]: { isActive: !rule.isActive }
|
|
}
|
|
};
|
|
|
|
this.ruleUpdated.emit(settings);
|
|
}
|
|
|
|
public ngOnDestroy() {
|
|
this.unsubscribeSubject.next();
|
|
this.unsubscribeSubject.complete();
|
|
}
|
|
}
|
|
|