Update models
This commit is contained in:
parent
82b549cf7e
commit
ec79f7c055
|
|
@ -172,7 +172,7 @@ abstract class GroupEntity extends Object
|
||||||
FormatNumberType get listDisplayAmountType => null;
|
FormatNumberType get listDisplayAmountType => null;
|
||||||
|
|
||||||
// ignore: unused_element
|
// ignore: unused_element
|
||||||
static void _initializeBuilder(CompanyEntityBuilder builder) =>
|
static void _initializeBuilder(GroupEntityBuilder builder) =>
|
||||||
builder..documents.replace(BuiltList<DocumentEntity>());
|
builder..documents.replace(BuiltList<DocumentEntity>());
|
||||||
|
|
||||||
static Serializer<GroupEntity> get serializer => _$groupEntitySerializer;
|
static Serializer<GroupEntity> get serializer => _$groupEntitySerializer;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'package:built_collection/built_collection.dart';
|
import 'package:built_collection/built_collection.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/group_model.dart';
|
import 'package:invoiceninja_flutter/data/models/group_model.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
|
|
@ -68,4 +69,20 @@ class GroupRepository {
|
||||||
|
|
||||||
return groupResponse.data;
|
return groupResponse.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<GroupEntity> uploadDocument(Credentials credentials, BaseEntity entity,
|
||||||
|
MultipartFile multipartFile) async {
|
||||||
|
final fields = <String, String>{
|
||||||
|
'_method': 'put',
|
||||||
|
};
|
||||||
|
|
||||||
|
final dynamic response = await webClient.post(
|
||||||
|
'${credentials.url}/groups/${entity.id}', credentials.token,
|
||||||
|
data: fields, multipartFile: multipartFile);
|
||||||
|
|
||||||
|
final GroupItemResponse groupResponse =
|
||||||
|
serializers.deserializeWith(GroupItemResponse.serializer, response);
|
||||||
|
|
||||||
|
return groupResponse.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,6 @@ class ProductRepository {
|
||||||
'_method': 'put',
|
'_method': 'put',
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO remove this include
|
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'${credentials.url}/products/${entity.id}', credentials.token,
|
'${credentials.url}/products/${entity.id}', credentials.token,
|
||||||
data: fields, multipartFile: multipartFile);
|
data: fields, multipartFile: multipartFile);
|
||||||
|
|
|
||||||
|
|
@ -234,3 +234,28 @@ Middleware<AppState> _loadGroups(GroupRepository repository) {
|
||||||
next(action);
|
next(action);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _saveDocument(GroupRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as SaveGroupDocumentRequest;
|
||||||
|
if (store.state.isEnterprisePlan) {
|
||||||
|
repository
|
||||||
|
.uploadDocument(
|
||||||
|
store.state.credentials, action.group, action.multipartFile)
|
||||||
|
.then((group) {
|
||||||
|
store.dispatch(SaveGroupSuccess(group));
|
||||||
|
action.completer.complete(null);
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(SaveGroupDocumentFailure(error));
|
||||||
|
action.completer.completeError(error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const error = 'Uploading documents requires an enterprise plan';
|
||||||
|
store.dispatch(SaveGroupDocumentFailure(error));
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,10 @@ class _GroupViewState extends State<GroupView>
|
||||||
),
|
),
|
||||||
DocumentGrid(
|
DocumentGrid(
|
||||||
documents: documents.toList(),
|
documents: documents.toList(),
|
||||||
//onUploadDocument: (path) => viewModel.onUploadDocument(context, path),
|
onUploadDocument: (path) =>
|
||||||
//onDeleteDocument: (document, password) => viewModel.onDeleteDocument(context, document, password),
|
viewModel.onUploadDocument(context, path),
|
||||||
|
onDeleteDocument: (document, password) =>
|
||||||
|
viewModel.onDeleteDocument(context, document, password),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue