Skip to content

Commit

Permalink
Version 1.61 (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
NomisNostab authored Sep 23, 2024
2 parents 072d80b + 8b0920a commit bcf3cdd
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 23 deletions.
1 change: 1 addition & 0 deletions Model/Members/MembersPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class MembersPageViewModel
[Display(Name = "Include Leaders")]
public bool IncludeLeaders { get; set; } = false;
public string GroupName { get; set; } = string.Empty;
public bool SuppressLastName { get; set; }
}
}
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; }
}
}
6 changes: 5 additions & 1 deletion Model/OAS/OASPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class OASPageViewModel
[Display(Name = "Break by Patrol")]
public bool BreakByPatrol { get; set; } = false;
public string StagesErrorMessage { get; set; } = "";
public bool FormatLikeTerrain { get; set; } = false;
public bool FormatLikeTerrain { get; set; } = true;
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; }
}
}
26 changes: 22 additions & 4 deletions Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public IWorkbook GeneratePatrolSheetsWorkbook(List<MemberListModel> sortedPatrol
//Adding cell style.
IStyle headingStyle = workbook.Styles.Add("headingStyle");
headingStyle.Font.Bold = true;
headingStyle.Font.Size = 40;
headingStyle.Font.Size = 30;
headingStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
headingStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
headingStyle.WrapText = true;
Expand Down 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
21 changes: 18 additions & 3 deletions Topo/Controller/MembersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MembersController : ComponentBase
[Inject]
public StorageService _storageService { get; set; }

[Inject]
[Inject]
IJSRuntime JS { get; set; }

[Inject]
Expand All @@ -35,6 +35,7 @@ protected override async Task OnInitializedAsync()

model.Units = _storageService.Units;
model.GroupName = _storageService.GroupNameDisplay;
model.SuppressLastName = _storageService.SuppressLastName;
if (!string.IsNullOrEmpty(_storageService.UnitId))
{
await UnitChange(_storageService.UnitId);
Expand All @@ -55,7 +56,7 @@ internal async Task UnitChange(string unitId)
_storageService.UnitId = model.UnitId;
model.UnitName = _storageService.UnitName;
model.Members = new List<MemberListModel>();
return;
return;
}
model.UnitId = unitId;
_storageService.UnitId = model.UnitId;
Expand Down Expand Up @@ -151,7 +152,21 @@ private async Task<byte[]> PatrolSheet(OutputType outputType = OutputType.PDF)
var groupName = _storageService.GroupName ?? "Group Name";
var unitName = _storageService.UnitName ?? "Unit Name";
var section = _storageService.Section;
var sortedMemberList = model.Members.Where(m => m.isAdultLeader == 0).OrderBy(m => m.patrol_name).ToList();
_storageService.SuppressLastName = model.SuppressLastName;
List<MemberListModel> sortedMemberList = new List<MemberListModel>();
foreach (var member in model.Members.Where(m => m.isAdultLeader == 0).OrderBy(m => m.patrol_name))
{
string lastName = _storageService.SuppressLastName ? member.last_name.Substring(0, 1).ToUpper() : member.last_name;
MemberListModel memberCopy = new MemberListModel
{
patrol_name = member.patrol_name,
first_name = member.first_name,
last_name = lastName,
isAdultLeader = member.isAdultLeader,
patrol_duty = member.patrol_duty
};
sortedMemberList.Add(memberCopy);
}
var serialisedSortedMemberList = JsonConvert.SerializeObject(sortedMemberList);

var report = await _reportService.GetPatrolSheetsReport(groupName, section, unitName, outputType, serialisedSortedMemberList);
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
54 changes: 49 additions & 5 deletions Topo/Controller/OasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Microsoft.JSInterop;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Topo.Model.OAS;
using Topo.Model.ReportGeneration;
Expand Down Expand Up @@ -47,11 +49,11 @@ 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);
}

}

