Starter...

This commit is contained in:
Hillel Coren 2020-03-02 21:20:12 +02:00
parent 5b0984ef18
commit 5aaf30f1f9
2 changed files with 238 additions and 202 deletions

View File

@ -2,17 +2,20 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/data/models/credit_model.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_screen_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_list_vm.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart'; import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart'; import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
import 'package:invoiceninja_flutter/ui/app/forms/save_cancel_buttons.dart';
import 'package:invoiceninja_flutter/ui/app/list_scaffold.dart';
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_list_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'credit_screen_vm.dart';
class CreditScreen extends StatelessWidget { class CreditScreen extends StatelessWidget {
const CreditScreen({ const CreditScreen({
@ -28,103 +31,118 @@ class CreditScreen extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final state = store.state; final state = store.state;
final company = state.selectedCompany; final company = state.company;
final userCompany = state.userCompany;
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final listUIState = state.uiState.creditUIState.listUIState; final listUIState = state.uiState.creditUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
return AppScaffold( return ListScaffold(
isChecked: isInMultiselect && isChecked: isInMultiselect &&
listUIState.selectedIds.length == viewModel.creditList.length, listUIState.selectedIds.length == viewModel.creditList.length,
showCheckbox: isInMultiselect, showCheckbox: isInMultiselect,
onCheckboxChanged: (value) { onHamburgerLongPress: () => store.dispatch(StartCreditMultiselect()),
final credits = viewModel.creditList onCheckboxChanged: (value) {
.map<InvoiceEntity>((creditId) => viewModel.creditMap[creditId]) final credits = viewModel.creditList
.where((credit) => value != listUIState.isSelected(credit)) .map<InvoiceEntity>((creditId) => viewModel.creditMap[creditId])
.toList(); .where((credit) => value != listUIState.isSelected(credit.id))
.toList();
viewModel.onEntityAction(
context, credits, EntityAction.toggleMultiselect); handleCreditAction(context, credits, EntityAction.toggleMultiselect);
}, },
appBarTitle: ListFilter( appBarTitle: ListFilter(
title: localization.credits title: localization.credits,
key: ValueKey(state.creditListState.filterClearedAt), key: ValueKey(state.creditListState.filterClearedAt),
entityType: EntityType.credit, filter: state.creditListState.filter,
onFilterChanged: (value) { onFilterChanged: (value) {
store.dispatch(FilterCredits(value)); store.dispatch(FilterCredits(value));
}, },
), ),
appBarActions: [ appBarActions: [
if (!viewModel.isInMultiselect) if (!viewModel.isInMultiselect)
ListFilterButton( ListFilterButton(
entityType: EntityType.credit, filter: state.creditListState.filter,
onFilterPressed: (String value) { onFilterPressed: (String value) {
store.dispatch(FilterCredits(value)); store.dispatch(FilterCredits(value));
}, },
), ),
if (viewModel.isInMultiselect) if (viewModel.isInMultiselect)
SaveCancelButtons( SaveCancelButtons(
saveLabel: localization.done, saveLabel: localization.done,
onSavePressed: listUIState.selectedIds.isEmpty onSavePressed: listUIState.selectedIds.isEmpty
? null ? null
: (context) async { : (context) async {
final credits = listUIState.selectedIds final credits = listUIState.selectedIds
.map<InvoiceEntity>( .map<InvoiceEntity>(
(creditId) => viewModel.creditMap[creditId]) (creditId) => viewModel.creditMap[creditId])
.toList(); .toList();
await showEntityActionsDialog( await showEntityActionsDialog(
entities: credits, context: context, multiselect: true, entities: credits,
completer: Completer<Null>() context: context,
..future.then((_) => multiselect: true,
store.dispatch(ClearCreditMultiselect())), completer: Completer<Null>()
); ..future.then<dynamic>(
}, (_) => store.dispatch(ClearCreditMultiselect())),
onCancelPressed: (context) => );
store.dispatch(ClearCreditMultiselect()), },
), onCancelPressed: (context) =>
], store.dispatch(ClearCreditMultiselect()),
body: CreditListBuilder(), ),
bottomNavigationBar: AppBottomBar( ],
entityType: EntityType.credit, body: CreditListBuilder(),
onSelectedSortField: (value) => store.dispatch(SortCredits(value)), bottomNavigationBar: AppBottomBar(
customValues1: company.getCustomFieldValues(CustomFieldType.credit1, entityType: EntityType.credit,
excludeBlank: true), onSelectedSortField: (value) {
customValues2: company.getCustomFieldValues(CustomFieldType.credit2, store.dispatch(SortCredits(value));
excludeBlank: true), },
onSelectedCustom1: (value) => sortFields: [
store.dispatch(FilterCreditsByCustom1(value)), CreditFields.number,
onSelectedCustom2: (value) => CreditFields.amount,
store.dispatch(FilterCreditsByCustom2(value)), CreditFields.updatedAt,
sortFields: [ ],
CreditFields.updatedAt, onSelectedState: (EntityState state, value) {
], store.dispatch(FilterCreditsByState(state));
onSelectedState: (EntityState state, value) { },
store.dispatch(FilterCreditsByState(state)); onCheckboxPressed: () {
}, if (store.state.creditListState.isInMultiselect()) {
onCheckboxPressed: () { store.dispatch(ClearCreditMultiselect());
if (store.state.creditListState.isInMultiselect()) { } else {
store.dispatch(ClearCreditMultiselect()); store.dispatch(StartCreditMultiselect());
} else { }
store.dispatch(StartCreditMultiselect()); },
} customValues1: company.getCustomFieldValues(CustomFieldType.invoice1,
}, excludeBlank: true),
), customValues2: company.getCustomFieldValues(CustomFieldType.invoice2,
floatingActionButton: user.canCreate(EntityType.credit) excludeBlank: true),
? FloatingActionButton( customValues3: company.getCustomFieldValues(CustomFieldType.invoice3,
heroTag: 'credit_fab', excludeBlank: true),
backgroundColor: Theme.of(context).primaryColorDark, customValues4: company.getCustomFieldValues(CustomFieldType.invoice4,
onPressed: () { excludeBlank: true),
store.dispatch( onSelectedCustom1: (value) =>
EditCredit(credit: InvoiceEntity(), context: context)); store.dispatch(FilterCreditsByCustom1(value)),
}, onSelectedCustom2: (value) =>
child: Icon( store.dispatch(FilterCreditsByCustom2(value)),
Icons.add, onSelectedCustom3: (value) =>
color: Colors.white, store.dispatch(FilterCreditsByCustom3(value)),
), onSelectedCustom4: (value) =>
tooltip: localization.newCredit, store.dispatch(FilterCreditsByCustom4(value)),
) ),
: null, floatingActionButton: userCompany.canCreate(EntityType.credit)
); ? FloatingActionButton(
heroTag: 'credit_fab',
backgroundColor: Theme.of(context).primaryColorDark,
onPressed: () {
createEntityByType(
context: context, entityType: EntityType.credit);
},
child: Icon(
Icons.add,
color: Colors.white,
),
tooltip: localization.newCredit,
)
: null,
);
} }
} }

View File

@ -2,17 +2,20 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/data/models/stub_model.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_screen_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_list_vm.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/redux/stub/stub_actions.dart'; import 'package:invoiceninja_flutter/redux/stub/stub_actions.dart';
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart'; import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
import 'package:invoiceninja_flutter/ui/app/forms/save_cancel_buttons.dart';
import 'package:invoiceninja_flutter/ui/app/list_scaffold.dart';
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
import 'package:invoiceninja_flutter/ui/stub/stub_list_vm.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'stub_screen_vm.dart';
class StubScreen extends StatelessWidget { class StubScreen extends StatelessWidget {
const StubScreen({ const StubScreen({
@ -28,103 +31,118 @@ class StubScreen extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context); final store = StoreProvider.of<AppState>(context);
final state = store.state; final state = store.state;
final company = state.selectedCompany; final company = state.company;
final userCompany = state.userCompany;
final localization = AppLocalization.of(context); final localization = AppLocalization.of(context);
final listUIState = state.uiState.stubUIState.listUIState; final listUIState = state.uiState.stubUIState.listUIState;
final isInMultiselect = listUIState.isInMultiselect(); final isInMultiselect = listUIState.isInMultiselect();
return AppScaffold( return ListScaffold(
isChecked: isInMultiselect && isChecked: isInMultiselect &&
listUIState.selectedIds.length == viewModel.stubList.length, listUIState.selectedIds.length == viewModel.stubList.length,
showCheckbox: isInMultiselect, showCheckbox: isInMultiselect,
onCheckboxChanged: (value) { onHamburgerLongPress: () => store.dispatch(StartStubMultiselect()),
final stubs = viewModel.stubList onCheckboxChanged: (value) {
.map<StubEntity>((stubId) => viewModel.stubMap[stubId]) final stubs = viewModel.stubList
.where((stub) => value != listUIState.isSelected(stub)) .map<StubEntity>((stubId) => viewModel.stubMap[stubId])
.toList(); .where((stub) => value != listUIState.isSelected(stub.id))
.toList();
viewModel.onEntityAction(
context, stubs, EntityAction.toggleMultiselect); handleStubAction(context, stubs, EntityAction.toggleMultiselect);
}, },
appBarTitle: ListFilter( appBarTitle: ListFilter(
title: localization.stubs title: localization.stubs,
key: ValueKey(state.stubListState.filterClearedAt), key: ValueKey(state.stubListState.filterClearedAt),
entityType: EntityType.stub, filter: state.stubListState.filter,
onFilterChanged: (value) { onFilterChanged: (value) {
store.dispatch(FilterStubs(value)); store.dispatch(FilterStubs(value));
}, },
), ),
appBarActions: [ appBarActions: [
if (!viewModel.isInMultiselect) if (!viewModel.isInMultiselect)
ListFilterButton( ListFilterButton(
entityType: EntityType.stub, filter: state.stubListState.filter,
onFilterPressed: (String value) { onFilterPressed: (String value) {
store.dispatch(FilterStubs(value)); store.dispatch(FilterStubs(value));
}, },
), ),
if (viewModel.isInMultiselect) if (viewModel.isInMultiselect)
SaveCancelButtons( SaveCancelButtons(
saveLabel: localization.done, saveLabel: localization.done,
onSavePressed: listUIState.selectedIds.isEmpty onSavePressed: listUIState.selectedIds.isEmpty
? null ? null
: (context) async { : (context) async {
final stubs = listUIState.selectedIds final stubs = listUIState.selectedIds
.map<StubEntity>( .map<StubEntity>(
(stubId) => viewModel.stubMap[stubId]) (stubId) => viewModel.stubMap[stubId])
.toList(); .toList();
await showEntityActionsDialog( await showEntityActionsDialog(
entities: stubs, context: context, multiselect: true, entities: stubs,
completer: Completer<Null>() context: context,
..future.then((_) => multiselect: true,
store.dispatch(ClearStubMultiselect())), completer: Completer<Null>()
); ..future.then<dynamic>(
}, (_) => store.dispatch(ClearStubMultiselect())),
onCancelPressed: (context) => );
store.dispatch(ClearStubMultiselect()), },
), onCancelPressed: (context) =>
], store.dispatch(ClearStubMultiselect()),
body: StubListBuilder(), ),
bottomNavigationBar: AppBottomBar( ],
entityType: EntityType.stub, body: StubListBuilder(),
onSelectedSortField: (value) => store.dispatch(SortStubs(value)), bottomNavigationBar: AppBottomBar(
customValues1: company.getCustomFieldValues(CustomFieldType.stub1, entityType: EntityType.stub,
excludeBlank: true), onSelectedSortField: (value) {
customValues2: company.getCustomFieldValues(CustomFieldType.stub2, store.dispatch(SortStubs(value));
excludeBlank: true), },
onSelectedCustom1: (value) => sortFields: [
store.dispatch(FilterStubsByCustom1(value)), StubFields.name,
onSelectedCustom2: (value) => StubFields.balance,
store.dispatch(FilterStubsByCustom2(value)), StubFields.updatedAt,
sortFields: [ ],
StubFields.updatedAt, onSelectedState: (EntityState state, value) {
], store.dispatch(FilterStubsByState(state));
onSelectedState: (EntityState state, value) { },
store.dispatch(FilterStubsByState(state)); onCheckboxPressed: () {
}, if (store.state.stubListState.isInMultiselect()) {
onCheckboxPressed: () { store.dispatch(ClearStubMultiselect());
if (store.state.stubListState.isInMultiselect()) { } else {
store.dispatch(ClearStubMultiselect()); store.dispatch(StartStubMultiselect());
} else { }
store.dispatch(StartStubMultiselect()); },
} customValues1: company.getCustomFieldValues(CustomFieldType.stub1,
}, excludeBlank: true),
), customValues2: company.getCustomFieldValues(CustomFieldType.stub2,
floatingActionButton: user.canCreate(EntityType.stub) excludeBlank: true),
? FloatingActionButton( customValues3: company.getCustomFieldValues(CustomFieldType.stub3,
heroTag: 'stub_fab', excludeBlank: true),
backgroundColor: Theme.of(context).primaryColorDark, customValues4: company.getCustomFieldValues(CustomFieldType.stub4,
onPressed: () { excludeBlank: true),
store.dispatch( onSelectedCustom1: (value) =>
EditStub(stub: StubEntity(), context: context)); store.dispatch(FilterStubsByCustom1(value)),
}, onSelectedCustom2: (value) =>
child: Icon( store.dispatch(FilterStubsByCustom2(value)),
Icons.add, onSelectedCustom3: (value) =>
color: Colors.white, store.dispatch(FilterStubsByCustom3(value)),
), onSelectedCustom4: (value) =>
tooltip: localization.newStub, store.dispatch(FilterStubsByCustom4(value)),
) ),
: null, floatingActionButton: userCompany.canCreate(EntityType.stub)
); ? FloatingActionButton(
heroTag: 'stub_fab',
backgroundColor: Theme.of(context).primaryColorDark,
onPressed: () {
createEntityByType(
context: context, entityType: EntityType.stub);
},
child: Icon(
Icons.add,
color: Colors.white,
),
tooltip: localization.newStub,
)
: null,
);
} }
} }