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