Skip to content

Commit

Permalink
Issue-45: Support multiple groups (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
NomisNostab authored Jan 9, 2023
2 parents b90f198 + b9a6bc4 commit e9b3519
Show file tree
Hide file tree
Showing 39 changed files with 113 additions and 60 deletions.
1 change: 1 addition & 0 deletions Model/AdditionalAwards/AdditionalAwardsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class AdditionalAwardsPageViewModel
public string UnitId { get; set; } = string.Empty;
public string UnitName { get; set; } = string.Empty;
public List<MemberListModel> Members { get; set; } = new List<MemberListModel>();
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/Approvals/ApprovalsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class ApprovalsPageViewModel
public string DateErrorMessage { get; set; } = string.Empty;
public bool ToBePresented { get; set; }
public bool IsPresented { get; set; }
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/Approvals/BackupRestorePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class BackupRestorePageViewModel
public string SelectedUnitName { get; set; } = string.Empty;
public Dictionary<string, string> Units { get; set; } = new Dictionary<string, string>();
public IBrowserFile approvalsFile { get; set; }
public string GroupName { get; set; } = string.Empty;
}
}
3 changes: 3 additions & 0 deletions Model/Index/IndexPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ public class IndexPageViewModel
public bool IsAuthenticated { get; set; }
public string Email { get; set; } = string.Empty;
public string FullName { get; set; } = string.Empty;
public string GroupId { get; set; } = string.Empty;
public Dictionary<string, string> Groups { get; set; } = new Dictionary<string, string>();

}
}
1 change: 1 addition & 0 deletions Model/Logbook/LogbookPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class LogbookPageViewModel
public string UnitName { get; set; } = string.Empty;
public List<MemberListModel> Members { get; set; } = new List<MemberListModel>();
public bool IncludeLeaders { get; set; } = false;
public string GroupName { get; set; } = string.Empty;
}
}
9 changes: 9 additions & 0 deletions Model/Login/GetProfilesResultModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Profile
public Member? member { get; set; }
public Unit? unit { get; set; }
public Group? group { get; set; }
public Branch? branch { get; set; }
public bool is_support_group { get; set; } = false;
}

public class Member
Expand All @@ -35,4 +37,11 @@ public class Group
public string[]? roles { get; set; }
}

public class Branch
{
public string? id { get; set; }
public string? name { get; set; }
public string[]? roles { get; set; }
}

}
1 change: 1 addition & 0 deletions Model/Members/MembersPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class MembersPageViewModel
public List<MemberListModel>? Members { get; set; }
[Display(Name = "Include Leaders")]
public bool IncludeLeaders { get; set; } = false;
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/Milestone/MilestonePageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class MilestonePageViewModel
[Required(ErrorMessage = "Select unit")]
public string UnitId { get; set; } = string.Empty;
public string UnitName { get; set; } = string.Empty;
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/OAS/OASPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public class OASPageViewModel
public bool BreakByPatrol { get; set; } = false;
public string StagesErrorMessage { get; set; } = "";
public bool FormatLikeTerrain { get; set; } = false;
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/Program/ProgramPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class ProgramPageViewModel
public DateTime CalendarSearchToDate { get; set; } = DateTime.Now;
public string DateErrorMessage { get; set; } = "";
public bool IncludeGroupEvents { get; set; } = true;
public string GroupName { get; set; } = string.Empty;
}

}
1 change: 1 addition & 0 deletions Model/SIA/SIAPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class SIAPageViewModel
public string UnitId { get; set; } = string.Empty;
public string UnitName { get; set; } = string.Empty;
public List<MemberListModel> Members { get; set; } = new List<MemberListModel>();
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Model/Wallchart/WallchartPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class WallchartPageViewModel
[Required(ErrorMessage = "Select unit")]
public string UnitId { get; set; } = string.Empty;
public string UnitName { get; set; } = string.Empty;
public string GroupName { get; set; } = string.Empty;
}
}
1 change: 1 addition & 0 deletions Topo/Controller/AdditionalAwardsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected override async Task OnInitializedAsync()
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

Expand Down
3 changes: 2 additions & 1 deletion Topo/Controller/ApprovalsBackupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ApprovalsBackupController : ComponentBase

