Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-177: Suppress last name on milestone, oas and wallchart #185

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Model/Milestone/MilestonePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class MilestonePageViewModel
public string UnitId { get; set; } = string.Empty;
public string UnitName { get; set; } = string.Empty;
public string GroupName { get; set; } = string.Empty;
public bool SuppressLastName { get; set; }
}
}
1 change: 1 addition & 0 deletions Model/OAS/OASPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class OASPageViewModel
public string GroupName { get; set; } = string.Empty;
public bool UseCore { get; set; } = false;
public bool[] CoreStages { get; set; } = new bool[9];
public bool SuppressLastName { get; set; }
}

}
2 changes: 2 additions & 0 deletions Model/Wallchart/WallchartPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class WallchartPageViewModel
public string GroupName { get; set; } = string.Empty;
public string ErrorMessage { get; set; } = string.Empty;
public bool BreakByPatrol { get; set; }

public bool SuppressLastName { get; set; }
}
}
24 changes: 21 additions & 3 deletions Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,16 @@ private void GenerateOASWorksheetBodyLikeTerrain(IWorksheet sheet, IList<IGroupi
foreach (var groupedAnswer in groupedAnswers.OrderBy(ga => ga.Key))
{
columnNumber++;
sheet.Range[rowNumber, columnNumber].Text = groupedAnswer.Key;
string memberName;
if (groupedAnswer.Key.Contains('|'))
{
memberName = groupedAnswer.Key.Split("|")[0];
}
else
{
memberName = groupedAnswer.Key;
}
sheet.Range[rowNumber, columnNumber].Text = memberName;
sheet.Range[rowNumber, columnNumber].BorderAround();
sheet.Range[rowNumber, columnNumber].CellStyle.Font.Bold = true;
sheet.Range[rowNumber, columnNumber].CellStyle.Rotation = 90;
Expand Down Expand Up @@ -1199,7 +1208,16 @@ private void GenerateOASWorksheetBodyOriginal(IWorksheet sheet, IList<IGrouping<
foreach (var groupedAnswer in groupedAnswers.OrderBy(ga => ga.Key))
{
columnNumber++;
sheet.Range[rowNumber, columnNumber].Text = groupedAnswer.Key;
string memberName;
if (groupedAnswer.Key.Contains('|'))
{
memberName = groupedAnswer.Key.Split("|")[0];
}
else
{
memberName = groupedAnswer.Key;
}
sheet.Range[rowNumber, columnNumber].Text = memberName;
sheet.Range[rowNumber, columnNumber].BorderAround();
sheet.Range[rowNumber, columnNumber].CellStyle.Font.Bold = true;

Expand Down Expand Up @@ -1272,7 +1290,7 @@ public IWorkbook GenerateOASWorksheetWorkbook(List<OASWorksheetAnswers> workshee
sheet.SetRowHeight(rowNumber, 25);

rowNumber++;
IList<IGrouping<string, OASWorksheetAnswers>> groupedAnswers = templatAnswerGroup.GroupBy(x => x.MemberName).ToList();
IList<IGrouping<string, OASWorksheetAnswers>> groupedAnswers = templatAnswerGroup.GroupBy(x => x.MemberName + "|" + x.MemberId).ToList();

if (formatLikeTerrain)
GenerateOASWorksheetBodyLikeTerrain(sheet, groupedAnswers, ref rowNumber, ref columnNumber);
Expand Down
2 changes: 2 additions & 0 deletions Topo/Controller/MilestoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected override void OnInitialized()
model.UnitName = _storageService.UnitName;
model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.SuppressLastName = _storageService.SuppressLastName;
}

internal async Task UnitChange(ChangeEventArgs e)
Expand Down Expand Up @@ -75,6 +76,7 @@ internal async Task MilestoneReportXlsxClick()

private async Task<byte[]> MilestoneReport(OutputType outputType = OutputType.PDF)
{
_storageService.SuppressLastName = model.SuppressLastName;
var milestoneSummaries = await _milestoneService.GetMilestoneSummaries(model.UnitId);

var groupName = _storageService.GroupName ?? "";
Expand Down
2 changes: 2 additions & 0 deletions Topo/Controller/OasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected override async Task OnInitializedAsync()
model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.Stages = await _oasService.GetOASStagesList();
model.SuppressLastName = _storageService.SuppressLastName;
if (!string.IsNullOrEmpty(_storageService.UnitId))
{
await UnitChange(_storageService.UnitId);
Expand Down Expand Up @@ -94,6 +95,7 @@ internal async Task OASWorksheetXlsxClick()

private async Task<byte[]> OASWorksheet(OutputType outputType = OutputType.PDF)
{
_storageService.SuppressLastName = model.SuppressLastName;
var sortedAnswers = new List<OASWorksheetAnswers>();
foreach (var selectedStageTemplate in model.SelectedStages)
{
Expand Down
2 changes: 2 additions & 0 deletions Topo/Controller/WallchartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected override void OnInitialized()

model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.SuppressLastName = _storageService.SuppressLastName;
}

internal async Task UnitChange(ChangeEventArgs e)
Expand Down Expand Up @@ -90,6 +91,7 @@ internal async Task WallchartReportXlsxClick()
private async Task<byte[]> WallchartReport(OutputType outputType = OutputType.PDF)
{
model.ErrorMessage = "";
_storageService.SuppressLastName = model.SuppressLastName;
var wallchartItems = await _wallchartService.GetWallchartItems(model.UnitId);
if (wallchartItems.Count == 0)
{
Expand Down
12 changes: 12 additions & 0 deletions Topo/Pages/Milestone.razor
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
</div>
</div>

<div class="mt-3 mb-3 row">
<div class="col-sm-3">
<InputCheckbox id="suppressLastName" class="form-check-input"
@bind-Value="model.SuppressLastName" />
<label class="form-check-label" for="suppressLastName">
Suppress Last Name
</label>
</div>
<div class="col-sm-9">
</div>
</div>

<div class="mt-3 mb-3 row">
<div class="col-sm">
<button type="submit" name="button" @onclick="MilestoneReportPdfClick" class="btn btn-primary">Milestone Report (pdf)</button>
Expand Down
5 changes: 5 additions & 0 deletions Topo/Pages/OAS.razor
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@
</label>
</div>
<div class="col-sm-3">
<InputCheckbox id="suppressLastName" class="form-check-input"
@bind-Value="model.SuppressLastName" />
<label class="form-check-label" for="suppressLastName">
Suppress Last Name
</label>
</div>
</div>

Expand Down
9 changes: 8 additions & 1 deletion Topo/Pages/Wallchart.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@
Break by Patrol
</label>
</div>
<div class="col-sm-9">
<div class="col-sm-3">
<InputCheckbox id="suppressLastName" class="form-check-input"
@bind-Value="model.SuppressLastName" />
<label class="form-check-label" for="suppressLastName">
Suppress Last Name
</label>
</div>
<div class="col-sm-6">
</div>
</div>

Expand Down
20 changes: 20 additions & 0 deletions Topo/Services/MembersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public interface IMembersService
public Task<List<MemberListModel>> GetMembersAsync(string unitId);
public void ClearMemberCache(string unitId);
public Task<MemberListModel> GetMember(string unitId, string memberId);
public Task<string> GetMemberLastName(string unitId, string memberId);
}

public class MembersService : IMembersService
Expand Down Expand Up @@ -88,6 +89,25 @@ public async Task<MemberListModel> GetMember(string unitId, string memberId)
return member ?? new MemberListModel();
}

public async Task<string> GetMemberLastName(string unitId, string memberId)
{
var members = await GetMembersAsync(unitId);
var member = members.Where(m => m.id == memberId).FirstOrDefault();
if (member == null || string.IsNullOrEmpty(member.last_name))
{
return "";
}
if (_storageService.SuppressLastName)
{
var lastName = member.last_name.Substring(0, 1).ToUpper();
return lastName;
}
else
{
return member.last_name;
}
}

private string GetAgeFromBirthdate(string dateOfBirth)
{
var birthday = DateTime.ParseExact(dateOfBirth, "yyyy-MM-dd", CultureInfo.InvariantCulture); // Date in AU format
Expand Down
2 changes: 1 addition & 1 deletion Topo/Services/MilestoneService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<List<MilestoneSummaryListModel>> GetMilestoneSummaries(string
unitMilestoneSummary.Add(
new MilestoneSummaryListModel
{
memberName = $"{member.first_name} {member.last_name}",
memberName = $"{member.first_name} {_membersService.GetMemberLastName(selectedUnitId, member.id).Result}",
currentLevel = currentLevel,
percentComplete = percentComplete,
milestone1ParticipateCommunity = milestone1Skipped ? 0 : (milestone1Awarded ? 6 : (int)milestone1.event_count.participant.community),
Expand Down
2 changes: 1 addition & 1 deletion Topo/Services/OASService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private async Task<List<OASWorksheetAnswers>> GenerateOASWorksheetAnswers(string
InputTitleSortIndex = item.InputGroupSort,
InputSortIndex = item.Id,
MemberId = member.id,
MemberName = $"{member.first_name} {member.last_name}",
MemberName = $"{member.first_name} {_membersService.GetMemberLastName(selectedUnitId, member.id).Result}",
MemberPatrol = member.patrol_name,
MemberAnswer = "",
Answered = false,
Expand Down
6 changes: 5 additions & 1 deletion Topo/Services/StorageService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Data.SqlTypes;
using System.Reflection;
using Topo.Model.AdditionalAwards;
using Topo.Model.Login;
using Topo.Model.Members;
Expand All @@ -14,6 +15,7 @@ public class StorageService
private bool _isAuthenticated;
private bool _isYouthMember;
private string _unitId = string.Empty;

public bool IsAuthenticated
{
get { return _isAuthenticated; }
Expand Down Expand Up @@ -123,6 +125,8 @@ public bool IsYouthMember
}
}

public bool SuppressLastName { get; set; }

public string Version = "1.60";
}
}
2 changes: 1 addition & 1 deletion Topo/Services/WallchartService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public async Task<List<WallchartItemModel>> GetWallchartItems(string selectedUni
}
wallchartItem.OASStageProgressions = oasResults.results.Where(o => o.status == "awarded" && o.section == _storageService.Section).Count();
// Member
wallchartItem.MemberName = $"{member.first_name} {member.last_name}";
wallchartItem.MemberName = $"{member.first_name} {_membersService.GetMemberLastName(selectedUnitId, member.id).Result}";
wallchartItem.MemberPatrol = member.patrol_name;
wallchartItem.IntroToScouting = await GetIntroToScouting(member.id);
wallchartItem.IntroToSection = await GetIntroToSection(member.id);
Expand Down