src/app/features/dashboard-widgets/progress-dashboard-widget/progress-dashboard/progress-dashboard-config.ts
import { Entity } from "../../../../core/entity/model/entity";
import { DatabaseEntity } from "../../../../core/entity/database-entity.decorator";
import { DatabaseField } from "../../../../core/entity/database-field.decorator";

@DatabaseEntity("ProgressDashboardConfig")
export class ProgressDashboardConfig extends Entity {
  static override isInternalEntity = true;

  @DatabaseField() title: string = $localize`Progress Widget`;
  @DatabaseField({ isArray: true }) parts: Array<ProgressDashboardPart> = [];

  getTotalPercentage() {
    const currentTotal = this.parts.reduce(
      (acc, entry) => acc + entry.currentValue,
      0,
    );
    const targetTotal = this.parts.reduce(
      (acc, entry) => acc + entry.targetValue,
      0,
    );
    return currentTotal / targetTotal;
  }
}

export interface ProgressDashboardPart {
  label: string;
  currentValue: number;
  targetValue: number;
}

results matching ""

    No results matching ""