Browse Source

add subtraction of progress from before project's startTime.

main
Gisle Aune 3 years ago
parent
commit
2807094971
  1. 6
      models/project.go
  2. 28
      services/loader.go
  3. 28
      svelte-ui/src/components/ItemProgress.svelte
  4. 5
      svelte-ui/src/components/ProgressNumbers.svelte
  5. 8
      svelte-ui/src/components/ProjectProgress.svelte
  6. 7
      svelte-ui/src/models/project.ts

6
models/project.go

@ -100,6 +100,12 @@ type ProjectUpdate struct {
type ProjectResult struct {
Project
Tasks []*TaskResult `json:"tasks"`
Subtractions []ProjectSubtraction `json:"subtractions"`
}
type ProjectSubtraction struct {
Item Item `json:"item"`
Amount int `json:"amount"`
}
type ProjectFilter struct {

28
services/loader.go

@ -234,7 +234,7 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes
if project.UserID != auth.UserID(ctx) {
return nil, slerrors.NotFound("Goal")
}
result := &models.ProjectResult{Project: *project}
result := &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}}
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
UserID: auth.UserID(ctx),
@ -301,10 +301,19 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes
}
for _, log := range result.Tasks[i].Logs {
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
continue
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{
Item: *result.Tasks[i].Item,
Amount: log.ItemAmount,
})
if log.SecondaryItemID != nil {
result.Subtractions = append(result.Subtractions, models.ProjectSubtraction{
Item: *log.SecondaryItem,
Amount: log.SecondaryItemAmount,
})
}
}
result.Tasks[i].CompletedAmount += log.Amount(result.Tasks[i].ItemID)
result.Tasks[i].CompletedAmount += log.Amount(log.ItemID)
}
}
@ -359,7 +368,7 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
results := make([]*models.ProjectResult, len(projects))
for i, project := range projects {
results[i] = &models.ProjectResult{Project: *project}
results[i] = &models.ProjectResult{Project: *project, Subtractions: []models.ProjectSubtraction{}}
results[i].Tasks = make([]*models.TaskResult, 0, 16)
for _, task := range tasks {
if task.ProjectID != project.ID {
@ -408,7 +417,16 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
}
for _, log := range taskResult.Logs {
if project.StartTime != nil && log.LoggedTime.Before(*project.StartTime) {
continue
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{
Item: *taskResult.Item,
Amount: log.ItemAmount,
})
if log.SecondaryItem != nil {
results[i].Subtractions = append(results[i].Subtractions, models.ProjectSubtraction{
Item: *log.SecondaryItem,
Amount: log.SecondaryItemAmount,
})
}
}
taskResult.CompletedAmount += log.Amount(taskResult.ItemID)

28
svelte-ui/src/components/ItemProgress.svelte

@ -9,6 +9,7 @@ import type { LogResult } from "../models/log";
amount: number
target: number
extras: number
subs: number
noTarget?: boolean
}
@ -26,7 +27,7 @@ import type { LogResult } from "../models/log";
for (const task of project.tasks) {
let entry = list.find(e => e.item.id === task.item.id);
if (entry == null) {
entry = {item: task.item, amount: 0, target: 0, extras: 0};
entry = {item: task.item, amount: 0, target: 0, extras: 0, subs: 0};
list.push(entry);
}
@ -47,7 +48,7 @@ import type { LogResult } from "../models/log";
if (log.secondaryItem != null) {
let entry = list.find(e => e.item.id === log.secondaryItemId);
if (entry == null) {
entry = {item: log.secondaryItem, amount: 0, target: 0, extras: 0};
entry = {item: log.secondaryItem, amount: 0, target: 0, extras: 0, subs: 0};
list.push(entry);
}
@ -55,6 +56,17 @@ import type { LogResult } from "../models/log";
}
}
}
for (const {item, amount} of project.subtractions) {
const entry = list.find(e => e.item.id === item.id);
if (entry == null) {
continue
}
entry.subs += amount;
entry.target -= amount;
entry.amount -= amount;
}
}
for (const log of logs) {
@ -67,7 +79,7 @@ import type { LogResult } from "../models/log";
if (item != null) {
let entry = list.find(e => e.item.id === item.id);
if (entry == null) {
entry = {item, amount: 0, target: 0, extras: 0, noTarget: true};
entry = {item, amount: 0, target: 0, extras: 0, noTarget: true, subs: 0};
list.push(entry);
}
@ -86,7 +98,7 @@ import type { LogResult } from "../models/log";
} else {
return b.target - a.target;
}
}).filter(l => l.extras > 0 || (l.target > 0 || l.noTarget));
}).filter(e => e.extras > 0 || (e.target > 0 || e.subs > 0 || e.noTarget));
}
</script>
@ -120,6 +132,11 @@ import type { LogResult } from "../models/log";
&times;{entry.extras}
</div>
{/if}
{#if entry.subs > 0}
<div class="subs" title="These items are from before the project's start time.">
–{entry.subs}
</div>
{/if}
</div>
{/each}
</div>
@ -166,4 +183,7 @@ import type { LogResult } from "../models/log";
div.ItemProgress div.entry .extras {
color: #484;
}
div.ItemProgress div.entry .subs {
color: #852a24;
}
</style>

5
svelte-ui/src/components/ProgressNumbers.svelte

@ -23,6 +23,11 @@
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
for (const {item, amount} of (project.subtractions||[])) {
progressAmount -= item.groupWeight * amount;
progressTarget -= item.groupWeight * amount;
}
progressAmount = Math.max(progressAmount - project.subtractAmount, 0);
progressTarget = Math.max(progressTarget - project.subtractAmount, 0);

8
svelte-ui/src/components/ProjectProgress.svelte

@ -1,4 +1,6 @@
<script lang="ts">
import type { ProjectSubtraction } from "../models/project";
import type { TaskResult } from "../models/task";
import Progress from "./Progress.svelte";
@ -6,6 +8,7 @@
tasks?: TaskResult[]
statusTag?: string
subtractAmount?: number,
subtractions?: ProjectSubtraction[]
}
export let project: ProjectLike;
@ -20,6 +23,11 @@
).reduce((n,m) => n+m, 0);
progressTarget = Math.max((project.tasks||[]).map(t => t.itemAmount * (t.item.groupWeight || 1)).reduce((n,m) => n+m, 0), 1);
for (const {item, amount} of (project.subtractions||[])) {
progressAmount -= item.groupWeight * amount;
progressTarget -= item.groupWeight * amount;
}
progressAmount = Math.max(progressAmount - (project.subtractAmount||0), 0);
progressTarget = Math.max(progressTarget - (project.subtractAmount||0), 0);
}

7
svelte-ui/src/models/project.ts

@ -1,4 +1,5 @@
import type { IconName } from "../external/icons";
import type Item from "./item";
import type { TaskResult } from "./task";
export default interface Project {
@ -19,6 +20,12 @@ export default interface Project {
export interface ProjectResult extends Project {
tasks: TaskResult[]
subtractions: ProjectSubtraction[]
}
export interface ProjectSubtraction {
item: Item
amount: number
}
export interface ProjectFilter {

Loading…
Cancel
Save