From ec1274b6b5f1c01a0d24c78aaf8c2e9e446c563b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 16 Feb 2023 14:50:07 +0200 Subject: [PATCH] Schedules --- lib/ui/schedule/edit/schedule_edit.dart | 197 ++++++++++++------------ lib/utils/i18n.dart | 5 + 2 files changed, 106 insertions(+), 96 deletions(-) diff --git a/lib/ui/schedule/edit/schedule_edit.dart b/lib/ui/schedule/edit/schedule_edit.dart index 42bec5370..039c385da 100644 --- a/lib/ui/schedule/edit/schedule_edit.dart +++ b/lib/ui/schedule/edit/schedule_edit.dart @@ -102,6 +102,7 @@ class _ScheduleEditState extends State { return ScrollableListView( children: [ FormCard( + isLast: schedule.template.isEmpty, children: [ DecoratedFormField( keyboardType: TextInputType.text, @@ -123,6 +124,15 @@ class _ScheduleEditState extends State { child: Text(localization.lookup(entry.value)), )) .toList()), + DatePicker( + labelText: localization.nextRun, + onSelected: (date, _) { + viewModel.onChanged( + schedule.rebuild((b) => b..nextRun = date)); + }, + selectedDate: schedule.nextRun, + firstDate: DateTime.now(), + ), AppDropdownButton( labelText: localization.frequency, value: schedule.frequencyId, @@ -140,104 +150,99 @@ class _ScheduleEditState extends State { .toList()), ], ), - FormCard(children: [ - DatePicker( - labelText: localization.nextSendDate, - onSelected: (date, _) { - viewModel.onChanged( - schedule.rebuild((b) => b..nextRun = date)); - }, - selectedDate: schedule.nextRun, - firstDate: DateTime.now(), - ), - AppDropdownButton( - labelText: localization.dateRange, - blankValue: null, - value: parameters.dateRange.isNotEmpty - ? DateRange.valueOf(parameters.dateRange) - : null, - onChanged: (dynamic value) { - final updated = schedule.rebuild( - (b) => b..parameters.dateRange = value.toString()); - viewModel.onChanged(updated); - }, - items: DateRange.values - .map((dateRange) => DropdownMenuItem( - child: Text( - localization.lookup(dateRange.toString())), - value: dateRange, - )) - .toList(), - ), - AppDropdownButton( - labelText: localization.status, - blankValue: null, - value: parameters.status, - onChanged: (dynamic value) { - viewModel.onChanged(schedule - .rebuild((b) => b..parameters.status = value)); - }, - items: [ - kStatementStatusAll, - kStatementStatusPaid, - kStatementStatusUnpaid, - ] - .map((value) => DropdownMenuItem( - child: Text(localization.lookup(value)), - value: value, - )) - .toList(), - ), - SizedBox(height: 20), - BoolDropdownButton( - label: localization.showAgingTable, - value: parameters.showAgingTable, - onChanged: (value) { - viewModel.onChanged(schedule.rebuild( - (b) => b..parameters.showAgingTable = value)); - }), - BoolDropdownButton( - label: localization.showPaymentsTable, - value: parameters.showPaymentsTable, - onChanged: (value) { - viewModel.onChanged(schedule.rebuild( - (b) => b..parameters.showPaymentsTable = value)); - }), - ]), - FormCard( - isLast: true, - children: [ - ClientPicker( - key: ValueKey('__client_picker_${_clientClearedAt}__'), - isRequired: false, - clientId: null, - clientState: state.clientState, - onSelected: (value) { - if (!parameters.clients.contains(value.id)) { - viewModel.onChanged(schedule.rebuild( - (b) => b..parameters.clients.add(value.id))); - } - setState(() { - _clientClearedAt = DateTime.now().toIso8601String(); - }); - }), + if (schedule.template.isNotEmpty) ...[ + FormCard(children: [ + AppDropdownButton( + labelText: localization.dateRange, + blankValue: null, + value: parameters.dateRange.isNotEmpty + ? DateRange.valueOf(parameters.dateRange) + : null, + onChanged: (dynamic value) { + final updated = schedule.rebuild( + (b) => b..parameters.dateRange = value.toString()); + viewModel.onChanged(updated); + }, + items: DateRange.values + .map((dateRange) => DropdownMenuItem( + child: Text( + localization.lookup(dateRange.toString())), + value: dateRange, + )) + .toList(), + ), + AppDropdownButton( + labelText: localization.status, + blankValue: null, + value: parameters.status, + onChanged: (dynamic value) { + viewModel.onChanged(schedule + .rebuild((b) => b..parameters.status = value)); + }, + items: [ + kStatementStatusAll, + kStatementStatusPaid, + kStatementStatusUnpaid, + ] + .map((value) => DropdownMenuItem( + child: Text(localization.lookup(value)), + value: value, + )) + .toList(), + ), SizedBox(height: 20), - if (parameters.clients.isEmpty) - HelpText(localization.allClients), - for (var clientId in parameters.clients) - ListTile( - title: - Text(state.clientState.get(clientId).displayName), - trailing: IconButton( - icon: Icon(Icons.clear), - onPressed: () { - viewModel.onChanged(schedule.rebuild( - (b) => b..parameters.clients.remove(clientId))); - }, + BoolDropdownButton( + label: localization.showAgingTable, + value: parameters.showAgingTable, + onChanged: (value) { + viewModel.onChanged(schedule.rebuild( + (b) => b..parameters.showAgingTable = value)); + }), + BoolDropdownButton( + label: localization.showPaymentsTable, + value: parameters.showPaymentsTable, + onChanged: (value) { + viewModel.onChanged(schedule.rebuild( + (b) => b..parameters.showPaymentsTable = value)); + }), + ]), + FormCard( + isLast: true, + children: [ + ClientPicker( + key: + ValueKey('__client_picker_${_clientClearedAt}__'), + isRequired: false, + clientId: null, + clientState: state.clientState, + onSelected: (value) { + if (!parameters.clients.contains(value.id)) { + viewModel.onChanged(schedule.rebuild( + (b) => b..parameters.clients.add(value.id))); + } + setState(() { + _clientClearedAt = + DateTime.now().toIso8601String(); + }); + }), + SizedBox(height: 20), + if (parameters.clients.isEmpty) + HelpText(localization.allClients), + for (var clientId in parameters.clients) + ListTile( + title: + Text(state.clientState.get(clientId).displayName), + trailing: IconButton( + icon: Icon(Icons.clear), + onPressed: () { + viewModel.onChanged(schedule.rebuild((b) => + b..parameters.clients.remove(clientId))); + }, + ), ), - ), - ], - ) + ], + ) + ], ], ); }, diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index e2859e5c0..e42cef878 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,6 +16,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'next_run': 'Next Run', 'all_clients': 'All Clients', 'show_aging_table': 'Show Aging Table', 'show_payments_table': 'Show Payments Table', @@ -94529,6 +94530,10 @@ String get allClients => _localizedValues[localeCode]['all_clients'] ?? _localizedValues['en']['all_clients']; +String get nextRun => + _localizedValues[localeCode]['next_run'] ?? + _localizedValues['en']['next_run']; + // STARTER: lang field - do not remove comment String lookup(String key) {