Add microsoft todo parsing logic
This commit is contained in:
parent
5820a23fe2
commit
9d0338f06b
|
@ -71,9 +71,9 @@ type body struct {
|
|||
}
|
||||
type pattern struct {
|
||||
Type string `json:"type"`
|
||||
Interval int `json:"interval"`
|
||||
Month int `json:"month"`
|
||||
DayOfMonth int `json:"dayOfMonth"`
|
||||
Interval int64 `json:"interval"`
|
||||
Month int64 `json:"month"`
|
||||
DayOfMonth int64 `json:"dayOfMonth"`
|
||||
DaysOfWeek []string `json:"daysOfWeek"`
|
||||
FirstDayOfWeek string `json:"firstDayOfWeek"`
|
||||
Index string `json:"index"`
|
||||
|
@ -110,6 +110,15 @@ type listsResponse struct {
|
|||
Value []*list `json:"value"`
|
||||
}
|
||||
|
||||
func (dtt *dateTimeTimeZone) toTime() (t time.Time, err error) {
|
||||
loc, err := time.LoadLocation(dtt.TimeZone)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
|
||||
return time.ParseInLocation(time.RFC3339Nano, dtt.DateTime+"Z", loc)
|
||||
}
|
||||
|
||||
func (m *Migration) AuthURL() string {
|
||||
return "https://login.microsoftonline.com/common/oauth2/v2.0/authorize" +
|
||||
"?client_id=" + config.MigrationMicrosoftTodoClientID.GetString() +
|
||||
|
@ -219,15 +228,92 @@ func getMicrosoftTodoData(token string) (microsoftTodoData []*list, err error) {
|
|||
func convertMicrosoftTodoData(todoData []*list) (vikunjsStructure []*models.NamespaceWithLists, err error) {
|
||||
|
||||
// One namespace with all lists
|
||||
// Lists only with naem
|
||||
vikunjsStructure = []*models.NamespaceWithLists{
|
||||
{
|
||||
Namespace: models.Namespace{
|
||||
Title: "Migrated from Microsoft Todo",
|
||||
},
|
||||
Lists: []*models.List{},
|
||||
},
|
||||
}
|
||||
|
||||
// Title
|
||||
// Description
|
||||
// Done Status
|
||||
// Priority
|
||||
// Reminders
|
||||
// Due Date
|
||||
// Repeating
|
||||
for _, l := range todoData {
|
||||
|
||||
// Lists only with title
|
||||
list := &models.List{
|
||||
Title: l.DisplayName,
|
||||
}
|
||||
|
||||
for _, t := range l.Tasks {
|
||||
task := &models.Task{
|
||||
Title: t.Title,
|
||||
Done: t.Status == "completed",
|
||||
}
|
||||
|
||||
// Done Status
|
||||
if task.Done {
|
||||
task.DoneAt, err = t.CompletedDateTime.toTime()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Description
|
||||
if t.Body != nil && t.Body.ContentType == "text" {
|
||||
task.Description = t.Body.Content
|
||||
}
|
||||
|
||||
// Priority
|
||||
switch t.Importance {
|
||||
case "low":
|
||||
task.Priority = 1
|
||||
case "normal":
|
||||
task.Priority = 2
|
||||
case "high":
|
||||
task.Priority = 3
|
||||
default:
|
||||
task.Priority = 0
|
||||
}
|
||||
|
||||
// Reminders
|
||||
if t.ReminderDateTime != nil {
|
||||
reminder, err := t.ReminderDateTime.toTime()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
task.Reminders = []time.Time{reminder}
|
||||
}
|
||||
|
||||
// Due Date
|
||||
if t.DueDateTime != nil {
|
||||
dueDate, err := t.DueDateTime.toTime()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
task.DueDate = dueDate
|
||||
}
|
||||
|
||||
// Repeating
|
||||
if t.Recurrence != nil && t.Recurrence.Pattern != nil {
|
||||
switch t.Recurrence.Pattern.Type {
|
||||
case "daily":
|
||||
task.RepeatAfter = t.Recurrence.Pattern.Interval * 60 * 60 * 24
|
||||
case "weekly":
|
||||
task.RepeatAfter = t.Recurrence.Pattern.Interval * 60 * 60 * 24 * 7
|
||||
case "monthly":
|
||||
task.RepeatAfter = t.Recurrence.Pattern.Interval * 60 * 60 * 24 * 30
|
||||
case "yearly":
|
||||
task.RepeatAfter = t.Recurrence.Pattern.Interval * 60 * 60 * 24 * 365
|
||||
}
|
||||
}
|
||||
|
||||
list.Tasks = append(list.Tasks, task)
|
||||
}
|
||||
|
||||
vikunjsStructure[0].Lists = append(vikunjsStructure[0].Lists, list)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue