This commit is contained in:
Hillel Coren 2018-12-18 18:09:54 +02:00
parent 90b6095d7e
commit d53e2e4576
4 changed files with 37 additions and 32 deletions

View File

@ -59,9 +59,9 @@ abstract class TaskEntity extends Object
id: --TaskEntity.counter, id: --TaskEntity.counter,
description: '', description: '',
duration: 0, duration: 0,
invoiceId: 0, invoiceId: null,
clientId: 0, clientId: null,
projectId: 0, projectId: null,
timeLog: '', timeLog: '',
isRunning: false, isRunning: false,
customValue1: '', customValue1: '',
@ -87,12 +87,15 @@ abstract class TaskEntity extends Object
int get duration; int get duration;
@nullable
@BuiltValueField(wireName: 'invoice_id') @BuiltValueField(wireName: 'invoice_id')
int get invoiceId; int get invoiceId;
@nullable
@BuiltValueField(wireName: 'client_id') @BuiltValueField(wireName: 'client_id')
int get clientId; int get clientId;
@nullable
@BuiltValueField(wireName: 'project_id') @BuiltValueField(wireName: 'project_id')
int get projectId; int get projectId;

View File

@ -125,15 +125,6 @@ class _$TaskEntitySerializer implements StructuredSerializer<TaskEntity> {
'duration', 'duration',
serializers.serialize(object.duration, serializers.serialize(object.duration,
specifiedType: const FullType(int)), 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', 'time_log',
serializers.serialize(object.timeLog, serializers.serialize(object.timeLog,
specifiedType: const FullType(String)), specifiedType: const FullType(String)),
@ -147,6 +138,24 @@ class _$TaskEntitySerializer implements StructuredSerializer<TaskEntity> {
serializers.serialize(object.customValue2, serializers.serialize(object.customValue2,
specifiedType: const FullType(String)), 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) { if (object.createdAt != null) {
result result
..add('created_at') ..add('created_at')
@ -506,15 +515,6 @@ class _$TaskEntity extends TaskEntity {
if (duration == null) { if (duration == null) {
throw new BuiltValueNullFieldError('TaskEntity', 'duration'); 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) { if (timeLog == null) {
throw new BuiltValueNullFieldError('TaskEntity', 'timeLog'); throw new BuiltValueNullFieldError('TaskEntity', 'timeLog');
} }

View File

@ -9,7 +9,6 @@ import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/data/web_client.dart'; import 'package:invoiceninja_flutter/data/web_client.dart';
class TaskRepository { class TaskRepository {
const TaskRepository({ const TaskRepository({
this.webClient = const WebClient(), this.webClient = const WebClient(),
}); });
@ -18,8 +17,8 @@ class TaskRepository {
Future<TaskEntity> loadItem( Future<TaskEntity> loadItem(
CompanyEntity company, AuthState auth, int entityId) async { CompanyEntity company, AuthState auth, int entityId) async {
final dynamic response = await webClient.get( final dynamic response =
'${auth.url}/tasks/$entityId', company.token); await webClient.get('${auth.url}/tasks/$entityId', company.token);
final TaskItemResponse taskResponse = final TaskItemResponse taskResponse =
serializers.deserializeWith(TaskItemResponse.serializer, response); serializers.deserializeWith(TaskItemResponse.serializer, response);
@ -46,14 +45,20 @@ class TaskRepository {
Future<TaskEntity> saveData( Future<TaskEntity> saveData(
CompanyEntity company, AuthState auth, TaskEntity task, CompanyEntity company, AuthState auth, TaskEntity task,
[EntityAction action]) async { [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); final data = serializers.serializeWith(TaskEntity.serializer, task);
dynamic response; dynamic response;
if (task.isNew) { if (task.isNew) {
response = await webClient.post( response = await webClient.post(
auth.url + '/tasks', auth.url + '/tasks', company.token, json.encode(data));
company.token,
json.encode(data));
} else { } else {
var url = auth.url + '/tasks/' + task.id.toString(); var url = auth.url + '/tasks/' + task.id.toString();
if (action != null) { if (action != null) {
@ -63,7 +68,7 @@ class TaskRepository {
} }
final TaskItemResponse taskResponse = final TaskItemResponse taskResponse =
serializers.deserializeWith(TaskItemResponse.serializer, response); serializers.deserializeWith(TaskItemResponse.serializer, response);
return taskResponse.data; return taskResponse.data;
} }

View File

@ -124,9 +124,6 @@ class _TaskEditState extends State<TaskEdit> {
entityMap: state.clientState.map, entityMap: state.clientState.map,
entityList: memoizedDropdownClientList( entityList: memoizedDropdownClientList(
state.clientState.map, state.clientState.list), state.clientState.map, state.clientState.list),
validator: (String val) => val.trim().isEmpty
? localization.pleaseSelectAClient
: null,
onSelected: (client) { onSelected: (client) {
viewModel.onChanged(task.rebuild((b) => b viewModel.onChanged(task.rebuild((b) => b
..clientId = client.id ..clientId = client.id