Support for templates
This commit is contained in:
parent
1b20ab8174
commit
81119d5f37
|
|
@ -12,6 +12,7 @@ import 'package:invoiceninja_flutter/main_app.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/task/task_actions.dart';
|
import 'package:invoiceninja_flutter/redux/task/task_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/task_status/task_status_selectors.dart';
|
import 'package:invoiceninja_flutter/redux/task_status/task_status_selectors.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/forms/design_picker.dart';
|
import 'package:invoiceninja_flutter/ui/app/forms/design_picker.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/files.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||||
|
|
@ -639,7 +640,7 @@ class _RunTemplateDialogState extends State<RunTemplateDialog> {
|
||||||
final credentials = state.credentials;
|
final credentials = state.credentials;
|
||||||
final url = '${credentials.url}/templates/preview/$jobHash';
|
final url = '${credentials.url}/templates/preview/$jobHash';
|
||||||
|
|
||||||
while (_data == null) {
|
while (_data == null && mounted) {
|
||||||
await Future.delayed(Duration(seconds: 3));
|
await Future.delayed(Duration(seconds: 3));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -669,46 +670,66 @@ class _RunTemplateDialogState extends State<RunTemplateDialog> {
|
||||||
},
|
},
|
||||||
child: Text(localization.close.toUpperCase()),
|
child: Text(localization.close.toUpperCase()),
|
||||||
),
|
),
|
||||||
TextButton(
|
if (_data != null) ...[
|
||||||
onPressed: _designId.isEmpty
|
TextButton(
|
||||||
? null
|
onPressed: () {
|
||||||
: () {
|
setState(() {
|
||||||
final credentials = state.credentials;
|
_data = null;
|
||||||
final url =
|
});
|
||||||
'${credentials.url}/${widget.entityType.pluralApiValue}/bulk';
|
},
|
||||||
final data = {
|
child: Text(
|
||||||
'ids': widget.entities.map((entity) => entity.id).toList(),
|
localization.reset.toUpperCase(),
|
||||||
'entity': widget.entityType.apiValue,
|
),
|
||||||
'template_id': _designId,
|
),
|
||||||
'send_email': _sendEmail,
|
TextButton(
|
||||||
'action': EntityAction.runTemplate.toApiParam(),
|
child: Text(localization.download.toUpperCase()),
|
||||||
};
|
onPressed: () {
|
||||||
|
final design = state.designState.map[_designId]!;
|
||||||
|
saveDownloadedFile(_data!, design.name);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
] else
|
||||||
|
TextButton(
|
||||||
|
onPressed: _designId.isEmpty || _isLoading
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
final credentials = state.credentials;
|
||||||
|
final url =
|
||||||
|
'${credentials.url}/${widget.entityType.pluralApiValue}/bulk';
|
||||||
|
final data = {
|
||||||
|
'ids':
|
||||||
|
widget.entities.map((entity) => entity.id).toList(),
|
||||||
|
'entity': widget.entityType.apiValue,
|
||||||
|
'template_id': _designId,
|
||||||
|
'send_email': _sendEmail,
|
||||||
|
'action': EntityAction.runTemplate.toApiParam(),
|
||||||
|
};
|
||||||
|
|
||||||
print('## DATA: $data');
|
print('## DATA: $data');
|
||||||
|
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
WebClient()
|
WebClient()
|
||||||
.post(url, credentials.token, data: jsonEncode(data))
|
.post(url, credentials.token, data: jsonEncode(data))
|
||||||
.then((response) async {
|
.then((response) async {
|
||||||
print('## RESPONSE: $response');
|
print('## RESPONSE: $response');
|
||||||
|
|
||||||
if (_sendEmail) {
|
if (_sendEmail) {
|
||||||
|
setState(() => _isLoading = false);
|
||||||
|
Navigator.of(navigatorKey.currentContext!).pop();
|
||||||
|
showToast(localization.exportedData);
|
||||||
|
} else {
|
||||||
|
final jobHash = response['message'];
|
||||||
|
await loadTemplate(jobHash);
|
||||||
|
setState(() => _isLoading = false);
|
||||||
|
}
|
||||||
|
}).catchError((error) {
|
||||||
|
print('## ERROR: $error');
|
||||||
setState(() => _isLoading = false);
|
setState(() => _isLoading = false);
|
||||||
Navigator.of(navigatorKey.currentContext!).pop();
|
});
|
||||||
showToast(localization.exportedData);
|
},
|
||||||
} else {
|
child: Text(localization.start.toUpperCase()),
|
||||||
final jobHash = response['message'];
|
),
|
||||||
await loadTemplate(jobHash);
|
|
||||||
setState(() => _isLoading = false);
|
|
||||||
}
|
|
||||||
}).catchError((error) {
|
|
||||||
print('## ERROR: $error');
|
|
||||||
setState(() => _isLoading = false);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Text(localization.start.toUpperCase()),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
content: _data != null
|
content: _data != null
|
||||||
? SizedBox(
|
? SizedBox(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue