Skip to content

Commit

Permalink
Version 1.40 (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
NomisNostab authored May 1, 2023
2 parents 1436b30 + 69bdada commit 64999c0
Show file tree
Hide file tree
Showing 19 changed files with 516 additions and 111 deletions.
1 change: 1 addition & 0 deletions Model/Login/LoginPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ public class LoginPageViewModel
[Display(Name = "Member Number")]
public string MemberNumber { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string LoginErrorMessage { get; set; } = string.Empty;
}
}
2 changes: 2 additions & 0 deletions Model/Program/AttendanceReportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class AttendanceReportItemModel
public string MemberId { get; set; } = string.Empty;
public string MemberName { get; set; } = string.Empty;
public string MemberNameAndRate { get; set; } = string.Empty;
public string MemberFirstName { get; set; } = string.Empty;
public string MemberLastName { get; set; } = string.Empty;
public string EventName { get; set; } = string.Empty;
public string EventNameDisplay { get; set; } = string.Empty;
public string EventChallengeArea { get; set; } = string.Empty;
Expand Down
10 changes: 8 additions & 2 deletions Model/Program/EventListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ public class EventListModel
public string ChallengeArea { get; set; } = string.Empty;
public string EventDisplay { get; set; } = string.Empty;

[Display(Name = "Date")]
public string EventDate => StartDateTime.ToShortDateString();
[Display(Name = "Date Time")]
public string EventDate => StartDateTime.Date == EndDateTime.Date
? $"{StartDateTime.ToString("dd/MM/yy HH:mm")} - {EndDateTime.ToString("HH:mm")}"
: $"{StartDateTime.ToString("dd/MM/yy HH:mm")} - {EndDateTime.ToString("HH:mm")} +{EndDateTime.DayOfYear - StartDateTime.DayOfYear}";

public List<EventAttendance> attendees = new List<EventAttendance>();

[Display(Name = "Status")]
public string EventStatus { get; set; } = string.Empty;
public bool IsUnitEvent { get; set; }
public string Organiser { get; set; } = string.Empty;
public string Location { get; set; } = string.Empty;
public string Lead { get; set; } = string.Empty;
public string Assist { get; set; } = string.Empty;
}

public class EventAttendance
Expand Down
2 changes: 1 addition & 1 deletion Model/Progress/ProgressDetailsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class OASSummary
public string Stream { get; set; } = string.Empty;
public int Stage { get; set; }
public DateTime Awarded { get; set; }

public string Section { get; set; } = string.Empty;
}

public class Stats
Expand Down
4 changes: 3 additions & 1 deletion Model/ReportGeneration/ReportGenerationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum ReportType
Wallchart,
AdditionalAwards,
Approvals,
PersonalProgress
PersonalProgress,
TermProgram
}

public enum OutputType
Expand All @@ -36,6 +37,7 @@ public class ReportGenerationRequest
public string EventName { get; set; } = string.Empty;
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public TimeSpan CurrentUtcOffset { get; set; } = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
public bool BreakByPatrol { get; set; } = false;
public bool GroupByMember { get; set; } = false;
public bool FormatLikeTerrain { get; set; } = false;
Expand Down
318 changes: 272 additions & 46 deletions Services/ReportService.cs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Topo/Controller/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class LoginController : ComponentBase
internal async Task LogInClick ()
{
var authenticationResult = await _loginService.LoginAsync(model.Branch, model.MemberNumber, model.Password);
model.LoginErrorMessage = "";
if (authenticationResult != null && authenticationResult.AuthenticationSuccessResultModel.AuthenticationResult != null)
{
await _loginService.GetUserAsync();
Expand All @@ -35,7 +36,10 @@ internal async Task LogInClick ()

NavigationManager.NavigateTo("index");
}

if (authenticationResult != null && authenticationResult.AuthenticationErrorResultModel != null)
{
model.LoginErrorMessage = authenticationResult.AuthenticationErrorResultModel.message;
}
}
}
}
21 changes: 21 additions & 0 deletions Topo/Controller/ProgramController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ private async Task<byte[]> AttendanceReport(OutputType outputType = OutputType.P

return report;
}

internal async Task TermProgramReportXlsxClick()
{
byte[] report = await TermProgramReport(OutputType.Excel);
var fileName = $"Term_Program_{_storageService.UnitName.Replace(' ', '_')}.xlsx";

// Send the data to JS to actually download the file
await JS.InvokeVoidAsync("BlazorDownloadFile", fileName, "application/vnd.ms-excel", report);
}

