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.

28 lines
989 B

  1. <script lang="ts">
  2. import type { TaskResult } from "../models/task";
  3. import Progress from "./Progress.svelte";
  4. interface ProjectLike {
  5. tasks?: TaskResult[]
  6. statusTag?: string
  7. subtractAmount?: number,
  8. }
  9. export let project: ProjectLike;
  10. let progressAmount: number;
  11. let progressTarget: number;
  12. $: {
  13. progressAmount = (project.tasks||[]).map(t => (t.active || t.statusTag === "to do" || t.statusTag === "on hold")
  14. ? Math.min(t.completedAmount, t.itemAmount) * (t.item.groupWeight || 1)
  15. : t.itemAmount * (t.item.groupWeight || 1)
  16. ).reduce((n,m) => n+m, 0);
  17. progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
  18. progressAmount = Math.max(progressAmount - (project.subtractAmount||0), 0);
  19. progressTarget = Math.max(progressTarget - (project.subtractAmount||0), 0);
  20. }
  21. </script>
  22. <Progress thin contextColor count={progressAmount} target={progressTarget} />