1
0
mirror of https://github.com/go-vikunja/app synced 2024-06-01 02:06:51 +00:00
app-mirror-github/lib/models/task.dart

89 lines
2.9 KiB
Dart
Raw Normal View History

import 'package:meta/meta.dart';
2021-06-04 09:34:25 +00:00
import 'package:json_annotation/json_annotation.dart';
import 'package:vikunja_app/components/date_extension.dart';
2021-06-04 09:34:25 +00:00
import 'package:vikunja_app/models/label.dart';
import 'package:vikunja_app/models/user.dart';
2022-04-15 18:14:04 +00:00
2021-06-04 09:34:25 +00:00
@JsonSerializable()
class Task {
int id, parentTaskId, priority, listId;
DateTime created, updated, dueDate, startDate, endDate;
List<DateTime> reminderDates;
String title, description;
bool done;
User createdBy;
Duration repeatAfter;
List<Task> subtasks;
List<Label> labels;
bool loading = false;
Task(
{@required this.id,
2021-06-04 09:34:25 +00:00
this.title,
this.description,
this.done = false,
2021-06-04 09:34:25 +00:00
this.reminderDates,
this.dueDate,
this.startDate,
this.endDate,
this.parentTaskId,
this.priority,
this.repeatAfter,
this.subtasks,
this.labels,
this.created,
this.updated,
this.createdBy,
this.listId});
Task.fromJson(Map<String, dynamic> json)
: id = json['id'],
title = json['title'],
2021-06-04 09:34:25 +00:00
description = json['description'],
done = json['done'],
2021-06-08 05:50:05 +00:00
reminderDates = (json['reminder_dates'] as List<dynamic>)
?.map((ts) => DateTime.parse(ts))
2021-06-04 09:34:25 +00:00
?.cast<DateTime>()
?.toList(),
2021-06-08 05:50:05 +00:00
dueDate = DateTime.parse(json['due_date']),
startDate = DateTime.parse(json['start_date']),
endDate = DateTime.parse(json['end_date']),
parentTaskId = json['parent_task_id'],
2021-06-04 09:34:25 +00:00
priority = json['priority'],
2021-06-08 05:50:05 +00:00
repeatAfter = Duration(seconds: json['repeat_after']),
2021-06-04 09:34:25 +00:00
labels = (json['labels'] as List<dynamic>)
?.map((label) => Label.fromJson(label))
?.cast<Label>()
?.toList(),
subtasks = (json['subtasks'] as List<dynamic>)
?.map((subtask) => Task.fromJson(subtask))
?.cast<Task>()
?.toList(),
2021-06-08 05:50:05 +00:00
updated = DateTime.parse(json['updated']),
created = DateTime.parse(json['created']),
listId = json['list_id'],
createdBy = json['created_by'] == null
? null
: User.fromJson(json['created_by']);
toJSON() => {
'id': id,
'title': title,
2021-06-04 09:34:25 +00:00
'description': description,
'done': done ?? false,
'reminder_dates':
reminderDates?.map((date) => date?.toIso8601String())?.toList(),
'due_date': dueDate?.toUtc()?.toIso8601String(),
'start_date': startDate?.toUtc()?.toIso8601String(),
'end_date': endDate?.toUtc()?.toIso8601String(),
2021-06-04 09:34:25 +00:00
'priority': priority,
2021-06-10 07:58:25 +00:00
'repeat_after': repeatAfter?.inSeconds,
2021-06-04 09:34:25 +00:00
'labels': labels?.map((label) => label.toJSON())?.toList(),
'subtasks': subtasks?.map((subtask) => subtask.toJSON())?.toList(),
2021-06-10 07:58:25 +00:00
'created_by': createdBy?.toJSON(),
'updated': updated?.toIso8601String(),
'created': created?.toIso8601String(),
};
}