-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #294 from GregFinzer/feature/bulkEmailFull
Feature/bulk email full
- Loading branch information
Showing
33 changed files
with
1,910 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
BedBrigade.Client/Pages/Administration/Admin/Email.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using BedBrigade.Common; | ||
using BedBrigade.Data.Models; | ||
using BedBrigade.Data.Services; | ||
using Microsoft.AspNetCore.Components; | ||
using Syncfusion.Blazor.DropDowns; | ||
|
||
namespace BedBrigade.Client.Pages.Administration.Admin | ||
{ | ||
public partial class Email : ComponentBase | ||
{ | ||
[Inject] private IUserDataService _svcUserDataService { get; set; } | ||
[Inject] private ILocationDataService _svcLocationDataService { get; set; } | ||
[Inject] private IScheduleDataService _svcScheduleDataService { get; set; } | ||
[Inject] private IEmailQueueDataService _svcEmailQueueDataService { get; set; } | ||
|
||
public BulkEmailModel Model { get; set; } = new(); | ||
private bool isSuccess; | ||
private bool isFailure; | ||
private bool showPlan; | ||
private string message; | ||
private bool isNationalAdmin; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
Model.Locations = (await _svcLocationDataService.GetAllAsync()).Data; | ||
var user = (await _svcUserDataService.GetCurrentLoggedInUser()).Data; | ||
Model.Body = (await _svcUserDataService.GetEmailSignature(user.UserName)).Data; | ||
Model.Schedules = (await _svcScheduleDataService.GetFutureSchedulesByLocationId(user.LocationId)).Data; | ||
Model.CurrentLocationId = user.LocationId; | ||
isNationalAdmin = user.LocationId == Constants.NationalLocationId; | ||
|
||
if (isNationalAdmin) | ||
{ | ||
Model.EmailRecipientOptions = EnumHelper.GetEnumNameValues<EmailRecipientOption>(); | ||
} | ||
else | ||
{ | ||
Model.EmailRecipientOptions = EnumHelper.GetEnumNameValues<EmailRecipientOption>().Where(x => x.Value != EmailRecipientOption.Everyone).ToList(); | ||
} | ||
|
||
Model.CurrentEmailRecipientOption = EmailRecipientOption.BedBrigadeLeadersForLocation; | ||
Model.ShowLocationDropdown = isNationalAdmin; | ||
Model.ShowEventDropdown = false; | ||
await BuildPlan(); | ||
} | ||
|
||
private async Task HandleValidSubmit() | ||
{ | ||
var emails = await _svcEmailQueueDataService.GetEmailsToSend(Model.CurrentLocationId, Model.CurrentEmailRecipientOption, Model.CurrentScheduleId); | ||
var result = await EmailQueueLogic.QueueBulkEmail(emails.Data, Model.Subject, Model.Body); | ||
if (result.Success) | ||
{ | ||
ShowSuccess("Email successfully queued."); | ||
} | ||
else | ||
{ | ||
ShowFailure("Email failed to queue. " + result.Message); | ||
} | ||
} | ||
|
||
private async void LocationChangeEvent(ChangeEventArgs<int, Location> args) | ||
{ | ||
Model.CurrentLocationId = args.Value; | ||
Model.Schedules = (await _svcScheduleDataService.GetFutureSchedulesByLocationId(Model.CurrentLocationId)).Data; | ||
Model.CurrentScheduleId = 0; | ||
await BuildPlan(); | ||
StateHasChanged(); | ||
} | ||
|
||
private async Task BuildPlan() | ||
{ | ||
message = (await _svcEmailQueueDataService.GetSendPlanMessage(Model.CurrentLocationId, Model.CurrentEmailRecipientOption, Model.CurrentScheduleId)).Data; | ||
showPlan = true; | ||
} | ||
|
||
private async void ScheduleChangeEvent(ChangeEventArgs<int, Data.Models.Schedule> args) | ||
{ | ||
Model.CurrentScheduleId = args.Value; | ||
await BuildPlan(); | ||
StateHasChanged(); | ||
} | ||
|
||
private async void EmailRecipientChangeEvent(ChangeEventArgs<EmailRecipientOption, EnumNameValue<EmailRecipientOption>> args) | ||
{ | ||
Model.CurrentEmailRecipientOption = args.Value; | ||
Model.ShowEventDropdown = Model.CurrentEmailRecipientOption.ToString().Contains("Event"); | ||
Model.ShowLocationDropdown = isNationalAdmin && (Model.CurrentEmailRecipientOption.ToString().Contains("Location") | ||
|| Model.CurrentEmailRecipientOption.ToString().Contains("Event")); | ||
await BuildPlan(); | ||
StateHasChanged(); | ||
} | ||
|
||
public void ShowSuccess(string successMessage) | ||
{ | ||
isSuccess = true; | ||
isFailure = false; | ||
showPlan = false; | ||
message = successMessage; | ||
} | ||
|
||
public void ShowFailure(string failureMessage) | ||
{ | ||
isFailure = true; | ||
isSuccess = false; | ||
showPlan = false; | ||
message = failureMessage; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BedBrigade.Common | ||
{ | ||
public static class DateUtil | ||
{ | ||
public static String MillisecondsToTimeLapse(long milliseconds) | ||
{ | ||
TimeSpan ts = TimeSpan.FromMilliseconds(milliseconds); | ||
|
||
string result; | ||
|
||
if ((long)ts.TotalDays == 1) | ||
result = string.Format("{0:n0} day, {1:n0} hours, {2:n0} minutes, {3:n0} seconds, {4:n0} milliseconds", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if (ts.TotalDays >= 1) | ||
result = string.Format("{0:n0} days, {1:n0} hours, {2:n0} minutes, {3:n0} seconds, {4:n0} milliseconds", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if ((long)ts.TotalHours == 1) | ||
result = string.Format("{0:n0} hr, {1:n0} minutes, {2:n0} seconds, {3:n0} milliseconds", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if (ts.TotalHours >= 1) | ||
result = string.Format("{0:n0} hours, {1:n0} minutes, {2:n0} seconds, {3:n0} milliseconds", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if ((long)ts.TotalMinutes == 1) | ||
result = string.Format("{0:n0} min, {1:n0} seconds, {2:n0} milliseconds", ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if (ts.TotalMinutes >= 1) | ||
result = string.Format("{0:n0} minutes, {1:n0} seconds, {2:n0} milliseconds", ts.Minutes, ts.Seconds, ts.Milliseconds); | ||
else if ((long)ts.TotalSeconds == 1) | ||
result = string.Format("{0:n0} second, {1:n0} milliseconds", ts.Seconds, ts.Milliseconds); | ||
else if (ts.TotalSeconds >= 1) | ||
result = string.Format("{0:n0} seconds, {1:n0} milliseconds", ts.Seconds, ts.Milliseconds); | ||
else | ||
result = string.Format("{0:n0} milliseconds", ts.Milliseconds); | ||
|
||
result = result.Replace(" 1 hours", " 1 hour"); | ||
result = result.Replace(" 1 minutes", " 1 minute"); | ||
result = result.Replace(" 1 seconds", " 1 second"); | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace BedBrigade.Common | ||
{ | ||
public enum EmailRecipientOption | ||
{ | ||
[Description("Bed Brigade Leaders Nationwide")] | ||
BedBrigadeLeadersNationwide, | ||
[Description("Bed Brigade Leaders for Location")] | ||
BedBrigadeLeadersForLocation, | ||
[Description("Bed Requestors for Location")] | ||
BedRequestorsForLocation, | ||
[Description("Bed Requestors Who Have NOT Received A Bed for Location")] | ||
BedRequestorsWhoHaveNotRecievedABed, | ||
[Description("Bed Requestors Who Have Received A Bed for Location")] | ||
BedRequestorsWhoHaveRecievedABed, | ||
[Description("Bed Requestors For An Event")] | ||
BedRequestorsForAnEvent, | ||
Everyone, | ||
[Description("Contact Us Requests for Location")] | ||
ContactUsForLocation, | ||
[Description("Volunteers for Location")] | ||
VolunteersForLocation, | ||
[Description("Volunteers With Delivery Vehicles for Location")] | ||
VolunteersWithDeliveryVehicles, | ||
[Description("Volunteers For An Event")] | ||
VolunteersForAnEvent, | ||
|
||
} | ||
} |
Oops, something went wrong.