private async Task<byte[]> TermProgramReport(OutputType outputType = OutputType.PDF)
{
var groupName = _storageService.GroupName ?? "Group Name";
var unitName = _storageService.UnitName ?? "Unit Name";
var section = _storageService.Section;

var serialisedTermProgramData = JsonConvert.SerializeObject(model.Events);
var report = await _reportService.GetTermProgramReport(groupName, section, unitName, outputType, serialisedTermProgramData);

return report;
}
}

}
9 changes: 9 additions & 0 deletions Topo/Pages/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
</div>
</div>

<div class="form-group mb-3 row">
<div class="col-sm-2"></div>
<div class="col-sm-3">
<label class="col-form-label validation-message">@model.LoginErrorMessage</label>
</div>
<div class="col-sm-7">
</div>
</div>

<div class="form-group mb-3 row">
<div class="col-sm-2"></div>
<div class="col-sm-3">
Expand Down
43 changes: 28 additions & 15 deletions Topo/Pages/Program.razor
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,57 @@
@if (model.Events != null && model.Events.Any())
{
<div class="row header">
<div class="col-sm-1">
<div class="col-sm-2">
<strong>Date</strong>
</div>
<div class="col-sm-3">
<strong>Program Name</strong>
</div>
<div class="col-sm-2">
<strong>Status</strong>
<strong>Event / Location</strong>
</div>
<div class="col-sm-1">
<strong>Organiser</strong>
</div>
<div class="col-sm-1">
<strong>Lead</strong>
</div>
<div class="col-sm-2">
<strong>Challenge Area</strong>
<strong>Assist</strong>
</div>
<div class="col-sm-1">
<strong>Challenge</strong>
</div>
<div class="col-sm-1">
<strong>Event</strong>
</div>
<div class="col-sm-3">
<div class="col-sm-2">
</div>
</div>

@foreach (var item in model?.Events)
{
<div class="row striped">
<div class="col-sm-1">
<div class="col-sm-2">
@item.EventDate
</div>
<div class="col-sm-3">
@item.EventName
</div>
<div class="col-sm-2">
@item.EventStatus
@item.EventName<br />@item.Location
</div>
<div class="col-sm-1">
@item.Organiser
</div>
<div class="col-sm-1">
@item.Lead
</div>
<div class="col-sm-2">
@item.Assist
</div>
<div class="col-sm-1">
@item.ChallengeArea
</div>
<div class="col-sm-1">
@(item.IsUnitEvent ? "Unit" : "Group")
</div>
<div class="col-sm-3">
<button @onclick="@(e => SignInSheetClick(item.Id))" class="btn btn-link pt-0 pb-0">Sign in Sheet</button>
<div class="col-sm-2">
<button @onclick="@(e => SignInSheetClick(item.Id))" class="btn btn-link pt-0 pb-0">Sign in</button>
<button @onclick="@(e => EventAttendanceClick(item.Id))" class="btn btn-link pt-0 pb-0">Attendance</button>
</div>
</div>
Expand All @@ -108,7 +120,8 @@
<div class="mt-3 mb-3 row">
<div class="col-sm">
<button type="submit" name="button" @onclick="AttendanceReportPdfClick" class="btn btn-primary">Attendance Report (pdf)</button> &nbsp;
<button type="submit" name="button" @onclick="AttendanceReportXlsxClick" class="btn btn-success">Attendance Report (xlsx)</button>
<button type="submit" name="button" @onclick="AttendanceReportXlsxClick" class="btn btn-success">Attendance Report (xlsx)</button> &nbsp;
<button type="submit" name="button" @onclick="TermProgramReportXlsxClick" class="btn btn-success">Term Program (xlsx)</button>
</div>
</div>

Expand Down
35 changes: 22 additions & 13 deletions Topo/Pages/Progress/Details.razor
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@
</div>
<div class="row">
<div class="col-sm-2">
<span>Creative:</span>
<span>Outdoors:</span>
</div>
<div class="col-sm-10">
<div class="row">
@foreach (var milestoneEvent in milestone.ParticipateLogs.Where(e => e.ChallengeArea == "creative"))
@foreach (var milestoneEvent in milestone.ParticipateLogs.Where(e => e.ChallengeArea == "outdoors"))
{
<div class="col-sm-2">
<span>@milestoneEvent.EventName</span><span><br />@milestoneEvent.EventDate.ToString("dd/MM/yy")</span>
Expand All @@ -92,11 +92,11 @@
</div>
<div class="row">
<div class="col-sm-2">
<span>Outdoors:</span>
<span>Creative:</span>
</div>
<div class="col-sm-10">
<div class="row">
@foreach (var milestoneEvent in milestone.ParticipateLogs.Where(e => e.ChallengeArea == "outdoors"))
@foreach (var milestoneEvent in milestone.ParticipateLogs.Where(e => e.ChallengeArea == "creative"))
{
<div class="col-sm-2">
<span>@milestoneEvent.EventName</span><span><br />@milestoneEvent.EventDate.ToString("dd/MM/yy")</span>
Expand Down Expand Up @@ -209,7 +209,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "bushcraft" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = model.OASSummaries.Where(o => o.Stream == "bushcraft" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -231,7 +232,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "bushwalking" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = model.OASSummaries.Where(o => o.Stream == "bushwalking" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -253,7 +255,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "camping" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "camping" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -275,7 +278,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "alpine" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "alpine" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -297,7 +301,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "cycling" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "cycling" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -319,7 +324,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "vertical" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "vertical" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -341,7 +347,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "aquatics" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "aquatics" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -363,7 +370,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "boating" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "boating" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand All @@ -385,7 +393,8 @@
}
else
{
<span>@model.OASSummaries.Where(o => o.Stream == "paddling" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault().Awarded.ToString("dd/MM/yy")</span>
var summary = @model.OASSummaries.Where(o => o.Stream == "paddling" && o.Stage == i).OrderByDescending(o => o.Awarded).FirstOrDefault();
<span>@summary.Awarded.ToString("dd/MM/yy") @summary.Section</span>
}
</div>
}
Expand Down
44 changes: 31 additions & 13 deletions Topo/Services/ProgramService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Newtonsoft.Json;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Globalization;
using Topo.Model.Program;
using System;

namespace Topo.Services
{
Expand Down Expand Up @@ -81,19 +83,33 @@ public async Task<List<EventListModel>> GetEventsForDates(DateTime fromDate, Dat
var getEventsResultModel = await _terrainAPIService.GetEventsAsync(GetUser(), fromDate.AddDays(-1), toDate);
if (getEventsResultModel != null && getEventsResultModel.results != null)
{
var events = getEventsResultModel.results.Select(e => new EventListModel()
var eventList = new List<EventListModel>();
foreach (var eventResult in getEventsResultModel.results)
{
Id = e.id,
EventName = e.title,
StartDateTime = e.start_datetime,
EndDateTime = e.end_datetime,
ChallengeArea = myTI.ToTitleCase(e.challenge_area.Replace("_", " ")),
EventStatus = myTI.ToTitleCase(e.status),
IsUnitEvent = e.invitee_type == "unit",
EventDisplay = $"{e.title} {e.start_datetime.ToShortDateString()}"
})
.ToList();
return events;
var getEventResultModel = await _terrainAPIService.GetEventAsync(eventResult.id);
var leads = getEventResultModel.attendance.leader_members.Select(a => string.Concat(a.first_name, " ", a.last_name.AsSpan(0, 1)));
var leadNames = string.Join(", ", leads);
var assists = getEventResultModel.attendance.assistant_members.Select(a => string.Concat(a.first_name, " ", a.last_name.AsSpan(0, 1)));
var assistNames = string.Join(", ", assists);
var organiserName = $"{getEventResultModel?.organiser?.first_name ?? ""} {getEventResultModel?.organiser?.last_name.Substring(0, 1) ?? ""}";
eventList.Add(new EventListModel()
{
Id = eventResult.id,
EventName = eventResult.title,
StartDateTime = eventResult.start_datetime,
EndDateTime = eventResult.end_datetime,
ChallengeArea = myTI.ToTitleCase(eventResult.challenge_area.Replace("_", " ").Replace("personal ", "")),
EventStatus = myTI.ToTitleCase(eventResult.status),
IsUnitEvent = eventResult.invitee_type == "unit",
EventDisplay = $"{eventResult.title} {eventResult.start_datetime.ToShortDateString()}",
Organiser = organiserName,
Lead = leadNames,
Assist = assistNames,
Location = getEventResultModel?.location ?? ""
});

}
return eventList;
}
return new List<EventListModel>();
}
Expand Down Expand Up @@ -204,6 +220,8 @@ public async Task<AttendanceReportModel> GenerateAttendanceReportData(DateTime f
{
MemberId = member.id,
MemberName = $"{member.first_name} {member.last_name}",
MemberFirstName = member.first_name,
MemberLastName = member.last_name,
EventName = programEvent.EventName,
EventChallengeArea = programEvent.ChallengeArea,
EventStartDate = programEvent.StartDateTime,
Expand Down
Loading

0 comments on commit 64999c0

Please sign in to comment.