Browse Source

add support for changing task item.

main
Gisle Aune 4 years ago
parent
commit
197fe227a4
  1. 18
      api/task.go
  2. 4
      models/task.go
  3. 4
      svelte-ui/src/forms/TaskForm.svelte
  4. 1
      svelte-ui/src/models/task.ts

18
api/task.go

@ -86,6 +86,24 @@ func Task(g *gin.RouterGroup, db database.Database) {
return nil, err return nil, err
} }
if update.ItemID != nil && *update.ItemID != task.ItemID {
_, err := l.FindItem(c.Request.Context(), *update.ItemID)
if err != nil {
return nil, err
}
logs, err := l.ListLogs(c.Request.Context(), models.LogFilter{
TaskIDs: []string{task.ID},
})
if err != nil {
return nil, err
}
if len(logs) > 0 {
return nil, slerrors.Forbidden("You cannot change the item if the task has logs.")
}
}
task.Update(update) task.Update(update)
if task.EndTime != nil && task.EndTime.Before(task.CreatedTime) { if task.EndTime != nil && task.EndTime.Before(task.CreatedTime) {
return nil, slerrors.BadRequest("Task end time must be later than it was created.") return nil, slerrors.BadRequest("Task end time must be later than it was created.")

4
models/task.go

@ -20,6 +20,9 @@ type Task struct {
} }
func (task *Task) Update(update TaskUpdate) { func (task *Task) Update(update TaskUpdate) {
if update.ItemID != nil {
task.ItemID = *update.ItemID
}
if update.ItemAmount != nil { if update.ItemAmount != nil {
task.ItemAmount = *update.ItemAmount task.ItemAmount = *update.ItemAmount
} }
@ -42,6 +45,7 @@ func (task *Task) Update(update TaskUpdate) {
} }
type TaskUpdate struct { type TaskUpdate struct {
ItemID *string `json:"itemId"`
ItemAmount *int `json:"itemAmount"` ItemAmount *int `json:"itemAmount"`
Name *string `json:"name"` Name *string `json:"name"`
Description *string `json:"description"` Description *string `json:"description"`

4
svelte-ui/src/forms/TaskForm.svelte

@ -86,7 +86,7 @@
clearEndTime: endTime == "", clearEndTime: endTime == "",
active: !completed, active: !completed,
name, description, itemAmount,
itemId, name, description, itemAmount,
}).then(() => { }).then(() => {
markStale("goal", "project", "task"); markStale("goal", "project", "task");
modalStore.close(); modalStore.close();
@ -108,7 +108,7 @@
<label for="description">Description</label> <label for="description">Description</label>
<textarea disabled={deletion} name="description" bind:value={description} /> <textarea disabled={deletion} name="description" bind:value={description} />
<label for="itemId">Item</label> <label for="itemId">Item</label>
<ItemSelect disabled={!creation} name="itemId" bind:value={itemId} />
<ItemSelect disabled={deletion} name="itemId" bind:value={itemId} />
<label for="itemAmount">Amount</label> <label for="itemAmount">Amount</label>
<input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} /> <input disabled={deletion} name="itemAmount" type="number" bind:value={itemAmount} />
<label for="endTime">Deadline (Optional)</label> <label for="endTime">Deadline (Optional)</label>

1
svelte-ui/src/models/task.ts

@ -38,6 +38,7 @@ export interface TaskInput {
} }
export interface TaskUpdate { export interface TaskUpdate {
itemId?: string
itemAmount?: number itemAmount?: number
name?: string name?: string
description?: string description?: string

Loading…
Cancel
Save