add project to logs, project composition mode to goals and fix unweighted counts for other composition modes.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
+54
-4
@@ -126,7 +126,20 @@ func (l *Loader) FindLog(ctx context.Context, id string) (*models.LogResult, err
|
||||
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)
|
||||
if log.SecondaryItemID != nil {
|
||||
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()
|
||||
itemIDs := stringset.New()
|
||||
projectIDs := stringset.New()
|
||||
for _, log := range logs {
|
||||
taskIDs.Add(log.TaskID)
|
||||
itemIDs.Add(log.ItemID)
|
||||
@@ -158,6 +172,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, task := range tasks {
|
||||
projectIDs.Add(task.ProjectID)
|
||||
}
|
||||
items, err := l.DB.Items().List(ctx, models.ItemFilter{
|
||||
UserID: auth.UserID(ctx),
|
||||
IDs: itemIDs.Strings(),
|
||||
@@ -165,6 +182,13 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
||||
if err != nil {
|
||||
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))
|
||||
for i, log := range logs {
|
||||
@@ -175,11 +199,20 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
||||
|
||||
for _, task := range tasks {
|
||||
if task.ID == log.TaskID {
|
||||
results[i].Task = task
|
||||
results[i].Task = &models.TaskWithProject{Task: *task}
|
||||
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 {
|
||||
if item.ID == log.ItemID {
|
||||
results[i].Item = item
|
||||
@@ -545,6 +578,15 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
||||
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
|
||||
result.Logs = make([]*models.GoalResultLog, 0, len(logs))
|
||||
for _, log := range logs {
|
||||
@@ -555,14 +597,22 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
||||
|
||||
for _, task := range tasks {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range result.Items {
|
||||
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
|
||||
|
||||
if goal.Unweighted {
|
||||
|
||||
Reference in New Issue
Block a user