public BackupRestorePageViewModel model = new BackupRestorePageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");
Expand All @@ -43,6 +43,7 @@ protected override async Task OnInitializedAsync()
_storageService.UnitName = _storageService.Units.Where(u => u.Key == model.SelectedUnitId).FirstOrDefault().Value;
model.SelectedUnitName = _storageService.UnitName;
}
model.GroupName = _storageService.GroupNameDisplay;
}

internal async Task UnitChange(ChangeEventArgs e)
Expand Down
3 changes: 2 additions & 1 deletion Topo/Controller/ApprovalsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ public class ApprovalsController : ComponentBase
};

public SfGrid<ApprovalsListModel> GridInstance { get; set; }
protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

model.GroupName = _storageService.GroupNameDisplay;
model.Units = _storageService.Units;
model.ApprovalSearchFromDate = DateTime.Now.AddMonths(-2);
model.ApprovalSearchToDate = DateTime.Now;
Expand Down
14 changes: 13 additions & 1 deletion Topo/Controller/IndexController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Topo.Model.Index;
using Topo.Services;
using Microsoft.AspNetCore.Components;
using System.Reflection;

namespace Topo.Controller
{
Expand All @@ -11,10 +12,21 @@ public class IndexController : ComponentBase

public IndexPageViewModel indexPageViewModel = new IndexPageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
indexPageViewModel.IsAuthenticated = _storageService.IsAuthenticated;
indexPageViewModel.FullName = _storageService.MemberName ?? "";
indexPageViewModel.Groups = _storageService.Groups;
indexPageViewModel.GroupId = _storageService.GroupId ?? "";
}

internal void GroupChange(ChangeEventArgs e)
{
var groupId = e.Value?.ToString() ?? "";
_storageService.GroupId = groupId;
_storageService.GroupName = _storageService.Groups.Where(u => u.Key == groupId).FirstOrDefault().Value;
indexPageViewModel.GroupId = groupId;
}

}
}
3 changes: 2 additions & 1 deletion Topo/Controller/LogbookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class LogbookController : ComponentBase

public LogbookPageViewModel model = new LogbookPageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

Expand Down
4 changes: 3 additions & 1 deletion Topo/Controller/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ internal async Task LogInClick ()
_storageService.MemberName = _storageService.GetProfilesResult.profiles[0].member?.name ?? "";
_storageService.GroupName = _storageService.GetProfilesResult.profiles[0].group?.name ?? "";
}
_storageService.Units = _loginService.GetUnits();
_storageService.Groups = _loginService.GetGroups();
_storageService.GroupId = _storageService.Groups.Count == 1 ? _storageService.Groups.FirstOrDefault().Key : "";
_storageService.GroupName = _storageService.Groups.Count == 1 ? _storageService.Groups.FirstOrDefault().Value : "";

NavigationManager.NavigateTo("index");
}
Expand Down
9 changes: 5 additions & 4 deletions Topo/Controller/MembersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ public class MembersController : ComponentBase

public MembersPageViewModel model = new MembersPageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

internal async Task UnitChange(ChangeEventArgs e)
Expand Down Expand Up @@ -71,12 +72,12 @@ private async Task<byte[]> PatrolList(bool includeLeaders, OutputType outputType
var unitName = _storageService.UnitName ?? "Unit Name";
var section = _storageService.Section;

model.Members = await _membersService.GetMembersAsync(model.UnitId);
var allMembers = await _membersService.GetMembersAsync(model.UnitId);
var sortedPatrolList = new List<MemberListModel>();
if (includeLeaders)
sortedPatrolList = model.Members.OrderBy(m => m.patrol_name).ToList();
sortedPatrolList = allMembers.OrderBy(m => m.patrol_name).ToList();
else
sortedPatrolList = model.Members.Where(m => m.isAdultLeader == 0).OrderBy(m => m.patrol_name).ToList();
sortedPatrolList = allMembers.Where(m => m.isAdultLeader == 0).OrderBy(m => m.patrol_name).ToList();
var serialisedSortedMemberList = JsonConvert.SerializeObject(sortedPatrolList);

var report = await _reportService.GetPatrolListReport(groupName, section, unitName, outputType, serialisedSortedMemberList, includeLeaders);
Expand Down
3 changes: 2 additions & 1 deletion Topo/Controller/MilestoneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public class MilestoneController : ComponentBase

public MilestonePageViewModel model = new MilestonePageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

Expand Down
2 changes: 1 addition & 1 deletion Topo/Controller/OasController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ protected override async Task OnInitializedAsync()
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

model.Stages = await _oasService.GetOASStagesList();
}

