Skip to content

Commit

Permalink
Merge pull request #1143 from k7hpn/fix/bootstrap-5
Browse files Browse the repository at this point in the history
Improve events in Mission Control
  • Loading branch information
k7hpn authored Oct 29, 2024
2 parents 1bcff2f + 5636ba9 commit c6952a8
Show file tree
Hide file tree
Showing 11 changed files with 1,545 additions and 1,638 deletions.
14 changes: 13 additions & 1 deletion src/GRA.Controllers/MissionControl/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public EventsController(ILogger<EventsController> logger,
PageTitle = "Events";
}

public static string Name
{
get
{
return "Events";
}
}

[HttpPost]
public async Task<IActionResult> AddEditStreaming(EventsDetailViewModel model)
{
Expand Down Expand Up @@ -274,7 +282,9 @@ public async Task<IActionResult> AddLocation(LocationsListViewModel model)

[Authorize(Policy = Policy.ManageLocations)]
public async Task<JsonResult> AddLocationReturnList(string name,
string address, string url, string telephone)
string address,
string url,
string telephone)
{
if (!string.IsNullOrWhiteSpace(url))
{
Expand All @@ -287,13 +297,15 @@ public async Task<JsonResult> AddLocationReturnList(string name,
return Json(new { success = false, message = "Invalid URL" });
}
}

var location = new Location
{
Name = name,
Address = address,
Url = url,
Telephone = telephone
};

location = await _eventService.AddLocationAsync(location);

string message = null;
Expand Down
158 changes: 86 additions & 72 deletions src/GRA.Controllers/MissionControl/LookupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace GRA.Controllers.MissionControl
[Authorize(Policy = Policy.AccessMissionControl)]
public class LookupController : Base.MCController
{
private readonly ILogger<LookupController> _logger;
private readonly ChallengeService _challengeService;
private readonly ILogger<LookupController> _logger;
private readonly TriggerService _triggerService;

public LookupController(ILogger<LookupController> logger,
Expand All @@ -27,90 +27,54 @@ public LookupController(ILogger<LookupController> logger,
TriggerService triggerService) : base(context)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_challengeService = challengeService
_challengeService = challengeService
?? throw new ArgumentNullException(nameof(challengeService));
_triggerService = triggerService
_triggerService = triggerService
?? throw new ArgumentNullException(nameof(triggerService));
}

[HttpPost]
public async Task<JsonResult> SecretCodeInUse(string secretCode)
public static string Name
{
return Json(await _triggerService.SecretCodeInUseAsync(secretCode));
get
{
return "Lookup";
}
}

public async Task<IActionResult> GetRequirementList(string badgeIds,
string challengeIds,
string scope,
[Authorize(Policy = Policy.ViewAllChallenges)]
public async Task<IActionResult> GetChallengeGroupList(string challengeGroupIds,
string search,
int page = 1,
int? thisBadge = null)
int page = 1)
{
var filter = new BaseFilter(page, 10)
var filter = new ChallengeGroupFilter(page, 10)
{
ActiveGroups = true,
Search = search
};

var badgeList = new List<int>();
if (thisBadge.HasValue)
{
badgeList.Add(thisBadge.Value);
}
if (!string.IsNullOrWhiteSpace(badgeIds))
{
badgeList.AddRange(badgeIds.Split(',')
.Where(_ => !string.IsNullOrWhiteSpace(_))
.Select(int.Parse)
.ToList());
}
if (badgeList.Count > 0)
{
filter.BadgeIds = badgeList;
}

if (!string.IsNullOrWhiteSpace(challengeIds))
if (!string.IsNullOrWhiteSpace(challengeGroupIds))
{
filter.ChallengeIds = challengeIds.Split(',')
filter.ChallengeGroupIds = challengeGroupIds.Split(',')
.Where(_ => !string.IsNullOrWhiteSpace(_))
.Select(int.Parse)
.ToList();
}
switch (scope)
{
case ("System"):
filter.SystemIds = new List<int> { GetId(ClaimType.SystemId) };
break;
case ("Branch"):
filter.BranchIds = new List<int> { GetId(ClaimType.BranchId) };
break;
case ("Mine"):
filter.UserIds = new List<int> { GetId(ClaimType.UserId) };
break;
default:
break;
}

var requirements = await _triggerService.PageRequirementAsync(filter);
var challengeGroupList = await _challengeService.GetPaginatedGroupListAsync(filter);
var paginateModel = new PaginateViewModel
{
ItemCount = requirements.Count,
ItemCount = challengeGroupList.Count,
CurrentPage = page,
ItemsPerPage = filter.Take.Value
};
var viewModel = new RequirementListViewModel
var viewModel = new ChallengeGroupsListViewModel
{
Requirements = requirements.Data,
PaginateModel = paginateModel
ChallengeGroups = challengeGroupList.Data,
PaginateModel = paginateModel,
CanEditGroups = UserHasPermission(Permission.EditChallengeGroups),
};
foreach (var requirement in requirements.Data)
{
if (!string.IsNullOrWhiteSpace(requirement.BadgePath))
{
requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath);
}
}

return PartialView("_RequirementsPartial", viewModel);
return PartialView("_ChallengeGroupListPartial", viewModel);
}

[Authorize(Policy = Policy.ViewAllChallenges)]
Expand Down Expand Up @@ -139,12 +103,15 @@ public async Task<IActionResult> GetChallengeList(string challengeIds,
case ("system"):
filter.SystemIds = new List<int> { GetId(ClaimType.SystemId) };
break;

case ("branch"):
filter.BranchIds = new List<int> { GetId(ClaimType.BranchId) };
break;

case ("mine"):
filter.UserIds = new List<int> { GetId(ClaimType.UserId) };
break;

default:
break;
}
Expand Down Expand Up @@ -176,40 +143,87 @@ public async Task<IActionResult> GetChallengeList(string challengeIds,
return PartialView("_ChallengeListPartial", viewModel);
}

[Authorize(Policy = Policy.ViewAllChallenges)]
public async Task<IActionResult> GetChallengeGroupList(string challengeGroupIds,
public async Task<IActionResult> GetRequirementList(string badgeIds,
string challengeIds,
string scope,
string search,
int page = 1)
int page = 1,
int? thisBadge = null)
{
var filter = new ChallengeGroupFilter(page, 10)
var filter = new BaseFilter(page, 10)
{
ActiveGroups = true,
Search = search
};

if (!string.IsNullOrWhiteSpace(challengeGroupIds))
var badgeList = new List<int>();
if (thisBadge.HasValue)
{
filter.ChallengeGroupIds = challengeGroupIds.Split(',')
badgeList.Add(thisBadge.Value);
}
if (!string.IsNullOrWhiteSpace(badgeIds))
{
badgeList.AddRange(badgeIds.Split(',')
.Where(_ => !string.IsNullOrWhiteSpace(_))
.Select(int.Parse)
.ToList());
}
if (badgeList.Count > 0)
{
filter.BadgeIds = badgeList;
}

if (!string.IsNullOrWhiteSpace(challengeIds))
{
filter.ChallengeIds = challengeIds.Split(',')
.Where(_ => !string.IsNullOrWhiteSpace(_))
.Select(int.Parse)
.ToList();
}
switch (scope)
{
case ("System"):
filter.SystemIds = new List<int> { GetId(ClaimType.SystemId) };
break;

var challengeGroupList = await _challengeService.GetPaginatedGroupListAsync(filter);
case ("Branch"):
filter.BranchIds = new List<int> { GetId(ClaimType.BranchId) };
break;

case ("Mine"):
filter.UserIds = new List<int> { GetId(ClaimType.UserId) };
break;

default:
break;
}

var requirements = await _triggerService.PageRequirementAsync(filter);
var paginateModel = new PaginateViewModel
{
ItemCount = challengeGroupList.Count,
ItemCount = requirements.Count,
CurrentPage = page,
ItemsPerPage = filter.Take.Value
};
var viewModel = new ChallengeGroupsListViewModel
var viewModel = new RequirementListViewModel
{
ChallengeGroups = challengeGroupList.Data,
PaginateModel = paginateModel,
CanEditGroups = UserHasPermission(Permission.EditChallengeGroups),
Requirements = requirements.Data,
PaginateModel = paginateModel
};
foreach (var requirement in requirements.Data)
{
if (!string.IsNullOrWhiteSpace(requirement.BadgePath))
{
requirement.BadgePath = _pathResolver.ResolveContentPath(requirement.BadgePath);
}
}

return PartialView("_ChallengeGroupListPartial", viewModel);
return PartialView("_RequirementsPartial", viewModel);
}

[HttpPost]
public async Task<JsonResult> SecretCodeInUse(string secretCode)
{
return Json(await _triggerService.SecretCodeInUseAsync(secretCode));
}
}
}
Loading

0 comments on commit c6952a8

Please sign in to comment.