Documents
This commit is contained in:
parent
cde902f38a
commit
be0d7f285a
|
|
@ -11,10 +11,15 @@ import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
|
||||
class DocumentGrid extends StatelessWidget {
|
||||
const DocumentGrid({@required this.documents, @required this.onFileUpload});
|
||||
const DocumentGrid({
|
||||
@required this.documents,
|
||||
@required this.onFileUpload,
|
||||
@required this.onDeleteDocument,
|
||||
});
|
||||
|
||||
final List<int> documents;
|
||||
final Function(String) onFileUpload;
|
||||
final Function(DocumentEntity) onDeleteDocument;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -63,8 +68,10 @@ class DocumentGrid extends StatelessWidget {
|
|||
primary: true,
|
||||
crossAxisCount: 2,
|
||||
children: documents
|
||||
.map((documentId) =>
|
||||
DocumentTile(state.documentState.map[documentId]))
|
||||
.map((documentId) => DocumentTile(
|
||||
document: state.documentState.map[documentId],
|
||||
onDeleteDocument: onDeleteDocument,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
|
|
@ -73,9 +80,13 @@ class DocumentGrid extends StatelessWidget {
|
|||
}
|
||||
|
||||
class DocumentTile extends StatelessWidget {
|
||||
const DocumentTile(this.document);
|
||||
const DocumentTile({
|
||||
@required this.document,
|
||||
@required this.onDeleteDocument,
|
||||
});
|
||||
|
||||
final DocumentEntity document;
|
||||
final Function(DocumentEntity) onDeleteDocument;
|
||||
|
||||
void showDocumentModal(BuildContext context) {
|
||||
showDialog<Column>(
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ class ExpenseViewDocuments extends StatelessWidget {
|
|||
return DocumentGrid(
|
||||
documents: documents,
|
||||
onFileUpload: (path) => viewModel.onFileUpload(context, path),
|
||||
onDeleteDocument: (document) =>
|
||||
viewModel.onDeleteDocument(context, document),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class ExpenseViewVM {
|
|||
@required this.onBackPressed,
|
||||
@required this.onRefreshed,
|
||||
@required this.onFileUpload,
|
||||
@required this.onDeleteDocument,
|
||||
@required this.isSaving,
|
||||
@required this.isLoading,
|
||||
@required this.isDirty,
|
||||
|
|
@ -71,92 +72,100 @@ class ExpenseViewVM {
|
|||
}
|
||||
|
||||
return ExpenseViewVM(
|
||||
state: state,
|
||||
company: state.selectedCompany,
|
||||
isSaving: state.isSaving,
|
||||
isLoading: state.isLoading,
|
||||
isDirty: expense.isNew,
|
||||
expense: expense,
|
||||
onEditPressed: (BuildContext context) {
|
||||
final Completer<ExpenseEntity> completer = Completer<ExpenseEntity>();
|
||||
store.dispatch(EditExpense(
|
||||
expense: expense, context: context, completer: completer));
|
||||
completer.future.then((expense) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: AppLocalization.of(context).updatedExpense,
|
||||
)));
|
||||
state: state,
|
||||
company: state.selectedCompany,
|
||||
isSaving: state.isSaving,
|
||||
isLoading: state.isLoading,
|
||||
isDirty: expense.isNew,
|
||||
expense: expense,
|
||||
onEditPressed: (BuildContext context) {
|
||||
final Completer<ExpenseEntity> completer = Completer<ExpenseEntity>();
|
||||
store.dispatch(EditExpense(
|
||||
expense: expense, context: context, completer: completer));
|
||||
completer.future.then((expense) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: AppLocalization.of(context).updatedExpense,
|
||||
)));
|
||||
});
|
||||
},
|
||||
onRefreshed: (context) => _handleRefresh(context),
|
||||
onBackPressed: () {
|
||||
if (state.uiState.currentRoute.contains(ExpenseScreen.route)) {
|
||||
store.dispatch(UpdateCurrentRoute(ExpenseScreen.route));
|
||||
}
|
||||
},
|
||||
onEntityPressed: (BuildContext context, EntityType entityType,
|
||||
[longPress = false]) {
|
||||
switch (entityType) {
|
||||
case EntityType.vendor:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: vendor,
|
||||
onEntityAction: (BuildContext context, BaseEntity vendor,
|
||||
EntityAction action) =>
|
||||
handleVendorAction(context, vendor, action));
|
||||
} else {
|
||||
store.dispatch(
|
||||
ViewVendor(vendorId: vendor.id, context: context));
|
||||
}
|
||||
break;
|
||||
case EntityType.client:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: client,
|
||||
onEntityAction: (BuildContext context, BaseEntity client,
|
||||
EntityAction action) =>
|
||||
handleClientAction(context, client, action));
|
||||
} else {
|
||||
store.dispatch(
|
||||
ViewClient(clientId: client.id, context: context));
|
||||
}
|
||||
break;
|
||||
case EntityType.invoice:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: invoice,
|
||||
client: client,
|
||||
onEntityAction: (BuildContext context, BaseEntity invoice,
|
||||
EntityAction action) =>
|
||||
handleInvoiceAction(context, invoice, action));
|
||||
} else {
|
||||
store.dispatch(
|
||||
ViewInvoice(invoiceId: invoice.id, context: context));
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
onEntityAction: (BuildContext context, EntityAction action) =>
|
||||
handleExpenseAction(context, expense, action),
|
||||
onFileUpload: (BuildContext context, String path) {
|
||||
final Completer<DocumentEntity> completer =
|
||||
Completer<DocumentEntity>();
|
||||
final document = DocumentEntity().rebuild((b) => b
|
||||
..expenseId = expense.id
|
||||
..path = path);
|
||||
store.dispatch(
|
||||
SaveDocumentRequest(document: document, completer: completer));
|
||||
completer.future.then((client) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: AppLocalization.of(context).uploadedDocument,
|
||||
)));
|
||||
});
|
||||
},
|
||||
onDeleteDocument: (BuildContext context, DocumentEntity document) {
|
||||
store.dispatch(DeleteDocumentRequest(
|
||||
snackBarCompleter(
|
||||
context, AppLocalization.of(context).deletedDocument),
|
||||
document.id));
|
||||
});
|
||||
},
|
||||
onRefreshed: (context) => _handleRefresh(context),
|
||||
onBackPressed: () {
|
||||
if (state.uiState.currentRoute.contains(ExpenseScreen.route)) {
|
||||
store.dispatch(UpdateCurrentRoute(ExpenseScreen.route));
|
||||
}
|
||||
},
|
||||
onEntityPressed: (BuildContext context, EntityType entityType,
|
||||
[longPress = false]) {
|
||||
switch (entityType) {
|
||||
case EntityType.vendor:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: vendor,
|
||||
onEntityAction: (BuildContext context, BaseEntity vendor,
|
||||
EntityAction action) =>
|
||||
handleVendorAction(context, vendor, action));
|
||||
} else {
|
||||
store.dispatch(ViewVendor(vendorId: vendor.id, context: context));
|
||||
}
|
||||
break;
|
||||
case EntityType.client:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: client,
|
||||
onEntityAction: (BuildContext context, BaseEntity client,
|
||||
EntityAction action) =>
|
||||
handleClientAction(context, client, action));
|
||||
} else {
|
||||
store.dispatch(ViewClient(clientId: client.id, context: context));
|
||||
}
|
||||
break;
|
||||
case EntityType.invoice:
|
||||
if (longPress) {
|
||||
showEntityActionsDialog(
|
||||
user: user,
|
||||
context: context,
|
||||
entity: invoice,
|
||||
client: client,
|
||||
onEntityAction: (BuildContext context, BaseEntity invoice,
|
||||
EntityAction action) =>
|
||||
handleInvoiceAction(context, invoice, action));
|
||||
} else {
|
||||
store.dispatch(
|
||||
ViewInvoice(invoiceId: invoice.id, context: context));
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
onEntityAction: (BuildContext context, EntityAction action) =>
|
||||
handleExpenseAction(context, expense, action),
|
||||
onFileUpload: (BuildContext context, String path) {
|
||||
final Completer<DocumentEntity> completer = Completer<DocumentEntity>();
|
||||
final document = DocumentEntity().rebuild((b) => b
|
||||
..expenseId = expense.id
|
||||
..path = path);
|
||||
store.dispatch(
|
||||
SaveDocumentRequest(document: document, completer: completer));
|
||||
completer.future.then((client) {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: SnackBarRow(
|
||||
message: AppLocalization.of(context).uploadedDocument,
|
||||
)));
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
final AppState state;
|
||||
|
|
@ -168,6 +177,7 @@ class ExpenseViewVM {
|
|||
final Function onBackPressed;
|
||||
final Function(BuildContext) onRefreshed;
|
||||
final Function(BuildContext, String) onFileUpload;
|
||||
final Function(BuildContext, DocumentEntity) onDeleteDocument;
|
||||
final bool isSaving;
|
||||
final bool isLoading;
|
||||
final bool isDirty;
|
||||
|
|
|
|||
Loading…
Reference in New Issue