Tasks
This commit is contained in:
parent
90b6095d7e
commit
d53e2e4576
|
|
@ -59,9 +59,9 @@ abstract class TaskEntity extends Object
|
|||
id: --TaskEntity.counter,
|
||||
description: '',
|
||||
duration: 0,
|
||||
invoiceId: 0,
|
||||
clientId: 0,
|
||||
projectId: 0,
|
||||
invoiceId: null,
|
||||
clientId: null,
|
||||
projectId: null,
|
||||
timeLog: '',
|
||||
isRunning: false,
|
||||
customValue1: '',
|
||||
|
|
@ -87,12 +87,15 @@ abstract class TaskEntity extends Object
|
|||
|
||||
int get duration;
|
||||
|
||||
@nullable
|
||||
@BuiltValueField(wireName: 'invoice_id')
|
||||
int get invoiceId;
|
||||
|
||||
@nullable
|
||||
@BuiltValueField(wireName: 'client_id')
|
||||
int get clientId;
|
||||
|
||||
@nullable
|
||||
@BuiltValueField(wireName: 'project_id')
|
||||
int get projectId;
|
||||
|
||||
|
|
|
|||
|
|
@ -125,15 +125,6 @@ class _$TaskEntitySerializer implements StructuredSerializer<TaskEntity> {
|
|||
'duration',
|
||||
serializers.serialize(object.duration,
|
||||
specifiedType: const FullType(int)),
|
||||
'invoice_id',
|
||||
serializers.serialize(object.invoiceId,
|
||||
specifiedType: const FullType(int)),
|
||||
'client_id',
|
||||
serializers.serialize(object.clientId,
|
||||
specifiedType: const FullType(int)),
|
||||
'project_id',
|
||||
serializers.serialize(object.projectId,
|
||||
specifiedType: const FullType(int)),
|
||||
'time_log',
|
||||
serializers.serialize(object.timeLog,
|
||||
specifiedType: const FullType(String)),
|
||||
|
|
@ -147,6 +138,24 @@ class _$TaskEntitySerializer implements StructuredSerializer<TaskEntity> {
|
|||
serializers.serialize(object.customValue2,
|
||||
specifiedType: const FullType(String)),
|
||||
];
|
||||
if (object.invoiceId != null) {
|
||||
result
|
||||
..add('invoice_id')
|
||||
..add(serializers.serialize(object.invoiceId,
|
||||
specifiedType: const FullType(int)));
|
||||
}
|
||||
if (object.clientId != null) {
|
||||
result
|
||||
..add('client_id')
|
||||
..add(serializers.serialize(object.clientId,
|
||||
specifiedType: const FullType(int)));
|
||||
}
|
||||
if (object.projectId != null) {
|
||||
result
|
||||
..add('project_id')
|
||||
..add(serializers.serialize(object.projectId,
|
||||
specifiedType: const FullType(int)));
|
||||
}
|
||||
if (object.createdAt != null) {
|
||||
result
|
||||
..add('created_at')
|
||||
|
|
@ -506,15 +515,6 @@ class _$TaskEntity extends TaskEntity {
|
|||
if (duration == null) {
|
||||
throw new BuiltValueNullFieldError('TaskEntity', 'duration');
|
||||
}
|
||||
if (invoiceId == null) {
|
||||
throw new BuiltValueNullFieldError('TaskEntity', 'invoiceId');
|
||||
}
|
||||
if (clientId == null) {
|
||||
throw new BuiltValueNullFieldError('TaskEntity', 'clientId');
|
||||
}
|
||||
if (projectId == null) {
|
||||
throw new BuiltValueNullFieldError('TaskEntity', 'projectId');
|
||||
}
|
||||
if (timeLog == null) {
|
||||
throw new BuiltValueNullFieldError('TaskEntity', 'timeLog');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import 'package:invoiceninja_flutter/data/models/models.dart';
|
|||
import 'package:invoiceninja_flutter/data/web_client.dart';
|
||||
|
||||
class TaskRepository {
|
||||
|
||||
const TaskRepository({
|
||||
this.webClient = const WebClient(),
|
||||
});
|
||||
|
|
@ -18,8 +17,8 @@ class TaskRepository {
|
|||
|
||||
Future<TaskEntity> loadItem(
|
||||
CompanyEntity company, AuthState auth, int entityId) async {
|
||||
final dynamic response = await webClient.get(
|
||||
'${auth.url}/tasks/$entityId', company.token);
|
||||
final dynamic response =
|
||||
await webClient.get('${auth.url}/tasks/$entityId', company.token);
|
||||
|
||||
final TaskItemResponse taskResponse =
|
||||
serializers.deserializeWith(TaskItemResponse.serializer, response);
|
||||
|
|
@ -42,18 +41,24 @@ class TaskRepository {
|
|||
|
||||
return taskResponse.data;
|
||||
}
|
||||
|
||||
|
||||
Future<TaskEntity> saveData(
|
||||
CompanyEntity company, AuthState auth, TaskEntity task,
|
||||
[EntityAction action]) async {
|
||||
// Workaround for API issue
|
||||
if (task.isNew) {
|
||||
task = task.rebuild((b) => b
|
||||
..id = null
|
||||
..timeLog = '[]');
|
||||
}
|
||||
|
||||
final data = serializers.serializeWith(TaskEntity.serializer, task);
|
||||
|
||||
dynamic response;
|
||||
|
||||
if (task.isNew) {
|
||||
response = await webClient.post(
|
||||
auth.url + '/tasks',
|
||||
company.token,
|
||||
json.encode(data));
|
||||
auth.url + '/tasks', company.token, json.encode(data));
|
||||
} else {
|
||||
var url = auth.url + '/tasks/' + task.id.toString();
|
||||
if (action != null) {
|
||||
|
|
@ -63,7 +68,7 @@ class TaskRepository {
|
|||
}
|
||||
|
||||
final TaskItemResponse taskResponse =
|
||||
serializers.deserializeWith(TaskItemResponse.serializer, response);
|
||||
serializers.deserializeWith(TaskItemResponse.serializer, response);
|
||||
|
||||
return taskResponse.data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,9 +124,6 @@ class _TaskEditState extends State<TaskEdit> {
|
|||
entityMap: state.clientState.map,
|
||||
entityList: memoizedDropdownClientList(
|
||||
state.clientState.map, state.clientState.list),
|
||||
validator: (String val) => val.trim().isEmpty
|
||||
? localization.pleaseSelectAClient
|
||||
: null,
|
||||
onSelected: (client) {
|
||||
viewModel.onChanged(task.rebuild((b) => b
|
||||
..clientId = client.id
|
||||
|
|
|
|||
Loading…
Reference in New Issue