internal async Task UnitChange(ChangeEventArgs e)
Expand Down Expand Up @@ -93,16 +95,13 @@ 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)
{
var templateList = await _oasService.GetOASTemplate(selectedStageTemplate.Replace("/latest.json", ""));
var selectedStage = model.Stages.Where(s => s.TemplateLink == selectedStageTemplate).FirstOrDefault() ?? new OASStageListModel();
var sortedTemplateAnswers = await _oasService.GenerateOASWorksheetAnswers(model.UnitId, selectedStage, model.HideCompletedMembers, templateList);
//sortedTemplateAnswers = sortedTemplateAnswers.Where(a => !a.MemberAnswer.HasValue || a.MemberAnswer > new DateTime(2024, 5, 1))
// .OrderBy(owa => owa.InputTitleSortIndex)
// .ThenBy(owa => owa.InputSortIndex)
// .ToList();
sortedAnswers.AddRange(sortedTemplateAnswers);
}

Expand All @@ -116,17 +115,62 @@ private async Task<byte[]> OASWorksheet(OutputType outputType = OutputType.PDF)
return report;
}

internal async Task GetCoreSelections(ChangeEventArgs arg)
{
model.SelectedStages = new string[0];
model.StagesErrorMessage = "";
if (model.UseCore)
{
List<OASStageListModel> coreStages = new List<OASStageListModel>();
for (int i = 0; i < 9; i++)
{
if (model.CoreStages[i])
{
coreStages = coreStages.Concat(GetCoreForStage(i + 1)).ToList();
}
}

foreach (var coreStage in coreStages)
{
model.SelectedStages = model.SelectedStages.Append(coreStage.TemplateLink).ToArray();
}

if (model.SelectedStages == null || model.SelectedStages.Length == 0)
{
model.StagesErrorMessage = "Please select at least one stage";
}
}
else
{
for (int i = 0; i < 9; i++)
{
model.CoreStages[i] = false;
}
model.StagesErrorMessage = "Please select at least one stage";
}

await JS.InvokeVoidAsync("BindSelect2");
await JS.InvokeVoidAsync("BindSelect2");
}

public async Task<bool> GetSelections(ElementReference elementReference)
{
model.SelectedStages = (await JS.InvokeAsync<List<string>>("getSelectedValues", _select2Reference)).ToArray<string>();
model.StagesErrorMessage = "";

if (model.SelectedStages == null || model.SelectedStages.Length == 0)
{
model.StagesErrorMessage = "Please select at least one stage";
return false;
}
return true;
}

private List<OASStageListModel> GetCoreForStage(int stageNumber)
{
var stages = model.Stages.Where(stage => stage.Stage == stageNumber && (stage.Stream == "Bushcraft" || stage.Stream == "Bushwalking" || stage.Stream == "Camping")).ToList();
return stages;
}
}

}
6 changes: 4 additions & 2 deletions Topo/Controller/ProgramController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ protected override async Task OnInitializedAsync()
model.GroupName = _storageService.GroupNameDisplay;
await _programService.GetCalendars();
model.Calendars = _storageService.Units;
model.CalendarSearchFromDate = DateTime.Now;
model.CalendarSearchToDate = DateTime.Now.AddMonths(4);
var quarter = (DateTime.Now.Month + 2) / 3;
var quarterStartMonth = (quarter - 1) * 3 + 1;
model.CalendarSearchFromDate = new DateTime(DateTime.Now.Year, quarterStartMonth, 1);
model.CalendarSearchToDate = model.CalendarSearchFromDate.AddMonths(4).AddDays(-1);
model.DateErrorMessage = "";
groupCalendarId = _storageService.GroupId ?? "";
model.CalendarId = _storageService.UnitId;
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)

Check warning on line 49 in Topo/Controller/WallchartController.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
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
7 changes: 7 additions & 0 deletions Topo/Pages/Members.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
<div class="col-sm">
<button type="submit" name="button" @onclick="PatrolSheetPdfClick" class="btn btn-primary">Generate Patrol sheets (pdf)</button>
<button type="submit" name="button" @onclick="PatrolSheetXlsxClick" class="btn btn-success">Generate Patrol sheets (xlsx)</button>
<div class="form-check-inline">
<InputCheckbox id="suppressLastName" class="form-check-input"
@bind-Value="model.SuppressLastName" />
<label class="form-check-label" for="suppressLastName">
Suppress Last Name
</label>
</div>
</div>
</div>
}
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
Loading

0 comments on commit bcf3cdd

Please sign in to comment.