|
@@ -1,12 +1,23 @@
|
|
|
import 'package:fis_lib_report/report/element_tag.dart';
|
|
|
+import 'package:fis_lib_report/report/element_type.dart';
|
|
|
+import 'package:fis_lib_report/report/inputImageList.dart';
|
|
|
+import 'package:fis_lib_report/report/inputText.dart';
|
|
|
+import 'package:fis_lib_report/report/interfaces/block_element.dart';
|
|
|
+import 'package:fis_lib_report/report/interfaces/element.dart';
|
|
|
+import 'package:fis_lib_report/report/paragraph.dart';
|
|
|
import 'package:fis_lib_report/report/report_template_document.dart';
|
|
|
-import 'package:fis_lib_report/report_info/block_element_info.dart';
|
|
|
+import 'package:fis_lib_report/report/rt_table.dart';
|
|
|
+import 'package:fis_lib_report/report_info/block_element_info_interface.dart';
|
|
|
+import 'package:fis_lib_report/report_info/element_info.dart';
|
|
|
+import 'package:fis_lib_report/report_info/input_image_list_info.dart';
|
|
|
+import 'package:fis_lib_report/report_info/paragraph_info.dart';
|
|
|
+import 'package:fis_lib_report/report_info/rt_table_info.dart';
|
|
|
|
|
|
class ReportInfo {
|
|
|
static ReportInfo? _reportInfo;
|
|
|
- List<BlockElementInfo> blocks = [];
|
|
|
- List<BlockElementInfo> headers = [];
|
|
|
- List<BlockElementInfo> footers = [];
|
|
|
+ List<IBlockElementInfo> blocks = [];
|
|
|
+ List<IBlockElementInfo> headers = [];
|
|
|
+ List<IBlockElementInfo> footers = [];
|
|
|
|
|
|
/// Gets the author of the report template.
|
|
|
String? author;
|
|
@@ -44,16 +55,136 @@ class ReportInfo {
|
|
|
version = reportTemplate.version;
|
|
|
id = reportTemplate.id;
|
|
|
for (var element in reportTemplate.header!) {
|
|
|
- headers.add(BlockElementInfo.fromElement(element));
|
|
|
+ headers.add(_initBlockElement(element));
|
|
|
}
|
|
|
for (var element in reportTemplate.blocks!) {
|
|
|
- blocks.add(BlockElementInfo.fromElement(element));
|
|
|
+ blocks.add(_initBlockElement(element));
|
|
|
}
|
|
|
for (var element in reportTemplate.footer!) {
|
|
|
- footers.add(BlockElementInfo.fromElement(element));
|
|
|
+ footers.add(_initBlockElement(element));
|
|
|
}
|
|
|
} catch (e) {
|
|
|
print(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ IBlockElementInfo? getBlockElement(IBlockElement block) {
|
|
|
+ final id = block.id;
|
|
|
+ for (var element in headers) {
|
|
|
+ if (element.id == id) {
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var element in blocks) {
|
|
|
+ if (element.id == id) {
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var element in footers) {
|
|
|
+ if (element.id == id) {
|
|
|
+ return element;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ IBlockElementInfo _initBlockElement(IBlockElement element) {
|
|
|
+ final _type = element.elementType!;
|
|
|
+ if (_type.name == ElementType.rtTable!.name) {
|
|
|
+ final table = element as RTTable;
|
|
|
+ return RTTableInfo.fromElement(table);
|
|
|
+ } else if (_type.name == ElementType.paragraph!.name) {
|
|
|
+ final paragraph = element as Paragraph;
|
|
|
+ return ParagraphInfo.fromElement(paragraph);
|
|
|
+ } else {
|
|
|
+ final inputImageList = element as InputImageList;
|
|
|
+ return InputImageListInfo.fromElement(inputImageList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void getSelectedInputImage(String imageUrl) {
|
|
|
+ for (var element in headers) {
|
|
|
+ if (_checkImageisSelected(element)) {
|
|
|
+ final inputImage = element as InputImageListInfo;
|
|
|
+ inputImage.addImage(imageUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var element in blocks) {
|
|
|
+ if (_checkImageisSelected(element)) {
|
|
|
+ final inputImage = element as InputImageListInfo;
|
|
|
+ inputImage.addImage(imageUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var element in footers) {
|
|
|
+ if (_checkImageisSelected(element)) {
|
|
|
+ final inputImage = element as InputImageListInfo;
|
|
|
+ inputImage.addImage(imageUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ElementInfo? getElementInfo(IElement element) {
|
|
|
+ try {
|
|
|
+ for (var e in headers) {
|
|
|
+ final elementInfo = _getBaseElementInfo(e, element);
|
|
|
+ if (elementInfo != null) {
|
|
|
+ return elementInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var e in blocks) {
|
|
|
+ final elementInfo = _getBaseElementInfo(e, element);
|
|
|
+ if (elementInfo != null) {
|
|
|
+ return elementInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var e in footers) {
|
|
|
+ final elementInfo = _getBaseElementInfo(e, element);
|
|
|
+ if (elementInfo != null) {
|
|
|
+ return elementInfo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ print(e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool _checkImageisSelected(IBlockElementInfo block) {
|
|
|
+ if (block is InputImageListInfo) {
|
|
|
+ final inputImage = block;
|
|
|
+ if (inputImage.isSelected!) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ ElementInfo? _getBaseElementInfo(IBlockElementInfo block, IElement element) {
|
|
|
+ ElementInfo? result;
|
|
|
+ final type = block.elementType;
|
|
|
+ if (type!.name == ElementType.paragraph!.name) {
|
|
|
+ final paragraph = block as ParagraphInfo;
|
|
|
+ for (var el in paragraph.elementInfos!) {
|
|
|
+ if (el.id == element.id) {
|
|
|
+ result = el;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (result == null) {
|
|
|
+ if (type.name == ElementType.rtTable!.name) {
|
|
|
+ final table = block as RTTableInfo;
|
|
|
+ final cells = table.cells!;
|
|
|
+ for (var cell in cells.values) {
|
|
|
+ for (var b in cell.blocks!) {
|
|
|
+ final info = _getBaseElementInfo(b, element);
|
|
|
+ if (info != null) {
|
|
|
+ result = info;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|