mirror of https://github.com/ghostfolio/ghostfolio
				
				
			
				 15 changed files with 10 additions and 196 deletions
			
			
		@ -1,45 +0,0 @@ | 
				
			|||
<ng-container *ngIf="value || value === 0 || value === null"> | 
				
			|||
  <div | 
				
			|||
    class="d-flex" | 
				
			|||
    [ngClass]="position === 'end' ? 'justify-content-end' : ''" | 
				
			|||
  > | 
				
			|||
    <ng-container *ngIf="isNumber || value === null"> | 
				
			|||
      <div *ngIf="colorizeSign && value > 0" class="mr-1 text-success">+</div> | 
				
			|||
      <div *ngIf="colorizeSign && value < 0" class="mr-1 text-danger">-</div> | 
				
			|||
      <div *ngIf="isPercent" [ngClass]="size === 'medium' ? 'h4 mb-0' : ''"> | 
				
			|||
        {{ formattedValue }}% | 
				
			|||
      </div> | 
				
			|||
      <div *ngIf="!isPercent" [ngClass]="size === 'medium' ? 'h4 mb-0' : ''"> | 
				
			|||
        <ng-container *ngIf="value === null"> | 
				
			|||
          <span class="text-monospace text-muted">***</span> | 
				
			|||
        </ng-container> | 
				
			|||
        <ng-container *ngIf="value !== null"> | 
				
			|||
          {{ formattedValue }} | 
				
			|||
        </ng-container> | 
				
			|||
      </div> | 
				
			|||
      <small *ngIf="currency && size === 'medium'" class="ml-1"> | 
				
			|||
        {{ currency }} | 
				
			|||
      </small> | 
				
			|||
      <div *ngIf="currency && size !== 'medium'" class="ml-1"> | 
				
			|||
        {{ currency }} | 
				
			|||
      </div> | 
				
			|||
    </ng-container> | 
				
			|||
    <ng-container *ngIf="isDate"> | 
				
			|||
      <div [ngClass]="size === 'medium' ? 'h4 mb-0' : ''"> | 
				
			|||
        {{ formattedDate }} | 
				
			|||
      </div> | 
				
			|||
    </ng-container> | 
				
			|||
  </div> | 
				
			|||
  <small *ngIf="label"> | 
				
			|||
    {{ label }} | 
				
			|||
  </small> | 
				
			|||
</ng-container> | 
				
			|||
 | 
				
			|||
<ngx-skeleton-loader | 
				
			|||
  *ngIf="value === undefined" | 
				
			|||
  animation="pulse" | 
				
			|||
  [theme]="{ | 
				
			|||
    height: '1.5rem', | 
				
			|||
    width: '5rem' | 
				
			|||
  }" | 
				
			|||
></ngx-skeleton-loader> | 
				
			|||
@ -1,5 +0,0 @@ | 
				
			|||
:host { | 
				
			|||
  display: flex; | 
				
			|||
  flex-direction: column; | 
				
			|||
  font-variant-numeric: tabular-nums; | 
				
			|||
} | 
				
			|||
@ -1,111 +0,0 @@ | 
				
			|||
import { | 
				
			|||
  ChangeDetectionStrategy, | 
				
			|||
  Component, | 
				
			|||
  Input, | 
				
			|||
  OnChanges, | 
				
			|||
  OnInit | 
				
			|||
} from '@angular/core'; | 
				
			|||
import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config'; | 
				
			|||
import { format, isDate } from 'date-fns'; | 
				
			|||
import { isNumber } from 'lodash'; | 
				
			|||
 | 
				
			|||
@Component({ | 
				
			|||
  selector: 'gf-value', | 
				
			|||
  changeDetection: ChangeDetectionStrategy.OnPush, | 
				
			|||
  templateUrl: './value.component.html', | 
				
			|||
  styleUrls: ['./value.component.scss'] | 
				
			|||
}) | 
				
			|||
export class ValueComponent implements OnChanges, OnInit { | 
				
			|||
  @Input() colorizeSign: boolean; | 
				
			|||
  @Input() currency: string; | 
				
			|||
  @Input() isCurrency: boolean; | 
				
			|||
  @Input() isInteger: boolean; | 
				
			|||
  @Input() isPercent: boolean; | 
				
			|||
  @Input() label: string; | 
				
			|||
  @Input() locale: string; | 
				
			|||
  @Input() position: string; | 
				
			|||
  @Input() size: string; | 
				
			|||
  @Input() value: number | string; | 
				
			|||
 | 
				
			|||
  public absoluteValue: number; | 
				
			|||
  public formattedDate: string; | 
				
			|||
  public formattedValue: string; | 
				
			|||
  public isDate: boolean; | 
				
			|||
  public isNumber: boolean; | 
				
			|||
  public useAbsoluteValue = false; | 
				
			|||
 | 
				
			|||
  public constructor() {} | 
				
			|||
 | 
				
			|||
  public ngOnInit() {} | 
				
			|||
 | 
				
			|||
  public ngOnChanges() { | 
				
			|||
    if (this.value || this.value === 0) { | 
				
			|||
      if (isNumber(this.value)) { | 
				
			|||
        this.isDate = false; | 
				
			|||
        this.isNumber = true; | 
				
			|||
        this.absoluteValue = Math.abs(<number>this.value); | 
				
			|||
 | 
				
			|||
        if (this.colorizeSign) { | 
				
			|||
          this.useAbsoluteValue = true; | 
				
			|||
          if (this.currency || this.isCurrency) { | 
				
			|||
            try { | 
				
			|||
              this.formattedValue = this.absoluteValue.toLocaleString( | 
				
			|||
                this.locale, | 
				
			|||
                { | 
				
			|||
                  maximumFractionDigits: 2, | 
				
			|||
                  minimumFractionDigits: 2 | 
				
			|||
                } | 
				
			|||
              ); | 
				
			|||
            } catch {} | 
				
			|||
          } else if (this.isPercent) { | 
				
			|||
            try { | 
				
			|||
              this.formattedValue = (this.absoluteValue * 100).toLocaleString( | 
				
			|||
                this.locale, | 
				
			|||
                { | 
				
			|||
                  maximumFractionDigits: 2, | 
				
			|||
                  minimumFractionDigits: 2 | 
				
			|||
                } | 
				
			|||
              ); | 
				
			|||
            } catch {} | 
				
			|||
          } | 
				
			|||
        } else if (this.isPercent) { | 
				
			|||
          try { | 
				
			|||
            this.formattedValue = (this.value * 100).toLocaleString( | 
				
			|||
              this.locale, | 
				
			|||
              { | 
				
			|||
                maximumFractionDigits: 2, | 
				
			|||
                minimumFractionDigits: 2 | 
				
			|||
              } | 
				
			|||
            ); | 
				
			|||
          } catch {} | 
				
			|||
        } else if (this.currency || this.isCurrency) { | 
				
			|||
          try { | 
				
			|||
            this.formattedValue = this.value?.toLocaleString(this.locale, { | 
				
			|||
              maximumFractionDigits: 2, | 
				
			|||
              minimumFractionDigits: 2 | 
				
			|||
            }); | 
				
			|||
          } catch {} | 
				
			|||
        } else if (this.isInteger) { | 
				
			|||
          try { | 
				
			|||
            this.formattedValue = this.value?.toLocaleString(this.locale, { | 
				
			|||
              maximumFractionDigits: 0, | 
				
			|||
              minimumFractionDigits: 0 | 
				
			|||
            }); | 
				
			|||
          } catch {} | 
				
			|||
        } | 
				
			|||
      } else { | 
				
			|||
        try { | 
				
			|||
          if (isDate(new Date(this.value))) { | 
				
			|||
            this.isDate = true; | 
				
			|||
            this.isNumber = false; | 
				
			|||
 | 
				
			|||
            this.formattedDate = format( | 
				
			|||
              new Date(<string>this.value), | 
				
			|||
              DEFAULT_DATE_FORMAT | 
				
			|||
            ); | 
				
			|||
          } | 
				
			|||
        } catch {} | 
				
			|||
      } | 
				
			|||
    } | 
				
			|||
  } | 
				
			|||
} | 
				
			|||
@ -1,13 +0,0 @@ | 
				
			|||
import { CommonModule } from '@angular/common'; | 
				
			|||
import { NgModule } from '@angular/core'; | 
				
			|||
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; | 
				
			|||
 | 
				
			|||
import { ValueComponent } from './value.component'; | 
				
			|||
 | 
				
			|||
@NgModule({ | 
				
			|||
  declarations: [ValueComponent], | 
				
			|||
  exports: [ValueComponent], | 
				
			|||
  imports: [CommonModule, NgxSkeletonLoaderModule], | 
				
			|||
  providers: [] | 
				
			|||
}) | 
				
			|||
export class GfValueModule {} | 
				
			|||
@ -1 +1 @@ | 
				
			|||
export * from './lib/ui.module'; | 
				
			|||
export * from './lib/value/value.module'; | 
				
			|||
 | 
				
			|||
@ -1,12 +0,0 @@ | 
				
			|||
import { CommonModule } from '@angular/common'; | 
				
			|||
import { NgModule } from '@angular/core'; | 
				
			|||
 | 
				
			|||
import { ValueComponent } from './value/value.component'; | 
				
			|||
// import { GfValueModule } from './value/value.module';
 | 
				
			|||
 | 
				
			|||
@NgModule({ | 
				
			|||
  imports: [CommonModule /*, GfValueModule*/], | 
				
			|||
  declarations: [ValueComponent], | 
				
			|||
  exports: [ValueComponent] | 
				
			|||
}) | 
				
			|||
export class UiModule {} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue