TF-3416 Handle open EML attachment in EML previewer

This commit is contained in:
dab246
2025-01-13 15:53:58 +07:00
committed by Dat H. Pham
parent 0ce99c745c
commit aa7fded1ff
28 changed files with 473 additions and 99 deletions
+42 -4
View File
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:math';
import 'js_interop_stub.dart' if (dart.library.html) 'dart:js_interop';
import 'dart:typed_data';
@@ -11,6 +12,8 @@ import 'package:flutter/material.dart';
import 'package:universal_html/html.dart' as html;
class HtmlUtils {
static final random = Random();
static const lineHeight100Percent = (
script: '''
document.querySelectorAll("*")
@@ -422,27 +425,62 @@ class HtmlUtils {
fileSizeSpan.textContent = formatFileSize(bytesJs.length);''';
}
static void openNewWindowByUrl(
static bool openNewWindowByUrl(
String url,
{
int width = 800,
int height = 600,
bool isFullScreen = false,
bool isCenter = true,
}
) async {
) {
try {
if (isFullScreen) {
final screenWidth = html.window.screen?.width;
final screenHeight = html.window.screen?.height;
final options = 'width=$screenWidth,height=$screenHeight';
html.window.open(url, '_blank', options);
html.Url.revokeObjectUrl(url);
return true;
}
final screenWidth = html.window.screen?.width ?? width;
final screenHeight = html.window.screen?.height ?? height;
final left = (screenWidth - width) ~/ 2;
final top = (screenHeight - height) ~/ 2;
int left, top;
if (isCenter) {
left = (screenWidth - width) ~/ 2;
top = (screenHeight - height) ~/ 2;
} else {
left = random.nextInt(screenWidth ~/ 2);
top = random.nextInt(screenHeight ~/ 2);
}
final options = 'width=$width,height=$height,top=$top,left=$left';
html.window.open(url, '_blank', options);
html.Url.revokeObjectUrl(url);
return true;
} catch (e) {
logError('AppUtils::openNewWindowByUrl:Exception = $e');
return false;
}
}
static void setWindowBrowserTitle(String title) {
try {
final titleElements = html.window.document.getElementsByTagName('title');
if (titleElements.isNotEmpty) {
titleElements.first.text = title;
}
} catch (e) {
logError('AppUtils::setWindowBrowserTitle:Exception = $e');
}
}
}
+29 -14
View File
@@ -1,5 +1,5 @@
import 'package:core/data/model/print_attachment.dart';
import 'package:core/data/model/preview_attachment.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/html/html_template.dart';
import 'package:core/utils/html/html_utils.dart';
@@ -26,7 +26,7 @@ class PreviewEmlFileUtils {
String? dateTime,
String? attachmentIcon,
String? emailContent,
List<PrintAttachment>? listAttachment,
List<PreviewAttachment>? listAttachment,
}) {
try {
return Element.html('''
@@ -83,23 +83,38 @@ class PreviewEmlFileUtils {
}
}
String _createAttachmentHtmlTag(PrintAttachment printAttachment) {
String _createAttachmentHtmlTag(PreviewAttachment previewAttachment) {
return '''
<div class="attachment-item">
<div class="icon">
<img width="16" height="16" src="${HtmlUtils.generateSVGImageData(printAttachment.iconBase64Data)}" alt="attachment-icon"/>
</div>
<div class="file-details">
<div class="file-name">${printAttachment.name}</div>
<div class="file-size">${printAttachment.size}</div>
</div>
</div>
${previewAttachment.link?.isNotEmpty == true
? '''
<a href="${previewAttachment.link}" class="attachment-item">
<div class="icon">
<img width="16" height="16" src="${HtmlUtils.generateSVGImageData(previewAttachment.iconBase64Data)}" alt="attachment-icon"/>
</div>
<div class="file-details">
<div class="file-name">${previewAttachment.name}</div>
<div class="file-size">${previewAttachment.size}</div>
</div>
</a>
'''
: '''
<div class="attachment-item">
<div class="icon">
<img width="16" height="16" src="${HtmlUtils.generateSVGImageData(previewAttachment.iconBase64Data)}" alt="attachment-icon"/>
</div>
<div class="file-details">
<div class="file-name">${previewAttachment.name}</div>
<div class="file-size">${previewAttachment.size}</div>
</div>
</div>
'''}
''';
}
String _createAttachmentsElement({
required String titleAttachment,
required List<PrintAttachment> listAttachment
required List<PreviewAttachment> listAttachment
}) {
try {
return '''
@@ -137,7 +152,7 @@ class PreviewEmlFileUtils {
String? ccAddress,
String? bccAddress,
String? replyToAddress,
List<PrintAttachment>? listAttachment,
List<PreviewAttachment>? listAttachment,
}) {
Document document = parse(HtmlUtils.createTemplateHtmlDocument(title: '$subject - $userName'));