This commit is contained in:
unknown 2018-06-13 12:37:51 -07:00
parent d3de804821
commit ad273af458
12 changed files with 18 additions and 15 deletions

View File

@ -58,6 +58,10 @@ abstract class BaseEntity {
@BuiltValueField(wireName: 'is_deleted') @BuiltValueField(wireName: 'is_deleted')
bool get isDeleted; bool get isDeleted;
bool isNew() {
return this.id == null;
}
bool isActive() { bool isActive() {
return this.archivedAt == null; return this.archivedAt == null;
} }

View File

@ -31,7 +31,7 @@ class ClientsRepository {
var data = serializers.serializeWith(ClientEntity.serializer, client); var data = serializers.serializeWith(ClientEntity.serializer, client);
var response; var response;
if (client.id == null) { if (client.isNew()) {
response = await webClient.post( response = await webClient.post(
auth.url + '/clients', company.token, json.encode(data)); auth.url + '/clients', company.token, json.encode(data));
} else { } else {

View File

@ -31,7 +31,7 @@ class ProductsRepository {
var data = serializers.serializeWith(ProductEntity.serializer, product); var data = serializers.serializeWith(ProductEntity.serializer, product);
var response; var response;
if (product.id == null) { if (product.isNew()) {
response = await webClient.post( response = await webClient.post(
auth.url + '/products', company.token, json.encode(data)); auth.url + '/products', company.token, json.encode(data));
} else { } else {

View File

@ -88,7 +88,7 @@ Middleware<AppState> _saveClient(ClientsRepository repository) {
.saveData(store.state.selectedCompany(), store.state.authState, .saveData(store.state.selectedCompany(), store.state.authState,
action.client) action.client)
.then((client) { .then((client) {
if (action.client.id == null) { if (action.client.isNew()) {
store.dispatch(AddClientSuccess(client)); store.dispatch(AddClientSuccess(client));
} else { } else {
store.dispatch(SaveClientSuccess(client)); store.dispatch(SaveClientSuccess(client));

View File

@ -88,7 +88,7 @@ Middleware<AppState> _saveProduct(ProductsRepository repository) {
.saveData(store.state.selectedCompany(), store.state.authState, .saveData(store.state.selectedCompany(), store.state.authState,
action.product) action.product)
.then((product) { .then((product) {
if (action.product.id == null) { if (action.product.isNew()) {
store.dispatch(AddProductSuccess(product)); store.dispatch(AddProductSuccess(product));
} else { } else {
store.dispatch(SaveProductSuccess(product)); store.dispatch(SaveProductSuccess(product));

View File

@ -23,7 +23,6 @@ class AppSearch extends StatelessWidget {
var localization = AppLocalization.of(context); var localization = AppLocalization.of(context);
return StoreConnector<AppState, ListUIState>( return StoreConnector<AppState, ListUIState>(
//distinct: true,
converter: (Store<AppState> store) => store.state.productListState(), converter: (Store<AppState> store) => store.state.productListState(),
builder: (BuildContext context, listUIState) { builder: (BuildContext context, listUIState) {
return listUIState.search == null return listUIState.search == null

View File

@ -75,7 +75,7 @@ class _ClientEditState extends State<ClientEdit>
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(client.id == null title: Text(client.isNew()
? localization.newClient ? localization.newClient
: client.displayName), // Text(localizations.clientDetails), : client.displayName), // Text(localizations.clientDetails),
actions: <Widget>[ actions: <Widget>[

View File

@ -50,7 +50,7 @@ class ClientEditVM {
final Completer<Null> completer = new Completer<Null>(); final Completer<Null> completer = new Completer<Null>();
store.dispatch(SaveClientRequest(completer, client)); store.dispatch(SaveClientRequest(completer, client));
return completer.future.then((_) { return completer.future.then((_) {
if (client.id == null) { if (client.isNew()) {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute(builder: (_) => ClientViewScreen())); MaterialPageRoute(builder: (_) => ClientViewScreen()));
@ -60,7 +60,7 @@ class ClientEditVM {
/* /*
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow( content: SnackBarRow(
message: client.id == null message: client.isNew()
? AppLocalization.of(context).successfullyCreatedClient ? AppLocalization.of(context).successfullyCreatedClient
: AppLocalization.of(context).successfullyUpdatedClient, : AppLocalization.of(context).successfullyUpdatedClient,
), ),

View File

@ -54,7 +54,7 @@ class _ClientViewState extends State<ClientView>
), ),
], ],
), ),
actions: widget.viewModel.client.id == null actions: widget.viewModel.client.isNew()
? [] ? []
: [ : [
IconButton( IconButton(

View File

@ -53,7 +53,7 @@ class ClientViewVM {
return ClientViewVM( return ClientViewVM(
isLoading: store.state.isLoading, isLoading: store.state.isLoading,
isDirty: client.id == null, isDirty: client.isNew(),
client: client, client: client,
onDelete: () => false, onDelete: () => false,
onEditClicked: (BuildContext context) { onEditClicked: (BuildContext context) {
@ -67,7 +67,7 @@ class ClientViewVM {
return completer.future.then((_) { return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow( content: SnackBarRow(
message: client.id == null message: client.isNew()
? AppLocalization.of(context).successfullyCreatedClient ? AppLocalization.of(context).successfullyCreatedClient
: AppLocalization.of(context).successfullyUpdatedClient, : AppLocalization.of(context).successfullyUpdatedClient,
), ),

View File

@ -33,7 +33,7 @@ class _ProductEditState extends State<ProductEdit> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(viewModel.product.id == null title: Text(viewModel.product.isNew()
? AppLocalization.of(context).newProduct ? AppLocalization.of(context).newProduct
: viewModel.product.productKey), : viewModel.product.productKey),
actions: <Widget>[ actions: <Widget>[
@ -56,7 +56,7 @@ class _ProductEditState extends State<ProductEdit> {
}, },
); );
}), }),
viewModel.product.id == null viewModel.product.isNew()
? Container() ? Container()
: ActionMenuButton( : ActionMenuButton(
entity: viewModel.product, entity: viewModel.product,

View File

@ -51,7 +51,7 @@ class ProductEditVM {
return ProductEditVM( return ProductEditVM(
isLoading: store.state.isLoading, isLoading: store.state.isLoading,
isDirty: product.id == null, isDirty: product.isNew(),
product: product, product: product,
onDelete: () => false, onDelete: () => false,
onSaveClicked: (BuildContext context, ProductEntity product) { onSaveClicked: (BuildContext context, ProductEntity product) {
@ -60,7 +60,7 @@ class ProductEditVM {
return completer.future.then((_) { return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow( content: SnackBarRow(
message: product.id == null message: product.isNew()
? AppLocalization.of(context).successfullyCreatedProduct ? AppLocalization.of(context).successfullyCreatedProduct
: AppLocalization.of(context).successfullyUpdatedProduct, : AppLocalization.of(context).successfullyUpdatedProduct,
), ),