Expand Down
7 changes: 4 additions & 3 deletions Topo/Controller/ProgramController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ protected override async Task OnInitializedAsync()
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

model.Calendars = await _programService.GetCalendars();
model.GroupName = _storageService.GroupNameDisplay;
await _programService.GetCalendars();
model.Calendars = _storageService.Units;
model.CalendarSearchFromDate = DateTime.Now;
model.CalendarSearchToDate = DateTime.Now.AddMonths(4);
model.DateErrorMessage = "";
var groupCalendars = await _programService.GetGroupCalendar();
groupCalendarId = groupCalendars.FirstOrDefault().Key;
groupCalendarId = _storageService.GroupId ?? "";
}

internal void CalendarChange(ChangeEventArgs e)
Expand Down
3 changes: 2 additions & 1 deletion Topo/Controller/SIAController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public class SIAController : ComponentBase

public SIAPageViewModel model = new SIAPageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

Expand Down
3 changes: 2 additions & 1 deletion Topo/Controller/WallchartController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public class WallchartController : ComponentBase

public WallchartPageViewModel model = new WallchartPageViewModel();

protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
if (!_storageService.IsAuthenticated)
NavigationManager.NavigateTo("index");

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

Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/AdditionalAwards.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">

<div class="mt-3 mb-3 row">
<h2>Additional Awards</h2>
<h2>Additional Awards @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/Approvals.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EditForm Model="@model">

<div class="mt-3 mb-3 row">
<h2>Approvals</h2>
<h2>Approvals @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/ApprovalsBackupResstore.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">
<DataAnnotationsValidator />
<div class="mt-3 mb-3 row">
<h2>Approvals Backup Restore</h2>
<h2>Approvals Backup Restore @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
14 changes: 14 additions & 0 deletions Topo/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ else
<div class="mt-3 mb-3 row">
<h2>Welcome @indexPageViewModel.FullName</h2>
</div>
<div class="mb-3 row">
<label for="unit" class="col-sm-2 col-form-label">
Select Group to access:
</label>
<div class="col-sm-3">
<select id="unit" class="form-select" value="@indexPageViewModel.GroupId" @onchange="GroupChange">
<option value="">Select group</option>
@foreach (var group in indexPageViewModel.Groups)
{
<option value="@group.Key">@group.Value</option>
}
</select>
</div>
</div>
<div class="mb-3 row">
<p>
Use Members to see the members of your units, print patrol lists and patrol corner sheets.
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/Logbook.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<EditForm Model="@model">
<div class="mt-3 mb-3 row">
<h2>Logbook</h2>
<h2>Logbook @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/Members.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">

<div class="mt-3 mb-3 row">
<h2>Members</h2>
<h2>Members @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/Milestone.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">
<DataAnnotationsValidator />
<div class="mt-3 mb-3 row">
<h2>Milestone</h2>
<h2>Milestone @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/OAS.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">
<DataAnnotationsValidator />
<div class="mt-3 mb-3 row">
<h2>Outdoor Adventure Skills</h2>
<h2>Outdoor Adventure Skills @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/Program.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model" >
<DataAnnotationsValidator />
<div class="mt-3 mb-3 row">
<h2>Program</h2>
<h2>Program @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
2 changes: 1 addition & 1 deletion Topo/Pages/SIA.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<EditForm Model="@model">

<div class="mt-3 mb-3 row">
<h2>Special Interest Areas</h2>
<h2>Special Interest Areas @model.GroupName</h2>
</div>

<div class="form-group mb-3 row">
Expand Down
Loading

0 comments on commit e9b3519

Please sign in to comment.