Add run_template action
This commit is contained in:
parent
bf9ef98a7a
commit
1b20ab8174
|
|
@ -543,6 +543,7 @@ void handleClientAction(BuildContext? context, List<BaseEntity> clients,
|
|||
case EntityAction.runTemplate:
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => RunTemplateDialog(
|
||||
entityType: EntityType.client,
|
||||
entities: clients,
|
||||
|
|
|
|||
|
|
@ -862,6 +862,7 @@ void handleInvoiceAction(BuildContext? context, List<BaseEntity> invoices,
|
|||
case EntityAction.runTemplate:
|
||||
showDialog<void>(
|
||||
context: navigatorKey.currentContext!,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => RunTemplateDialog(
|
||||
entityType: EntityType.invoice,
|
||||
entities: invoices,
|
||||
|
|
|
|||
|
|
@ -414,6 +414,7 @@ void handlePaymentAction(
|
|||
case EntityAction.runTemplate:
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => RunTemplateDialog(
|
||||
entityType: EntityType.payment,
|
||||
entities: payments,
|
||||
|
|
|
|||
|
|
@ -392,6 +392,7 @@ void handleProjectAction(
|
|||
case EntityAction.runTemplate:
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => RunTemplateDialog(
|
||||
entityType: EntityType.project,
|
||||
entities: projects,
|
||||
|
|
|
|||
|
|
@ -546,6 +546,7 @@ void handleTaskAction(
|
|||
case EntityAction.runTemplate:
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => RunTemplateDialog(
|
||||
entityType: EntityType.task,
|
||||
entities: tasks,
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import 'package:invoiceninja_flutter/utils/oauth.dart';
|
|||
|
||||
import 'package:invoiceninja_flutter/utils/web_stub.dart'
|
||||
if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
void showRefreshDataDialog(
|
||||
{required BuildContext context, bool includeStatic = false}) async {
|
||||
|
|
@ -630,28 +631,27 @@ class _RunTemplateDialogState extends State<RunTemplateDialog> {
|
|||
String _designId = '';
|
||||
bool _sendEmail = false;
|
||||
bool _isLoading = false;
|
||||
Uint8List? _data;
|
||||
|
||||
Future<Uint8List> loadTemplate(String jobHash) async {
|
||||
Future<bool> loadTemplate(String jobHash) async {
|
||||
final store = StoreProvider.of<AppState>(context);
|
||||
final state = store.state;
|
||||
final credentials = state.credentials;
|
||||
final url = '${credentials.url}/templates/preview/$jobHash';
|
||||
|
||||
Uint8List? data;
|
||||
|
||||
while (data == null) {
|
||||
while (_data == null) {
|
||||
await Future.delayed(Duration(seconds: 3));
|
||||
|
||||
try {
|
||||
final response =
|
||||
await WebClient().post(url, credentials.token, rawResponse: true);
|
||||
data = response.bodyBytes;
|
||||
_data = response.bodyBytes;
|
||||
} catch (error) {
|
||||
print('## CATCH ERROR: $error');
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
return _data != null;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -699,8 +699,7 @@ class _RunTemplateDialogState extends State<RunTemplateDialog> {
|
|||
showToast(localization.exportedData);
|
||||
} else {
|
||||
final jobHash = response['message'];
|
||||
final data = await loadTemplate(jobHash);
|
||||
print('## DATA LENGTH: ${data.length}');
|
||||
await loadTemplate(jobHash);
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}).catchError((error) {
|
||||
|
|
@ -711,51 +710,63 @@ class _RunTemplateDialogState extends State<RunTemplateDialog> {
|
|||
child: Text(localization.start.toUpperCase()),
|
||||
),
|
||||
],
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
localization.lookup(widget.entities.length == 1
|
||||
? widget.entityType.snakeCase
|
||||
: widget.entityType.plural),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
content: _data != null
|
||||
? SizedBox(
|
||||
width: 600,
|
||||
child: PdfPreview(
|
||||
build: (format) => _data!,
|
||||
canChangeOrientation: false,
|
||||
canChangePageFormat: false,
|
||||
allowPrinting: false,
|
||||
allowSharing: false,
|
||||
canDebug: false,
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
localization.lookup(widget.entities.length == 1
|
||||
? widget.entityType.snakeCase
|
||||
: widget.entityType.plural),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
...widget.entities
|
||||
.map((entity) => Text(entity.listDisplayName))
|
||||
.toList(),
|
||||
if (_isLoading) ...[
|
||||
SizedBox(height: 32),
|
||||
LinearProgressIndicator()
|
||||
] else ...[
|
||||
SizedBox(height: 16),
|
||||
DesignPicker(
|
||||
autofocus: true,
|
||||
entityType: widget.entityType,
|
||||
initialValue: _designId,
|
||||
onSelected: (design) {
|
||||
setState(() {
|
||||
_designId = design?.id ?? '';
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
value: _sendEmail,
|
||||
title: Text(
|
||||
localization.sendEmail,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_sendEmail = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
...widget.entities
|
||||
.map((entity) => Text(entity.listDisplayName))
|
||||
.toList(),
|
||||
if (_isLoading) ...[
|
||||
SizedBox(height: 30),
|
||||
LinearProgressIndicator()
|
||||
] else ...[
|
||||
SizedBox(height: 8),
|
||||
DesignPicker(
|
||||
autofocus: true,
|
||||
entityType: widget.entityType,
|
||||
initialValue: _designId,
|
||||
onSelected: (design) {
|
||||
setState(() {
|
||||
_designId = design?.id ?? '';
|
||||
});
|
||||
},
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
value: _sendEmail,
|
||||
title: Text(
|
||||
localization.sendEmail,
|
||||
),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_sendEmail = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue