Add designs templates

This commit is contained in:
Hillel Coren 2023-11-09 13:07:20 +02:00
parent 2be0ed2089
commit b83b2e4361
2 changed files with 41 additions and 22 deletions

View File

@ -98,3 +98,16 @@ String? getDesignIdForVendorByEntity(
return settings.defaultInvoiceDesignId; return settings.defaultInvoiceDesignId;
} }
} }
bool hasDesignTemplatesForEntityType(
BuiltMap<String, DesignEntity> designMap, EntityType entityType) {
var hasMatch = false;
designMap.forEach((designId, design) {
if (design.supportsEntityType(entityType)) {
hasMatch = true;
}
});
return hasMatch;
}

View File

@ -11,6 +11,7 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:invoiceninja_flutter/main_app.dart'; import 'package:invoiceninja_flutter/main_app.dart';
import 'package:invoiceninja_flutter/redux/design/design_selectors.dart';
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.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/files.dart';
@ -88,6 +89,7 @@ class _InvoicePdfViewState extends State<InvoicePdfView> {
invoice, invoice,
_isDeliveryNote, _isDeliveryNote,
_activityId, _activityId,
_designId,
).then((response) async { ).then((response) async {
setState(() { setState(() {
_response = response; _response = response;
@ -176,8 +178,10 @@ class _InvoicePdfViewState extends State<InvoicePdfView> {
), ),
); );
final designSelector = final designSelector = _activityId != null ||
_activityId != null || (kIsWeb && state.prefState.enableNativeBrowser) (kIsWeb && state.prefState.enableNativeBrowser) ||
!hasDesignTemplatesForEntityType(
state.designState.map, invoice.entityType!)
? SizedBox() ? SizedBox()
: Padding( : Padding(
padding: const EdgeInsets.only(left: 17), padding: const EdgeInsets.only(left: 17),
@ -195,6 +199,7 @@ class _InvoicePdfViewState extends State<InvoicePdfView> {
}, },
label: localization.design, label: localization.design,
showBlank: true, showBlank: true,
entityType: invoice.entityType,
), ),
), ),
), ),
@ -310,6 +315,7 @@ Future<Response?> _loadPDF(
InvoiceEntity invoice, InvoiceEntity invoice,
bool isDeliveryNote, bool isDeliveryNote,
String? activityId, String? activityId,
String? designId,
) async { ) async {
http.Response? response; http.Response? response;