diff --git a/models/log.go b/models/log.go index 800b85c..1809977 100644 --- a/models/log.go +++ b/models/log.go @@ -57,7 +57,7 @@ type LogUpdate struct { ItemAmount *int `json:"itemAmount"` SecondaryItemID *string `json:"secondaryItemId"` SecondaryItemAmount *int `json:"secondaryItemAmount"` - ClearSecondaryItem bool `json:"clearSecondaryItem"` + ClearSecondaryItem bool `json:"clearSecondaryItemId"` } type LogResult struct { diff --git a/services/loader.go b/services/loader.go index 0bad31d..802e878 100644 --- a/services/loader.go +++ b/services/loader.go @@ -246,7 +246,9 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes break } } - result.Tasks[i].CompletedAmount = len(result.Tasks[i].Logs) + for _, log := range result.Tasks[i].Logs { + result.Tasks[i].CompletedAmount += log.Amount(result.Tasks[i].ItemID) + } } return result, nil @@ -317,8 +319,9 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter) break } } - taskResult.CompletedAmount = len(taskResult.Logs) - + for _, log := range taskResult.Logs { + taskResult.CompletedAmount += log.Amount(taskResult.ItemID) + } results[i].Tasks = append(results[i].Tasks, taskResult) } } @@ -346,7 +349,9 @@ func (l *Loader) FindTask(ctx context.Context, id string) (*models.TaskResult, e return nil, err } - result.CompletedAmount = len(result.Logs) + for _, log := range result.Logs { + result.CompletedAmount += log.Amount(result.ItemID) + } return result, nil } @@ -421,7 +426,9 @@ func (l *Loader) ListTasks(ctx context.Context, filter models.TaskFilter) ([]*mo } } - result.CompletedAmount = len(result.Logs) + for _, log := range result.Logs { + result.CompletedAmount += log.Amount(result.ItemID) + } results = append(results, result) } diff --git a/svelte-ui/src/forms/LogForm.svelte b/svelte-ui/src/forms/LogForm.svelte index aecf6e7..8513c92 100644 --- a/svelte-ui/src/forms/LogForm.svelte +++ b/svelte-ui/src/forms/LogForm.svelte @@ -84,7 +84,7 @@ import ItemSelect from "../components/ItemSelect.svelte"; stuffLogClient.updateLog(log.id, { loggedTime: new Date(loggedTime).toISOString(), secondaryItemId: secondaryItemId || null, - clearSecondaryItemId: secondaryItemId == "", + clearSecondaryItemId: !secondaryItemId, description, itemAmount, secondaryItemAmount }).then(() => { markStale("project", "task", "goal", "log");