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.
		
		
		
		
		
			
		
			
				
					
					
						
							107 lines
						
					
					
						
							2.8 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							107 lines
						
					
					
						
							2.8 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 {
							 | 
						|
								  addCircleOutline,
							 | 
						|
								  checkmarkCircleOutline,
							 | 
						|
								  ellipsisHorizontal,
							 | 
						|
								  optionsOutline,
							 | 
						|
								  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() categoryName: string;
							 | 
						|
								  @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({
							 | 
						|
								      addCircleOutline,
							 | 
						|
								      checkmarkCircleOutline,
							 | 
						|
								      ellipsisHorizontal,
							 | 
						|
								      optionsOutline,
							 | 
						|
								      removeCircleOutline,
							 | 
						|
								      warningOutline
							 | 
						|
								    });
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  public ngOnInit() {
							 | 
						|
								    this.deviceType = this.deviceService.getDeviceInfo().deviceType;
							 | 
						|
								  }
							 | 
						|
								
							 | 
						|
								  public onCustomizeRule(rule: PortfolioReportRule) {
							 | 
						|
								    const dialogRef = this.dialog.open(GfRuleSettingsDialogComponent, {
							 | 
						|
								      data: {
							 | 
						|
								        rule,
							 | 
						|
								        categoryName: this.categoryName,
							 | 
						|
								        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();
							 | 
						|
								  }
							 | 
						|
								}
							 | 
						|
								
							 |