Browse Source

add item to log entries.

main
Gisle Aune 4 years ago
parent
commit
00218bb817
  1. 1
      models/log.go
  2. 19
      services/loader.go
  3. 21
      svelte-ui/src/components/LogEntry.svelte
  4. 2
      svelte-ui/src/models/log.ts

1
models/log.go

@ -31,6 +31,7 @@ type LogUpdate struct {
type LogResult struct { type LogResult struct {
Log Log
Task *Task `json:"task"` Task *Task `json:"task"`
Item *Item `json:"item"`
} }
type LogFilter struct { type LogFilter struct {

19
services/loader.go

@ -127,6 +127,7 @@ func (l *Loader) FindLog(ctx context.Context, id string) (*models.LogResult, err
} }
result.Task, _ = l.DB.Tasks().Find(ctx, id) result.Task, _ = l.DB.Tasks().Find(ctx, id)
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID)
return result, nil return result, nil
} }
@ -139,8 +140,10 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
} }
taskIDs := stringset.New() taskIDs := stringset.New()
itemIDs := stringset.New()
for _, log := range logs { for _, log := range logs {
taskIDs.Add(log.TaskID) taskIDs.Add(log.TaskID)
itemIDs.Add(log.ItemID)
} }
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{ tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
UserID: auth.UserID(ctx), UserID: auth.UserID(ctx),
@ -149,6 +152,13 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
if err != nil { if err != nil {
return nil, err return nil, err
} }
items, err := l.DB.Items().List(ctx, models.ItemFilter{
UserID: auth.UserID(ctx),
IDs: itemIDs.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 {
@ -163,6 +173,13 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
break break
} }
} }
for _, item := range items {
if item.ID == log.ItemID {
results[i].Item = item
break
}
}
} }
return results, nil return results, nil
@ -495,6 +512,8 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
result.CompletedAmount += item.GroupWeight result.CompletedAmount += item.GroupWeight
break break
} }
resultLog.Item = &item.Item
} }
break break

21
svelte-ui/src/components/LogEntry.svelte

@ -29,7 +29,12 @@
</div> </div>
<div class="description"> <div class="description">
<p>{log.description}</p> <p>{log.description}</p>
<div class="item">
<div class="item-icon">
<Icon name={log.item.icon} />
</div>
<div class="item-name">{log.item.name} ({log.item.groupWeight})</div>
</div>
<OptionRow> <OptionRow>
<Option open={mdLogEdit}>Edit Log</Option> <Option open={mdLogEdit}>Edit Log</Option>
<Option open={mdLogDelete}>Delete Log</Option> <Option open={mdLogDelete}>Delete Log</Option>
@ -92,4 +97,18 @@
div.log { div.log {
padding: 0.25em 1ch; padding: 0.25em 1ch;
} }
div.item {
display: flex;
flex-direction: row;
margin-top: 0.25em;
margin-bottom: 0em;
font-size: 0.75em;
}
div.item div.item-icon {
padding: 0.25em 0.5ch 0.25em 0;
}
div.item div.item-name {
padding: 0.125em;
}
</style> </style>

2
svelte-ui/src/models/log.ts

@ -1,3 +1,4 @@
import type Item from "./item";
import type Task from "./task"; import type Task from "./task";
export default interface Log { export default interface Log {
@ -16,6 +17,7 @@ export interface LogFilter {
export interface LogResult extends Log { export interface LogResult extends Log {
task: Task task: Task
item: Item
} }
export interface LogInput { export interface LogInput {

Loading…
Cancel
Save