This commit is contained in:
Hillel Coren 2018-12-25 14:41:02 +02:00
parent db695d929e
commit 3c7da9933b
6 changed files with 40 additions and 20 deletions

View File

@ -102,6 +102,7 @@ class _InvoiceViewState extends State<InvoiceView> {
leading: Icon(FontAwesomeIcons.users, size: 18.0),
trailing: Icon(Icons.navigate_next),
onTap: () => viewModel.onClientPressed(context),
onLongPress: () => viewModel.onClientPressed(context, true),
),
),
Container(
@ -125,6 +126,8 @@ class _InvoiceViewState extends State<InvoiceView> {
leading: Icon(FontAwesomeIcons.creditCard, size: 18.0),
trailing: Icon(Icons.navigate_next),
onTap: () => viewModel.onPaymentPressed(context, payment),
onLongPress: () =>
viewModel.onPaymentPressed(context, payment, true),
),
),
]);

View File

@ -62,9 +62,9 @@ class EntityViewVM {
final bool isDirty;
final Function(BuildContext, EntityAction) onActionSelected;
final Function(BuildContext, [InvoiceItemEntity]) onEditPressed;
final Function(BuildContext) onClientPressed;
final Function(BuildContext, [bool]) onClientPressed;
final Function(BuildContext) onPaymentsPressed;
final Function(BuildContext, PaymentEntity) onPaymentPressed;
final Function(BuildContext, PaymentEntity, [bool]) onPaymentPressed;
final Function(BuildContext) onRefreshed;
final Function onBackPressed;
@ -94,8 +94,8 @@ class InvoiceViewVM extends EntityViewVM {
bool isDirty,
Function(BuildContext, EntityAction) onActionSelected,
Function(BuildContext, [InvoiceItemEntity]) onEditPressed,
Function(BuildContext) onClientPressed,
Function(BuildContext, PaymentEntity) onPaymentPressed,
Function(BuildContext, [bool]) onClientPressed,
Function(BuildContext, PaymentEntity, [bool]) onPaymentPressed,
Function(BuildContext) onPaymentsPressed,
Function(BuildContext) onRefreshed,
Function onBackPressed,
@ -154,10 +154,15 @@ class InvoiceViewVM extends EntityViewVM {
store.dispatch(UpdateCurrentRoute(InvoiceScreen.route));
}
},
onClientPressed: (BuildContext context) =>
store.dispatch(ViewClient(clientId: client.id, context: context)),
onPaymentPressed: (BuildContext context, PaymentEntity payment) => store
.dispatch(ViewPayment(paymentId: payment.id, context: context)),
onClientPressed: (BuildContext context, [bool longPress = false]) =>
store.dispatch(longPress
? EditClient(client: client, context: context)
: ViewClient(clientId: client.id, context: context)),
onPaymentPressed: (BuildContext context, PaymentEntity payment,
[bool longPress = false]) =>
store.dispatch(longPress
? EditPayment(payment: payment, context: context)
: ViewPayment(paymentId: payment.id, context: context)),
onPaymentsPressed: (BuildContext context) {
store.dispatch(FilterPaymentsByEntity(
entityId: invoice.id, entityType: EntityType.invoice));

View File

@ -103,6 +103,7 @@ class _PaymentViewState extends State<PaymentView> {
leading: Icon(FontAwesomeIcons.users, size: 18.0),
trailing: Icon(Icons.navigate_next),
onTap: () => viewModel.onTapClient(context),
onLongPress: () => viewModel.onTapClient(context, true),
),
),
Container(
@ -116,6 +117,7 @@ class _PaymentViewState extends State<PaymentView> {
leading: Icon(FontAwesomeIcons.filePdf, size: 18.0),
trailing: Icon(Icons.navigate_next),
onTap: () => viewModel.onTapInvoice(context),
onLongPress: () => viewModel.onTapInvoice(context, true),
),
),
Container(

View File

@ -60,10 +60,16 @@ class PaymentViewVM {
onEditPressed: (BuildContext context) {
store.dispatch(EditPayment(payment: payment, context: context));
},
onTapClient: (context) =>
store.dispatch(ViewClient(clientId: client.id, context: context)),
onTapInvoice: (context) => store.dispatch(
ViewInvoice(invoiceId: payment.invoiceId, context: context)),
onTapClient: (context, [bool longPress = false]) => store.dispatch(
longPress
? EditClient(client: client, context: context)
: ViewClient(clientId: client.id, context: context)),
onTapInvoice: (context, [bool longPress = false]) => store.dispatch(
longPress
? EditInvoice(
invoice: state.invoiceState.map[payment.invoiceId],
context: context)
: ViewInvoice(invoiceId: payment.invoiceId, context: context)),
onActionSelected: (BuildContext context, EntityAction action) {
final localization = AppLocalization.of(context);
switch (action) {
@ -94,8 +100,8 @@ class PaymentViewVM {
final CompanyEntity company;
final Function(BuildContext, EntityAction) onActionSelected;
final Function(BuildContext) onEditPressed;
final Function(BuildContext) onTapInvoice;
final Function(BuildContext) onTapClient;
final Function(BuildContext, [bool]) onTapInvoice;
final Function(BuildContext, [bool]) onTapClient;
final bool isSaving;
final bool isLoading;
final bool isDirty;

View File

@ -35,7 +35,7 @@ class _ProjectViewState extends State<ProjectView> {
void initState() {
super.initState();
Timer.periodic(Duration(seconds: 1),
(Timer timer) => mounted ? setState(() => false) : false);
(Timer timer) => mounted ? setState(() => false) : false);
}
@override
@ -68,8 +68,8 @@ class _ProjectViewState extends State<ProjectView> {
value1: formatDuration(
taskDurationForProject(project, viewModel.state.taskState.map)),
label2: localization.budgeted,
value2:
formatDuration(Duration(hours: project.budgetedHours.toInt()), showSeconds: false),
value2: formatDuration(Duration(hours: project.budgetedHours.toInt()),
showSeconds: false),
),
Material(
color: Theme.of(context).canvasColor,
@ -78,6 +78,7 @@ class _ProjectViewState extends State<ProjectView> {
leading: Icon(FontAwesomeIcons.users, size: 18.0),
trailing: Icon(Icons.navigate_next),
onTap: () => viewModel.onClientPressed(context),
onLongPress: () => viewModel.onClientPressed(context, true),
),
),
Container(

View File

@ -54,6 +54,7 @@ class ProjectViewVM {
factory ProjectViewVM.fromStore(Store<AppState> store) {
final state = store.state;
final project = state.projectState.map[state.projectUIState.selectedId];
final client = state.clientState.map[project.clientId];
Future<Null> _handleRefresh(BuildContext context) {
final completer = snackBarCompleter(
@ -74,8 +75,10 @@ class ProjectViewVM {
store.dispatch(EditProject(project: project, context: context));
},
onRefreshed: (context) => _handleRefresh(context),
onClientPressed: (BuildContext context) => store
.dispatch(ViewClient(clientId: project.clientId, context: context)),
onClientPressed: (BuildContext context, [bool longPress = false]) =>
store.dispatch(longPress
? EditClient(client: client, context: context)
: ViewClient(clientId: project.clientId, context: context)),
onTasksPressed: (BuildContext context) {
store.dispatch(FilterTasksByEntity(
entityId: project.id, entityType: EntityType.project));
@ -120,7 +123,7 @@ class ProjectViewVM {
final CompanyEntity company;
final Function(BuildContext, EntityAction) onActionSelected;
final Function(BuildContext) onEditPressed;
final Function(BuildContext) onClientPressed;
final Function(BuildContext, [bool]) onClientPressed;
final Function onBackPressed;
final Function(BuildContext) onAddTaskPressed;
final Function(BuildContext) onTasksPressed;