add task and item filters to goals.
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-01-19 22:12:10 +01:00
parent 99cc6fac3c
commit a187e91c3c
8 changed files with 122 additions and 21 deletions
+21 -5
View File
@@ -535,11 +535,12 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
}
// Apply logs
result.Logs = make([]*models.LogResult, 0, len(logs))
result.Logs = make([]*models.GoalResultLog, 0, len(logs))
for _, log := range logs {
resultLog := &models.LogResult{
Log: *log,
resultLog := &models.GoalResultLog{
LogResult: models.LogResult{Log: *log},
}
contributes := false
for _, task := range tasks {
if task.ID == log.TaskID {
@@ -550,7 +551,7 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
for _, item := range result.Items {
amount := log.Amount(item.ID)
if amount > 0 && (goal.ItemID == nil || *goal.ItemID == item.ID) {
if amount > 0 && goal.Accepts(&item.Item, resultLog.Task) {
item.CompletedAmount += amount
if goal.Unweighted {
@@ -558,21 +559,36 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
} else {
result.CompletedAmount += amount * item.GroupWeight
}
contributes = true
} else {
amount = 0
}
if item.ID == log.ItemID {
resultLog.Item = &item.Item
if amount > 0 {
resultLog.ItemCounted = true
}
if log.SecondaryItemID == nil {
break
}
}
if log.SecondaryItemID != nil && item.ID == *log.SecondaryItemID {
if amount > 0 {
resultLog.SecondaryItemCounted = true
}
resultLog.SecondaryItem = &item.Item
}
}
result.Logs = append(result.Logs, resultLog)
if contributes {
result.Logs = append(result.Logs, resultLog)
}
}
}