Bulk download
This commit is contained in:
parent
ddd3588624
commit
d7fb664491
|
|
@ -306,6 +306,21 @@ class DeleteCreditsFailure implements StopSaving {
|
|||
final List<InvoiceEntity> credits;
|
||||
}
|
||||
|
||||
class DownloadCreditsRequest implements StartSaving {
|
||||
DownloadCreditsRequest(this.completer, this.creditIds);
|
||||
|
||||
final Completer completer;
|
||||
final List<String> creditIds;
|
||||
}
|
||||
|
||||
class DownloadCreditsSuccess implements StopSaving {}
|
||||
|
||||
class DownloadCreditsFailure implements StopSaving {
|
||||
DownloadCreditsFailure(this.error);
|
||||
|
||||
final Object error;
|
||||
}
|
||||
|
||||
class RestoreCreditsRequest implements StartSaving {
|
||||
RestoreCreditsRequest(this.completer, this.creditIds);
|
||||
|
||||
|
|
@ -520,6 +535,11 @@ Future handleCreditAction(
|
|||
filterEntity: state.clientState.map[credit.clientId],
|
||||
);
|
||||
break;
|
||||
case EntityAction.download:
|
||||
store.dispatch(DownloadCreditsRequest(
|
||||
snackBarCompleter<Null>(context, localization.exportedData),
|
||||
creditIds));
|
||||
break;
|
||||
case EntityAction.restore:
|
||||
final message = creditIds.length > 1
|
||||
? localization.restoredCredits
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ List<Middleware<AppState>> createStoreCreditsMiddleware([
|
|||
final emailCredit = _emailCredit(repository);
|
||||
final bulkEmailCredits = _bulkEmailCredits(repository);
|
||||
final markSentCredit = _markSentCredit(repository);
|
||||
final downloadCredits = _downloadCredits(repository);
|
||||
final saveDocument = _saveDocument(repository);
|
||||
|
||||
return [
|
||||
|
|
@ -49,6 +50,7 @@ List<Middleware<AppState>> createStoreCreditsMiddleware([
|
|||
TypedMiddleware<AppState, EmailCreditRequest>(emailCredit),
|
||||
TypedMiddleware<AppState, BulkEmailCreditsRequest>(bulkEmailCredits),
|
||||
TypedMiddleware<AppState, MarkSentCreditRequest>(markSentCredit),
|
||||
TypedMiddleware<AppState, DownloadCreditsRequest>(downloadCredits),
|
||||
TypedMiddleware<AppState, SaveCreditDocumentRequest>(saveDocument),
|
||||
];
|
||||
}
|
||||
|
|
@ -340,6 +342,29 @@ Middleware<AppState> _loadCredits(CreditRepository repository) {
|
|||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _downloadCredits(CreditRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as DownloadCreditsRequest;
|
||||
repository
|
||||
.bulkAction(
|
||||
store.state.credentials, action.creditIds, EntityAction.download)
|
||||
.then((invoices) {
|
||||
store.dispatch(DownloadCreditsSuccess());
|
||||
if (action.completer != null) {
|
||||
action.completer.complete(null);
|
||||
}
|
||||
}).catchError((Object error) {
|
||||
print(error);
|
||||
store.dispatch(DownloadCreditsFailure(error));
|
||||
if (action.completer != null) {
|
||||
action.completer.completeError(error);
|
||||
}
|
||||
});
|
||||
|
||||
next(action);
|
||||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _bulkEmailCredits(CreditRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as BulkEmailCreditsRequest;
|
||||
|
|
|
|||
|
|
@ -306,6 +306,21 @@ class DeleteQuotesFailure implements StopSaving {
|
|||
final List<InvoiceEntity> quotes;
|
||||
}
|
||||
|
||||
class DownloadQuotesRequest implements StartSaving {
|
||||
DownloadQuotesRequest(this.completer, this.invoiceIds);
|
||||
|
||||
final Completer completer;
|
||||
final List<String> invoiceIds;
|
||||
}
|
||||
|
||||
class DownloadQuotesSuccess implements StopSaving {}
|
||||
|
||||
class DownloadQuotesFailure implements StopSaving {
|
||||
DownloadQuotesFailure(this.error);
|
||||
|
||||
final Object error;
|
||||
}
|
||||
|
||||
class RestoreQuotesRequest implements StartSaving {
|
||||
RestoreQuotesRequest(this.completer, this.quoteIds);
|
||||
|
||||
|
|
@ -533,6 +548,11 @@ Future handleQuoteAction(
|
|||
..entityType = EntityType.recurringInvoice
|
||||
..designId = designId));
|
||||
break;
|
||||
case EntityAction.download:
|
||||
store.dispatch(DownloadQuotesRequest(
|
||||
snackBarCompleter<Null>(context, localization.exportedData),
|
||||
quoteIds));
|
||||
break;
|
||||
case EntityAction.restore:
|
||||
final message = quoteIds.length > 1
|
||||
? localization.restoredQuotes
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ List<Middleware<AppState>> createStoreQuotesMiddleware([
|
|||
final emailQuote = _emailQuote(repository);
|
||||
final bulkEmailQuotes = _bulkEmailQuotes(repository);
|
||||
final markSentQuote = _markSentQuote(repository);
|
||||
final downloadQuotes = _downloadQuotes(repository);
|
||||
final saveDocument = _saveDocument(repository);
|
||||
|
||||
return [
|
||||
|
|
@ -51,6 +52,7 @@ List<Middleware<AppState>> createStoreQuotesMiddleware([
|
|||
TypedMiddleware<AppState, EmailQuoteRequest>(emailQuote),
|
||||
TypedMiddleware<AppState, BulkEmailQuotesRequest>(bulkEmailQuotes),
|
||||
TypedMiddleware<AppState, MarkSentQuotesRequest>(markSentQuote),
|
||||
TypedMiddleware<AppState, DownloadQuotesRequest>(downloadQuotes),
|
||||
TypedMiddleware<AppState, SaveQuoteDocumentRequest>(saveDocument),
|
||||
];
|
||||
}
|
||||
|
|
@ -333,6 +335,29 @@ Middleware<AppState> _loadQuote(QuoteRepository repository) {
|
|||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _downloadQuotes(QuoteRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as DownloadQuotesRequest;
|
||||
repository
|
||||
.bulkAction(
|
||||
store.state.credentials, action.invoiceIds, EntityAction.download)
|
||||
.then((invoices) {
|
||||
store.dispatch(DownloadQuotesSuccess());
|
||||
if (action.completer != null) {
|
||||
action.completer.complete(null);
|
||||
}
|
||||
}).catchError((Object error) {
|
||||
print(error);
|
||||
store.dispatch(DownloadQuotesFailure(error));
|
||||
if (action.completer != null) {
|
||||
action.completer.completeError(error);
|
||||
}
|
||||
});
|
||||
|
||||
next(action);
|
||||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _bulkEmailQuotes(QuoteRepository repository) {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as BulkEmailQuotesRequest;
|
||||
|
|
|
|||
Loading…
Reference in New Issue