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

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

@ -29,7 +29,12 @@
</div>
<div class="description">
<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>
<Option open={mdLogEdit}>Edit Log</Option>
<Option open={mdLogDelete}>Delete Log</Option>
@ -92,4 +97,18 @@
div.log {
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>

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

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

Loading…
Cancel
Save