|
|
@ -1,4 +1,5 @@ |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
|
|
|
import 'package:win_text_editor/framework/controllers/logger.dart'; |
|
|
|
import 'package:win_text_editor/modules/data_format/services/mustache_service.dart'; |
|
|
|
import 'package:win_text_editor/modules/data_format/services/mustache_service.dart'; |
|
|
|
import 'package:win_text_editor/shared/base/base_content_controller.dart'; |
|
|
|
import 'package:win_text_editor/shared/base/base_content_controller.dart'; |
|
|
|
import 'grid_view_controller.dart'; |
|
|
|
import 'grid_view_controller.dart'; |
|
|
@ -30,27 +31,31 @@ class DataFormatController extends BaseContentController { |
|
|
|
// Apply the template to grid data |
|
|
|
// Apply the template to grid data |
|
|
|
void applyTemplate() { |
|
|
|
void applyTemplate() { |
|
|
|
if (_templateText.isEmpty) { |
|
|
|
if (_templateText.isEmpty) { |
|
|
|
_resultTextNotifier.value = 'Error: Template is empty'; |
|
|
|
_resultTextNotifier.value = '错误:模板文本不能为空'; |
|
|
|
|
|
|
|
Logger().error(_resultTextNotifier.value); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Validate template syntax |
|
|
|
// Validate template syntax |
|
|
|
if (!MustacheService.validateTemplate(_templateText)) { |
|
|
|
if (!MustacheService.validateTemplate(_templateText)) { |
|
|
|
_resultTextNotifier.value = 'Error: Invalid Mustache template syntax'; |
|
|
|
_resultTextNotifier.value = '错误:模板语法不正确'; |
|
|
|
|
|
|
|
Logger().error(_resultTextNotifier.value); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get variables from template |
|
|
|
// Get variables from template |
|
|
|
final templateVars = MustacheService.getTemplateVariables(_templateText); |
|
|
|
final templateVars = MustacheService.getTemplateVariables(_templateText); |
|
|
|
if (templateVars.isEmpty) { |
|
|
|
if (templateVars.isEmpty) { |
|
|
|
_resultTextNotifier.value = 'Error: No variables found in template'; |
|
|
|
_resultTextNotifier.value = '错误:模板中没有找到变量'; |
|
|
|
|
|
|
|
Logger().error(_resultTextNotifier.value); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get grid data |
|
|
|
// Get grid data |
|
|
|
final gridData = gridController.csvData; |
|
|
|
final gridData = gridController.csvData; |
|
|
|
if (gridData.isEmpty || gridData.length < 2) { |
|
|
|
if (gridData.isEmpty || gridData.length < 2) { |
|
|
|
_resultTextNotifier.value = 'Error: No CSV data loaded'; |
|
|
|
_resultTextNotifier.value = '错误:没有CSV数据'; |
|
|
|
|
|
|
|
Logger().error(_resultTextNotifier.value); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -60,7 +65,8 @@ class DataFormatController extends BaseContentController { |
|
|
|
// Check if all template variables exist in headers |
|
|
|
// Check if all template variables exist in headers |
|
|
|
final missingVars = templateVars.where((varName) => !headers.contains(varName)).toList(); |
|
|
|
final missingVars = templateVars.where((varName) => !headers.contains(varName)).toList(); |
|
|
|
if (missingVars.isNotEmpty) { |
|
|
|
if (missingVars.isNotEmpty) { |
|
|
|
_resultTextNotifier.value = 'Error: Template variables not found in CSV headers: ${missingVars.join(', ')}'; |
|
|
|
_resultTextNotifier.value = '错误:没有找到模板变量: ${missingVars.join(', ')}'; |
|
|
|
|
|
|
|
Logger().error(_resultTextNotifier.value); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -84,7 +90,7 @@ class DataFormatController extends BaseContentController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_resultTextNotifier.value = resultBuffer.toString(); |
|
|
|
_resultTextNotifier.value = resultBuffer.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|