Web
This commit is contained in:
parent
2ba09d25b5
commit
79609a397f
|
|
@ -5,6 +5,14 @@ import 'package:invoiceninja_flutter/data/models/entities.dart';
|
|||
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/expense/expense_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/project/project_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/task/task_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/live_text.dart';
|
||||
|
|
@ -16,6 +24,8 @@ import 'package:invoiceninja_flutter/ui/app/history_drawer_vm.dart';
|
|||
import 'package:invoiceninja_flutter/utils/icons.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
|
||||
import 'actions_menu_button.dart';
|
||||
|
||||
class HistoryDrawer extends StatelessWidget {
|
||||
const HistoryDrawer({
|
||||
Key key,
|
||||
|
|
@ -39,57 +49,8 @@ class HistoryDrawer extends StatelessWidget {
|
|||
continue;
|
||||
}
|
||||
|
||||
String clientId;
|
||||
switch (history.entityType) {
|
||||
case EntityType.invoice:
|
||||
clientId = (entity as InvoiceEntity).clientId;
|
||||
break;
|
||||
case EntityType.payment:
|
||||
clientId = (entity as PaymentEntity).clientId;
|
||||
break;
|
||||
case EntityType.task:
|
||||
clientId = (entity as TaskEntity).clientId;
|
||||
break;
|
||||
case EntityType.expense:
|
||||
clientId = (entity as ExpenseEntity).clientId;
|
||||
break;
|
||||
case EntityType.project:
|
||||
clientId = (entity as ProjectEntity).clientId;
|
||||
break;
|
||||
}
|
||||
|
||||
widgets.add(ListTile(
|
||||
key: ValueKey('__${history.id}_${history.entityType}__'),
|
||||
leading: Icon(getEntityIcon(history.entityType)),
|
||||
title: Text(entity.listDisplayName.isEmpty
|
||||
? formatNumber(entity.listDisplayAmount, context,
|
||||
formatNumberType: entity.listDisplayAmountType)
|
||||
: entity.listDisplayName),
|
||||
subtitle: Text(localization.lookup('${history.entityType}')),
|
||||
// TODO this needs to be localized
|
||||
trailing: LiveText(
|
||||
() => timeago.format(history.dateTime, locale: 'en_short'),
|
||||
duration: Duration(minutes: 1),
|
||||
),
|
||||
onTap: () {
|
||||
if (state.prefState.isHistoryFloated) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
viewEntityById(
|
||||
context: context,
|
||||
entityId: history.id,
|
||||
entityType: history.entityType);
|
||||
},
|
||||
onLongPress: () {
|
||||
if (state.prefState.isHistoryFloated) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
showEntityActionsDialog(
|
||||
context: context,
|
||||
entities: [entity],
|
||||
client: state.clientState.map[clientId],
|
||||
);
|
||||
},
|
||||
widgets.add(HistoryListTile(
|
||||
history: history,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -131,3 +92,117 @@ class HistoryDrawer extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HistoryListTile extends StatefulWidget {
|
||||
const HistoryListTile({@required this.history});
|
||||
|
||||
final HistoryRecord history;
|
||||
|
||||
@override
|
||||
_HistoryListTileState createState() => _HistoryListTileState();
|
||||
}
|
||||
|
||||
class _HistoryListTileState extends State<HistoryListTile> {
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = AppLocalization.of(context);
|
||||
final store = StoreProvider.of<AppState>(context);
|
||||
final state = store.state;
|
||||
|
||||
final history = widget.history;
|
||||
final entity =
|
||||
state.getEntityMap(history.entityType)[history.id] as BaseEntity;
|
||||
|
||||
String clientId;
|
||||
switch (history.entityType) {
|
||||
case EntityType.invoice:
|
||||
clientId = (entity as InvoiceEntity).clientId;
|
||||
break;
|
||||
case EntityType.payment:
|
||||
clientId = (entity as PaymentEntity).clientId;
|
||||
break;
|
||||
case EntityType.task:
|
||||
clientId = (entity as TaskEntity).clientId;
|
||||
break;
|
||||
case EntityType.expense:
|
||||
clientId = (entity as ExpenseEntity).clientId;
|
||||
break;
|
||||
case EntityType.project:
|
||||
clientId = (entity as ProjectEntity).clientId;
|
||||
break;
|
||||
}
|
||||
|
||||
return Container(
|
||||
//onEnter: (event) => setState(() => _isHovered = true),
|
||||
//onExit: (event) => setState(() => _isHovered = false),
|
||||
child: ListTile(
|
||||
key: ValueKey('__${history.id}_${history.entityType}__'),
|
||||
leading: Icon(getEntityIcon(history.entityType)),
|
||||
title: Text(entity.listDisplayName.isEmpty
|
||||
? formatNumber(entity.listDisplayAmount, context,
|
||||
formatNumberType: entity.listDisplayAmountType)
|
||||
: entity.listDisplayName),
|
||||
subtitle: Text(localization.lookup('${history.entityType}')),
|
||||
// TODO this needs to be localized
|
||||
trailing: _isHovered
|
||||
? ActionMenuButton(
|
||||
entityActions: entity.getActions(
|
||||
userCompany: state.userCompany, includeEdit: true),
|
||||
isSaving: false,
|
||||
entity: entity,
|
||||
onSelected: (context, action) {
|
||||
print('selected $action');
|
||||
switch (history.entityType) {
|
||||
case EntityType.client:
|
||||
handleClientAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.product:
|
||||
handleProductAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.invoice:
|
||||
handleInvoiceAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.payment:
|
||||
handlePaymentAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.task:
|
||||
handleTaskAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.expense:
|
||||
handleExpenseAction(context, [entity], action);
|
||||
break;
|
||||
case EntityType.project:
|
||||
handleProjectAction(context, [entity], action);
|
||||
break;
|
||||
}
|
||||
},
|
||||
)
|
||||
: LiveText(
|
||||
() => timeago.format(history.dateTime, locale: 'en_short'),
|
||||
duration: Duration(minutes: 1),
|
||||
),
|
||||
onTap: () {
|
||||
if (state.prefState.isHistoryFloated) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
viewEntityById(
|
||||
context: context,
|
||||
entityId: history.id,
|
||||
entityType: history.entityType);
|
||||
},
|
||||
onLongPress: () {
|
||||
if (state.prefState.isHistoryFloated) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
showEntityActionsDialog(
|
||||
context: context,
|
||||
entities: [entity],
|
||||
client: state.clientState.map[clientId],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue