1
0

Repeating tasks (#25)

This commit is contained in:
konrad
2018-11-26 20:24:00 +00:00
committed by Gitea
parent 3f44e3b83e
commit 06fc9f7886
7 changed files with 54 additions and 25 deletions

View File

@ -26,6 +26,7 @@ type ListTask struct {
RemindersUnix []int64 `xorm:"JSON TEXT" json:"reminderDates"`
CreatedByID int64 `xorm:"int(11)" json:"-"` // ID of the user who put that task on the list
ListID int64 `xorm:"int(11) INDEX" json:"listID" param:"list"`
RepeatAfter int64 `xorm:"int(11) INDEX" json:"repeatAfter"`
Created int64 `xorm:"created" json:"created"`
Updated int64 `xorm:"updated" json:"updated"`

View File

@ -55,7 +55,7 @@ func (i *ListTask) Create(doer *User) (err error) {
i.CreatedByID = u.ID
i.CreatedBy = u
_, err = x.Cols("text", "description", "done", "due_date_unix", "reminder_unix", "created_by_id", "list_id", "created", "updated").Insert(i)
_, err = x.Insert(i)
return err
}
@ -80,6 +80,17 @@ func (i *ListTask) Update() (err error) {
return
}
// When a repeating task is marked, as done, we update all deadlines and reminders and set it as undone
if !ot.Done && i.Done && ot.RepeatAfter > 0 {
ot.DueDateUnix = ot.DueDateUnix + ot.RepeatAfter
for in, r := range ot.RemindersUnix {
ot.RemindersUnix[in] = r + ot.RepeatAfter
}
i.Done = false
}
// For whatever reason, xorm dont detect if done is updated, so we need to update this every time by hand
// Which is why we merge the actual task struct with the one we got from the
// The user struct overrides values in the actual one.
@ -92,7 +103,7 @@ func (i *ListTask) Update() (err error) {
ot.Done = false
}
_, err = x.ID(i.ID).Cols("text", "description", "done", "due_date_unix", "reminders_unix").Update(ot)
_, err = x.ID(i.ID).Cols("text", "description", "done", "due_date_unix", "reminders_unix", "repeat_after").Update(ot)
*i = ot
return
}