|
@ -126,7 +126,20 @@ func (l *Loader) FindLog(ctx context.Context, id string) (*models.LogResult, err |
|
|
Task: nil, |
|
|
Task: nil, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
result.Task, _ = l.DB.Tasks().Find(ctx, id) |
|
|
|
|
|
|
|
|
task, err := l.DB.Tasks().Find(ctx, id) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
project, err := l.DB.Projects().Find(ctx, id) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
result.Task = &models.TaskWithProject{ |
|
|
|
|
|
Task: *task, |
|
|
|
|
|
Project: project, |
|
|
|
|
|
} |
|
|
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID) |
|
|
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID) |
|
|
if log.SecondaryItemID != nil { |
|
|
if log.SecondaryItemID != nil { |
|
|
result.SecondaryItem, _ = l.DB.Items().Find(ctx, *log.SecondaryItemID) |
|
|
result.SecondaryItem, _ = l.DB.Items().Find(ctx, *log.SecondaryItemID) |
|
@ -144,6 +157,7 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode |
|
|
|
|
|
|
|
|
taskIDs := stringset.New() |
|
|
taskIDs := stringset.New() |
|
|
itemIDs := stringset.New() |
|
|
itemIDs := stringset.New() |
|
|
|
|
|
projectIDs := stringset.New() |
|
|
for _, log := range logs { |
|
|
for _, log := range logs { |
|
|
taskIDs.Add(log.TaskID) |
|
|
taskIDs.Add(log.TaskID) |
|
|
itemIDs.Add(log.ItemID) |
|
|
itemIDs.Add(log.ItemID) |
|
@ -158,6 +172,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
for _, task := range tasks { |
|
|
|
|
|
projectIDs.Add(task.ProjectID) |
|
|
|
|
|
} |
|
|
items, err := l.DB.Items().List(ctx, models.ItemFilter{ |
|
|
items, err := l.DB.Items().List(ctx, models.ItemFilter{ |
|
|
UserID: auth.UserID(ctx), |
|
|
UserID: auth.UserID(ctx), |
|
|
IDs: itemIDs.Strings(), |
|
|
IDs: itemIDs.Strings(), |
|
@ -165,6 +182,13 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
projects, err := l.DB.Projects().List(ctx, models.ProjectFilter{ |
|
|
|
|
|
UserID: auth.UserID(ctx), |
|
|
|
|
|
IDs: projectIDs.Strings(), |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
results := make([]*models.LogResult, len(logs)) |
|
|
results := make([]*models.LogResult, len(logs)) |
|
|
for i, log := range logs { |
|
|
for i, log := range logs { |
|
@ -175,11 +199,20 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode |
|
|
|
|
|
|
|
|
for _, task := range tasks { |
|
|
for _, task := range tasks { |
|
|
if task.ID == log.TaskID { |
|
|
if task.ID == log.TaskID { |
|
|
results[i].Task = task |
|
|
|
|
|
|
|
|
results[i].Task = &models.TaskWithProject{Task: *task} |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if results[i].Task != nil { |
|
|
|
|
|
for _, project := range projects { |
|
|
|
|
|
if project.ID == results[i].Task.ProjectID { |
|
|
|
|
|
results[i].Task.Project = project |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for _, item := range items { |
|
|
for _, item := range items { |
|
|
if item.ID == log.ItemID { |
|
|
if item.ID == log.ItemID { |
|
|
results[i].Item = item |
|
|
results[i].Item = item |
|
@ -545,6 +578,15 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models. |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
projectIDs := stringset.New() |
|
|
|
|
|
for _, task := range tasks { |
|
|
|
|
|
projectIDs.Add(task.ProjectID) |
|
|
|
|
|
} |
|
|
|
|
|
projects, err := l.DB.Projects().List(ctx, models.ProjectFilter{ |
|
|
|
|
|
UserID: userID, |
|
|
|
|
|
IDs: projectIDs.Strings(), |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// Apply logs
|
|
|
// Apply logs
|
|
|
result.Logs = make([]*models.GoalResultLog, 0, len(logs)) |
|
|
result.Logs = make([]*models.GoalResultLog, 0, len(logs)) |
|
|
for _, log := range logs { |
|
|
for _, log := range logs { |
|
@ -555,14 +597,22 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models. |
|
|
|
|
|
|
|
|
for _, task := range tasks { |
|
|
for _, task := range tasks { |
|
|
if task.ID == log.TaskID { |
|
|
if task.ID == log.TaskID { |
|
|
resultLog.Task = task |
|
|
|
|
|
|
|
|
resultLog.Task = &models.TaskWithProject{Task: *task} |
|
|
|
|
|
|
|
|
|
|
|
for _, project := range projects { |
|
|
|
|
|
if project.ID == task.ProjectID { |
|
|
|
|
|
resultLog.Task.Project = project |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, item := range result.Items { |
|
|
for _, item := range result.Items { |
|
|
amount := log.Amount(item.ID) |
|
|
amount := log.Amount(item.ID) |
|
|
if amount > 0 && goal.Accepts(&item.Item, resultLog.Task) { |
|
|
|
|
|
|
|
|
if amount > 0 && goal.Accepts(&item.Item, &resultLog.Task.Task) { |
|
|
item.CompletedAmount += amount |
|
|
item.CompletedAmount += amount |
|
|
|
|
|
|
|
|
if goal.Unweighted { |
|
|
if goal.Unweighted { |
|
|