Emaıl templates.
This commit is contained in:
@@ -130,6 +130,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
|
||||
public bool AreCertificatesAvailable => AvailableCertificates.Count > 0;
|
||||
|
||||
public ObservableCollection<EmailTemplate> AvailableEmailTemplates { get; } = [];
|
||||
public ObservableCollection<MailAttachmentViewModel> IncludedAttachments { get; set; } = [];
|
||||
public ObservableCollection<MailAccount> Accounts { get; set; } = [];
|
||||
public ObservableCollection<AccountContact> ToItems { get; set; } = [];
|
||||
@@ -148,6 +149,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IFolderService _folderService;
|
||||
private readonly IAccountService _accountService;
|
||||
private readonly IEmailTemplateService _emailTemplateService;
|
||||
private readonly IWinoRequestDelegator _worker;
|
||||
public readonly IFontService FontService;
|
||||
public readonly IPreferencesService PreferencesService;
|
||||
@@ -161,6 +163,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
INativeAppService nativeAppService,
|
||||
IFolderService folderService,
|
||||
IAccountService accountService,
|
||||
IEmailTemplateService emailTemplateService,
|
||||
IWinoRequestDelegator worker,
|
||||
IContactService contactService,
|
||||
IFontService fontService,
|
||||
@@ -178,6 +181,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
_mimeFileService = mimeFileService;
|
||||
_fileService = fileService;
|
||||
_accountService = accountService;
|
||||
_emailTemplateService = emailTemplateService;
|
||||
_worker = worker;
|
||||
_smimeCertificateService = smimeCertificateService;
|
||||
|
||||
@@ -520,6 +524,7 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
CurrentMailDraftItem = mailItem;
|
||||
|
||||
await UpdatePendingOperationStateAsync();
|
||||
await LoadEmailTemplatesAsync();
|
||||
await TryPrepareComposeAsync(true);
|
||||
}
|
||||
}
|
||||
@@ -539,9 +544,25 @@ public partial class ComposePageViewModel : MailBaseViewModel,
|
||||
// Set the new draft item and prepare it.
|
||||
CurrentMailDraftItem = message.MailItemViewModel;
|
||||
await UpdatePendingOperationStateAsync();
|
||||
await LoadEmailTemplatesAsync();
|
||||
await TryPrepareComposeAsync(true);
|
||||
}
|
||||
|
||||
private async Task LoadEmailTemplatesAsync()
|
||||
{
|
||||
var templates = await _emailTemplateService.GetEmailTemplatesAsync().ConfigureAwait(false);
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
AvailableEmailTemplates.Clear();
|
||||
|
||||
foreach (var template in templates)
|
||||
{
|
||||
AvailableEmailTemplates.Add(template);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public async void Receive(SynchronizationActionsAdded message)
|
||||
{
|
||||
if (!ShouldTrackDraftSynchronizationState(message.AccountId))
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Mail.ViewModels;
|
||||
|
||||
public partial class CreateEmailTemplatePageViewModel(
|
||||
IEmailTemplateService emailTemplateService,
|
||||
IMailDialogService dialogService,
|
||||
INavigationService navigationService) : MailBaseViewModel
|
||||
{
|
||||
private readonly IEmailTemplateService _emailTemplateService = emailTemplateService;
|
||||
private readonly IMailDialogService _dialogService = dialogService;
|
||||
|
||||
private EmailTemplate _editingTemplate;
|
||||
|
||||
public INavigationService NavigationService { get; } = navigationService;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string TemplateName { get; set; } = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string TemplateDescription { get; set; } = string.Empty;
|
||||
|
||||
[ObservableProperty]
|
||||
public partial bool IsExistingTemplate { get; set; }
|
||||
|
||||
public async Task<string> LoadAsync(object parameter)
|
||||
{
|
||||
EmailTemplate template = null;
|
||||
|
||||
var templateId = parameter switch
|
||||
{
|
||||
Guid guid when guid != Guid.Empty => guid,
|
||||
string value when Guid.TryParse(value, out var parsedGuid) => parsedGuid,
|
||||
EmailTemplate emailTemplate when emailTemplate.Id != Guid.Empty => emailTemplate.Id,
|
||||
_ => Guid.Empty
|
||||
};
|
||||
|
||||
if (templateId != Guid.Empty)
|
||||
{
|
||||
template = await _emailTemplateService.GetEmailTemplateAsync(templateId).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_editingTemplate = template;
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
IsExistingTemplate = template != null;
|
||||
TemplateName = template?.Name ?? string.Empty;
|
||||
TemplateDescription = template?.Description ?? string.Empty;
|
||||
});
|
||||
|
||||
return template?.HtmlContent ?? string.Empty;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(string htmlContent)
|
||||
{
|
||||
var trimmedName = TemplateName?.Trim() ?? string.Empty;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(trimmedName))
|
||||
{
|
||||
_dialogService.InfoBarMessage(
|
||||
Translator.GeneralTitle_Error,
|
||||
Translator.SettingsEmailTemplates_NameRequired,
|
||||
InfoBarMessageType.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var template = _editingTemplate ?? new EmailTemplate
|
||||
{
|
||||
Id = Guid.NewGuid()
|
||||
};
|
||||
|
||||
template.Name = trimmedName;
|
||||
template.Description = TemplateDescription?.Trim() ?? string.Empty;
|
||||
template.HtmlContent = htmlContent ?? string.Empty;
|
||||
|
||||
if (_editingTemplate == null)
|
||||
{
|
||||
await _emailTemplateService.CreateEmailTemplateAsync(template).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _emailTemplateService.UpdateEmailTemplateAsync(template).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_editingTemplate = template;
|
||||
NavigationService.GoBack();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync()
|
||||
{
|
||||
if (_editingTemplate == null)
|
||||
return;
|
||||
|
||||
var shouldDelete = await _dialogService.ShowConfirmationDialogAsync(
|
||||
string.Format(Translator.DialogMessage_DeleteEmailTemplateConfirmationMessage, _editingTemplate.Name),
|
||||
Translator.DialogMessage_DeleteEmailTemplateConfirmationTitle,
|
||||
Translator.Buttons_Delete).ConfigureAwait(false);
|
||||
|
||||
if (!shouldDelete)
|
||||
return;
|
||||
|
||||
await _emailTemplateService.DeleteEmailTemplateAsync(_editingTemplate).ConfigureAwait(false);
|
||||
NavigationService.GoBack();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities.Mail;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Messaging.Client.Navigation;
|
||||
|
||||
namespace Wino.Mail.ViewModels;
|
||||
|
||||
public partial class EmailTemplatesPageViewModel(IEmailTemplateService emailTemplateService) : MailBaseViewModel
|
||||
{
|
||||
private readonly IEmailTemplateService _emailTemplateService = emailTemplateService;
|
||||
|
||||
public ObservableCollection<EmailTemplate> EmailTemplates { get; } = [];
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
var templates = await _emailTemplateService.GetEmailTemplatesAsync().ConfigureAwait(false);
|
||||
|
||||
await ExecuteUIThread(() =>
|
||||
{
|
||||
EmailTemplates.Clear();
|
||||
|
||||
foreach (var template in templates)
|
||||
{
|
||||
EmailTemplates.Add(template);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void CreateTemplate()
|
||||
{
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
Translator.SettingsEmailTemplates_CreatePageTitle,
|
||||
WinoPage.CreateEmailTemplatePage));
|
||||
}
|
||||
|
||||
public void OpenTemplate(EmailTemplate template)
|
||||
{
|
||||
if (template == null)
|
||||
return;
|
||||
|
||||
var title = string.IsNullOrWhiteSpace(template.Name)
|
||||
? Translator.SettingsEmailTemplates_EditPageTitle
|
||||
: template.Name;
|
||||
|
||||
Messenger.Send(new BreadcrumbNavigationRequested(
|
||||
title,
|
||||
WinoPage.CreateEmailTemplatePage,
|
||||
template.Id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user